Skip to content

Commit

Permalink
[libc] Allow reading and writing __FE_DENORM if available on x86_64.
Browse files Browse the repository at this point in the history
Some libcs define __FE_DENORM on x86_64. This change allows reading the
bits corresponding to that non-standard exception.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D105004
  • Loading branch information
Siva Chandra Reddy committed Jun 30, 2021
1 parent 804dc3d commit 230df8a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion libc/utils/FPUtil/x86_64/FEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ static constexpr uint16_t MXCSRRoundingControlBitPosition = 13;
// 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;
Expand All @@ -62,6 +65,9 @@ static inline uint16_t getStatusValueForExcept(int excepts) {
// 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) |
Expand All @@ -70,6 +76,9 @@ static inline uint16_t getStatusValueForExcept(int excepts) {

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) |
Expand Down

0 comments on commit 230df8a

Please sign in to comment.