[libc-commits] [libc] 230df8a - [libc] Allow reading and writing __FE_DENORM if available on x86_64.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Wed Jun 30 10:32:32 PDT 2021
Author: Siva Chandra Reddy
Date: 2021-06-30T17:32:24Z
New Revision: 230df8a419f244827895ffe5b6db298a209b741a
URL: https://github.com/llvm/llvm-project/commit/230df8a419f244827895ffe5b6db298a209b741a
DIFF: https://github.com/llvm/llvm-project/commit/230df8a419f244827895ffe5b6db298a209b741a.diff
LOG: [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
Added:
Modified:
libc/utils/FPUtil/x86_64/FEnv.h
Removed:
################################################################################
diff --git a/libc/utils/FPUtil/x86_64/FEnv.h b/libc/utils/FPUtil/x86_64/FEnv.h
index cd11c388f41f4..47e9dce7508e1 100644
--- a/libc/utils/FPUtil/x86_64/FEnv.h
+++ b/libc/utils/FPUtil/x86_64/FEnv.h
@@ -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;
@@ -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) |
@@ -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) |
More information about the libc-commits
mailing list