Skip to content

Commit 230df8a

Browse files
author
Siva Chandra Reddy
committed
[libc] Allow reading and writing __FE_DENORM if available on x86_64.
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
1 parent 804dc3d commit 230df8a

File tree

1 file changed

+10
-1
lines changed
  • libc/utils/FPUtil/x86_64

1 file changed

+10
-1
lines changed

libc/utils/FPUtil/x86_64/FEnv.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ static constexpr uint16_t MXCSRRoundingControlBitPosition = 13;
4343
// encoding as well as the same bit positions.
4444
struct ExceptionFlags {
4545
static constexpr uint16_t Invalid = 0x1;
46-
static constexpr uint16_t Denormal = 0x2; // This flag is not used
46+
// Some libcs define __FE_DENORM corresponding to the denormal input
47+
// exception and include it in FE_ALL_EXCEPTS. We define and use it to
48+
// support compiling against headers provided by such libcs.
49+
static constexpr uint16_t Denormal = 0x2;
4750
static constexpr uint16_t DivByZero = 0x4;
4851
static constexpr uint16_t Overflow = 0x8;
4952
static constexpr uint16_t Underflow = 0x10;
@@ -62,6 +65,9 @@ static inline uint16_t getStatusValueForExcept(int excepts) {
6265
// We will make use of the fact that exception control bits are single
6366
// bit flags in the control registers.
6467
return (excepts & FE_INVALID ? ExceptionFlags::Invalid : 0) |
68+
#ifdef __FE_DENORM
69+
(excepts & __FE_DENORM ? ExceptionFalgs::Denormal : 0) |
70+
#endif // __FE_DENORM
6571
(excepts & FE_DIVBYZERO ? ExceptionFlags::DivByZero : 0) |
6672
(excepts & FE_OVERFLOW ? ExceptionFlags::Overflow : 0) |
6773
(excepts & FE_UNDERFLOW ? ExceptionFlags::Underflow : 0) |
@@ -70,6 +76,9 @@ static inline uint16_t getStatusValueForExcept(int excepts) {
7076

7177
static inline int exceptionStatusToMacro(uint16_t status) {
7278
return (status & ExceptionFlags::Invalid ? FE_INVALID : 0) |
79+
#ifdef __FE_DENORM
80+
(status & ExceptionFalgs::Denormal ? __FE_DENORM : 0) |
81+
#endif // __FE_DENORM
7382
(status & ExceptionFlags::DivByZero ? FE_DIVBYZERO : 0) |
7483
(status & ExceptionFlags::Overflow ? FE_OVERFLOW : 0) |
7584
(status & ExceptionFlags::Underflow ? FE_UNDERFLOW : 0) |

0 commit comments

Comments
 (0)