简体   繁体   中英

How exactly does the RISC-V immediate encoding notation work?

I thought I've understood this but I think I've confused myself.

RISC-V RV32G 编码

I was under the impression that [11:0] was the order of the immediate bits within the encoding. As an example, addi x1, x2, 12 would have an immediate of 000000001100; the immediate would start at bit 20 within the addi instruction encoding.

I'm confused how this logic applies to the same notation used within the U-type encoding [31:12]. I understand the U-type immediate is 20 bits but I'm now unsure of how to interpret the notation.

U-type is for lui , where the immediate goes into the high 20 bits of Rd, and the lower 12 bits are cleared. Or for auipc , same decoding; bits [31:12] come from the instruction, the low 12 are implicit 0.

So the bit-numbers are the position within the decoded value , not just within the immediate itself.

The position within the diagram shows you where each value-bit comes from in the machine encoding; the [hi:lo] bit-range numbers show you which value bit (in a full 32 or 64-bit integer) this field maps to.

For more general stuff about the rest of RISC-V immediates, see the design comments in the ISA docs, quoted and expanded upon in a couple SO Q&As:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM