Change APFloat::convertFromInteger to take the incoming
authorDale Johannesen <dalej@apple.com>
Fri, 21 Sep 2007 22:09:37 +0000 (22:09 +0000)
committerDale Johannesen <dalej@apple.com>
Fri, 21 Sep 2007 22:09:37 +0000 (22:09 +0000)
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

include/llvm/ADT/APInt.h
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/ExecutionEngine/ExecutionEngine.cpp
lib/Support/APFloat.cpp
lib/Support/APInt.cpp

index 97fe4e9201a8e43498d6e4432340db65abf7e133..01b49d0864fb89b1e230c35283f82da751293448 100644 (file)
@@ -172,7 +172,7 @@ public:
   /// @param numWords the number of words in bigVal
   /// @param bigVal a sequence of words to form the initial value of the APInt
   /// @brief Construct an APInt of numBits width, initialized as bigVal[].
-  APInt(uint32_t numBits, uint32_t numWords, uint64_t bigVal[]);
+  APInt(uint32_t numBits, uint32_t numWords, const uint64_t bigVal[]);
 
   /// This constructor interprets Val as a string in the given radix. The 
   /// interpretation stops when the first charater that is not suitable for the
index 34fca4d6239f932a4620e95d2d51527be1721f95..340125e761c3483367b4e9f01233800753abdd48 100644 (file)
@@ -3215,7 +3215,8 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
           const uint64_t zero[] = {0, 0};
           APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero));
           uint64_t x = 1ULL << ShiftAmt;
-          (void)apf.convertFromInteger(&x, 1, false, APFloat::rmTowardZero);
+          (void)apf.convertFromInteger(&x, MVT::getSizeInBits(NVT), false, 
+                                       APFloat::rmTowardZero);
           Tmp2 = DAG.getConstantFP(apf, VT);
           Tmp3 = DAG.getSetCC(TLI.getSetCCResultTy(),
                             Node->getOperand(0), Tmp2, ISD::SETLT);
index 92c0f2445bcb2c5bd55cec05f892573301671df8..042868d7bb1ff8390112bb2056b3fd4e8a365415 100644 (file)
@@ -1595,8 +1595,10 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     case ISD::SINT_TO_FP: {
       const uint64_t zero[] = {0, 0};
       APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero));
-      (void)apf.convertFromInteger(&Val, 1, Opcode==ISD::SINT_TO_FP,
-                                  APFloat::rmTowardZero);
+      (void)apf.convertFromInteger(&Val, 
+                               MVT::getSizeInBits(Operand.getValueType()), 
+                               Opcode==ISD::SINT_TO_FP,
+                               APFloat::rmTowardZero);
       return getConstantFP(apf, VT);
     }
     case ISD::BIT_CONVERT:
index afff142f9f5b6d27c072c243c426e4d508366fa8..c72663e0d4d436414bfbc9aff8dd12ed22a5865f 100644 (file)
@@ -393,10 +393,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
         GV.FloatVal = float(GV.IntVal.roundToDouble());
       else if (CE->getType() == Type::DoubleTy)
         GV.DoubleVal = GV.IntVal.roundToDouble();
-       else if (CE->getType() == Type::X86_FP80Ty) {
+      else if (CE->getType() == Type::X86_FP80Ty) {
         const uint64_t zero[] = {0, 0};
         APFloat apf = APFloat(APInt(80, 2, zero));
-        (void)apf.convertFromInteger(GV.IntVal.getRawData(), 2, false, 
+        (void)apf.convertFromInteger(GV.IntVal.getRawData(), 
+                               GV.IntVal.getBitWidth(), false,
                                APFloat::rmTowardZero);
         GV.IntVal = apf.convertToAPInt();
       }
@@ -411,7 +412,8 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
       else if (CE->getType() == Type::X86_FP80Ty) {
         const uint64_t zero[] = { 0, 0};
         APFloat apf = APFloat(APInt(80, 2, zero));
-        (void)apf.convertFromInteger(GV.IntVal.getRawData(), 2, true,
+        (void)apf.convertFromInteger(GV.IntVal.getRawData(), 
+                               GV.IntVal.getBitWidth(), true,
                                APFloat::rmTowardZero);
         GV.IntVal = apf.convertToAPInt();
       }
index d3147426cb4cdace02ccf85cd7a8a72e61735fd0..1fab6cae47e8039c431b8f7675c58e06083f3fcb 100644 (file)
@@ -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;
 }
 
index 4a4474dbe7e98a2936373e068e4197c36d3d38ee..63bde6c426274aeb1808b5e826caa8022eaa53b8 100644 (file)
@@ -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");