[llvm-commits] [llvm] r42746 - /llvm/trunk/lib/Support/APFloat.cpp
Neil Booth
neil at daikokuya.co.uk
Mon Oct 8 07:39:42 PDT 2007
Author: neil
Date: Mon Oct 8 09:39:42 2007
New Revision: 42746
URL: http://llvm.org/viewvc/llvm-project?rev=42746&view=rev
Log:
Use APInt::tcExtract. It's cleaner, and works :)
Modified:
llvm/trunk/lib/Support/APFloat.cpp
Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=42746&r1=42745&r2=42746&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Mon Oct 8 09:39:42 2007
@@ -1556,32 +1556,27 @@
unsigned int srcCount,
roundingMode rounding_mode)
{
- unsigned int dstCount;
- lostFraction lost_fraction;
+ unsigned int omsb, precision, dstCount;
integerPart *dst;
+ lostFraction lost_fraction;
category = fcNormal;
- exponent = semantics->precision - 1;
-
+ omsb = APInt::tcMSB(src, srcCount) + 1;
dst = significandParts();
dstCount = partCount();
+ precision = semantics->precision;
- /* 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);
+ /* We want the most significant PRECISON bits of SRC. There may not
+ be that many; extract what we can. */
+ if (precision <= omsb) {
+ exponent = omsb - 1;
lost_fraction = lostFractionThroughTruncation(src, srcCount,
- dstCount * integerPartWidth);
+ omsb - precision);
+ APInt::tcExtract(dst, dstCount, src, precision, omsb - precision);
+ } else {
+ exponent = precision - 1;
+ lost_fraction = lfExactlyZero;
+ APInt::tcExtract(dst, dstCount, src, omsb, 0);
}
return normalize(rounding_mode, lost_fraction);
More information about the llvm-commits
mailing list