fixing bf16_to_f32 for subnormal numbers

This commit is contained in:
Nicolas Brunie 2023-09-22 18:30:13 -07:00
parent 577fcd787c
commit b1bbccf04d
1 changed files with 5 additions and 11 deletions

View File

@ -74,17 +74,11 @@ float32_t bf16_to_f32( bfloat16_t a )
} }
/*------------------------------------------------------------------------ /*------------------------------------------------------------------------
*------------------------------------------------------------------------*/ *------------------------------------------------------------------------*/
if ( ! exp ) { // packToF32UI simply packs bitfields without any numerical change
if ( ! frac ) { // which means it can be used directly for any BF16 to f32 conversions which
uiZ = packToF32UI( sign, 0, 0 ); // does not require bits manipulation
goto uiZ; // (that is everything where the 16-bit are just padded right with 16 zeros, including
} // subnormal numbers)
normExpSig = softfloat_normSubnormalBF16Sig( frac );
exp = normExpSig.exp - 1;
frac = normExpSig.sig;
}
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
uiZ = packToF32UI( sign, exp, ((uint_fast32_t) frac) <<16 ); uiZ = packToF32UI( sign, exp, ((uint_fast32_t) frac) <<16 );
uiZ: uiZ:
uZ.ui = uiZ; uZ.ui = uiZ;