为什么以这种方式对RISC-V S-B和U-J指令类型进行编码? [英] Why are RISC-V S-B and U-J instruction types encoded in this way?

查看:698
本文介绍了为什么以这种方式对RISC-V S-B和U-J指令类型进行编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读一本书计算机组织和设计RISC-V版" ,并且遇到了S-B和U-J指令类型的编码.

I am reading a book "Computer Organization and Design RISC-V Edition", and I came across the encoding for S-B and U-J instruction types.

我上面提到的那些类型具有奇怪的编码立即数字段.

Those types I have mentioned above has strange encoded immediate field.

S-B类型将立即数字段分为两部分.这是有道理的,因为所有指令的编码都必须相似.但是我不明白为什么下面用这种方式对立即数字段进行编码.

S-B types separate the immediate field into 2 parts. This makes sense since all instructions encoding has to be similar. But I cannot understand why the immediate field is encoded in this way below.

imm[12, 10:5], imm[4:1, 11]

代替

imm[11:5], imm[4:0]

U-J类型也具有这种奇怪的编码立即数字段

U-J types also have this strange encoded immediate field

imm[20,10:1,11,19:12]

代替

imm[19:0]

有人可以解释吗?

推荐答案

所选编码与其他编码非常吻合,从而简化了硬件,但以牺牲了必须生成指令的软件,必须解码指令的软件以及,是学习或使用RISC V的程序员;).

The chosen encodings line up very nicely with other encodings, simplifying the hardware at the expense of software that has to generate instructions, software that has to decode instructions, and, programmers learning or working with RISC V ;).

S格式将立即数分解为imm[11:5]imm[4:0].立即数被拆分的原因是要使其他字段(即寄存器字段rs2rs1)与R-Type指令中的两个源寄存器字段保持在同一位置. (与MIPS相比,MIPS的功能类似但不完全),从而消除了寄存器名称宽度(例如5位宽)的多路复用器和一些额外的布线以及控制信号.)

The S-Format breaks up the immediate into imm[11:5] and imm[4:0].  The reason this immediate is broken up is to keep the other fields, namely the register fields, rs2 and rs1, in the same position as with the two source register fields in R-Type instructions.  (As compared with MIPS, which did similar but not as completely, this obviates a register name width (e.g. 5 bit wide) mux and several extra wirings, as well a control signal.)

S格式允许立即使用12位.

The S-Format allows for a 12 bit immediate.

分支的(S)B类型使用13位立即数,尽管13位立即数的最后一个(最低有效位)始终为零所以它不被存储! ;因此,它实际上需要像S格式一样对12位进行编码,但是由于它们在实际使用中发生了移位(左移一位,例如* 2),因此与S-相比,所有位实际上都偏离了1位位置.立即格式化. (移位并非难事或缓慢,但要花费不动产.通常,仅通过将输入位连接到偏移输出位的位置,而不是使用专用移位器,就可以完成恒定量的移位. ALU;但是,这仍然是即时且数据路径大小的布线,因此大约需要12到32+条额外的布线.)

Whereas the (S)B-Type for branches uses a 13 bit immediate, though the last (Least Significant Bit) of the 13-bit immediate is always zero so it is not stored!  So, it needs to actually encode 12 bits just like the S-Format, but because they are shifted in actual usage (left by one, e.g. *2), all the bits are essentially off by 1 bit position as compared with the S-Format immediate.  (Shifting is not hard or slow but costs silicon real-estate.  Typically, such a shift by a constant amount would be done by simply wiring the input bits to offset output bit positions rather than using a dedicated shifter we would see in an ALU; however, still this is immediate and datapath sized wiring so ~12 to 32+ extra wires.)

为了不必(尽可能)移动立即存储的 的部分,并与S-Format中的立即执行很好地对齐,未存储的LSB位置(来自S格式)用于存储SB格式立即数的第11位.这样,位10:1与S格式即刻完全准确地对齐.

In order to not have to shift (as much as possible of) the part of the immediate that is stored, and so as to line nicely with the immediate in S-Format, the not stored LSB position (from S-Format) is used to store bit 11 of the SB-Format immediate.  This way bits 10:1 line up exactly with the S-Format immediate.

但是为什么不直接将分支的第12位放在那儿,这样会使S-Format与另一位保持对齐(即11:1)呢?因为在指令的立即数中编码的最高位用于对符号进行扩展,所以将立即数扩展到32位(对于RV32,对于RV64,则为64位;对于RV128,128位,则有很多导线!).因此,通过将符号位与S格式12位立即保留在同一位置,可以共享相同的符号扩展硬件(具有上述相同的优点和缺点;-).因此,可以选择将第11位(SB型立即数的下一个最高有效位)存储在0位位置(相对于S格式).

But why not put bit 12 of the branch immediate there instead, which would keep one more bit in alignment (i.e. 11:1) with the S-Format?  Because the highest bit encoded in the immediate of the instruction is used to sign extend the immediate to 32-bits (for RV32, or 64-bits for RV64, 128 for RV128, lots of wires!).  So, by keeping the sign bit in the same place as with the S-Format 12 bit immediate, the same sign extension hardware can be shared (with the same first-described-above pros and cons ;-).  Hence, the choice to store bit 11, the next most significant bit of the SB-Type immediate, in the 0 bit position (relative to S-Format).

SB(已经给定S)的成本只有两根左右(1位)线和一根​​1位多路复用器以及一个1位控制信号,与其他方式相比成本最低.

The cost for SB (given S already) is only two or so (1-bit) wires and one 1-bit mux and a 1-bit control signal — minimal compared to alternatives.

请参见以下演示文稿,幻灯片46,

See the following presentation, slide 46, titled "RISC-V Immediate Encoding", and subtitled: "Why is it so confusing?!?!"

UJ-Type的作用类似,将符号位与其他指令的符号位保持在相同的位位置,同时将其他位尽可能多地与其他格式对齐.

The UJ-Type does similar, keeping the sign bit in the same bit position as the sign bit of other instructions, while aligning as many of the other bits as possible with other formats.

请参见同一演示文稿的幻灯片60.

See slide 60 of the same presentation.

这篇关于为什么以这种方式对RISC-V S-B和U-J指令类型进行编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆