FMAX.H

RISC-V FMAX.H Instruction Details

Instruction ManualR-type

FMAX.H selects the numerically larger value from two half-precision floating-point operands.

Instruction Syntax

fmax.h rd, rs1, rs2
Operand Breakdown
rd: destination floating-point register receiving the formatted result.
rs1/rs2: source floating-point registers; arithmetic/rounding forms with rm use rm or dynamic frm for rounding mode.
ZfhFloating-Point Arithmetic

Instruction Behavior

FMAX.H uses the OP-FP encoding with the Zfh format to select the numerically larger value from two half-precision source operands. Ordinary FMIN/FMAX returns the non-NaN operand when exactly one input is NaN, returns canonical NaN when both inputs are NaN, and sets NV if either input is a signaling NaN. The official rule orders -0.0 below +0.0.

FMAX.H Decode And Execute Animation

Shows the Zfh-extension half-precision OP-FP flow: decode fields, read FP operands, perform FMAX semantics, then write rd.

rd
rs1
rs2
fmax.h
,
,
Execution Context
FLEN=>=32 / fmt=H (10)
funct3: FMAX selects maximum
fflags: example fflags remains 0
31..27
26..25
24..20
19..15
14..12
11..7
6..0
00101
FMAX
10
fmt=H
01100
rs2
01011
rs1
001
funct3=001
01010
rd
1010011
OP-FP
Execution Data Path
instruction
0x2CC59553
opcode
1010011 -> OP-FP
funct5/fmt
00101 + H(10) -> FMAX.H
funct3
001 -> FMAX selects maximum
rd/rs
fa0(f10) / fa1(f11) / fa2(f12)
read
-0.0, 0.0
FP op
FMAX(-0.0, 0.0) = 0.0
write
fa0(f10) = 0.0; example fflags remains 0
Current Step

Fetch: show the 32-bit OP-FP encoding

The word is split as an R-type OP-FP instruction; half-precision OP-FP instructions use opcode 1010011.

encoding: 0x2CC59553
syntax : fmax.h fa0(f10), fa1(f11), fa2(f12)
result : fa0(f10) = 0.0; example fflags remains 0

The default example shows the official signed-zero ordering: -0.0 is less than +0.0. With NaNs, ordinary FMIN/FMAX returns the non-NaN operand for a single NaN and canonical NaN for two NaNs; signaling NaN sets NV.

Half-precision Calculation
rs1
fa1(f11) = -0.0
rs2
fa2(f12) = 0.0
result
FMAX(-0.0, 0.0) = 0.0

The default example shows the official signed-zero ordering: -0.0 is less than +0.0. With NaNs, ordinary FMIN/FMAX returns the non-NaN operand for a single NaN and canonical NaN for two NaNs; signaling NaN sets NV.

This animation shows only Zfh-extension ISA-visible OP-FP encoding, example numeric results, and fflags relationship; it does not model FPU pipelines, latency, every IEEE 754 corner case, or microarchitecture.

Quick Understanding & Search Notes

FMAX.H is not a compare that writes 0/1; it selects a half-precision result in the floating-point register file. The key points are single-NaN returns non-NaN, two NaNs return canonical NaN, and -0.0 is ordered below +0.0.

The OP-FP fields use the Zfh format; funct5=00101, with funct3 distinguishing FMIN from FMAX.
Ordinary FMIN/FMAX NaN handling and the NV flag for signaling NaN come from the official F-extension semantics, applied to the H/Q format.
The instruction does not read rm and does not perform arithmetic that creates a newly rounded significand.

Common Usage Scenarios

Floating-Point Compare

Understand this scenario with real code like «fmax.h f10, f11, f12 ; f10 = max(f11, f12)».

Numerical Computing

Understand this scenario with real code like «fmax.h f10, f11, f12 ; f10 = max(f11, f12)».

Pre-Use Checklist

Syntax Check
  • rd: destination floating-point register receiving the formatted result.
  • rs1/rs2: source floating-point registers; arithmetic/rounding forms with rm use rm or dynamic frm for rounding mode.
Semantic Check
  • Confirm the floating-point format suffix (.H/.S/.D/.Q) matches the data width.
  • Decide whether software must inspect fflags for NV, DZ, OF, UF, or NX.

Pitfalls / Common Confusions

Ordinary FMIN/FMAX returns the non-NaN operand when exactly one input is NaN; do not treat it as always propagating NaN.
A signaling NaN sets NV; quiet NaN and signaling NaN differ in exception-flag behavior.
-0.0 is ordered below +0.0 by the official rule, which affects the sign of FMIN/FMAX results.
FMIN/FMAX has no rm rounding field and is not rounded add/subtract/multiply/divide arithmetic.

FAQ

What does FMAX.H do with one NaN operand?

Ordinary FMIN/FMAX returns the other non-NaN operand when exactly one operand is NaN; it returns canonical NaN when both operands are NaN.

Does FMAX.H use rm rounding?

No. FMIN/FMAX is a selection operation; its funct3 selects minimum or maximum semantics, not a rounding mode.