Skip to content

Apparent inconsistency in semantics of CmmInt?

The comment attached to the CmmInt constructor of CmmLit claims the following:

Interpretation: the 2's complement representation of the value is truncated to the specified size. This is easier than trying to keep the value within range, because we don't know whether it will be used as a signed or unsigned value (the CmmType doesn't distinguish between signed & unsigned).

I would interpret this to mean that, for instance,

  • a 16-bit value of 1 would be represented by CmmInt 1 W16
  • a 16-bit value of 0x7fff would be represented by CmmInt 0x7fff W16
  • a 16-bit value of -1 would be represented by CmmInt 0xffff W16
  • a 16-bit value of -0x8001 would be represented by CmmInt 0xffff W16

However, this does not appear to be how this value is treated within the compiler. Rather, the Integer field appears to encode the value itself. Perhaps my interpretation is wrong?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information