diff --git a/libc/src/__support/FPUtil/FloatProperties.h b/libc/src/__support/FPUtil/FloatProperties.h index 6fc8b6ac1bb06f..cbef3908220cd0 100644 --- a/libc/src/__support/FPUtil/FloatProperties.h +++ b/libc/src/__support/FPUtil/FloatProperties.h @@ -109,16 +109,27 @@ template <> struct FloatProperties { "Unexpected size of 'long double' type."); static constexpr uint32_t BIT_WIDTH = (sizeof(BitsType) * 8) - 48; + static constexpr BitsType FULL_WIDTH_MASK = ((BitsType(1) << BIT_WIDTH) - 1); static constexpr uint32_t MANTISSA_WIDTH = 63; static constexpr uint32_t EXPONENT_WIDTH = 15; static constexpr BitsType MANTISSA_MASK = (BitsType(1) << MANTISSA_WIDTH) - 1; + + // The x86 80 bit float represents the leading digit of the mantissa + // explicitly. This is the mask for that bit. + static constexpr BitsType EXPLICIT_BIT_MASK = (BitsType(1) << MANTISSA_WIDTH); + static constexpr BitsType SIGN_MASK = BitsType(1) << (EXPONENT_WIDTH + MANTISSA_WIDTH + 1); static constexpr BitsType EXPONENT_MASK = ((BitsType(1) << EXPONENT_WIDTH) - 1) << (MANTISSA_WIDTH + 1); static constexpr uint32_t EXPONENT_BIAS = 16383; + static constexpr BitsType EXP_MANT_MASK = + MANTISSA_MASK + EXPLICIT_BIT_MASK + EXPONENT_MASK; + static_assert(EXP_MANT_MASK == (~SIGN_MASK & FULL_WIDTH_MASK), + "Exponent and mantissa masks are not as expected."); + // If a number x is a NAN, then it is a quiet NAN if: // QuietNaNMask & bits(x) != 0 // Else, it is a signalling NAN.