Home | History | Annotate | Download | only in Support

Lines Matching full:apint

1 //===-- APInt.cpp - Implement APInt class ---------------------------------===//
15 #include "llvm/ADT/APInt.h"
30 #define DEBUG_TYPE "apint"
36 assert(result && "APInt memory allocation fails!");
45 assert(result && "APInt memory allocation fails!");
77 void APInt::initSlowCase(unsigned numBits, uint64_t val, bool isSigned) {
85 void APInt::initSlowCase(const APInt& that) {
90 void APInt::initFromArray(ArrayRef<uint64_t> bigVal) {
107 APInt::APInt(unsigned numBits, ArrayRef<uint64_t> bigVal)
112 APInt::APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[])
117 APInt::APInt(unsigned numbits, StringRef Str, uint8_t radix)
123 APInt& APInt::AssignSlowCase(const APInt& RHS) {
155 APInt& APInt::operator=(uint64_t RHS) {
165 /// This method 'profiles' an APInt for use with FoldingSet.
166 void APInt::Profile(FoldingSetNodeID& ID) const {
196 /// @brief Prefix increment operator. Increments the APInt by one.
197 APInt& APInt::operator++() {
225 /// @brief Prefix decrement operator. Decrements the APInt by one.
226 APInt& APInt::operator--() {
249 /// Adds the RHS APint to this APInt.
252 APInt& APInt::operator+=(const APInt& RHS) {
276 /// Subtracts the RHS APInt from this APInt
279 APInt& APInt::operator-=(const APInt& RHS) {
291 /// @brief Multiply a multi-digit APInt by a single digit (64-bit) integer.
356 APInt& APInt::operator*=(const APInt& RHS) {
398 APInt& APInt::operator&=(const APInt& RHS) {
410 APInt& APInt::operator|=(const APInt& RHS) {
422 APInt& APInt::operator^=(const APInt& RHS) {
435 APInt APInt::AndSlowCase(const APInt& RHS) const {
440 return APInt(val, getBitWidth());
443 APInt APInt::OrSlowCase(const APInt& RHS) const {
448 return APInt(val, getBitWidth());
451 APInt APInt::XorSlowCase(const APInt& RHS) const {
457 APInt Result(val, getBitWidth());
463 APInt APInt::operator*(const APInt& RHS) const {
466 return APInt(BitWidth, VAL * RHS.VAL);
467 APInt Result(*this);
472 APInt APInt::operator+(const APInt& RHS) const {
475 return APInt(BitWidth, VAL + RHS.VAL);
476 APInt Result(BitWidth, 0);
482 APInt APInt::operator-(const APInt& RHS) const {
485 return APInt(BitWidth, VAL - RHS.VAL);
486 APInt Result(BitWidth, 0);
492 bool APInt::EqualSlowCase(const APInt& RHS) const {
512 bool APInt::EqualSlowCase(uint64_t Val) const {
520 bool APInt::ult(const APInt& RHS) const {
552 bool APInt::slt(const APInt& RHS) const {
560 APInt lhs(*this);
561 APInt rhs(RHS);
588 void APInt::setBit(unsigned bitPosition) {
597 void APInt::clearBit(unsigned bitPosition) {
609 void APInt::flipBit(unsigned bitPosition) {
615 unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) {
656 APInt tmp(sufficient, StringRef(p, slen), radix);
668 hash_code llvm::hash_value(const APInt &Arg) {
675 bool APInt::isSplat(unsigned SplatSizeInBits) const {
683 /// This function returns the high "numBits" bits of this APInt.
684 APInt APInt::getHiBits(unsigned numBits) const {
688 /// This function returns the low "numBits" bits of this APInt.
689 APInt APInt::getLoBits(unsigned numBits) const {
694 unsigned APInt::countLeadingZerosSlowCase() const {
722 unsigned APInt::countLeadingOnes() const {
749 unsigned APInt::countTrailingZeros() const {
761 unsigned APInt::countTrailingOnesSlowCase() const {
771 unsigned APInt::countPopulationSlowCase() const {
790 APInt APInt::byteSwap() const {
793 return APInt(BitWidth, ByteSwap_16(uint16_t(VAL)));
795 return APInt(BitWidth, ByteSwap_32(unsigned(VAL)));
801 return APInt(BitWidth, (uint64_t(Tmp2) << 32) | Tmp1);
804 return APInt(BitWidth, ByteSwap_64(VAL));
806 APInt Result(getNumWords() * APINT_BITS_PER_WORD, 0);
817 APInt llvm::APIntOps::GreatestCommonDivisor(const APInt& API1,
818 const APInt& API2) {
819 APInt A = API1, B = API2;
821 APInt T = B;
828 APInt llvm::APIntOps::RoundDoubleToAPInt(double Double, unsigned width) {
843 return APInt(width, 0u);
850 return isNeg ? -APInt(width, mantissa >> (52 - exp)) :
851 APInt(width, mantissa >> (52 - exp));
856 return APInt(width, 0);
859 APInt Tmp(width, mantissa);
864 /// This function converts this APInt to a double.
871 double APInt::roundToDouble(bool isSigned) const {
887 APInt Tmp(isNeg ? -(*this) : (*this));
932 APInt APInt::trunc(unsigned width) const {
933 assert(width < BitWidth && "Invalid APInt Truncate request");
937 return APInt(width, getRawData()[0]);
939 APInt Result(getMemory(getNumWords(width)), width);
955 APInt APInt::sext(unsigned width) const {
956 assert(width > BitWidth && "Invalid APInt SignExtend request");
961 return APInt(width, val >> (APINT_BITS_PER_WORD - width));
964 APInt Result(getMemory(getNumWords(width)), width);
996 APInt APInt::zext(unsigned width) const {
997 assert(width > BitWidth && "Invalid APInt ZeroExtend request");
1000 return APInt(width, VAL);
1002 APInt Result(getMemory(getNumWords(width)), width);
1015 APInt APInt::zextOrTrunc(unsigned width) const {
1023 APInt APInt::sextOrTrunc(unsigned width) const {
1031 APInt APInt::zextOrSelf(unsigned width) const {
1037 APInt APInt::sextOrSelf(unsigned width) const {
1043 /// Arithmetic right-shift this APInt by shiftAmt.
1045 APInt APInt::ashr(const APInt &shiftAmt) const {
1049 /// Arithmetic right-shift this APInt by shiftAmt.
1051 APInt APInt::ashr(unsigned shiftAmt) const {
1060 return APInt(BitWidth, 0); // undefined
1063 return APInt(BitWidth,
1073 return APInt(BitWidth, -1ULL, true);
1075 return APInt(BitWidth, 0);
1129 APInt Result(val, BitWidth);
1134 /// Logical right-shift this APInt by shiftAmt.
1136 APInt APInt::lshr(const APInt &shiftAmt) const {
1140 /// Logical right-shift this APInt by shiftAmt.
1142 APInt APInt::lshr(unsigned shiftAmt) const {
1145 return APInt(BitWidth, 0);
1147 return APInt(BitWidth, this->VAL >> shiftAmt);
1154 return APInt(BitWidth, 0);
1168 APInt Result(val, BitWidth);
1183 APInt Result(val, BitWidth);
1199 APInt Result(val, BitWidth);
1204 /// Left-shift this APInt by shiftAmt.
1206 APInt APInt::shl(const APInt &shiftAmt) const {
1211 APInt APInt::shlSlowCase(unsigned shiftAmt) const {
1216 return APInt(BitWidth, 0);
1234 APInt Result(val, BitWidth);
1249 APInt Result(val, BitWidth);
1262 APInt Result(val, BitWidth);
1267 APInt APInt::rotl(const APInt &rotateAmt) const {
1271 APInt APInt::rotl(unsigned rotateAmt) const {
1278 APInt APInt::rotr(const APInt &rotateAmt) const {
1282 APInt APInt::rotr(unsigned rotateAmt) const {
1296 APInt APInt::sqrt() const {
1313 return APInt(BitWidth, results[ (isSingleWord() ? VAL : pVal[0]) ]);
1321 return APInt(BitWidth,
1327 // was adapted to APInt from a wikipedia article on such computations.
1331 APInt testy(BitWidth, 16);
1332 APInt x_old(BitWidth, 1);
1333 APInt x_new(BitWidth, 0);
1334 APInt two(BitWidth, 2);
1357 APInt square(x_old * x_old);
1358 APInt nextSquare((x_old + 1) * (x_old +1));
1361 assert(this->ule(nextSquare) && "Error in APInt::sqrt computation");
1362 APInt midpoint((nextSquare - square).udiv(two));
1363 APInt offset(*this - square);
1369 /// Computes the multiplicative inverse of this APInt for a given modulo. The
1374 APInt APInt::multiplicativeInverse(const APInt& modulo) const {
1375 assert(ult(modulo) && "This APInt must be smaller than the modulo");
1385 APInt r[2] = { modulo, *this };
1386 APInt t[2] = { APInt(BitWidth, 0), APInt(BitWidth, 1) };
1387 APInt q(BitWidth, 0);
1399 // If this APInt and the modulo are not coprime, there is no multiplicative
1404 return APInt(BitWidth, 0);
1417 APInt::ms APInt::magic() const {
1418 const APInt& d = *this;
1420 APInt ad, anc, delta, q1, r1, q2, r2, t;
1421 APInt signedMin = APInt::getSignedMinValue(d.getBitWidth());
1461 APInt::mu APInt::magicu(unsigned LeadingZeros) const {
1462 const APInt& d = *this;
1464 APInt nc, delta, q1, r1, q2, r2;
1467 APInt allOnes = APInt::getAllOnesValue(d.getBitWidth()).lshr(LeadingZeros);
1468 APInt signedMin = APInt::getSignedMinValue(d.getBitWidth());
1469 APInt signedMax = APInt::getSignedMaxValue(d.getBitWidth());
1671 void APInt::divide(const APInt LHS, unsigned lhsWords,
1672 const APInt &RHS, unsigned rhsWords,
1673 APInt *Quotient, APInt *Remainder)
1802 assert(!Quotient->isSingleWord() && "Quotient APInt not large enough");
1833 assert(!Remainder->isSingleWord() && "Remainder APInt not large enough");
1849 APInt APInt::udiv(const APInt& RHS) const {
1855 return APInt(BitWidth, VAL / RHS.VAL);
1860 unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
1863 unsigned lhsWords = !lhsBits ? 0 : (APInt::whichWord(lhsBits - 1) + 1);
1868 return APInt(BitWidth, 0);
1871 return APInt(BitWidth, 0);
1874 return APInt(BitWidth, 1);
1877 return APInt(BitWidth, this->pVal[0] / RHS.pVal[0]);
1881 APInt Quotient(1,0); // to hold result.
1886 APInt APInt::sdiv(const APInt &RHS) const {
1897 APInt APInt::urem(const APInt& RHS) const {
1901 return APInt(BitWidth, VAL % RHS.VAL);
1910 unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
1916 return APInt(BitWidth, 0);
1922 return APInt(BitWidth, 0);
1925 return APInt(BitWidth, pVal[0] % RHS.pVal[0]);
1929 APInt Remainder(1,0);
1934 APInt APInt::srem(const APInt &RHS) const {
1945 void APInt::udivrem(const APInt &LHS, const APInt &RHS,
1946 APInt &Quotient, APInt &Remainder) {
1954 Quotient = APInt(LHS.BitWidth, QuotVal);
1955 Remainder = APInt(LHS.BitWidth, RemVal);
1961 unsigned lhsWords = !lhsBits ? 0 : (APInt::whichWord(lhsBits - 1) + 1);
1963 unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
1988 Quotient = APInt(LHS.getBitWidth(), lhsValue / rhsValue);
1989 Remainder = APInt(LHS.getBitWidth(), lhsValue % rhsValue);
1997 void APInt::sdivrem(const APInt &LHS, const APInt &RHS,
1998 APInt &Quotient, APInt &Remainder) {
2001 APInt::udivrem(-LHS, -RHS, Quotient, Remainder);
2003 APInt::udivrem(-LHS, RHS, Quotient, Remainder);
2008 APInt::udivrem(LHS, -RHS, Quotient, Remainder);
2011 APInt::udivrem(LHS, RHS, Quotient, Remainder);
2015 APInt APInt::sadd_ov(const APInt &RHS, bool &Overflow) const {
2016 APInt Res = *this+RHS;
2022 APInt APInt::uadd_ov(const APInt &RHS, bool &Overflow) const {
2023 APInt Res = *this+RHS;
2028 APInt APInt::ssub_ov(const APInt &RHS, bool &Overflow) const {
2029 APInt Res = *this - RHS;
2035 APInt APInt::usub_ov(const APInt &RHS, bool &Overflow) const {
2036 APInt Res = *this-RHS;
2041 APInt APInt::sdiv_ov(const APInt &RHS, bool &Overflow) const {
2047 APInt APInt::smul_ov(const APInt &RHS, bool &Overflow) const {
2048 APInt Res = *this * RHS;
2057 APInt APInt::umul_ov(const APInt &RHS, bool &Overflow) const {
2058 APInt Res = *this * RHS;
2067 APInt APInt::sshl_ov(const APInt &ShAmt, bool &Overflow) const {
2070 return APInt(BitWidth, 0);
2080 APInt APInt::ushl_ov(const APInt &ShAmt, bool &Overflow) const {
2083 return APInt(BitWidth, 0);
2093 void APInt::fromString(unsigned numbits, StringRef str, uint8_t radix) {
2121 // Set up an APInt for the digit to add outside the loop so we don't
2123 APInt apdigit(getBitWidth(), 0);
2124 APInt apradix(getBitWidth(), radix);
2153 void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
2222 APInt Tmp(*this);
2255 APInt divisor(Radix == 10? 4 : 8, Radix);
2257 APInt APdigit(1, 0);
2258 APInt tmp2(Tmp.getBitWidth(), 0);
2272 /// Returns the APInt as a std::string. Note that this is an inefficient method.
2274 std::string APInt::toString(unsigned Radix = 10, bool Signed = true) const {
2281 void APInt::dump() const {
2285 dbgs() << "APInt(" << BitWidth << "b, "
2289 void APInt::print(raw_ostream &OS, bool isSigned) const {
2349 APInt::tcSet(integerPart *dst, integerPart part, unsigned int parts)
2362 APInt::tcAssign(integerPart *dst, const integerPart *src, unsigned int parts)
2372 APInt::tcIsZero(const integerPart *src, unsigned int parts)
2385 APInt::tcExtractBit(const integerPart *parts, unsigned int bit)
2393 APInt::tcSetBit(integerPart *parts, unsigned int bit)
2400 APInt::tcClearBit(integerPart *parts, unsigned int bit)
2409 APInt::tcLSB(const integerPart *parts, unsigned int n)
2427 APInt::tcMSB(const integerPart *parts, unsigned int n)
2449 APInt::tcExtract(integerPart *dst, unsigned int dstCount,const integerPart *src,
2483 APInt::tcAdd(integerPart *dst, const integerPart *rhs,
2508 APInt::tcSubtract(integerPart *dst, const integerPart *rhs,
2533 APInt::tcNegate(integerPart *dst, unsigned int parts)
2551 APInt::tcMultiplyPart(integerPart *dst, const integerPart *src,
2644 APInt::tcMultiply(integerPart *dst, const integerPart *lhs,
2667 APInt::tcFullMultiply(integerPart *dst, const integerPart *lhs,
2701 APInt::tcDivide(integerPart *lhs, const integerPart *rhs,
2748 APInt::tcShiftLeft(integerPart *dst, unsigned int parts, unsigned int count)
2782 APInt::tcShiftRight(integerPart *dst, unsigned int parts, unsigned int count)
2814 APInt::tcAnd(integerPart *dst, const integerPart *rhs, unsigned int parts)
2824 APInt::tcOr(integerPart *dst, const integerPart *rhs, unsigned int parts)
2834 APInt::tcXor(integerPart *dst, const integerPart *rhs, unsigned int parts)
2844 APInt::tcComplement(integerPart *dst, unsigned int parts)
2854 APInt::tcCompare(const integerPart *lhs, const integerPart *rhs,
2873 APInt::tcIncrement(integerPart *dst, unsigned int parts)
2886 APInt::tcDecrement(integerPart *dst, unsigned int parts) {
2901 APInt::tcSetLeastSignificantBits(integerPart *dst, unsigned int parts,