[llvm-commits] [llvm] r42733 - in /llvm/trunk: include/llvm/ADT/APFloat.h lib/Support/APFloat.cpp
Neil Booth
neil at daikokuya.co.uk
Sun Oct 7 05:07:54 PDT 2007
Author: neil
Date: Sun Oct 7 07:07:53 2007
New Revision: 42733
URL: http://llvm.org/viewvc/llvm-project?rev=42733&view=rev
Log:
Reimplement convertFromUnsignedInteger so it is passed a const bignum.
It used to modify its argument in-place.
This interface is saner and the implementation more efficient. It will
be needed for decimal->binary 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=42733&r1=42732&r2=42733&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APFloat.h (original)
+++ llvm/trunk/include/llvm/ADT/APFloat.h Sun Oct 7 07:07:53 2007
@@ -266,8 +266,8 @@
cmpResult compareAbsoluteValue(const APFloat &) const;
opStatus handleOverflow(roundingMode);
bool roundAwayFromZero(roundingMode, lostFraction, unsigned int) const;
- opStatus convertFromUnsignedInteger(integerPart *, unsigned int,
- roundingMode);
+ opStatus convertFromUnsignedParts(const integerPart *, unsigned int,
+ roundingMode);
opStatus convertFromHexadecimalString(const char *, roundingMode);
char *convertNormalToHexString(char *, unsigned int, bool,
roundingMode) const;
Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=42733&r1=42732&r2=42733&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Sun Oct 7 07:07:53 2007
@@ -1548,30 +1548,41 @@
return opInexact;
}
+/* Convert an unsigned integer SRC to a floating point number,
+ rounding according to ROUNDING_MODE. The sign of the floating
+ point number is not modified. */
APFloat::opStatus
-APFloat::convertFromUnsignedInteger(integerPart *parts,
- unsigned int partCount,
- roundingMode rounding_mode)
+APFloat::convertFromUnsignedParts(const integerPart *src,
+ unsigned int srcCount,
+ roundingMode rounding_mode)
{
- unsigned int msb, precision;
+ unsigned int dstCount;
lostFraction lost_fraction;
-
- msb = APInt::tcMSB(parts, partCount) + 1;
- precision = semantics->precision;
+ integerPart *dst;
category = fcNormal;
- exponent = precision - 1;
+ exponent = semantics->precision - 1;
- if(msb > precision) {
- exponent += (msb - precision);
- lost_fraction = shiftRight(parts, partCount, msb - precision);
- msb = precision;
- } else
- lost_fraction = lfExactlyZero;
+ dst = significandParts();
+ dstCount = partCount();
- /* Copy the bit image. */
- zeroSignificand();
- APInt::tcAssign(significandParts(), parts, partCountForBits(msb));
+ /* We need to capture the non-zero most significant parts. */
+ while (srcCount > dstCount && src[srcCount - 1] == 0)
+ srcCount--;
+
+ /* Copy the bit image of as many parts as we can. If we are wider,
+ zero-out remaining parts. */
+ if (dstCount >= srcCount) {
+ APInt::tcAssign(dst, src, srcCount);
+ while (srcCount < dstCount)
+ dst[srcCount++] = 0;
+ lost_fraction = lfExactlyZero;
+ } else {
+ exponent += (srcCount - dstCount) * integerPartWidth;
+ APInt::tcAssign(dst, src + (srcCount - dstCount), dstCount);
+ lost_fraction = lostFractionThroughTruncation(src, srcCount,
+ dstCount * integerPartWidth);
+ }
return normalize(rounding_mode, lost_fraction);
}
@@ -1594,7 +1605,7 @@
}
APInt::tcAssign(copy, api.getRawData(), partCount);
- status = convertFromUnsignedInteger(copy, partCount, rounding_mode);
+ status = convertFromUnsignedParts(copy, partCount, rounding_mode);
return status;
}
More information about the llvm-commits
mailing list