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

查看:44
本文介绍了为什么 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 类型将立即数字段分成 2 部分.这是有道理的,因为所有指令编码都必须相似.但我不明白为什么下面的直接字段以这种方式编码.

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 中的两个源寄存器字段相同的位置-输入说明. (与 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-Format 一样编码 12 位,但是因为它们在实际使用中被移位(左移 1,例如 *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 格式的立即数很好地对齐,未存储的LSB 位置(来自 S 格式)用于存储 SB 格式立即数的第 11 位.这样,位 10:1 完全与 S-Format 立即对齐.

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 格式对齐(即 11:1)? 因为指令的立即数中编码的最高位用于将立即数符号扩展为 32 位(对于 RV32,或 64 位对于 RV64,128 位对于 RV128,很多线!).因此,通过将符号位保持在与 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,标题为RISC-V 立即编码",副标题为:为什么这么混乱?!?!"

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天全站免登陆