[llvm] [CHERI] Add a Support utility for determining alignment requirements of CHERI capabilities. (PR #197402)

Owen Anderson via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 03:46:16 PDT 2026


resistor wrote:

> I agree that we should avoid the lookup table, but also shouldn't be importing the full cheri-compressed-cap just for this one function that is needed.
> 
> We just need to calculate the exponent for the given length. If we are in the IE case we return -1 shifted by exponent plus the number of bits taken from the mantissa.

I started looking into this, with a prototype implementation here, which is derived as directly as I could from the CHERI v9 spec: https://gist.github.com/resistor/414e16427cca02aeb727fb1c646af90b

This ran into several issues: 
* There are constants 3 and 12 that appear in a few places. The spec doesn't make it clear how these are derived from parametric values like MW.
* AFAICT CHERIv9 never actually specifies MW for 32-bit addresses. Is MW=14 there as well, by omission?
* Specification language like `C is an additional carry bit from rounding up the truncated (to E_initial + 3 + MW−4 bits) length` is very hard to interpret, "rounding up" not being an operation I would normally expect to produce a carry bit.
* My understanding is that the RVY format does not exactly match the CHERIv9 format?
* My understanding is that that the "round up representable length" portion will need to be different on CHERIoT, so we'll end up with two significantly different paths.

https://github.com/llvm/llvm-project/pull/197402


More information about the llvm-commits mailing list