Webcentive RISC-V Reference

mulw

Signed 32-bit multiply

Extension
M
XLEN
RV64 only
Assembly (riscv-unified-db)
mulw xd, xs1, xs2
Length
32-bit

Encoding

31252420191514121176210
0000001rs2rs1000rd0111011

Match 0x0200003b, mask 0xfe00707f. Source: mulw rd rs1 rs2 31..25=1 14..12=0 6..2=0x0E 1..0=3 in riscv-opcodes/extensions/rv64_m.

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

Description

Multiplies the lower 32 bits of the source registers, placing the sign-extension of the lower 32 bits of the result into the destination register.

Any overflow is thrown away.

Note: In RV64, MUL can be used to obtain the upper 32 bits of the 64-bit product, but signed arguments must be proper 32-bit signed values, whereas unsigned arguments must have their upper 32 bits clear. If the arguments are not known to be sign- or zero-extended, an alternative is to shift both arguments left by 32 bits, then use MULH[[S]U].

Description from riscv-unified-db, reformatted.

Operation

Bits<32> src1 = X[xs1][31:0];
Bits<32> src2 = X[xs2][31:0];

Bits<32> result = src1 * src2;
Bits<1> sign_bit = result[31];

# return the sign-extended result
X[xd] = {{32{sign_bit}}, result};

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages