[libc-commits] [PATCH] D105004: [libc] Allow reading and writing __FE_DENORM if available on x86_64.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Jun 28 00:37:42 PDT 2021


sivachandra created this revision.
sivachandra added a reviewer: lntue.
Herald added subscribers: libc-commits, ecnelises, tschuett, pengfei.
Herald added a project: libc-project.
sivachandra requested review of this revision.

Some libcs define __FE_DENORM on x86_64. This change allows reading the
bits corresponding to that non-standard exception.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105004

Files:
  libc/utils/FPUtil/x86_64/FEnv.h


Index: libc/utils/FPUtil/x86_64/FEnv.h
===================================================================
--- libc/utils/FPUtil/x86_64/FEnv.h
+++ 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) |


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105004.354798.patch
Type: text/x-patch
Size: 1748 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210628/119e75a5/attachment.bin>


More information about the libc-commits mailing list