RV64I基礎整數指令集


      RV64I是RV32I的超集,RV32I是RV64I的子集。RV64I包括RV32I的所有40條指令,另外增加了12條RV32I中沒有的指令,還有三條移位指令(slli, srli,srai)也進行小小的改動。

      在RV64I中,整數寄存器是64位的,即xlen=64,所以每條指令中的寄存器都是64位運算,立即數符號位擴展也是到64位。

      下面介紹一下RV64I中新增的指令,對於同一條指令在RV64I和RV32I中,操作的不同,會在RV32I指令集的介紹中給出備注。

ld

ld rd, offset(rs1)     //x[rd] = M[x[rs1] + sext(offset)][63:0]
雙字加載 (Load Doubleword). I-type, RV64I.
從地址 x[rs1] + sign-extend(offset)讀取八個字節,寫入 x[rd]。
壓縮形式: c.ldsp rd, offset; c.ld rd, offset(rs1)


    imm                          
    11 10 9 8 7 6 5 4 3 2 1 0 rs1 func3 rd opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ld I                                   0 1 1           0 0 0 0 0 1 1

例子:

0000000000000000 <.text>:
    0:    00513503              ld    x10,5(x2)
    4:    fec1b283              ld    x5,-20(x3)


lwu

lwu rd, offset(rs1)    //x[rd] = M[x[rs1] + sext(offset)][31:0]
無符號字加載 (Load Word, Unsigned). I-type, RV64I.
從地址 x[rs1] + sign-extend(offset)讀取四個字節,零擴展后寫入 x[rd]。

    imm                          
    11 10 9 8 7 6 5 4 3 2 1 0 rs1 func3 rd opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
lwu I                                   1 1 0           0 0 0 0 0 1 1

例子:

0:    00516503              lwu    x10,5(x2)
4:    fec1e283              lwu    x5,-20(x3)


sd

sd rs2, offset(rs1)    // M[x[rs1] + sext(offset) ]= x[rs2][63: 0]
存雙字(Store Doubleword)
. S-type, RV64I.
x[rs2]中的 8 字節存入內存地址 x[rs1]+sign-extend(offset)

壓縮形式c.sdsp rs2, offset; c.sd rs2, offset(rs1)

    imm         imm                
    11 10 9 8 7 6 5 rs2 rs1 func3 4 3 2 1 0 opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
sd S                                   0 1 1           0 1 0 0 0 1 1

例子:

0:    00a132a3              sd    x10,5(x2)
4:    fe51b623              sd    x5,-20(x3)


addiw

addiw rd, rs1, immediate    // x[rd] = sext((x[rs1] + sext(immediate))[31:0])
加立即數字(Add Word Immediate).
I-type, RV64I.
把符號位擴展的立即數加到 x[rs1],將結果截斷為 32 位,把符號位擴展的結果寫入 x[rd]
。忽略算術溢出。
壓縮形式c.addiw rd, imm


    imm                          
    11 10 9 8 7 6 5 4 3 2 1 0 rs1 func3 rd opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
addiw I                                   0 0 0           0 0 1 1 0 1 1

例子:

0:    0142851b              addiw    x10,x5,20
4:    fec2851b              addiw    x10,x5,-20


slliw

slliw rd, rs1, shamt    // x[rd] = sext((x[rs1] ≪ shamt)[31: 0])
立即數邏輯左移字(Shift Left Logical Word Immediate)
. I-type, RV64I.
把寄存器 x[rs1]左移 shamt 位,空出的位置填入 0,結果截為 32
位,進行有符號擴展后寫入x[rd]。僅當 shamt[5]=0 時,指令才是有效的。


                shamt                          
                5 4 3 2 1 0 rs1 func3 rd opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
slliw I 0 0 0 0 0 0                       0 0 1           0 0 1 1 0 1 1

例子:

0:    0064951b              slliw    x10,x9,0x6
4:    0024951b              slliw    x10,x9,0x2


srliw

srliw rd, rs1, shamt     //x[rd] = sext(x[rs1][31: 0] ≫u shamt)
立即數邏輯右移字(Shift Right Logical Word Immediate). I-type, RV64I.
把寄存器 x[rs1]右移 shamt 位,空出的位置填入 0,結果截為 32 位,進行有符號擴展后寫入x[rd]。僅當 shamt[5]=0 時,指令才是有效的。

                shamt                          
                5 4 3 2 1 0 rs1 func3 rd opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
srliw I 0 0 0 0 0 0                       1 0 1           0 0 1 1 0 1 1

例子:

0:    0064d51b              srliw    x10,x9,0x6
4:    0024d51b              srliw    x10,x9,0x2


sraiw

sraiw rd, rs1, shamt    //x[rd] = sext(x[rs1][31: 0] ≫s shamt)
立即數算術右移字(Shift Right Arithmetic Word Immediate). I-type, RV64I.
把寄存器 x[rs1]的低 32 位右移 shamt 位,空位用 x[rs1][31]填充,結果進行有符號擴展后寫入 x[rd]。僅當 shamt[5]=0 時指令有效。
壓縮形式: c.srai rd, shamt


                shamt                          
                5 4 3 2 1 0 rs1 func3 rd opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
sraiw I 0 1 0 0 0 0                       1 0 1           0 0 1 1 0 1 1

例子:

0:    4064d51b              sraiw    x10,x9,0x6
4:    4024d51b              sraiw    x10,x9,0x2


addw

addw rd, rs1, rs2   //x[rd] = sext((x[rs1] + x[rs2])[31:0])
加字(Add Word). R-type, RV64I.
把寄存器 x[rs2]加到寄存器 x[rs1]上,將結果截斷為 32 位,把符號位擴展的結果寫入 x[rd]。忽略算術溢出。
壓縮形式: c.addw rd, rs2

                               
    func7 rs2 rs1 func3 rd opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
addw R 0 0 0 0 0 0 0                     0 0 0           0 1 1 1 0 1 1

例子:

0:    0034853b              addw    x10,x9,x3


subw

subw rd, rs1, rs2   //x[rd] = sext((x[rs1] - x[rs2])[31: 0])
減去字(Substract Word). R-type, RV64I.
x[rs1]減去 x[rs2],結果截為 32 位,有符號擴展后寫入 x[rd]。忽略算術溢出。
壓縮形式: c.subw rd, rs2

                               
    func7 rs2 rs1 func3 rd opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
subw R 0 1 0 0 0 0 0                     0 0 0           0 1 1 1 0 1 1

例子:

4:    4034853b              subw    x10,x9,x3
 


sllw

sllw rd, rs1, rs2     //x[rd] = sext((x[rs1] ≪ x[rs2][4: 0])[31: 0])
邏輯左移字(Shift Left Logical Word). R-type, RV64I.
把寄存器 x[rs1]的低 32 位左移 x[rs2]位,空出的位置填入 0,結果進行有符號擴展后寫入x[rd]。 x[rs2]的低 5 位代表移動位數,其高位則被忽略。


                               
    func7 rs2 rs1 func3 rd opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
sllw R 0 0 0 0 0 0 0                     0 0 1           0 1 1 1 0 1 1

例子:

8:    0034953b              sllw    x10,x9,x3
 


srlw


srlw rd, rs1, rs2     //x[rd] = sext(x[rs1][31: 0] ≫u x[rs2][4: 0])
邏輯右移字(Shift Right Logical Word). R-type, RV64I.
把寄存器 x[rs1]的低 32 位右移 x[rs2]位,空出的位置填入 0,結果進行有符號擴展后寫入x[rd]。 x[rs2]的低 5 位代表移動位數,其高位則被忽略。

                               
    func7 rs2 rs1 func3 rd opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
srlw R 0 0 0 0 0 0 0                     1 0 1           0 1 1 1 0 1 1

例子:

c:    0034d53b              srlw    x10,x9,x3
 


sraw

sraw rd, rs1, rs2     //x[rd] = sext(x[rs1][31: 0] ≫s x[rs2][4: 0])
算術右移字(Shift Right Arithmetic Word). R-type, RV64I only.
把寄存器 x[rs1]的低 32 位右移 x[rs2]位,空位用 x[rs1][31]填充,結果進行有符號擴展后寫 入 x[rd]。 x[rs2]的低 5 位為移動位數,高位則被忽略。



                               
    func7 rs2 rs1 func3 rd opcode
name type 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
sraw R 0 1 0 1 0 0 0                     1 0 1           0 1 1 1 0 1 1

例子:

10:    4034d53b              sraw    x10,x9,x3







免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM