M: multiply and divide
All are R-format with funct7 = 0000001. The opcode is 0110011 (OP) for the
full-width forms and 0111011 (OP-32) for the RV64 word forms. Zmmul is the multiply
half of M (mul, mulh, mulhsu, mulhu, mulw)
without division. Division by zero does not trap: the quotient is all ones and the remainder is the dividend;
overflow of the most negative number divided by −1 gives that number back.
| Instruction | funct3 | Opcode | What it does |
|---|---|---|---|
mul | 000 | 0110011 | Low XLEN bits of rs1 × rs2. |
mulh | 001 | 0110011 | High bits, signed × signed. |
mulhsu | 010 | 0110011 | High bits, signed × unsigned. |
mulhu | 011 | 0110011 | High bits, unsigned × unsigned. |
div | 100 | 0110011 | Signed division. |
divu | 101 | 0110011 | Unsigned division. |
rem | 110 | 0110011 | Signed remainder. |
remu | 111 | 0110011 | Unsigned remainder. |
mulw (rv64) | 000 | 0111011 | 32-bit multiply, sign-extended. |
divw (rv64) | 100 | 0111011 | 32-bit signed division. |
divuw (rv64) | 101 | 0111011 | 32-bit unsigned division. |
remw (rv64) | 110 | 0111011 | 32-bit signed remainder. |
remuw (rv64) | 111 | 0111011 | 32-bit unsigned remainder. |
A: atomic instructions
Opcode 0101111 (AMO). Bits 31:27 are the operation, bit 26 is aq (acquire) and bit 25
is rl (release), written as a suffix: .aq, .rl or .aqrl.
funct3 gives the width: 010 word (.w), 011 doubleword (.d, RV64; on RV32 with
Zacas a register pair), 000 byte and 001 halfword (Zabha), 100 quadword (Zacas, RV64). The operands are
rd, rs2, (rs1); the load-reserved forms have rd, (rs1) and rs2 = 0. The address must be
naturally aligned. Zalrsc is lr and sc; Zaamo is the
amo* instructions; A is both.
| Operation | Bits 31:27 | Instructions | Extension |
|---|---|---|---|
| Load-reserved | 00010 | lr.w, lr.d | Zalrsc |
| Store-conditional (rd = 0 on success) | 00011 | sc.w, sc.d | Zalrsc |
| Swap | 00001 | amoswap.w, .d, .b, .h | Zaamo (.b .h: Zabha) |
| Add | 00000 | amoadd.w, .d, .b, .h | Zaamo |
| Xor | 00100 | amoxor.w, .d, .b, .h | Zaamo |
| And | 01100 | amoand.w, .d, .b, .h | Zaamo |
| Or | 01000 | amoor.w, .d, .b, .h | Zaamo |
| Signed minimum | 10000 | amomin.w, .d, .b, .h | Zaamo |
| Signed maximum | 10100 | amomax.w, .d, .b, .h | Zaamo |
| Unsigned minimum | 11000 | amominu.w, .d, .b, .h | Zaamo |
| Unsigned maximum | 11100 | amomaxu.w, .d, .b, .h | Zaamo |
| Compare-and-swap (rd is the expected value and receives the old one) | 00101 | amocas.w, .d, .q, .b, .h | Zacas (.b .h also need Zabha) |
Memory ordering: the A instructions follow the RVWMO model; aq and rl make the access an acquire
or a release. The explorer shows an AMO as a read and a write of memory.