Why is the C.ADDI16SP immediate range not every integer?
The immediate is encoded with a 16-byte scale, so only nonzero multiples of 16 from -512 through 496 are encodable.
Add a nonzero signed 6-bit immediate scaled by 16 to x2/sp. A 16-bit CI-format instruction sharing encoding space with C.LUI.
C.ADDI16SP shares encoding space with C.LUI but fixes the destination field to x2/sp. It sign-extends scattered nonzero nzimm[9:4] and adds it to x2/sp; this immediate represents 16-byte multiples from -512 through 496. It expands to addi x2, x2, nzimm[9:4]; the nzimm=0 encoding is reserved.
Read and write fixed x2/sp, restore the scaled immediate, then calculate and commit the XLEN-bit result.
rd/rs1 is fixed to 00010. inst[12] and inst[6:2] restore nzimm[9:4]; the low four bits are zero and the immediate is sign-extended to XLEN.
Assumes C is available and instruction fetch succeeds. Teaching steps do not represent processor pipelines or cycles; multiples of 16 preserve the original low four bits of sp and do not repair a misaligned sp.
C.ADDI16SP is a 16-bit C-extension instruction: it reads and writes fixed x2/sp and adds sign-extended nonzero nzimm[9:4]. It encodes only 16-byte multiples from -512 through 496.
A function prologue or epilogue can adjust fixed x2/sp by a nonzero multiple of 16; with old sp=0x1000 and nzimm=-32, successful execution gives sp=0x0fe0, equivalent to addi x2, x2, -32.
The immediate is encoded with a 16-byte scale, so only nonzero multiples of 16 from -512 through 496 are encodable.
C.ADDI16SP is valid only when nzimm is nonzero; the nzimm=0 encoding is reserved.