diff --git a/libc/utils/FPUtil/x86_64/FEnv.h b/libc/utils/FPUtil/x86_64/FEnv.h --- a/libc/utils/FPUtil/x86_64/FEnv.h +++ b/libc/utils/FPUtil/x86_64/FEnv.h @@ -43,7 +43,10 @@ // encoding as well as the same bit positions. struct ExceptionFlags { static constexpr uint16_t Invalid = 0x1; - static constexpr uint16_t Denormal = 0x2; // This flag is not used + // Some libcs define __FE_DENORM corresponding to the denormal input + // exception and include it in FE_ALL_EXCEPTS. We define and use it to + // support compiling against headers provided by such libcs. + static constexpr uint16_t Denormal = 0x2; static constexpr uint16_t DivByZero = 0x4; static constexpr uint16_t Overflow = 0x8; static constexpr uint16_t Underflow = 0x10; @@ -62,6 +65,9 @@ // We will make use of the fact that exception control bits are single // bit flags in the control registers. return (excepts & FE_INVALID ? ExceptionFlags::Invalid : 0) | +#ifdef __FE_DENORM + (excepts & __FE_DENORM ? ExceptionFalgs::Denormal : 0) | +#endif // __FE_DENORM (excepts & FE_DIVBYZERO ? ExceptionFlags::DivByZero : 0) | (excepts & FE_OVERFLOW ? ExceptionFlags::Overflow : 0) | (excepts & FE_UNDERFLOW ? ExceptionFlags::Underflow : 0) | @@ -70,6 +76,9 @@ static inline int exceptionStatusToMacro(uint16_t status) { return (status & ExceptionFlags::Invalid ? FE_INVALID : 0) | +#ifdef __FE_DENORM + (status & ExceptionFalgs::Denormal ? __FE_DENORM : 0) | +#endif // __FE_DENORM (status & ExceptionFlags::DivByZero ? FE_DIVBYZERO : 0) | (status & ExceptionFlags::Overflow ? FE_OVERFLOW : 0) | (status & ExceptionFlags::Underflow ? FE_UNDERFLOW : 0) |