[libc-commits] [PATCH] D95637: [libc] Set the ES bit when raising FP exceptions on x86

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Jan 28 13:11:10 PST 2021


michaelrj updated this revision to Diff 319946.
michaelrj marked 2 inline comments as done.
michaelrj edited the summary of this revision.
michaelrj added a comment.

documentation changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95637/new/

https://reviews.llvm.org/D95637

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
@@ -48,6 +48,8 @@
   static constexpr uint16_t Inexact = 0x20;
 };
 
+static constexpr uint16_t ExceptionSummaryStatusBit = 0x80;
+
 // The exception control bits occupy six bits, one bit for each exception.
 // In the x87 control word, they occupy the first 6 bits. In the MXCSR
 // register, they occupy bits 7 to 12.
@@ -194,6 +196,14 @@
       (statusValue & internal::getMXCSR()));
 }
 
+// This function returns a bitmap of which exceptions selected are enabled.
+static inline int isEnabled(int excepts) {
+  uint16_t x87CW = internal::getX87ControlWord();
+  return excepts & (~x87CW);
+  // The exceptions are enabled if the bit is zero (unmasked),
+  // so that is why the negation before the & operation.
+}
+
 static inline int raiseExcept(int excepts) {
   uint16_t statusValue = internal::getStatusValueForExcept(excepts);
 
@@ -214,6 +224,9 @@
     internal::X87State state;
     internal::getX87State(state);
     state.StatusWord |= internal::ExceptionFlags::Invalid;
+    if (isEnabled(internal::ExceptionFlags::Invalid)) {
+      state.StatusWord |= internal::ExceptionSummaryStatusBit;
+    }
     internal::writeX87State(state);
     internal::fwait();
   }
@@ -221,6 +234,9 @@
     internal::X87State state;
     internal::getX87State(state);
     state.StatusWord |= internal::ExceptionFlags::DivByZero;
+    if (isEnabled(internal::ExceptionFlags::DivByZero)) {
+      state.StatusWord |= internal::ExceptionSummaryStatusBit;
+    }
     internal::writeX87State(state);
     internal::fwait();
   }
@@ -228,6 +244,9 @@
     internal::X87State state;
     internal::getX87State(state);
     state.StatusWord |= internal::ExceptionFlags::Overflow;
+    if (isEnabled(internal::ExceptionFlags::Overflow)) {
+      state.StatusWord |= internal::ExceptionSummaryStatusBit;
+    }
     internal::writeX87State(state);
     internal::fwait();
   }
@@ -235,6 +254,9 @@
     internal::X87State state;
     internal::getX87State(state);
     state.StatusWord |= internal::ExceptionFlags::Underflow;
+    if (isEnabled(internal::ExceptionFlags::Underflow)) {
+      state.StatusWord |= internal::ExceptionSummaryStatusBit;
+    }
     internal::writeX87State(state);
     internal::fwait();
   }
@@ -242,6 +264,9 @@
     internal::X87State state;
     internal::getX87State(state);
     state.StatusWord |= internal::ExceptionFlags::Inexact;
+    if (isEnabled(internal::ExceptionFlags::Inexact)) {
+      state.StatusWord |= internal::ExceptionSummaryStatusBit;
+    }
     internal::writeX87State(state);
     internal::fwait();
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95637.319946.patch
Type: text/x-patch
Size: 2728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210128/0fceec45/attachment.bin>


More information about the libc-commits mailing list