Home/Instructions/Multiply High
MULH

RISC-V MULH Instruction Details

Instruction ManualR-type

Signed multiply, return upper XLEN bits of full 2×XLEN-bit product

Instruction Syntax

mulh rd, rs1, rs2
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
MArithmeticMultiplication

Instruction Behavior

MULH performs signed×signed multiplication (both rs1 and rs2 treated as signed) and returns the upper XLEN bits of the full 2×XLEN-bit product to rd. When both halves of the same product are required, the recommended sequence is MULH followed by MUL with the same source order; the MULH destination must not equal either source. It is defined by M and is also included in Zmmul.

MULH Decode And Execute Animation

Starts with machine-code field decoding, then shows operand reads, instruction-specific execution, and ISA-visible state update.

rd
rs1
rs2
mulh
,
,
Execution Context
a6(x16)
0xFFFFFFF0
t2(x7)
0x00000007
31..25
24..20
19..15
14..12
11..7
6..0
0000001
funct7
00111
rs2
10000
rs1
001
funct3
00101
rd
0110011
opcode
Execution Data Path
instruction
0x027812B3
opcode
0110011 -> OP
funct3
001 -> MULH
funct7
0000001 -> integer multiply selector
rd / rs1 / rs2
t0(x5) / a6(x16)=0xFFFFFFF0 (-16) / t2(x7)=0x00000007 (7)
32-bit multiply
-16 x 7 -> full[63:0]=0xFFFFFFFFFFFFFF90 -> product[63:32]=0xFFFFFFFF (signed rs1 x signed rs2)
x5
t0(x5) = 0xFFFFFFFF
Current Step

Concept Step: receive the 32-bit instruction encoding

The machine code is split by the current instruction format; the animation starts from encoding/decode.

encoding: 0x027812B3
syntax : mulh t0(x5), a6(x16), t2(x7)
result : t0(x5) = 0xFFFFFFFF
Architectural Result
t0(x5) = 0xFFFFFFFF

This animation shows ISA-visible decode and state changes, not any specific CPU pipeline, cache, prediction, or timing implementation.

Common Usage Scenarios

Signed product high half

Understand this scenario with real code like «mulh t0, a0, a1 # t0 = upper XLEN bits of signed(a0 * a1)».

Pre-Use Checklist

Syntax Check
  • Verify rd, rs1, rs2 (and rs3) are valid GPRs.
  • Confirm funct3 and funct7 encoding is correct.
Semantic Check
  • Check if the result affects subsequent branches or address calculations.
  • Ensure the rd register is not overwritten by another instruction.

Pitfalls / Common Confusions

Only returns upper half, need MUL for lower half
For the manual's fusion recommendation, a paired MUL must preserve source order and the MULH destination must not equal either source