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

Neil Booth neil at daikokuya.co.uk
Wed Oct 3 08:16:42 PDT 2007


Author: neil
Date: Wed Oct  3 10:16:41 2007
New Revision: 42576

URL: http://llvm.org/viewvc/llvm-project?rev=42576&view=rev
Log:
Tweak RoundAwayFromZero the bit number below which is truncated, and make
it const.

Preparation for APFloat -> hexadecimal string conversion.

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=42576&r1=42575&r2=42576&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/APFloat.h (original)
+++ llvm/trunk/include/llvm/ADT/APFloat.h Wed Oct  3 10:16:41 2007
@@ -253,7 +253,7 @@
     opStatus addOrSubtract(const APFloat &, roundingMode, bool subtract);
     cmpResult compareAbsoluteValue(const APFloat &) const;
     opStatus handleOverflow(roundingMode);
-    bool roundAwayFromZero(roundingMode, lostFraction);
+    bool roundAwayFromZero(roundingMode, lostFraction, unsigned int) const;
     opStatus convertFromUnsignedInteger(integerPart *, unsigned int,
 					roundingMode);
     lostFraction combineLostFractions(lostFraction, lostFraction);

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

==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Wed Oct  3 10:16:41 2007
@@ -184,7 +184,8 @@
       return digitValue == 0 ? lfLessThanHalf: lfMoreThanHalf;
   }
 
-  /* Return the fraction lost were a bignum truncated.  */
+  /* Return the fraction lost were a bignum truncated losing the least
+     significant BITS bits.  */
   lostFraction
   lostFractionThroughTruncation(integerPart *parts,
                                 unsigned int partCount,
@@ -694,16 +695,20 @@
   return opInexact;
 }
 
-/* This routine must work for fcZero of both signs, and fcNormal
-   numbers.  */
+/* Returns TRUE if, when truncating the current number, with BIT the
+   new LSB, with the given lost fraction and rounding mode, the result
+   would need to be rounded away from zero (i.e., by increasing the
+   signficand).  This routine must work for fcZero of both signs, and
+   fcNormal numbers.  */
 bool
 APFloat::roundAwayFromZero(roundingMode rounding_mode,
-                           lostFraction lost_fraction)
+                           lostFraction lost_fraction,
+                           unsigned int bit) const
 {
   /* NaNs and infinities should not have lost fractions.  */
   assert(category == fcNormal || category == fcZero);
 
-  /* Our caller has already handled this case.  */
+  /* Current callers never pass this so we don't handle it.  */
   assert(lost_fraction != lfExactlyZero);
 
   switch(rounding_mode) {
@@ -719,7 +724,7 @@
 
     /* Our zeroes don't have a significand to test.  */
     if(lost_fraction == lfExactlyHalf && category != fcZero)
-      return significandParts()[0] & 1;
+      return APInt::tcExtractBit(significandParts(), bit);
 
     return false;
 
@@ -802,7 +807,7 @@
   }
 
   /* Increment the significand if we're rounding away from zero.  */
-  if(roundAwayFromZero(rounding_mode, lost_fraction)) {
+  if(roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
     if(omsb == 0)
       exponent = semantics->minExponent;
 
@@ -1451,7 +1456,7 @@
   }
 
   if(lost_fraction != lfExactlyZero
-     && tmp.roundAwayFromZero(rounding_mode, lost_fraction))
+     && tmp.roundAwayFromZero(rounding_mode, lost_fraction, 0))
     tmp.incrementSignificand();
 
   msb = tmp.significandMSB();





More information about the llvm-commits mailing list