aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.co.uk>2007-10-08 14:39:42 +0000
committerNeil Booth <neil@daikokuya.co.uk>2007-10-08 14:39:42 +0000
commitbfa82b54224322c5ddf42b5f78b432f6ae2eca2a (patch)
tree3fc6dfe2b3aa8e41ec40c2b892b44070037616ec /lib
parenta0f524ae0c66af6bf502c3292db1271c76c3a007 (diff)
downloadexternal_llvm-bfa82b54224322c5ddf42b5f78b432f6ae2eca2a.zip
external_llvm-bfa82b54224322c5ddf42b5f78b432f6ae2eca2a.tar.gz
external_llvm-bfa82b54224322c5ddf42b5f78b432f6ae2eca2a.tar.bz2
Use APInt::tcExtract. It's cleaner, and works :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42746 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Support/APFloat.cpp33
1 files changed, 14 insertions, 19 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp
index 388bbd7..d05c24e 100644
--- a/lib/Support/APFloat.cpp
+++ b/lib/Support/APFloat.cpp
@@ -1556,32 +1556,27 @@ APFloat::convertFromUnsignedParts(const integerPart *src,
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);