fcvt.s.h

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.s.h will never round, and so the 'rm' field is effectively ignored.

Assembly format

fcvt.s.h fd, fs1, rm

Decode Variables

Bits<5> fs1 = $encoding[19:15];
Bits<3> rm = $encoding[14:12];
Bits<5> fd = $encoding[11:7];

Execution

check_f_ok($encoding);
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) {
    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 {
  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 {
    assert(false, "TODO: implement roundPackToF16");
  }
}
mark_f_state_dirty();

Exceptions

This instruction may result in the following synchronous exceptions:

  • IllegalInstruction

Encoding

svg

Defining extension

Access

M

Always

Containing profiles

  • Mandatory: RVA20S64, RVA20U64, RVA22S64, RVA22U64, RVA23S64, RVA23U64, RVB23S64, RVB23U64

  • Optional: None