diff options
author | Dale Johannesen <dalej@apple.com> | 2007-09-21 22:09:37 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2007-09-21 22:09:37 +0000 |
commit | 4230512f32759410b2fcf8bef1037d6c3b4ecad6 (patch) | |
tree | 41a70987c8e1c8169b9b795b985a7e3665739e37 /llvm/lib/Support/APFloat.cpp | |
parent | 361e52f39ca714f88f2509b21eede156f954bad0 (diff) | |
download | bcm5719-llvm-4230512f32759410b2fcf8bef1037d6c3b4ecad6.tar.gz bcm5719-llvm-4230512f32759410b2fcf8bef1037d6c3b4ecad6.zip |
Change APFloat::convertFromInteger to take the incoming
bit width instead of number of words allocated, which
makes it actually work for int->APF conversions.
Adjust callers. Add const to one of the APInt constructors
to prevent surprising match when called with const
argument.
llvm-svn: 42210
Diffstat (limited to 'llvm/lib/Support/APFloat.cpp')
-rw-r--r-- | llvm/lib/Support/APFloat.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp index d3147426cb4..1fab6cae47e 100644 --- a/llvm/lib/Support/APFloat.cpp +++ b/llvm/lib/Support/APFloat.cpp @@ -1180,7 +1180,8 @@ APFloat::mod(const APFloat &rhs, roundingMode rounding_mode) if (fs==opInvalidOp) return fs; - fs = V.convertFromInteger(x, parts, true, rmNearestTiesToEven); + fs = V.convertFromInteger(x, parts * integerPartWidth, true, + rmNearestTiesToEven); assert(fs==opOK); // should always work fs = V.multiply(rhs, rounding_mode); @@ -1459,28 +1460,30 @@ APFloat::convertFromUnsignedInteger(integerPart *parts, } APFloat::opStatus -APFloat::convertFromInteger(const integerPart *parts, - unsigned int partCount, bool isSigned, - roundingMode rounding_mode) +APFloat::convertFromInteger(const integerPart *parts, unsigned int width, + bool isSigned, roundingMode rounding_mode) { - unsigned int width; + unsigned int partCount = partCountForBits(width); opStatus status; - integerPart *copy; - - copy = new integerPart[partCount]; - APInt::tcAssign(copy, parts, partCount); - - width = partCount * integerPartWidth; + APInt api = APInt(width, partCount, parts); + integerPart *copy = new integerPart[partCount]; sign = false; - if(isSigned && APInt::tcExtractBit(parts, width - 1)) { - sign = true; - APInt::tcNegate(copy, partCount); + if(isSigned) { + if (APInt::tcExtractBit(parts, width - 1)) { + sign = true; + if (width < partCount * integerPartWidth) + api = api.sext(partCount * integerPartWidth); + } + else if (width < partCount * integerPartWidth) + api = api.zext(partCount * integerPartWidth); + } else { + if (width < partCount * integerPartWidth) + api = api.zext(partCount * integerPartWidth); } + APInt::tcAssign(copy, api.getRawData(), partCount); status = convertFromUnsignedInteger(copy, partCount, rounding_mode); - delete [] copy; - return status; } |