mulh
Signed multiply high
- Extension
- M
- XLEN
- RV32 and RV64
- Assembly (riscv-unified-db)
mulh xd, xs1, xs2- Length
- 32-bit
Encoding
| 3125 | 2420 | 1915 | 1412 | 117 | 62 | 10 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0000001 | rs2 | rs1 | 001 | rd | 01100 | 11 | |||||||||||||||||||||||||
Match 0x02001033, mask 0xfe00707f. Source: mulh rd rs1 rs2 31..25=1 14..12=1 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
Multiply the signed values in xs1 to 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:
--- mulh 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 sign extend the sources
Bits<1> xs1_sign_bit = X[xs1][xlen()-1];
Bits<MXLEN `* 2> src1 = {{xlen(){xs1_sign_bit}}, X[xs1]};
Bits<1> xs2_sign_bit = X[xs2][xlen()-1];
Bits<MXLEN `* 2> src2 = {{xlen(){xs2_sign_bit}}, X[xs2]};
# grab the high half of the result, and put it in xd
X[xd] = (src1 * src2)[(xlen()*8'd2)-1:xlen()];Pseudocode in riscv-unified-db’s IDL, quoted unchanged.