Index: include/llvm/ADT/APInt.h =================================================================== --- include/llvm/ADT/APInt.h +++ include/llvm/ADT/APInt.h @@ -82,7 +82,7 @@ union { uint64_t VAL; ///< Used to store the <= 64 bits integer value. uint64_t *pVal; ///< Used to store the >64 bits integer value. - }; + } U; /// This enum is used to hold the constants we needed for APInt. enum { @@ -99,7 +99,9 @@ /// /// This constructor is used only internally for speed of construction of /// temporaries. It is unsafe for general use so it is not public. - APInt(uint64_t *val, unsigned bits) : BitWidth(bits), pVal(val) {} + APInt(uint64_t *val, unsigned bits) : BitWidth(bits) { + U.pVal = val; + } /// \brief Determine if this APInt just has one word to store value. /// @@ -149,16 +151,16 @@ // Mask out the high bits. uint64_t mask = UINT64_MAX >> (APINT_BITS_PER_WORD - wordBits); if (isSingleWord()) - VAL &= mask; + U.VAL &= mask; else - pVal[getNumWords() - 1] &= mask; + U.pVal[getNumWords() - 1] &= mask; return *this; } /// \brief Get the word corresponding to a bit position /// \returns the corresponding word for the specified bit position. uint64_t getWord(unsigned bitPosition) const { - return isSingleWord() ? VAL : pVal[whichWord(bitPosition)]; + return isSingleWord() ? U.VAL : U.pVal[whichWord(bitPosition)]; } /// \brief Convert a char array into an APInt @@ -238,10 +240,10 @@ /// \param val the initial value of the APInt /// \param isSigned how to treat signedness of val APInt(unsigned numBits, uint64_t val, bool isSigned = false) - : BitWidth(numBits), VAL(0) { + : BitWidth(numBits) { assert(BitWidth && "bitwidth too small"); if (isSingleWord()) { - VAL = val; + U.VAL = val; clearUnusedBits(); } else { initSlowCase(val, isSigned); @@ -281,22 +283,23 @@ /// Simply makes *this a copy of that. /// @brief Copy Constructor. - APInt(const APInt &that) : BitWidth(that.BitWidth), VAL(0) { + APInt(const APInt &that) : BitWidth(that.BitWidth) { if (isSingleWord()) - VAL = that.VAL; + U.VAL = that.U.VAL; else initSlowCase(that); } /// \brief Move Constructor. - APInt(APInt &&that) : BitWidth(that.BitWidth), VAL(that.VAL) { + APInt(APInt &&that) : BitWidth(that.BitWidth) { + memcpy(&U, &that.U, sizeof(U)); that.BitWidth = 0; } /// \brief Destructor. ~APInt() { if (needsCleanup()) - delete[] pVal; + delete[] U.pVal; } /// \brief Default constructor that creates an uninteresting APInt @@ -304,7 +307,7 @@ /// /// This is useful for object deserialization (pair this with the static /// method Read). - explicit APInt() : BitWidth(1), VAL(0) {} + explicit APInt() : BitWidth(1) { U.VAL = 0; } /// \brief Returns whether this instance allocated memory. bool needsCleanup() const { return !isSingleWord(); } @@ -342,7 +345,7 @@ /// This checks to see if the value has all bits of the APInt are set or not. bool isAllOnesValue() const { if (isSingleWord()) - return VAL == UINT64_MAX >> (APINT_BITS_PER_WORD - BitWidth); + return U.VAL == UINT64_MAX >> (APINT_BITS_PER_WORD - BitWidth); return countPopulationSlowCase() == BitWidth; } @@ -391,7 +394,7 @@ /// \returns true if the argument APInt value is a power of two > 0. bool isPowerOf2() const { if (isSingleWord()) - return isPowerOf2_64(VAL); + return isPowerOf2_64(U.VAL); return countPopulationSlowCase() == 1; } @@ -576,8 +579,8 @@ /// conversions. const uint64_t *getRawData() const { if (isSingleWord()) - return &VAL; - return &pVal[0]; + return &U.VAL; + return &U.pVal[0]; } /// @} @@ -630,10 +633,10 @@ /// \returns true if *this is zero, false otherwise. bool operator!() const { if (isSingleWord()) - return !VAL; + return !U.VAL; for (unsigned i = 0; i != getNumWords(); ++i) - if (pVal[i]) + if (U.pVal[i]) return false; return true; } @@ -648,7 +651,7 @@ APInt &operator=(const APInt &RHS) { // If the bitwidths are the same, we can avoid mucking with memory if (isSingleWord() && RHS.isSingleWord()) { - VAL = RHS.VAL; + U.VAL = RHS.U.VAL; BitWidth = RHS.BitWidth; return clearUnusedBits(); } @@ -664,12 +667,12 @@ // where half of the output is left in a moved-from state. if (this == &that) return *this; - delete[] pVal; + delete[] U.pVal; } // Use memcpy so that type based alias analysis sees both VAL and pVal // as modified. - memcpy(&VAL, &that.VAL, sizeof(uint64_t)); + memcpy(&U, &that.U, sizeof(U)); // If 'this == &that', avoid zeroing our own bitwidth by storing to 'that' // first. @@ -719,10 +722,10 @@ /// the LHS. APInt &operator|=(uint64_t RHS) { if (isSingleWord()) { - VAL |= RHS; + U.VAL |= RHS; clearUnusedBits(); } else { - pVal[0] |= RHS; + U.pVal[0] |= RHS; } return *this; } @@ -742,10 +745,10 @@ /// the LHS. APInt &operator^=(uint64_t RHS) { if (isSingleWord()) { - VAL ^= RHS; + U.VAL ^= RHS; clearUnusedBits(); } else { - pVal[0] ^= RHS; + U.pVal[0] ^= RHS; } return *this; } @@ -795,7 +798,7 @@ APInt operator&(const APInt &RHS) const { assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); if (isSingleWord()) - return APInt(getBitWidth(), VAL & RHS.VAL); + return APInt(getBitWidth(), U.VAL & RHS.U.VAL); return AndSlowCase(RHS); } @@ -807,7 +810,7 @@ APInt operator|(const APInt &RHS) const { assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); if (isSingleWord()) - return APInt(getBitWidth(), VAL | RHS.VAL); + return APInt(getBitWidth(), U.VAL | RHS.U.VAL); return OrSlowCase(RHS); } @@ -819,7 +822,7 @@ APInt operator^(const APInt &RHS) const { assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); if (isSingleWord()) - return APInt(BitWidth, VAL ^ RHS.VAL); + return APInt(BitWidth, U.VAL ^ RHS.U.VAL); return XorSlowCase(RHS); } @@ -856,7 +859,7 @@ if (isSingleWord()) { if (shiftAmt >= BitWidth) return APInt(BitWidth, 0); // avoid undefined shift results - return APInt(BitWidth, VAL << shiftAmt); + return APInt(BitWidth, U.VAL << shiftAmt); } return shlSlowCase(shiftAmt); } @@ -947,7 +950,7 @@ bool operator[](unsigned bitPosition) const { assert(bitPosition < getBitWidth() && "Bit position out of bounds!"); return (maskBit(bitPosition) & - (isSingleWord() ? VAL : pVal[whichWord(bitPosition)])) != + (isSingleWord() ? U.VAL : U.pVal[whichWord(bitPosition)])) != 0; } @@ -962,7 +965,7 @@ bool operator==(const APInt &RHS) const { assert(BitWidth == RHS.BitWidth && "Comparison requires equal bit widths"); if (isSingleWord()) - return VAL == RHS.VAL; + return U.VAL == RHS.U.VAL; return EqualSlowCase(RHS); } @@ -974,7 +977,7 @@ /// \returns true if *this == Val bool operator==(uint64_t Val) const { if (isSingleWord()) - return VAL == Val; + return U.VAL == Val; return EqualSlowCase(Val); } @@ -1206,11 +1209,11 @@ /// \brief Set every bit to 1. void setAllBits() { if (isSingleWord()) - VAL = UINT64_MAX; + U.VAL = UINT64_MAX; else { // Set all the bits in all the words. for (unsigned i = 0; i < getNumWords(); ++i) - pVal[i] = UINT64_MAX; + U.pVal[i] = UINT64_MAX; } // Clear the unused ones clearUnusedBits(); @@ -1227,9 +1230,9 @@ /// \brief Set every bit to 0. void clearAllBits() { if (isSingleWord()) - VAL = 0; + U.VAL = 0; else - memset(pVal, 0, getNumWords() * APINT_WORD_SIZE); + memset(U.pVal, 0, getNumWords() * APINT_WORD_SIZE); } /// \brief Set a given bit to 0. @@ -1240,10 +1243,10 @@ /// \brief Toggle every bit to its opposite value. void flipAllBits() { if (isSingleWord()) - VAL ^= UINT64_MAX; + U.VAL ^= UINT64_MAX; else { for (unsigned i = 0; i < getNumWords(); ++i) - pVal[i] ^= UINT64_MAX; + U.pVal[i] ^= UINT64_MAX; } clearUnusedBits(); } @@ -1318,9 +1321,9 @@ /// uint64_t. Otherwise an assertion will result. uint64_t getZExtValue() const { if (isSingleWord()) - return VAL; + return U.VAL; assert(getActiveBits() <= 64 && "Too many bits for uint64_t"); - return pVal[0]; + return U.pVal[0]; } /// \brief Get sign extended value @@ -1330,10 +1333,10 @@ /// int64_t. Otherwise an assertion will result. int64_t getSExtValue() const { if (isSingleWord()) - return int64_t(VAL << (APINT_BITS_PER_WORD - BitWidth)) >> + return int64_t(U.VAL << (APINT_BITS_PER_WORD - BitWidth)) >> (APINT_BITS_PER_WORD - BitWidth); assert(getMinSignedBits() <= 64 && "Too many bits for int64_t"); - return int64_t(pVal[0]); + return int64_t(U.pVal[0]); } /// \brief Get bits required for string value. @@ -1353,7 +1356,7 @@ unsigned countLeadingZeros() const { if (isSingleWord()) { unsigned unusedBits = APINT_BITS_PER_WORD - BitWidth; - return llvm::countLeadingZeros(VAL) - unusedBits; + return llvm::countLeadingZeros(U.VAL) - unusedBits; } return countLeadingZerosSlowCase(); } @@ -1394,7 +1397,7 @@ /// of ones from the least significant bit to the first zero bit. unsigned countTrailingOnes() const { if (isSingleWord()) - return llvm::countTrailingOnes(VAL); + return llvm::countTrailingOnes(U.VAL); return countTrailingOnesSlowCase(); } @@ -1406,7 +1409,7 @@ /// \returns 0 if the value is zero, otherwise returns the number of set bits. unsigned countPopulation() const { if (isSingleWord()) - return llvm::countPopulation(VAL); + return llvm::countPopulation(U.VAL); return countPopulationSlowCase(); } @@ -1465,7 +1468,7 @@ uint64_t I; double D; } T; - T.I = (isSingleWord() ? VAL : pVal[0]); + T.I = (isSingleWord() ? U.VAL : U.pVal[0]); return T.D; } @@ -1479,7 +1482,7 @@ unsigned I; float F; } T; - T.I = unsigned((isSingleWord() ? VAL : pVal[0])); + T.I = unsigned((isSingleWord() ? U.VAL : U.pVal[0])); return T.F; } @@ -1537,7 +1540,7 @@ // get 0. If VAL is 0, we get UINT64_MAX which gets truncated to // UINT32_MAX. if (BitWidth == 1) - return VAL - 1; + return U.VAL - 1; // Handle the zero case. if (!getBoolValue()) Index: lib/IR/LLVMContextImpl.h =================================================================== --- lib/IR/LLVMContextImpl.h +++ lib/IR/LLVMContextImpl.h @@ -52,12 +52,12 @@ struct DenseMapAPIntKeyInfo { static inline APInt getEmptyKey() { APInt V(nullptr, 0); - V.VAL = 0; + V.U.VAL = 0; return V; } static inline APInt getTombstoneKey() { APInt V(nullptr, 0); - V.VAL = 1; + V.U.VAL = 1; return V; } static unsigned getHashValue(const APInt &Key) { Index: lib/Support/APInt.cpp =================================================================== --- lib/Support/APInt.cpp +++ lib/Support/APInt.cpp @@ -76,48 +76,48 @@ void APInt::initSlowCase(uint64_t val, bool isSigned) { - pVal = getClearedMemory(getNumWords()); - pVal[0] = val; + U.pVal = getClearedMemory(getNumWords()); + U.pVal[0] = val; if (isSigned && int64_t(val) < 0) for (unsigned i = 1; i < getNumWords(); ++i) - pVal[i] = -1ULL; + U.pVal[i] = -1ULL; clearUnusedBits(); } void APInt::initSlowCase(const APInt& that) { - pVal = getMemory(getNumWords()); - memcpy(pVal, that.pVal, getNumWords() * APINT_WORD_SIZE); + U.pVal = getMemory(getNumWords()); + memcpy(U.pVal, that.U.pVal, getNumWords() * APINT_WORD_SIZE); } void APInt::initFromArray(ArrayRef bigVal) { assert(BitWidth && "Bitwidth too small"); assert(bigVal.data() && "Null pointer detected!"); if (isSingleWord()) - VAL = bigVal[0]; + U.VAL = bigVal[0]; else { // Get memory, cleared to 0 - pVal = getClearedMemory(getNumWords()); + U.pVal = getClearedMemory(getNumWords()); // Calculate the number of words to copy unsigned words = std::min(bigVal.size(), getNumWords()); // Copy the words from bigVal to pVal - memcpy(pVal, bigVal.data(), words * APINT_WORD_SIZE); + memcpy(U.pVal, bigVal.data(), words * APINT_WORD_SIZE); } // Make sure unused high bits are cleared clearUnusedBits(); } APInt::APInt(unsigned numBits, ArrayRef bigVal) - : BitWidth(numBits), VAL(0) { + : BitWidth(numBits) { initFromArray(bigVal); } APInt::APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[]) - : BitWidth(numBits), VAL(0) { + : BitWidth(numBits) { initFromArray(makeArrayRef(bigVal, numWords)); } APInt::APInt(unsigned numbits, StringRef Str, uint8_t radix) - : BitWidth(numbits), VAL(0) { + : BitWidth(numbits) { assert(BitWidth && "Bitwidth too small"); fromString(numbits, Str, radix); } @@ -130,25 +130,24 @@ if (BitWidth == RHS.getBitWidth()) { // assume same bit-width single-word case is already handled assert(!isSingleWord()); - memcpy(pVal, RHS.pVal, getNumWords() * APINT_WORD_SIZE); + memcpy(U.pVal, RHS.U.pVal, getNumWords() * APINT_WORD_SIZE); return *this; } if (isSingleWord()) { // assume case where both are single words is already handled assert(!RHS.isSingleWord()); - VAL = 0; - pVal = getMemory(RHS.getNumWords()); - memcpy(pVal, RHS.pVal, RHS.getNumWords() * APINT_WORD_SIZE); + U.pVal = getMemory(RHS.getNumWords()); + memcpy(U.pVal, RHS.U.pVal, RHS.getNumWords() * APINT_WORD_SIZE); } else if (getNumWords() == RHS.getNumWords()) - memcpy(pVal, RHS.pVal, RHS.getNumWords() * APINT_WORD_SIZE); + memcpy(U.pVal, RHS.U.pVal, RHS.getNumWords() * APINT_WORD_SIZE); else if (RHS.isSingleWord()) { - delete [] pVal; - VAL = RHS.VAL; + delete [] U.pVal; + U.VAL = RHS.U.VAL; } else { - delete [] pVal; - pVal = getMemory(RHS.getNumWords()); - memcpy(pVal, RHS.pVal, RHS.getNumWords() * APINT_WORD_SIZE); + delete [] U.pVal; + U.pVal = getMemory(RHS.getNumWords()); + memcpy(U.pVal, RHS.U.pVal, RHS.getNumWords() * APINT_WORD_SIZE); } BitWidth = RHS.BitWidth; return clearUnusedBits(); @@ -156,10 +155,10 @@ APInt& APInt::operator=(uint64_t RHS) { if (isSingleWord()) - VAL = RHS; + U.VAL = RHS; else { - pVal[0] = RHS; - memset(pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE); + U.pVal[0] = RHS; + memset(U.pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE); } return clearUnusedBits(); } @@ -169,13 +168,13 @@ ID.AddInteger(BitWidth); if (isSingleWord()) { - ID.AddInteger(VAL); + ID.AddInteger(U.VAL); return; } unsigned NumWords = getNumWords(); for (unsigned i = 0; i < NumWords; ++i) - ID.AddInteger(pVal[i]); + ID.AddInteger(U.pVal[i]); } /// This function adds a single "digit" integer, y, to the multiple @@ -198,9 +197,9 @@ /// @brief Prefix increment operator. Increments the APInt by one. APInt& APInt::operator++() { if (isSingleWord()) - ++VAL; + ++U.VAL; else - add_1(pVal, pVal, getNumWords(), 1); + add_1(U.pVal, U.pVal, getNumWords(), 1); return clearUnusedBits(); } @@ -227,9 +226,9 @@ /// @brief Prefix decrement operator. Decrements the APInt by one. APInt& APInt::operator--() { if (isSingleWord()) - --VAL; + --U.VAL; else - sub_1(pVal, getNumWords(), 1); + sub_1(U.pVal, getNumWords(), 1); return clearUnusedBits(); } @@ -254,18 +253,18 @@ APInt& APInt::operator+=(const APInt& RHS) { assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); if (isSingleWord()) - VAL += RHS.VAL; + U.VAL += RHS.U.VAL; else { - add(pVal, pVal, RHS.pVal, getNumWords()); + add(U.pVal, U.pVal, RHS.U.pVal, getNumWords()); } return clearUnusedBits(); } APInt& APInt::operator+=(uint64_t RHS) { if (isSingleWord()) - VAL += RHS; + U.VAL += RHS; else - add_1(pVal, pVal, getNumWords(), RHS); + add_1(U.pVal, U.pVal, getNumWords(), RHS); return clearUnusedBits(); } @@ -289,17 +288,17 @@ APInt& APInt::operator-=(const APInt& RHS) { assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); if (isSingleWord()) - VAL -= RHS.VAL; + U.VAL -= RHS.U.VAL; else - sub(pVal, pVal, RHS.pVal, getNumWords()); + sub(U.pVal, U.pVal, RHS.U.pVal, getNumWords()); return clearUnusedBits(); } APInt& APInt::operator-=(uint64_t RHS) { if (isSingleWord()) - VAL -= RHS; + U.VAL -= RHS; else - sub_1(pVal, getNumWords(), RHS); + sub_1(U.pVal, getNumWords(), RHS); return clearUnusedBits(); } @@ -374,7 +373,7 @@ APInt& APInt::operator*=(const APInt& RHS) { assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); if (isSingleWord()) { - VAL *= RHS.VAL; + U.VAL *= RHS.U.VAL; clearUnusedBits(); return *this; } @@ -400,12 +399,12 @@ uint64_t *dest = getMemory(destWords); // Perform the long multiply - mul(dest, pVal, lhsWords, RHS.pVal, rhsWords); + mul(dest, U.pVal, lhsWords, RHS.U.pVal, rhsWords); // Copy result back into *this clearAllBits(); unsigned wordsToCopy = destWords >= getNumWords() ? getNumWords() : destWords; - memcpy(pVal, dest, wordsToCopy * APINT_WORD_SIZE); + memcpy(U.pVal, dest, wordsToCopy * APINT_WORD_SIZE); clearUnusedBits(); // delete dest array and return @@ -416,48 +415,48 @@ APInt& APInt::operator&=(const APInt& RHS) { assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); if (isSingleWord()) { - VAL &= RHS.VAL; + U.VAL &= RHS.U.VAL; return *this; } unsigned numWords = getNumWords(); for (unsigned i = 0; i < numWords; ++i) - pVal[i] &= RHS.pVal[i]; + U.pVal[i] &= RHS.U.pVal[i]; return *this; } APInt &APInt::operator&=(uint64_t RHS) { if (isSingleWord()) { - VAL &= RHS; + U.VAL &= RHS; return *this; } - pVal[0] &= RHS; + U.pVal[0] &= RHS; unsigned numWords = getNumWords(); for (unsigned i = 1; i < numWords; ++i) - pVal[i] = 0; + U.pVal[i] = 0; return *this; } APInt& APInt::operator|=(const APInt& RHS) { assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); if (isSingleWord()) { - VAL |= RHS.VAL; + U.VAL |= RHS.U.VAL; return *this; } unsigned numWords = getNumWords(); for (unsigned i = 0; i < numWords; ++i) - pVal[i] |= RHS.pVal[i]; + U.pVal[i] |= RHS.U.pVal[i]; return *this; } APInt& APInt::operator^=(const APInt& RHS) { assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); if (isSingleWord()) { - VAL ^= RHS.VAL; + U.VAL ^= RHS.U.VAL; return *this; } unsigned numWords = getNumWords(); for (unsigned i = 0; i < numWords; ++i) - pVal[i] ^= RHS.pVal[i]; + U.pVal[i] ^= RHS.U.pVal[i]; return *this; } @@ -465,7 +464,7 @@ unsigned numWords = getNumWords(); uint64_t* val = getMemory(numWords); for (unsigned i = 0; i < numWords; ++i) - val[i] = pVal[i] & RHS.pVal[i]; + val[i] = U.pVal[i] & RHS.U.pVal[i]; return APInt(val, getBitWidth()); } @@ -473,7 +472,7 @@ unsigned numWords = getNumWords(); uint64_t *val = getMemory(numWords); for (unsigned i = 0; i < numWords; ++i) - val[i] = pVal[i] | RHS.pVal[i]; + val[i] = U.pVal[i] | RHS.U.pVal[i]; return APInt(val, getBitWidth()); } @@ -481,7 +480,7 @@ unsigned numWords = getNumWords(); uint64_t *val = getMemory(numWords); for (unsigned i = 0; i < numWords; ++i) - val[i] = pVal[i] ^ RHS.pVal[i]; + val[i] = U.pVal[i] ^ RHS.U.pVal[i]; return APInt(val, getBitWidth()); } @@ -489,20 +488,20 @@ APInt APInt::operator*(const APInt& RHS) const { assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); if (isSingleWord()) - return APInt(BitWidth, VAL * RHS.VAL); + return APInt(BitWidth, U.VAL * RHS.U.VAL); APInt Result(*this); Result *= RHS; return Result; } bool APInt::EqualSlowCase(const APInt& RHS) const { - return std::equal(pVal, pVal + getNumWords(), RHS.pVal); + return std::equal(U.pVal, U.pVal + getNumWords(), RHS.U.pVal); } bool APInt::EqualSlowCase(uint64_t Val) const { unsigned n = getActiveBits(); if (n <= APINT_BITS_PER_WORD) - return pVal[0] == Val; + return U.pVal[0] == Val; else return false; } @@ -510,7 +509,7 @@ bool APInt::ult(const APInt& RHS) const { assert(BitWidth == RHS.BitWidth && "Bit widths must be same for comparison"); if (isSingleWord()) - return VAL < RHS.VAL; + return U.VAL < RHS.U.VAL; // Get active bit length of both operands unsigned n1 = getActiveBits(); @@ -526,14 +525,14 @@ // If they bot fit in a word, just compare the low order word if (n1 <= APINT_BITS_PER_WORD && n2 <= APINT_BITS_PER_WORD) - return pVal[0] < RHS.pVal[0]; + return U.pVal[0] < RHS.U.pVal[0]; // Otherwise, compare all words unsigned topWord = whichWord(std::max(n1,n2)-1); for (int i = topWord; i >= 0; --i) { - if (pVal[i] > RHS.pVal[i]) + if (U.pVal[i] > RHS.U.pVal[i]) return false; - if (pVal[i] < RHS.pVal[i]) + if (U.pVal[i] < RHS.U.pVal[i]) return true; } return false; @@ -542,8 +541,8 @@ bool APInt::slt(const APInt& RHS) const { assert(BitWidth == RHS.BitWidth && "Bit widths must be same for comparison"); if (isSingleWord()) { - int64_t lhsSext = SignExtend64(VAL, BitWidth); - int64_t rhsSext = SignExtend64(RHS.VAL, BitWidth); + int64_t lhsSext = SignExtend64(U.VAL, BitWidth); + int64_t rhsSext = SignExtend64(RHS.U.VAL, BitWidth); return lhsSext < rhsSext; } @@ -561,9 +560,9 @@ void APInt::setBit(unsigned bitPosition) { if (isSingleWord()) - VAL |= maskBit(bitPosition); + U.VAL |= maskBit(bitPosition); else - pVal[whichWord(bitPosition)] |= maskBit(bitPosition); + U.pVal[whichWord(bitPosition)] |= maskBit(bitPosition); } void APInt::setBits(unsigned loBit, unsigned hiBit) { @@ -584,17 +583,17 @@ uint64_t mask = UINT64_MAX; mask >>= (APINT_BITS_PER_WORD - (hiBit - loBit)); mask <<= whichBit(loBit); - pVal[loWord] |= mask; + U.pVal[loWord] |= mask; } else { // Set bits span multiple words, create a lo mask with set bits starting // at loBit, a hi mask with set bits below hiBit and set all bits of the // words in between. uint64_t loMask = UINT64_MAX << whichBit(loBit); uint64_t hiMask = UINT64_MAX >> (64 - whichBit(hiBit1) - 1); - pVal[loWord] |= loMask; - pVal[hiWord] |= hiMask; + U.pVal[loWord] |= loMask; + U.pVal[hiWord] |= hiMask; for (unsigned word = loWord + 1; word < hiWord; ++word) - pVal[word] = UINT64_MAX; + U.pVal[word] = UINT64_MAX; } } } @@ -603,9 +602,9 @@ /// @brief Set a given bit to 0. void APInt::clearBit(unsigned bitPosition) { if (isSingleWord()) - VAL &= ~maskBit(bitPosition); + U.VAL &= ~maskBit(bitPosition); else - pVal[whichWord(bitPosition)] &= ~maskBit(bitPosition); + U.pVal[whichWord(bitPosition)] &= ~maskBit(bitPosition); } /// @brief Toggle every bit to its opposite value. @@ -625,7 +624,7 @@ "Illegal bit extraction"); if (isSingleWord()) - return APInt(numBits, VAL >> bitPosition); + return APInt(numBits, U.VAL >> bitPosition); unsigned loBit = whichBit(bitPosition); unsigned loWord = whichWord(bitPosition); @@ -633,12 +632,12 @@ // Single word result extracting bits from a single word source. if (loWord == hiWord) - return APInt(numBits, pVal[loWord] >> loBit); + return APInt(numBits, U.pVal[loWord] >> loBit); // Extracting bits that start on a source word boundary can be done // as a fast memory copy. if (loBit == 0) - return APInt(numBits, makeArrayRef(pVal + loWord, 1 + hiWord - loWord)); + return APInt(numBits, makeArrayRef(U.pVal + loWord, 1 + hiWord - loWord)); // General case - shift + copy source words directly into place. APInt Result(numBits, 0); @@ -646,10 +645,10 @@ unsigned NumDstWords = Result.getNumWords(); for (unsigned word = 0; word < NumDstWords; ++word) { - uint64_t w0 = pVal[loWord + word]; + uint64_t w0 = U.pVal[loWord + word]; uint64_t w1 = - (loWord + word + 1) < NumSrcWords ? pVal[loWord + word + 1] : 0; - Result.pVal[word] = (w0 >> loBit) | (w1 << (APINT_BITS_PER_WORD - loBit)); + (loWord + word + 1) < NumSrcWords ? U.pVal[loWord + word + 1] : 0; + Result.U.pVal[word] = (w0 >> loBit) | (w1 << (APINT_BITS_PER_WORD - loBit)); } return Result.clearUnusedBits(); @@ -710,9 +709,9 @@ hash_code llvm::hash_value(const APInt &Arg) { if (Arg.isSingleWord()) - return hash_combine(Arg.VAL); + return hash_combine(Arg.U.VAL); - return hash_combine_range(Arg.pVal, Arg.pVal + Arg.getNumWords()); + return hash_combine_range(Arg.U.pVal, Arg.U.pVal + Arg.getNumWords()); } bool APInt::isSplat(unsigned SplatSizeInBits) const { @@ -737,7 +736,7 @@ unsigned APInt::countLeadingZerosSlowCase() const { unsigned Count = 0; for (int i = getNumWords()-1; i >= 0; --i) { - integerPart V = pVal[i]; + integerPart V = U.pVal[i]; if (V == 0) Count += APINT_BITS_PER_WORD; else { @@ -753,7 +752,7 @@ unsigned APInt::countLeadingOnes() const { if (isSingleWord()) - return llvm::countLeadingOnes(VAL << (APINT_BITS_PER_WORD - BitWidth)); + return llvm::countLeadingOnes(U.VAL << (APINT_BITS_PER_WORD - BitWidth)); unsigned highWordBits = BitWidth % APINT_BITS_PER_WORD; unsigned shift; @@ -764,13 +763,13 @@ shift = APINT_BITS_PER_WORD - highWordBits; } int i = getNumWords() - 1; - unsigned Count = llvm::countLeadingOnes(pVal[i] << shift); + unsigned Count = llvm::countLeadingOnes(U.pVal[i] << shift); if (Count == highWordBits) { for (i--; i >= 0; --i) { - if (pVal[i] == -1ULL) + if (U.pVal[i] == -1ULL) Count += APINT_BITS_PER_WORD; else { - Count += llvm::countLeadingOnes(pVal[i]); + Count += llvm::countLeadingOnes(U.pVal[i]); break; } } @@ -780,30 +779,30 @@ unsigned APInt::countTrailingZeros() const { if (isSingleWord()) - return std::min(unsigned(llvm::countTrailingZeros(VAL)), BitWidth); + return std::min(unsigned(llvm::countTrailingZeros(U.VAL)), BitWidth); unsigned Count = 0; unsigned i = 0; - for (; i < getNumWords() && pVal[i] == 0; ++i) + for (; i < getNumWords() && U.pVal[i] == 0; ++i) Count += APINT_BITS_PER_WORD; if (i < getNumWords()) - Count += llvm::countTrailingZeros(pVal[i]); + Count += llvm::countTrailingZeros(U.pVal[i]); return std::min(Count, BitWidth); } unsigned APInt::countTrailingOnesSlowCase() const { unsigned Count = 0; unsigned i = 0; - for (; i < getNumWords() && pVal[i] == -1ULL; ++i) + for (; i < getNumWords() && U.pVal[i] == -1ULL; ++i) Count += APINT_BITS_PER_WORD; if (i < getNumWords()) - Count += llvm::countTrailingOnes(pVal[i]); + Count += llvm::countTrailingOnes(U.pVal[i]); return std::min(Count, BitWidth); } unsigned APInt::countPopulationSlowCase() const { unsigned Count = 0; for (unsigned i = 0; i < getNumWords(); ++i) - Count += llvm::countPopulation(pVal[i]); + Count += llvm::countPopulation(U.pVal[i]); return Count; } @@ -822,24 +821,24 @@ APInt APInt::byteSwap() const { assert(BitWidth >= 16 && BitWidth % 16 == 0 && "Cannot byteswap!"); if (BitWidth == 16) - return APInt(BitWidth, ByteSwap_16(uint16_t(VAL))); + return APInt(BitWidth, ByteSwap_16(uint16_t(U.VAL))); if (BitWidth == 32) - return APInt(BitWidth, ByteSwap_32(unsigned(VAL))); + return APInt(BitWidth, ByteSwap_32(unsigned(U.VAL))); if (BitWidth == 48) { - unsigned Tmp1 = unsigned(VAL >> 16); + unsigned Tmp1 = unsigned(U.VAL >> 16); Tmp1 = ByteSwap_32(Tmp1); - uint16_t Tmp2 = uint16_t(VAL); + uint16_t Tmp2 = uint16_t(U.VAL); Tmp2 = ByteSwap_16(Tmp2); return APInt(BitWidth, (uint64_t(Tmp2) << 32) | Tmp1); } if (BitWidth == 64) - return APInt(BitWidth, ByteSwap_64(VAL)); + return APInt(BitWidth, ByteSwap_64(U.VAL)); APInt Result(getNumWords() * APINT_BITS_PER_WORD, 0); for (unsigned I = 0, N = getNumWords(); I != N; ++I) - Result.pVal[I] = ByteSwap_64(pVal[N - I - 1]); + Result.U.pVal[I] = ByteSwap_64(U.pVal[N - I - 1]); if (Result.BitWidth != BitWidth) { - lshrNear(Result.pVal, Result.pVal, getNumWords(), + lshrNear(Result.U.pVal, Result.U.pVal, getNumWords(), Result.BitWidth - BitWidth); Result.BitWidth = BitWidth; } @@ -849,13 +848,13 @@ APInt APInt::reverseBits() const { switch (BitWidth) { case 64: - return APInt(BitWidth, llvm::reverseBits(VAL)); + return APInt(BitWidth, llvm::reverseBits(U.VAL)); case 32: - return APInt(BitWidth, llvm::reverseBits(VAL)); + return APInt(BitWidth, llvm::reverseBits(U.VAL)); case 16: - return APInt(BitWidth, llvm::reverseBits(VAL)); + return APInt(BitWidth, llvm::reverseBits(U.VAL)); case 8: - return APInt(BitWidth, llvm::reverseBits(VAL)); + return APInt(BitWidth, llvm::reverseBits(U.VAL)); default: break; } @@ -970,13 +969,13 @@ uint64_t mantissa; unsigned hiWord = whichWord(n-1); if (hiWord == 0) { - mantissa = Tmp.pVal[0]; + mantissa = Tmp.U.pVal[0]; if (n > 52) mantissa >>= n - 52; // shift down, we want the top 52 bits. } else { assert(hiWord > 0 && "huh?"); - uint64_t hibits = Tmp.pVal[hiWord] << (52 - n % APINT_BITS_PER_WORD); - uint64_t lobits = Tmp.pVal[hiWord-1] >> (11 + n % APINT_BITS_PER_WORD); + uint64_t hibits = Tmp.U.pVal[hiWord] << (52 - n % APINT_BITS_PER_WORD); + uint64_t lobits = Tmp.U.pVal[hiWord-1] >> (11 + n % APINT_BITS_PER_WORD); mantissa = hibits | lobits; } @@ -1003,12 +1002,12 @@ // Copy full words. unsigned i; for (i = 0; i != width / APINT_BITS_PER_WORD; i++) - Result.pVal[i] = pVal[i]; + Result.U.pVal[i] = U.pVal[i]; // Truncate and copy any partial word. unsigned bits = (0 - width) % APINT_BITS_PER_WORD; if (bits != 0) - Result.pVal[i] = pVal[i] << bits >> bits; + Result.U.pVal[i] = U.pVal[i] << bits >> bits; return Result; } @@ -1018,7 +1017,7 @@ assert(width > BitWidth && "Invalid APInt SignExtend request"); if (width <= APINT_BITS_PER_WORD) { - uint64_t val = VAL << (APINT_BITS_PER_WORD - BitWidth); + uint64_t val = U.VAL << (APINT_BITS_PER_WORD - BitWidth); val = (int64_t)val >> (width - BitWidth); return APInt(width, val >> (APINT_BITS_PER_WORD - width)); } @@ -1030,7 +1029,7 @@ uint64_t word = 0; for (i = 0; i != BitWidth / APINT_BITS_PER_WORD; i++) { word = getRawData()[i]; - Result.pVal[i] = word; + Result.U.pVal[i] = word; } // Read and sign-extend any partial word. @@ -1042,14 +1041,14 @@ // Write remaining full words. for (; i != width / APINT_BITS_PER_WORD; i++) { - Result.pVal[i] = word; + Result.U.pVal[i] = word; word = (int64_t)word >> (APINT_BITS_PER_WORD - 1); } // Write any partial word. bits = (0 - width) % APINT_BITS_PER_WORD; if (bits != 0) - Result.pVal[i] = word << bits >> bits; + Result.U.pVal[i] = word << bits >> bits; return Result; } @@ -1059,17 +1058,17 @@ assert(width > BitWidth && "Invalid APInt ZeroExtend request"); if (width <= APINT_BITS_PER_WORD) - return APInt(width, VAL); + return APInt(width, U.VAL); APInt Result(getMemory(getNumWords(width)), width); // Copy words. unsigned i; for (i = 0; i != getNumWords(); i++) - Result.pVal[i] = getRawData()[i]; + Result.U.pVal[i] = getRawData()[i]; // Zero remaining words. - memset(&Result.pVal[i], 0, (Result.getNumWords() - i) * APINT_WORD_SIZE); + memset(&Result.U.pVal[i], 0, (Result.getNumWords() - i) * APINT_WORD_SIZE); return Result; } @@ -1120,7 +1119,7 @@ if (isSingleWord()) { if (shiftAmt == BitWidth) return APInt(BitWidth, 0); // undefined - return APInt(BitWidth, SignExtend64(VAL, BitWidth) >> shiftAmt); + return APInt(BitWidth, SignExtend64(U.VAL, BitWidth) >> shiftAmt); } // If all the bits were shifted out, the result is, technically, undefined. @@ -1148,7 +1147,7 @@ if (wordShift == 0) { // Move the words containing significant bits for (unsigned i = 0; i <= breakWord; ++i) - val[i] = pVal[i+offset]; // move whole word + val[i] = U.pVal[i+offset]; // move whole word // Adjust the top significant word for sign bit fill, if negative if (isNegative()) @@ -1159,13 +1158,13 @@ for (unsigned i = 0; i < breakWord; ++i) { // This combines the shifted corresponding word with the low bits from // the next word (shifted into this word's high bits). - val[i] = (pVal[i+offset] >> wordShift) | - (pVal[i+offset+1] << (APINT_BITS_PER_WORD - wordShift)); + val[i] = (U.pVal[i+offset] >> wordShift) | + (U.pVal[i+offset+1] << (APINT_BITS_PER_WORD - wordShift)); } // Shift the break word. In this case there are no bits from the next word // to include in this word. - val[breakWord] = pVal[breakWord+offset] >> wordShift; + val[breakWord] = U.pVal[breakWord+offset] >> wordShift; // Deal with sign extension in the break word, and possibly the word before // it. @@ -1202,7 +1201,7 @@ if (shiftAmt >= BitWidth) return APInt(BitWidth, 0); else - return APInt(BitWidth, this->VAL >> shiftAmt); + return APInt(BitWidth, this->U.VAL >> shiftAmt); } // If all the bits were shifted out, the result is 0. This avoids issues @@ -1222,7 +1221,7 @@ // If we are shifting less than a word, compute the shift with a simple carry if (shiftAmt < APINT_BITS_PER_WORD) { - lshrNear(val, pVal, getNumWords(), shiftAmt); + lshrNear(val, U.pVal, getNumWords(), shiftAmt); APInt Result(val, BitWidth); Result.clearUnusedBits(); return Result; @@ -1235,7 +1234,7 @@ // If we are shifting whole words, just move whole words if (wordShift == 0) { for (unsigned i = 0; i < getNumWords() - offset; ++i) - val[i] = pVal[i+offset]; + val[i] = U.pVal[i+offset]; for (unsigned i = getNumWords()-offset; i < getNumWords(); i++) val[i] = 0; APInt Result(val, BitWidth); @@ -1246,10 +1245,10 @@ // Shift the low order words unsigned breakWord = getNumWords() - offset -1; for (unsigned i = 0; i < breakWord; ++i) - val[i] = (pVal[i+offset] >> wordShift) | - (pVal[i+offset+1] << (APINT_BITS_PER_WORD - wordShift)); + val[i] = (U.pVal[i+offset] >> wordShift) | + (U.pVal[i+offset+1] << (APINT_BITS_PER_WORD - wordShift)); // Shift the break word. - val[breakWord] = pVal[breakWord+offset] >> wordShift; + val[breakWord] = U.pVal[breakWord+offset] >> wordShift; // Remaining words are 0 for (unsigned i = breakWord+1; i < getNumWords(); ++i) @@ -1286,8 +1285,8 @@ if (shiftAmt < APINT_BITS_PER_WORD) { uint64_t carry = 0; for (unsigned i = 0; i < getNumWords(); i++) { - val[i] = pVal[i] << shiftAmt | carry; - carry = pVal[i] >> (APINT_BITS_PER_WORD - shiftAmt); + val[i] = U.pVal[i] << shiftAmt | carry; + carry = U.pVal[i] >> (APINT_BITS_PER_WORD - shiftAmt); } APInt Result(val, BitWidth); Result.clearUnusedBits(); @@ -1303,7 +1302,7 @@ for (unsigned i = 0; i < offset; i++) val[i] = 0; for (unsigned i = offset; i < getNumWords(); i++) - val[i] = pVal[i-offset]; + val[i] = U.pVal[i-offset]; APInt Result(val, BitWidth); Result.clearUnusedBits(); return Result; @@ -1312,9 +1311,9 @@ // Copy whole words from this to Result. unsigned i = getNumWords() - 1; for (; i > offset; --i) - val[i] = pVal[i-offset] << wordShift | - pVal[i-offset-1] >> (APINT_BITS_PER_WORD - wordShift); - val[offset] = pVal[0] << wordShift; + val[i] = U.pVal[i-offset] << wordShift | + U.pVal[i-offset-1] >> (APINT_BITS_PER_WORD - wordShift); + val[offset] = U.pVal[0] << wordShift; for (i = 0; i < offset; ++i) val[i] = 0; APInt Result(val, BitWidth); @@ -1381,7 +1380,7 @@ /* 21-30 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, /* 31 */ 6 }; - return APInt(BitWidth, results[ (isSingleWord() ? VAL : pVal[0]) ]); + return APInt(BitWidth, results[ (isSingleWord() ? U.VAL : U.pVal[0]) ]); } // If the magnitude of the value fits in less than 52 bits (the precision of @@ -1390,7 +1389,8 @@ // This should be faster than the algorithm below. if (magnitude < 52) { return APInt(BitWidth, - uint64_t(::round(::sqrt(double(isSingleWord()?VAL:pVal[0]))))); + uint64_t(::round(::sqrt(double(isSingleWord() ? U.VAL + : U.pVal[0]))))); } // Okay, all the short cuts are exhausted. We must compute it. The following @@ -1768,7 +1768,7 @@ // Initialize the dividend memset(U, 0, (m+n+1)*sizeof(unsigned)); for (unsigned i = 0; i < lhsWords; ++i) { - uint64_t tmp = (LHS.getNumWords() == 1 ? LHS.VAL : LHS.pVal[i]); + uint64_t tmp = (LHS.getNumWords() == 1 ? LHS.U.VAL : LHS.U.pVal[i]); U[i * 2] = (unsigned)(tmp & mask); U[i * 2 + 1] = (unsigned)(tmp >> (sizeof(unsigned)*CHAR_BIT)); } @@ -1777,7 +1777,7 @@ // Initialize the divisor memset(V, 0, (n)*sizeof(unsigned)); for (unsigned i = 0; i < rhsWords; ++i) { - uint64_t tmp = (RHS.getNumWords() == 1 ? RHS.VAL : RHS.pVal[i]); + uint64_t tmp = (RHS.getNumWords() == 1 ? RHS.U.VAL : RHS.U.pVal[i]); V[i * 2] = (unsigned)(tmp & mask); V[i * 2 + 1] = (unsigned)(tmp >> (sizeof(unsigned)*CHAR_BIT)); } @@ -1837,12 +1837,12 @@ // Set up the Quotient value's memory. if (Quotient->BitWidth != LHS.BitWidth) { if (Quotient->isSingleWord()) - Quotient->VAL = 0; + Quotient->U.VAL = 0; else - delete [] Quotient->pVal; + delete [] Quotient->U.pVal; Quotient->BitWidth = LHS.BitWidth; if (!Quotient->isSingleWord()) - Quotient->pVal = getClearedMemory(Quotient->getNumWords()); + Quotient->U.pVal = getClearedMemory(Quotient->getNumWords()); } else Quotient->clearAllBits(); @@ -1854,13 +1854,13 @@ uint64_t tmp = uint64_t(Q[0]) | (uint64_t(Q[1]) << (APINT_BITS_PER_WORD / 2)); if (Quotient->isSingleWord()) - Quotient->VAL = tmp; + Quotient->U.VAL = tmp; else - Quotient->pVal[0] = tmp; + Quotient->U.pVal[0] = tmp; } else { assert(!Quotient->isSingleWord() && "Quotient APInt not large enough"); for (unsigned i = 0; i < lhsWords; ++i) - Quotient->pVal[i] = + Quotient->U.pVal[i] = uint64_t(Q[i*2]) | (uint64_t(Q[i*2+1]) << (APINT_BITS_PER_WORD / 2)); } } @@ -1870,12 +1870,12 @@ // Set up the Remainder value's memory. if (Remainder->BitWidth != RHS.BitWidth) { if (Remainder->isSingleWord()) - Remainder->VAL = 0; + Remainder->U.VAL = 0; else - delete [] Remainder->pVal; + delete [] Remainder->U.pVal; Remainder->BitWidth = RHS.BitWidth; if (!Remainder->isSingleWord()) - Remainder->pVal = getClearedMemory(Remainder->getNumWords()); + Remainder->U.pVal = getClearedMemory(Remainder->getNumWords()); } else Remainder->clearAllBits(); @@ -1885,13 +1885,13 @@ uint64_t tmp = uint64_t(R[0]) | (uint64_t(R[1]) << (APINT_BITS_PER_WORD / 2)); if (Remainder->isSingleWord()) - Remainder->VAL = tmp; + Remainder->U.VAL = tmp; else - Remainder->pVal[0] = tmp; + Remainder->U.pVal[0] = tmp; } else { assert(!Remainder->isSingleWord() && "Remainder APInt not large enough"); for (unsigned i = 0; i < rhsWords; ++i) - Remainder->pVal[i] = + Remainder->U.pVal[i] = uint64_t(R[i*2]) | (uint64_t(R[i*2+1]) << (APINT_BITS_PER_WORD / 2)); } } @@ -1910,8 +1910,8 @@ // First, deal with the easy case if (isSingleWord()) { - assert(RHS.VAL != 0 && "Divide by zero?"); - return APInt(BitWidth, VAL / RHS.VAL); + assert(RHS.U.VAL != 0 && "Divide by zero?"); + return APInt(BitWidth, U.VAL / RHS.U.VAL); } // Get some facts about the LHS and RHS number of bits and words @@ -1933,7 +1933,7 @@ return APInt(BitWidth, 1); } else if (lhsWords == 1 && rhsWords == 1) { // All high words are zero, just use native divide - return APInt(BitWidth, this->pVal[0] / RHS.pVal[0]); + return APInt(BitWidth, this->U.pVal[0] / RHS.U.pVal[0]); } // We have to compute it the hard way. Invoke the Knuth divide algorithm. @@ -1956,8 +1956,8 @@ APInt APInt::urem(const APInt& RHS) const { assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); if (isSingleWord()) { - assert(RHS.VAL != 0 && "Remainder by zero?"); - return APInt(BitWidth, VAL % RHS.VAL); + assert(RHS.U.VAL != 0 && "Remainder by zero?"); + return APInt(BitWidth, U.VAL % RHS.U.VAL); } // Get some facts about the LHS @@ -1981,7 +1981,7 @@ return APInt(BitWidth, 0); } else if (lhsWords == 1) { // All high words are zero, just use native remainder - return APInt(BitWidth, pVal[0] % RHS.pVal[0]); + return APInt(BitWidth, U.pVal[0] % RHS.U.pVal[0]); } // We have to compute it the hard way. Invoke the Knuth divide algorithm. @@ -2007,9 +2007,9 @@ // First, deal with the easy case if (LHS.isSingleWord()) { - assert(RHS.VAL != 0 && "Divide by zero?"); - uint64_t QuotVal = LHS.VAL / RHS.VAL; - uint64_t RemVal = LHS.VAL % RHS.VAL; + assert(RHS.U.VAL != 0 && "Divide by zero?"); + uint64_t QuotVal = LHS.U.VAL / RHS.U.VAL; + uint64_t RemVal = LHS.U.VAL % RHS.U.VAL; Quotient = APInt(LHS.BitWidth, QuotVal); Remainder = APInt(LHS.BitWidth, RemVal); return; @@ -2042,8 +2042,8 @@ if (lhsWords == 1 && rhsWords == 1) { // There is only one word to consider so use the native versions. - uint64_t lhsValue = LHS.isSingleWord() ? LHS.VAL : LHS.pVal[0]; - uint64_t rhsValue = RHS.isSingleWord() ? RHS.VAL : RHS.pVal[0]; + uint64_t lhsValue = LHS.isSingleWord() ? LHS.U.VAL : LHS.U.pVal[0]; + uint64_t rhsValue = RHS.isSingleWord() ? RHS.U.VAL : RHS.U.pVal[0]; Quotient = APInt(LHS.getBitWidth(), lhsValue / rhsValue); Remainder = APInt(LHS.getBitWidth(), lhsValue % rhsValue); return; @@ -2170,9 +2170,11 @@ assert((((slen-1)*64)/22 <= numbits || radix != 10) && "Insufficient bit width"); - // Allocate memory - if (!isSingleWord()) - pVal = getClearedMemory(getNumWords()); + // Allocate memory if needed + if (isSingleWord()) + U.VAL = 0; + else + U.pVal = getClearedMemory(getNumWords()); // Figure out if we can shift instead of multiply unsigned shift = (radix == 16 ? 4 : radix == 8 ? 3 : radix == 2 ? 1 : 0); @@ -2197,9 +2199,9 @@ // Add in the digit we just interpreted if (apdigit.isSingleWord()) - apdigit.VAL = digit; + apdigit.U.VAL = digit; else - apdigit.pVal[0] = digit; + apdigit.U.pVal[0] = digit; *this += apdigit; } // If its negative, put it in two's complement form