Webcentive RISC-V Reference

fclass.s

Floating-Point Classify Single-Precision

Extension
F
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
fclass.s xd, fs1
Length
32-bit

Encoding

312726252420191514121176210
111000000000rs1001rd1010011

Match 0xe0001053, mask 0xfff0707f. Source: fclass.s rd rs1 24..20=0 31..27=0x1C 14..12=1 26..25=0 6..2=0x14 1..0=3 in riscv-opcodes/extensions/rv_f.

FieldBitsriscv-opcodes name
rs119:15rs1
rd11:7rd

Description

The fclass.s instruction examines the value in floating-point register fs1 and writes to integer register xd a 10-bit mask that indicates the class of the floating-point number.

The format of the mask is described in the table below. The corresponding bit in xd will be set if the property is true and clear otherwise. All other bits in xd are cleared. Note that exactly one bit in xd will be set. fclass.s does not set the floating-point exception flags.

Format of result of fclass instruction.

xd bitMeaning
0fs1 is $-\infty$.
1fs1 is a negative normal number.
2fs1 is a negative subnormal number.
3fs1 is $-0$.
4fs1 is $+0$.
5fs1 is a positive subnormal number.
6fs1 is a positive normal number.
7fs1 is $+\infty$.
8fs1 is a signaling NaN.
9fs1 is a quiet NaN.

Description from riscv-unified-db, reformatted.

Operation

check_f_ok($encoding);

Bits<32> sp_value = F[fs1][31:0];

if (implemented?(ExtensionName::D)) {
  # check for an incorrectly NaN-boxed value
  if (F[fs1][63:32] != 32'hffffffff) {
    sp_value = SP_CANONICAL_NAN;
  }
}

if (is_sp_neg_inf?(sp_value)) {
  X[xd] = 1 << 0;
} else if (is_sp_neg_norm?(sp_value)) {
  X[xd] = 1 `<< 1;
} else if (is_sp_neg_subnorm?(sp_value)) {
  X[xd] = 1 `<< 2;
} else if (is_sp_neg_zero?(sp_value)) {
  X[xd] = 1 `<< 3;
} else if (is_sp_pos_zero?(sp_value)) {
  X[xd] = 1 `<< 4;
} else if (is_sp_pos_subnorm?(sp_value)) {
  X[xd] = 1 `<< 5;
} else if (is_sp_pos_norm?(sp_value)) {
  X[xd] = 1 `<< 6;
} else if (is_sp_pos_inf?(sp_value)) {
  X[xd] = 1 `<< 7;
} else if (is_sp_signaling_nan?(sp_value)) {
  X[xd] = 1 `<< 8;
} else {
  assert(is_sp_quiet_nan?(sp_value), "Unexpected SP value");
  X[xd] = 1 `<< 9;
}

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages