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 byCmmInt 1 W16
- a 16-bit value of
0x7fff
would be represented byCmmInt 0x7fff W16
- a 16-bit value of
-1
would be represented byCmmInt 0xffff W16
- a 16-bit value of
-0x8001
would be represented byCmmInt 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?