aboutsummaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2007-09-21 22:09:37 +0000
committerDale Johannesen <dalej@apple.com>2007-09-21 22:09:37 +0000
commit910993e8dc49a25d9da3b53de4a82568c14e91cc (patch)
tree3dbc8815c0b1b48e3bdaf73a2b46004c3827bbcf /lib/Support
parent3f65f02d25b920c3cef4dd8a8fc8fc76cad1236e (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42210 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/APFloat.cpp35
-rw-r--r--lib/Support/APInt.cpp2
2 files changed, 20 insertions, 17 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp
index d3147426cb..1fab6cae47 100644
--- a/lib/Support/APFloat.cpp
+++ b/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;
}
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp
index 4a4474dbe7..63bde6c426 100644
--- a/lib/Support/APInt.cpp
+++ b/lib/Support/APInt.cpp
@@ -58,7 +58,7 @@ APInt::APInt(uint32_t numBits, uint64_t val, bool isSigned)
clearUnusedBits();
}
-APInt::APInt(uint32_t numBits, uint32_t numWords, uint64_t bigVal[])
+APInt::APInt(uint32_t numBits, uint32_t numWords, const uint64_t bigVal[])
: BitWidth(numBits), VAL(0) {
assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");