Home/Instructions/Unsigned Maximum
MAXU

RISC-V MAXU Instruction Details

Instruction ManualR-type

Return the maximum of rs1 and rs2 using unsigned comparison.

Instruction Syntax

maxu 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.
BZbbBit ManipulationInteger Operation

Instruction Encoding

31..25
funct7
24..20
rs2
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

MAXU uses opcode 0110011 (0x33), funct3 111, funct7 0000101. The rs1 and rs2 fields select the two source registers, and rd selects the destination register.

Format: R-type
opcode: 0110011 (0x33)
funct3: 111 (0x7)
funct7: 0000101 (0x05)

Instruction Behavior

MAXU is a Zbb integer min/max instruction. It compares x[rs1] and x[rs2] as unsigned values and writes the original XLEN-bit value that is larger under that ordering to rd. It does not set condition codes and does not branch.

Quick Understanding & Search Notes

MAXU is useful for branchless clamp, min/max selection, and cases where the original value must be preserved after comparison. It returns the selected rs1 or rs2 bit pattern, not a comparison bit.

Forms with U use unsigned ordering; forms without U use two's-complement signed ordering.
Zbb min/max instructions do not read or write floating-point state and do not set integer condition codes.

Common Usage Scenarios

Integer Comparison

Understand this scenario with real code like «maxu x10, x11, x12 ; x10 = unsigned_max(x11, x12)».

Branchless Selection

Understand this scenario with real code like «maxu x10, x11, x12 ; x10 = unsigned_max(x11, x12)».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is R-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

Pitfalls / Common Confusions

MAXU uses unsigned comparison; use MAX for signed comparisons.
The result is the selected original register value, not Boolean 0/1.
The instruction sets no condition codes; RISC-V has no implicit integer flags register.

FAQ

Does MAXU return 0 or 1?

No. It returns the original XLEN-bit value selected from rs1 or rs2 by the comparison rule.

How do I choose between MAXU and MAX?

Use the U form when data is ordered as unsigned; use the non-U form for signed two's-complement ordering.