mul
Signed multiply
- Extension
- M
- XLEN
- RV32 and RV64
- Assembly (riscv-unified-db)
mul xd, xs1, xs2- Length
- 32-bit
Encoding
| 3125 | 2420 | 1915 | 1412 | 117 | 62 | 10 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0000001 | rs2 | rs1 | 000 | rd | 01100 | 11 | |||||||||||||||||||||||||
Match 0x02000033, mask 0xfe00707f. Source: mul rd rs1 rs2 31..25=1 14..12=0 6..2=0x0C 1..0=3 in riscv-opcodes/extensions/rv_m.
| Field | Bits | riscv-opcodes name |
|---|---|---|
| rs2 | 24:20 | rs2 |
| rs1 | 19:15 | rs1 |
| rd | 11:7 | rd |
Description
MUL performs an XLEN-bitxXLEN-bit multiplication of xs1 by xs2 and places the lower
XLEN bits in the destination register.
Any overflow is thrown away.
Note: If both the high and low bits of the same product are required, then the recommended code sequence is: MULH[[S]U] xdh, xs1, xs2; MUL xdl, xs1, xs2 (source register specifiers must be in same order and xdh cannot be the same as xs1 or xs2). Microarchitectures can then fuse these into a single multiply operation instead of performing two separate multiplies.
Description from riscv-unified-db, reformatted.
Operation
XReg src1 = X[xs1]; XReg src2 = X[xs2]; X[xd] = (src1 * src2)[MXLEN-1:0];
Pseudocode in riscv-unified-db’s IDL, quoted unchanged.