fcvt.h.s

Convert half-precision float to a single-precision float

This instruction is defined by:

Encoding

svg

Synopsis

Converts a half-precision number in floating-point register fs1 into a single-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.

Access

M HS U VS VU

Always

Always

Always

Always

Always

Decode Variables

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

Execution

  • Pruned, XLEN == 64

  • Original

check_f_ok($encoding);
Bits<16> hp_value = F[fs1][15:0];
Bits<1> sign = hp_value[15];
Bits<5> exp = hp_value[14:10];
Bits<10> frac = hp_value[9:0];
if (exp == 0x1F) {
  if (frac != 0) {
    if ((hp_value & 0x0200) != 0) {
      set_fp_flag(FpFlag::NV);
    }
    F[fd] = 16'h7e00;
  } else {
    F[fd] = packToF32UI(sign, 0xFF, 0);
  }
} else {
  if (exp != 0) {
    if (frac != 0) {
      F[fd] = packToF32UI(sign, 0, 0);
    } else {
      Bits<6> norm_exp;
      (norm_exp, frac = softfloat_normSubnormalF16Sig(frac));
      exp = norm_exp - 1;
      F[fd] = packToF32UI(sign, exp + 0x70, frac << 13);
    }
  } else {
    F[fd] = packToF32UI(sign, exp + 0x70, frac << 13);
  }
}
mark_f_state_dirty();
check_f_ok($encoding);
Bits<16> hp_value = F[fs1][15:0];
Bits<1> sign = hp_value[15];
Bits<5> exp = hp_value[14:10];
Bits<10> frac = hp_value[9:0];
if (exp == 0x1F) {
  if (frac != 0) {
    if ((hp_value & 0x0200) != 0) {
      set_fp_flag(FpFlag::NV);
    }
    F[fd] = HP_CANONICAL_NAN;
  } else {
    F[fd] = packToF32UI(sign, 0xFF, 0);
  }
} else {
  if (exp != 0) {
    if (frac != 0) {
      F[fd] = packToF32UI(sign, 0, 0);
    } else {
      Bits<6> norm_exp;
      (norm_exp, frac = softfloat_normSubnormalF16Sig(frac));
      exp = norm_exp - 1;
      F[fd] = packToF32UI(sign, exp + 0x70, frac << 13);
    }
  } else {
    F[fd] = packToF32UI(sign, exp + 0x70, frac << 13);
  }
}
mark_f_state_dirty();

Exceptions

This instruction may result in the following synchronous exceptions:

  • IllegalInstruction