[llvm-commits] [llvm] r72606 - in /llvm/trunk: include/llvm/ADT/APFloat.h lib/Support/APFloat.cpp

Mike Stump mrs at apple.com
Fri May 29 20:49:45 PDT 2009


Author: mrs
Date: Fri May 29 22:49:43 2009
New Revision: 72606

URL: http://llvm.org/viewvc/llvm-project?rev=72606&view=rev
Log:
Add support for letting the client choose different flavors of NaNs.  Testcase to be
added in clang.

Modified:
    llvm/trunk/include/llvm/ADT/APFloat.h
    llvm/trunk/lib/Support/APFloat.cpp

Modified: llvm/trunk/include/llvm/ADT/APFloat.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APFloat.h?rev=72606&r1=72605&r2=72606&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/APFloat.h (original)
+++ llvm/trunk/include/llvm/ADT/APFloat.h Fri May 29 22:49:43 2009
@@ -174,7 +174,7 @@
     // Constructors.
     APFloat(const fltSemantics &, const char *);
     APFloat(const fltSemantics &, integerPart);
-    APFloat(const fltSemantics &, fltCategory, bool negative);
+    APFloat(const fltSemantics &, fltCategory, bool negative, unsigned type=0);
     explicit APFloat(double d);
     explicit APFloat(float f);
     explicit APFloat(const APInt &, bool isIEEE = false);
@@ -188,8 +188,9 @@
     static APFloat getInf(const fltSemantics &Sem, bool Negative = false) {
       return APFloat(Sem, fcInfinity, Negative);
     }
-    static APFloat getNaN(const fltSemantics &Sem, bool Negative = false) {
-      return APFloat(Sem, fcNaN, Negative);
+    static APFloat getNaN(const fltSemantics &Sem, bool Negative = false,
+                          long unsigned type=0) {
+      return APFloat(Sem, fcNaN, Negative, type);
     }
 
     /// Profile - Used to insert APFloat objects, or objects that contain
@@ -296,7 +297,7 @@
     opStatus modSpecials(const APFloat &);
 
     /* Miscellany.  */
-    void makeNaN(void);
+    void makeNaN(unsigned = 0);
     opStatus normalize(roundingMode, lostFraction);
     opStatus addOrSubtract(const APFloat &, roundingMode, bool subtract);
     cmpResult compareAbsoluteValue(const APFloat &) const;

Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=72606&r1=72605&r2=72606&view=diff

==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Fri May 29 22:49:43 2009
@@ -598,12 +598,18 @@
 
 /* Make this number a NaN, with an arbitrary but deterministic value
    for the significand.  If double or longer, this is a signalling NaN,
-   which may not be ideal. */
+   which may not be ideal.  If float, this is QNaN(0).  */
 void
-APFloat::makeNaN(void)
+APFloat::makeNaN(unsigned type)
 {
   category = fcNaN;
-  APInt::tcSet(significandParts(), ~0U, partCount());
+  // FIXME: Add double and long double support for QNaN(0).
+  if (semantics->precision == 24 && semantics->maxExponent == 127) {
+    type |=  0x7fc00000U;
+    type &= ~0x80000000U;
+  } else
+    type = ~0U;
+  APInt::tcSet(significandParts(), type, partCount());
 }
 
 APFloat &
@@ -662,16 +668,16 @@
 }
 
 APFloat::APFloat(const fltSemantics &ourSemantics,
-                 fltCategory ourCategory, bool negative)
+                 fltCategory ourCategory, bool negative, unsigned type)
 {
   assertArithmeticOK(ourSemantics);
   initialize(&ourSemantics);
   category = ourCategory;
   sign = negative;
-  if(category == fcNormal)
+  if (category == fcNormal)
     category = fcZero;
   else if (ourCategory == fcNaN)
-    makeNaN();
+    makeNaN(type);
 }
 
 APFloat::APFloat(const fltSemantics &ourSemantics, const char *text)





More information about the llvm-commits mailing list