Webcentive RISC-V Reference

mul

Signed multiply

Extension
M
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
mul xd, xs1, xs2
Length
32-bit

Encoding

31252420191514121176210
0000001rs2rs1000rd0110011

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.

FieldBitsriscv-opcodes name
rs224:20rs2
rs119:15rs1
rd11:7rd

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.

Specification and related pages