← Home

fcvt.h.s

Convert single-precision float to a half-precision float

Converts a single-precision number in floating-point register _fs1_ into a half-precision floating-point number in floating-point register _fd_.

`fcvt.h.s` rounds according to the _rm_ field.

All floating-point conversion instructions set the Inexact exception flag if the rounded result differs from the operand value and the Invalid exception flag is not set.

Assembly format

fcvt.h.s fd, fs1, rm

Encoding

313029282726252423222120191817161514131211109876543210
010001000000fs1rmfd1010011

Decode variables

VariableBitsWidth
fs1[19:15]5
rm[14:12]3
fd[11:7]5

Execution

check_f_ok($encoding);

# STATUS: INCOMPLETE. Narrowing single -> half loses precision, so it needs
# IEEE 754 rounding (per _rm_), overflow/underflow and inexact handling.
# Only the NaN, infinity and zero cases below are handled. Every other
# input hits the assert(false) TODO. softfloat_roundPackToF16 does not exist
# in fp.idl yet.
Bits<32> sp_value = F[fs1][31:0];

Bits<1> sign = sp_value[31];
Bits<8> exp = sp_value[30:23];
Bits<23> frac = sp_value[22:0];

if (exp == 0xFF) {
  if (frac != 0) {
    # NaN. A signaling NaN has the quiet bit (frac[22]) clear and raises NV.
    if ((sp_value & 0x00400000) == 0) {
      set_fp_flag(FpFlag::NV);
    }
    F[fd] = nan_box(16, FLEN, HP_CANONICAL_NAN);
  } else {
    F[fd] = nan_box(16, FLEN, packToF16UI( sign, 0x1F, 0 ));
  }
} else {

  # frac is a 24-bit significand, the bottom 9 bits LSB are extracted and OR-red
  # into a sticky flag, the top 15 MSBs are extracted, the LSB of this top slice
  # is OR-red with the sticky
  Bits<16> frac16 = (frac >> 9) | ((frac & 0x1ff) != 0 ? 1 : 0);
  if ((exp | frac16) == 0) {
    F[fd] = nan_box(16, FLEN, packToF16UI( sign, 0, 0 ));
  } else {
    # TODO: finite nonzero inputs need softfloat_roundPackToF16, which is not implemented.
    # The frac16/sticky computation above is unverified draft code.
    assert(false, "TODO: implement roundPackToF16");
    # F[fd] = softfloat_roundPackToF16(sign, exp - 0x71, frac16 | 0x4000);
  }

}

mark_f_state_dirty();

Defined by

one of Zfhmin, Zhinxmin

Access

SUVSVU
AlwaysAlwaysAlwaysAlways

Version af3eaf9+cheriot.f635218

Data from the RISC-V Unified Database, copyright RISC-V International and contributors.

CHERIoT extensions from the CHERIoT specification and Sail model, copyright Microsoft and the CHERIoT Platform contributors.

This site is provided as a community resource and is NOT affiliated with nor endorsed by RISC-V International.