Introduction
The B extension of the architecture strings is the three extensions Zba, Zbb and Zbs together; Zbc
(carry-less multiply) is separate. Some Zbb instructions are shared with the scalar cryptography extension Zbkb
(andn, orn, xnor, rol, ror, rori,
rev8), and clmul and clmulh with Zbkc; see
cryptography. “rv64” marks instructions that exist only on RV64.
In the tables funct7 or the top six bits of the immediate are given in binary; the opcode is
0110011 (OP), 0010011 (OP-IMM), 0111011 (OP-32) or
0011011 (OP-IMM-32).
Zba: address generation
| Instruction | Opcode | funct7 | funct3 | What it does |
|---|---|---|---|---|
sh1add | OP | 0010000 | 010 | rd = rs2 + (rs1 << 1) |
sh2add | OP | 0010000 | 100 | rd = rs2 + (rs1 << 2) |
sh3add | OP | 0010000 | 110 | rd = rs2 + (rs1 << 3) |
add.uw (rv64) | OP-32 | 0000100 | 000 | rd = rs2 + zero-extended low word of rs1. With rs2 = x0 it is zext.w. |
sh1add.uw, sh2add.uw, sh3add.uw (rv64) | OP-32 | 0010000 | 010, 100, 110 | As shnadd with the zero-extended low word of rs1. |
slli.uw (rv64) | OP-IMM-32 | 000010 + 6-bit shamt | 001 | rd = (zero-extended low word of rs1) << shamt |
Zbb: basic bit manipulation
| Instruction | Opcode | Bits 31:20 / funct7 | funct3 | What it does |
|---|---|---|---|---|
andn, orn, xnor | OP | 0100000 | 111, 110, 100 | rs1 and not rs2; rs1 or not rs2; not (rs1 xor rs2) |
clz, ctz, cpop | OP-IMM | 011000000000, …0001, …0010 | 001 | Count leading zeros, trailing zeros, set bits |
clzw, ctzw, cpopw (rv64) | OP-IMM-32 | as above | 001 | The same on the low word |
max, maxu, min, minu | OP | 0000101 | 110, 111, 100, 101 | Signed and unsigned maximum and minimum |
sext.b, sext.h | OP-IMM | 011000000100, 011000000101 | 001 | Sign-extend a byte or halfword |
zext.h | OP (rv32) / OP-32 (rv64) | 0000100, rs2 = 0 | 100 | Zero-extend a halfword |
rol, ror | OP | 0110000 | 001, 101 | Rotate left or right by rs2 |
rolw, rorw (rv64) | OP-32 | 0110000 | 001, 101 | Rotate the low word |
rori | OP-IMM | 011000 + shamt (rv64) / 0110000 + shamt (rv32) | 101 | Rotate right by an immediate |
roriw (rv64) | OP-IMM-32 | 0110000 | 101 | Rotate the low word right by an immediate |
orc.b | OP-IMM | 001010000111 | 101 | Each byte becomes 0xFF if any bit of it is set, else 0 |
rev8 | OP-IMM | 011010011000 (rv32) / 011010111000 (rv64) | 101 | Reverse the byte order |
Zbc: carry-less multiplication
| Instruction | Opcode | funct7 | funct3 | What it does |
|---|---|---|---|---|
clmul | OP | 0000101 | 001 | Low half of the carry-less product |
clmulr | OP | 0000101 | 010 | The product bits XLEN−1 to 2·XLEN−2 (reversed) |
clmulh | OP | 0000101 | 011 | High half of the carry-less product |
Zbs: single-bit instructions
| Instruction | Opcode | funct7 (or top six bits) | funct3 | What it does |
|---|---|---|---|---|
bclr, bclri | OP, OP-IMM | 0100100 (010010 + shamt on RV64) | 001 | Clear bit rs2 (or the immediate) |
bext, bexti | OP, OP-IMM | 0100100 | 101 | Extract bit: rd = (rs1 >> n) and 1 |
binv, binvi | OP, OP-IMM | 0110100 (011010) | 001 | Invert a bit |
bset, bseti | OP, OP-IMM | 0010100 (001010) | 001 | Set a bit |