Convert half-precision float to a single-precision float
Converts a half-precision number in floating-point register _fs1_ into a single-precision floating-point number in floating-point register _fd_.
`fcvt.s.h` will never round, and so the 'rm' field is effectively ignored.
fcvt.s.h fd, fs1, rm
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 00000000 | 1 | 0 | fs1 | rm | fd | 1 | 0 | 1 | 00 | 11 | |||||||||||||||||||
| Variable | Bits | Width |
|---|---|---|
fs1 | [19:15] | 5 |
rm | [14:12] | 3 |
fd | [11:7] | 5 |
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];
Bits<32> sp_value = 0;
# Widening half -> single is always exact, so no rounding is needed.
if (exp == 0x1F) {
if (frac != 0) {
# NaN. A signaling NaN has the quiet bit (frac[9]) clear and raises NV.
# Either way the result is the canonical single-precision NaN.
if ((hp_value & 0x0200) == 0) {
set_fp_flag(FpFlag::NV);
}
sp_value = SP_CANONICAL_NAN;
} else {
sp_value = packToF32UI(sign, 0xFF, 0);
}
} else if (exp == 0) {
if (frac == 0) {
sp_value = packToF32UI(sign, 0, 0);
} else {
# Subnormal half: value = frac * 2^-24. Shift the leading 1 of frac up to
# bit 10 (the implicit-bit position), drop it, and rebias the exponent.
Bits<16> frac16 = frac;
Bits<8> shift_dist = count_leading_zeros(16, frac16) - 5;
Bits<32> norm_frac = ((frac16 << shift_dist) & 0x3FF);
sp_value = packToF32UI(sign, 0x71 - shift_dist, norm_frac << 13);
}
} else {
# Normal half: rebias the exponent (127 - 15 = 0x70) and widen the fraction
# from 10 to 23 bits.
Bits<8> sp_exp = exp;
Bits<32> frac32 = frac;
sp_value = packToF32UI(sign, sp_exp + 0x70, frac32 << 13);
}
if (implemented?(ExtensionName::D)) {
F[fd] = nan_box(32, 64, sp_value);
} else {
F[fd] = sp_value;
}
mark_f_state_dirty();
one of Zfhmin, Zhinxmin
| S | U | VS | VU |
|---|---|---|---|
| Always | Always | Always | Always |
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.