miki1307
miki1307

Reputation: 157

What are the operands of C.LUI instruction(compressed subset of RISC-V)?

In the RISC-V mannual for this instructions is written:

C.LUI loads the non-zero 6-bit immediate field into bits 17–12 of the destination register, clearsthe bottom 12 bits, and sign-extends bit 17 into all higher bits of the destination

And from this I made the conclusion that the immediate should be 6 bits, but then I was compiling something and this line can be compiled but the immediate is more than 6 bits wide, so I am confused c.lui x14,0xffff8

Upvotes: 1

Views: 873

Answers (1)

yflelion
yflelion

Reputation: 1746

c.lui will accept any 20 bits immediate as long as all the bits 5 to 19 have the same value ( 1 or 0).
So basically c.lui will accept any value between 0xfffe0 and 0xfffff and any value between 1 and 0x1f. 0x0 is not accepted also (see https://riscv.org//wp-content/uploads/2017/05/riscv-spec-v2.2.pdf)

With your example
c.lui a4, 0xffff8 will give the instruction 0x7761 The immediate extracted from this instruction is 0x38 if you shift it by 12 you will get 0x38000 and after that when you sign extend it you will get: 0xffff8000

Upvotes: 6

Related Questions