21.9FCLASS: The Classify Instruction

Part I Linux boot: required Vol. I (Unprivileged) pp. 119–120 · ~3 min read

  • fclass

FCLASS.S inspects an f-register and writes a 10-bit one-hot mask into an integer register — exactly one bit set, no exception flags touched, rounding irrelevant. It’s the tool math libraries use to branch on value categories without risking NaN signaling.

FCLASS result mask (Table 28)
rs1 is…Field-pattern decode
bit 0−∞sign=1, exp=max, sig=0
bit 1negative normalsign=1, 0 < exp < max
bit 2negative subnormalsign=1, exp=0, sig≠0
bit 3−0sign=1, exp=0, sig=0
bit 4+0sign=0, exp=0, sig=0
bit 5positive subnormalsign=0, exp=0, sig≠0
bit 6positive normalsign=0, 0 < exp < max
bit 7+∞sign=0, exp=max, sig=0
bit 8signaling NaNexp=max, sig≠0, quiet bit clear
bit 9quiet NaNexp=max, sig≠0, quiet bit set
Dotted-underlined cells have explanations — click one.
−∞bit 0−normalbit 1−subnormalbit 2−0bit 3+0bit 4+subnormalbit 5+normalbit 6+∞bit 7sNaN · bit 8qNaN · bit 9

Ten classes: eight on the extended number line (sign-split), two NaN classes off it.

FCLASS is encoded under OP-FP with funct5 = FCLASS, rm fixed at 001, rs2 = 0 — and it never sets flags, even for signaling NaN inputs.

Hardware Designer Notes

FCLASS is nearly free: the special-case detectors your FPU already needs (zero, subnormal, ∞, NaN, quiet bit) ARE the classify unit — route them to a 10-bit one-hot writeback and you’re done. If you recode values internally, classify from the recoded form carefully: the sNaN/qNaN distinction must survive recoding.

Minimal Linux-boot hart MUST

  • One-hot output, exactly one bit set, bits 31:10 zero (RV64: 63:10)
  • No fflags updates on any input, sNaN included

MAY simplify / trap-and-emulate

  • Share the classify logic with the FPU front-end — every FP op already decodes these patterns for special-case handling

Check yourself — FCLASS

1.FCLASS.S of −0.0 writes what to rd?

2.Does FCLASS.S of a signaling NaN set the invalid flag?

3.Which classes can a hardware classify unit derive purely from exponent/significand field patterns?

3 questions