Webcentive RISC-V Reference

mulhsu

Signed/unsigned multiply high

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

Encoding

31252420191514121176210
0000001rs2rs1010rd0110011

Match 0x02002033, mask 0xfe00707f. Source: mulhsu rd rs1 rs2 31..25=1 14..12=2 6..2=0x0C 1..0=3 in riscv-opcodes/extensions/rv_m.

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

Description

Multiply the signed value in xs1 by the unsigned value in xs2, and store the upper half of the result in xd. The lower half is thrown away.

If both the upper and lower halves are needed, it suggested to use the sequence:

--- mulhsu xdh, xs1, xs2 mul xdl, xs1, xs2 ---

Microarchitectures may look for that sequence and fuse the operations.

Description from riscv-unified-db, reformatted.

Operation

# enlarge and extend the sources
Bits<1> xs1_sign_bit = X[xs1][MXLEN-1];
Bits<MXLEN*8'd2> src1 = {{MXLEN{xs1_sign_bit}}, X[xs1]};
Bits<MXLEN*8'd2> src2 = {{MXLEN{1'b0}}, X[xs2]};

X[xd] = (src1 * src2)[(MXLEN*8'd2)-1:MXLEN];

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

Specification and related pages