Home | History | Annotate | Download | only in Support

Lines Matching refs: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 /// Profile - 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 {
458 return APInt(val, getBitWidth()).clearUnusedBits();
461 APInt APInt::operator*(const APInt& RHS) const {
464 return APInt(BitWidth, VAL * RHS.VAL);
465 APInt Result(*this);
470 APInt APInt::operator+(const APInt& RHS) const {
473 return APInt(BitWidth, VAL + RHS.VAL);
474 APInt Result(BitWidth, 0);
479 APInt APInt::operator-(const APInt& RHS) const {
482 return APInt(BitWidth, VAL - RHS.VAL);
483 APInt Result(BitWidth, 0);
488 bool APInt::EqualSlowCase(const APInt& RHS) const {
508 bool APInt::EqualSlowCase(uint64_t Val) const {
516 bool APInt::ult(const APInt& RHS) const {
548 bool APInt::slt(const APInt& RHS) const {
556 APInt lhs(*this);
557 APInt rhs(RHS);
584 void APInt::setBit(unsigned bitPosition) {
593 void APInt::clearBit(unsigned bitPosition) {
605 void APInt::flipBit(unsigned bitPosition) {
611 unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) {
652 APInt tmp(sufficient, StringRef(p, slen), radix);
664 hash_code llvm::hash_value(const APInt &Arg) {
671 /// HiBits - This function returns the high "numBits" bits of this APInt.
672 APInt APInt::getHiBits(unsigned numBits) const {
676 /// LoBits - This function returns the low "numBits" bits of this APInt.
677 APInt APInt::getLoBits(unsigned numBits) const {
682 unsigned APInt::countLeadingZerosSlowCase() const {
710 unsigned APInt::countLeadingOnes() const {
737 unsigned APInt::countTrailingZeros() const {
749 unsigned APInt::countTrailingOnesSlowCase() const {
759 unsigned APInt::countPopulationSlowCase() const {
778 APInt APInt::byteSwap() const {
781 return APInt(BitWidth, ByteSwap_16(uint16_t(VAL)));
783 return APInt(BitWidth, ByteSwap_32(unsigned(VAL)));
789 return APInt(BitWidth, (uint64_t(Tmp2) << 32) | Tmp1);
792 return APInt(BitWidth, ByteSwap_64(VAL));
794 APInt Result(getNumWords() * APINT_BITS_PER_WORD, 0);
805 APInt llvm::APIntOps::GreatestCommonDivisor(const APInt& API1,
806 const APInt& API2) {
807 APInt A = API1, B = API2;
809 APInt T = B;
816 APInt llvm::APIntOps::RoundDoubleToAPInt(double Double, unsigned width) {
831 return APInt(width, 0u);
838 return isNeg ? -APInt(width, mantissa >> (52 - exp)) :
839 APInt(width, mantissa >> (52 - exp));
844 return APInt(width, 0);
847 APInt Tmp(width, mantissa);
852 /// RoundToDouble - This function converts this APInt to a double.
859 double APInt::roundToDouble(bool isSigned) const {
875 APInt Tmp(isNeg ? -(*this) : (*this));
920 APInt APInt::trunc(unsigned width) const {
921 assert(width < BitWidth && "Invalid APInt Truncate request");
925 return APInt(width, getRawData()[0]);
927 APInt Result(getMemory(getNumWords(width)), width);
943 APInt APInt::sext(unsigned width) const {
944 assert(width > BitWidth && "Invalid APInt SignExtend request");
949 return APInt(width, val >> (APINT_BITS_PER_WORD - width));
952 APInt Result(getMemory(getNumWords(width)), width);
984 APInt APInt::zext(unsigned width) const {
985 assert(width > BitWidth && "Invalid APInt ZeroExtend request");
988 return APInt(width, VAL);
990 APInt Result(getMemory(getNumWords(width)), width);
1003 APInt APInt::zextOrTrunc(unsigned width) const {
1011 APInt APInt::sextOrTrunc(unsigned width) const {
1019 APInt APInt::zextOrSelf(unsigned width) const {
1025 APInt APInt::sextOrSelf(unsigned width) const {
1031 /// Arithmetic right-shift this APInt by shiftAmt.
1033 APInt APInt::ashr(const APInt &shiftAmt) const {
1037 /// Arithmetic right-shift this APInt by shiftAmt.
1039 APInt APInt::ashr(unsigned shiftAmt) const {
1048 return APInt(BitWidth, 0); // undefined
1051 return APInt(BitWidth,
1061 return APInt(BitWidth, -1ULL, true);
1063 return APInt(BitWidth, 0);
1117 return APInt(val, BitWidth).clearUnusedBits();
1120 /// Logical right-shift this APInt by shiftAmt.
1122 APInt APInt::lshr(const APInt &shiftAmt) const {
1126 /// Logical right-shift this APInt by shiftAmt.
1128 APInt APInt::lshr(unsigned shiftAmt) const {
1131 return APInt(BitWidth, 0);
1133 return APInt(BitWidth, this->VAL >> shiftAmt);
1140 return APInt(BitWidth, 0);
1154 return APInt(val, BitWidth).clearUnusedBits();
1167 return APInt(val,BitWidth).clearUnusedBits();
1181 return APInt(val, BitWidth).clearUnusedBits();
1184 /// Left-shift this APInt by shiftAmt.
1186 APInt APInt::shl(const APInt &shiftAmt) const {
1191 APInt APInt::shlSlowCase(unsigned shiftAmt) const {
1196 return APInt(BitWidth, 0);
1214 return APInt(val, BitWidth).clearUnusedBits();
1227 return APInt(val,BitWidth).clearUnusedBits();
1238 return APInt(val, BitWidth).clearUnusedBits();
1241 APInt APInt::rotl(const APInt &rotateAmt) const {
1245 APInt APInt::rotl(unsigned rotateAmt) const {
1252 APInt APInt::rotr(const APInt &rotateAmt) const {
1256 APInt APInt::rotr(unsigned rotateAmt) const {
1270 APInt APInt::sqrt() const {
1287 return APInt(BitWidth, results[ (isSingleWord() ? VAL : pVal[0]) ]);
1296 return APInt(BitWidth,
1299 return APInt(BitWidth,
1306 // was adapted to APINt from a wikipedia article on such computations.
1310 APInt testy(BitWidth, 16);
1311 APInt x_old(BitWidth, 1);
1312 APInt x_new(BitWidth, 0);
1313 APInt two(BitWidth, 2);
1336 APInt square(x_old * x_old);
1337 APInt nextSquare((x_old + 1) * (x_old +1));
1340 assert(this->ule(nextSquare) && "Error in APInt::sqrt computation");
1341 APInt midpoint((nextSquare - square).udiv(two));
1342 APInt offset(*this - square);
1348 /// Computes the multiplicative inverse of this APInt for a given modulo. The
1353 APInt APInt::multiplicativeInverse(const APInt& modulo) const {
1354 assert(ult(modulo) && "This APInt must be smaller than the modulo");
1364 APInt r[2] = { modulo, *this };
1365 APInt t[2] = { APInt(BitWidth, 0), APInt(BitWidth, 1) };
1366 APInt q(BitWidth, 0);
1378 // If this APInt and the modulo are not coprime, there is no multiplicative
1383 return APInt(BitWidth, 0);
1396 APInt::ms APInt::magic() const {
1397 const APInt& d = *this;
1399 APInt ad, anc, delta, q1, r1, q2, r2, t;
1400 APInt signedMin = APInt::getSignedMinValue(d.getBitWidth());
1440 APInt::mu APInt::magicu(unsigned LeadingZeros) const {
1441 const APInt& d = *this;
1443 APInt nc, delta, q1, r1, q2, r2;
1446 APInt allOnes = APInt::getAllOnesValue(d.getBitWidth()).lshr(LeadingZeros);
1447 APInt signedMin = APInt::getSignedMinValue(d.getBitWidth());
1448 APInt signedMax = APInt::getSignedMaxValue(d.getBitWidth());
1667 void APInt::divide(const APInt LHS, unsigned lhsWords,
1668 const APInt &RHS, unsigned rhsWords,
1669 APInt *Quotient, APInt *Remainder)
1796 assert(!Quotient->isSingleWord() && "Quotient APInt not large enough");
1827 assert(!Remainder->isSingleWord() && "Remainder APInt not large enough");
1843 APInt APInt::udiv(const APInt& RHS) const {
1849 return APInt(BitWidth, VAL / RHS.VAL);
1854 unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
1857 unsigned lhsWords = !lhsBits ? 0 : (APInt::whichWord(lhsBits - 1) + 1);
1862 return APInt(BitWidth, 0);
1865 return APInt(BitWidth, 0);
1868 return APInt(BitWidth, 1);
1871 return APInt(BitWidth, this->pVal[0] / RHS.pVal[0]);
1875 APInt Quotient(1,0); // to hold result.
1880 APInt APInt::sdiv(const APInt &RHS) const {
1891 APInt APInt::urem(const APInt& RHS) const {
1895 return APInt(BitWidth, VAL % RHS.VAL);
1904 unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
1910 return APInt(BitWidth, 0);
1916 return APInt(BitWidth, 0);
1919 return APInt(BitWidth, pVal[0] % RHS.pVal[0]);
1923 APInt Remainder(1,0);
1928 APInt APInt::srem(const APInt &RHS) const {
1939 void APInt::udivrem(const APInt &LHS, const APInt &RHS,
1940 APInt &Quotient, APInt &Remainder) {
1943 unsigned lhsWords = !lhsBits ? 0 : (APInt::whichWord(lhsBits - 1) + 1);
1945 unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
1970 Quotient = APInt(LHS.getBitWidth(), lhsValue / rhsValue);
1971 Remainder = APInt(LHS.getBitWidth(), lhsValue % rhsValue);
1979 void APInt::sdivrem(const APInt &LHS, const APInt &RHS,
1980 APInt &Quotient, APInt &Remainder) {
1983 APInt::udivrem(-LHS, -RHS, Quotient, Remainder);
1985 APInt::udivrem(-LHS, RHS, Quotient, Remainder);
1990 APInt::udivrem(LHS, -RHS, Quotient, Remainder);
1993 APInt::udivrem(LHS, RHS, Quotient, Remainder);
1997 APInt APInt::sadd_ov(const APInt &RHS, bool &Overflow) const {
1998 APInt Res = *this+RHS;
2004 APInt APInt::uadd_ov(const APInt &RHS, bool &Overflow) const {
2005 APInt Res = *this+RHS;
2010 APInt APInt::ssub_ov(const APInt &RHS, bool &Overflow) const {
2011 APInt Res = *this - RHS;
2017 APInt APInt::usub_ov(const APInt &RHS, bool &Overflow) const {
2018 APInt Res = *this-RHS;
2023 APInt APInt::sdiv_ov(const APInt &RHS, bool &Overflow) const {
2029 APInt APInt::smul_ov(const APInt &RHS, bool &Overflow) const {
2030 APInt Res = *this * RHS;
2039 APInt APInt::umul_ov(const APInt &RHS, bool &Overflow) const {
2040 APInt Res = *this * RHS;
2049 APInt APInt::sshl_ov(unsigned ShAmt, bool &Overflow) const {
2065 void APInt::fromString(unsigned numbits, StringRef str, uint8_t radix) {
2093 // Set up an APInt for the digit to add outside the loop so we don't
2095 APInt apdigit(getBitWidth(), 0);
2096 APInt apradix(getBitWidth(), radix);
2125 void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
2194 APInt Tmp(*this);
2227 APInt divisor(Radix == 10? 4 : 8, Radix);
2229 APInt APdigit(1, 0);
2230 APInt tmp2(Tmp.getBitWidth(), 0);
2244 /// toString - This returns the APInt as a std::string. Note that this is an
2247 std::string APInt::toString(unsigned Radix = 10, bool Signed = true) const {
2254 void APInt::dump() const {
2258 dbgs() << "APInt(" << BitWidth << "b, "
2262 void APInt::print(raw_ostream &OS, bool isSigned) const {
2323 APInt::tcSet(integerPart *dst, integerPart part, unsigned int parts)
2336 APInt::tcAssign(integerPart *dst, const integerPart *src, unsigned int parts)
2346 APInt::tcIsZero(const integerPart *src, unsigned int parts)
2359 APInt::tcExtractBit(const integerPart *parts, unsigned int bit)
2367 APInt::tcSetBit(integerPart *parts, unsigned int bit)
2374 APInt::tcClearBit(integerPart *parts, unsigned int bit)
2383 APInt::tcLSB(const integerPart *parts, unsigned int n)
2401 APInt::tcMSB(const integerPart *parts, unsigned int n)
2423 APInt::tcExtract(integerPart *dst, unsigned int dstCount,const integerPart *src,
2457 APInt::tcAdd(integerPart *dst, const integerPart *rhs,
2482 APInt::tcSubtract(integerPart *dst, const integerPart *rhs,
2507 APInt::tcNegate(integerPart *dst, unsigned int parts)
2525 APInt::tcMultiplyPart(integerPart *dst, const integerPart *src,
2618 APInt::tcMultiply(integerPart *dst, const integerPart *lhs,
2641 APInt::tcFullMultiply(integerPart *dst, const integerPart *lhs,
2675 APInt::tcDivide(integerPart *lhs, const integerPart *rhs,
2722 APInt::tcShiftLeft(integerPart *dst, unsigned int parts, unsigned int count)
2756 APInt::tcShiftRight(integerPart *dst, unsigned int parts, unsigned int count)
2788 APInt::tcAnd(integerPart *dst, const integerPart *rhs, unsigned int parts)
2798 APInt::tcOr(integerPart *dst, const integerPart *rhs, unsigned int parts)
2808 APInt::tcXor(integerPart *dst, const integerPart *rhs, unsigned int parts)
2818 APInt::tcComplement(integerPart *dst, unsigned int parts)
2828 APInt::tcCompare(const integerPart *lhs, const integerPart *rhs,
2847 APInt::tcIncrement(integerPart *dst, unsigned int parts)
2860 APInt::tcDecrement(integerPart *dst, unsigned int parts) {
2875 APInt::tcSetLeastSignificantBits(integerPart *dst, unsigned int parts,