Reason for irregular encoding in UJ and SB format.

25 views
Skip to first unread message

Neeraj Goel

unread,
Feb 10, 2020, 12:56:07 AM2/10/20
to riscv...@groups.riscv.org
Dear all,

I could not understand the rationale behind scattered immediate bits in SB and UJ format, therefore, could not justify to students. If somebody has insight please share. 

Instruction encoding and format is pasted for quick reference:

image.png

Regards,
Neeraj

--
Dr. Neeraj Goel,
Assistant Professor,
Department of Computer Science & Engineering,
Room no 203, Ramanujan Block, Permanent Campus, 
IIT Ropar. Dist Rupnagar, Punjab. 140001

Neel Gala

unread,
Feb 10, 2020, 1:04:48 AM2/10/20
to Neeraj Goel, riscv...@groups.riscv.org
It is meant to reduce the logic to deduce immediate fields. You can refer to the running commentary in section of the unprivileged-spec:

"... By rotating bits in the instruction encoding of B and J immediates instead of using dynamic hard-
ware muxes to multiply the immediate by 2, we reduce instruction signal fanout and immediate
mux costs by around a factor of 2. The scrambled immediate encoding will add negligible time
to static or ahead-of-time compilation. .. "


--
You received this message because you are subscribed to the Google Groups "RISC-V Teach" group.
To unsubscribe from this group and stop receiving emails from it, send an email to riscv-teach...@groups.riscv.org.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/riscv-teach/CAKqE0-P1vtGuSLU3S84yYsUvSRVHsSBwdeoP02VmHmpVWYMZ-g%40mail.gmail.com.


--
Neel Gala
Senior Project Officer
RISE LAB, IIT-Madras

Ray Simar

unread,
Feb 10, 2020, 11:46:49 AM2/10/20
to RISC-V Teach
Hi Neeraj,

This is a great question and one I cover with my students in my classes.  I break the development of this encoding into a few steps.  First, note how the opcode field is consistent across all instruction classes.  Then note the rd, rs1, and rs2 fields always occupy the same bits of the instruction, whenever they are present.  This situation helps with the instruction decoding and the design of the control logic for the read and write ports of the register file.  However, these conditions quickly begin to place restrictions on the encoding of the immediates.

At this point, I have the students recall how the "sign"-bit of a two's complement number is critical in sign-extending a two's complement number.  I then ask them to note where the msb is for each of the immediate fields in each instruction class.  The surprising, and clever, result is that the msb of each immediate field is always in bit 31 of an instruction.  This can be used to simplify the logic that sign extends the immediates.

Finally, I point out that the tendency of us to want to keep all of the immediate bits grouped together in a more human readable form, is certainly not necessary, and can even make our design and implementation more complex.

I hope this is helpful.  Let me know if you have any questions.

Ray Simar
Professor in the Practice
Department of Electrical and Computer Engineering
Rice University
Reply all
Reply to author
Forward
0 new messages