Home | History | Annotate | Download | only in Support

Lines Matching refs:APInt

1 //===-- APInt.cpp - Implement APInt class ---------------------------------===//
15 #define DEBUG_TYPE "apint"
16 #include "llvm/ADT/APInt.h"
35 assert(result && "APInt memory allocation fails!");
44 assert(result && "APInt memory allocation fails!");
76 void APInt::initSlowCase(unsigned numBits, uint64_t val, bool isSigned) {
84 void APInt::initSlowCase(const APInt& that) {
89 void APInt::initFromArray(ArrayRef<uint64_t> bigVal) {
106 APInt::APInt(unsigned numBits, ArrayRef<uint64_t> bigVal)
111 APInt::APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[])
116 APInt::APInt(unsigned numbits, StringRef Str, uint8_t radix)
122 APInt& APInt::AssignSlowCase(const APInt& RHS) {
154 APInt& APInt::operator=(uint64_t RHS) {
164 /// Profile - This method 'profiles' an APInt for use with FoldingSet.
165 void APInt::Profile(FoldingSetNodeID& ID) const {
195 /// @brief Prefix increment operator. Increments the APInt by one.
196 APInt& APInt::operator++() {
224 /// @brief Prefix decrement operator. Decrements the APInt by one.
225 APInt& APInt::operator--() {
248 /// Adds the RHS APint to this APInt.
251 APInt& APInt::operator+=(const APInt& RHS) {
275 /// Subtracts the RHS APInt from this APInt
278 APInt& APInt::operator-=(const APInt& RHS) {
290 /// @brief Multiply a multi-digit APInt by a single digit (64-bit) integer.
355 APInt& APInt::operator*=(const APInt& RHS) {
397 APInt& APInt::operator&=(const APInt& RHS) {
409 APInt& APInt::operator|=(const APInt& RHS) {
421 APInt& APInt::operator^=(const APInt& RHS) {
434 APInt APInt::AndSlowCase(const APInt& RHS) const {
439 return APInt(val, getBitWidth());
442 APInt APInt::OrSlowCase(const APInt& RHS) const {
447 return APInt(val, getBitWidth());
450 APInt APInt::XorSlowCase(const APInt& RHS) const {
457 return APInt(val, getBitWidth()).clearUnusedBits();
460 APInt APInt::operator*(const APInt& RHS) const {
463 return APInt(BitWidth, VAL * RHS.VAL);
464 APInt Result(*this);
469 APInt APInt::operator+(const APInt& RHS) const {
472 return APInt(BitWidth, VAL + RHS.VAL);
473 APInt Result(BitWidth, 0);
478 APInt APInt::operator-(const APInt& RHS) const {
481 return APInt(BitWidth, VAL - RHS.VAL);
482 APInt Result(BitWidth, 0);
487 bool APInt::EqualSlowCase(const APInt& RHS) const {
507 bool APInt::EqualSlowCase(uint64_t Val) const {
515 bool APInt::ult(const APInt& RHS) const {
547 bool APInt::slt(const APInt& RHS) const {
555 APInt lhs(*this);
556 APInt rhs(RHS);
583 void APInt::setBit(unsigned bitPosition) {
592 void APInt::clearBit(unsigned bitPosition) {
604 void APInt::flipBit(unsigned bitPosition) {
610 unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) {
651 APInt tmp(sufficient, StringRef(p, slen), radix);
663 hash_code llvm::hash_value(const APInt &Arg) {
670 /// HiBits - This function returns the high "numBits" bits of this APInt.
671 APInt APInt::getHiBits(unsigned numBits) const {
675 /// LoBits - This function returns the low "numBits" bits of this APInt.
676 APInt APInt::getLoBits(unsigned numBits) const {
681 unsigned APInt::countLeadingZerosSlowCase() const {
709 unsigned APInt::countLeadingOnes() const {
736 unsigned APInt::countTrailingZeros() const {
748 unsigned APInt::countTrailingOnesSlowCase() const {
758 unsigned APInt::countPopulationSlowCase() const {
777 APInt APInt::byteSwap() const {
780 return APInt(BitWidth, ByteSwap_16(uint16_t(VAL)));
782 return APInt(BitWidth, ByteSwap_32(unsigned(VAL)));
788 return APInt(BitWidth, (uint64_t(Tmp2) << 32) | Tmp1);
791 return APInt(BitWidth, ByteSwap_64(VAL));
793 APInt Result(getNumWords() * APINT_BITS_PER_WORD, 0);
804 APInt llvm::APIntOps::GreatestCommonDivisor(const APInt& API1,
805 const APInt& API2) {
806 APInt A = API1, B = API2;
808 APInt T = B;
815 APInt llvm::APIntOps::RoundDoubleToAPInt(double Double, unsigned width) {
830 return APInt(width, 0u);
837 return isNeg ? -APInt(width, mantissa >> (52 - exp)) :
838 APInt(width, mantissa >> (52 - exp));
843 return APInt(width, 0);
846 APInt Tmp(width, mantissa);
851 /// RoundToDouble - This function converts this APInt to a double.
858 double APInt::roundToDouble(bool isSigned) const {
874 APInt Tmp(isNeg ? -(*this) : (*this));
919 APInt APInt::trunc(unsigned width) const {
920 assert(width < BitWidth && "Invalid APInt Truncate request");
924 return APInt(width, getRawData()[0]);
926 APInt Result(getMemory(getNumWords(width)), width);
942 APInt APInt::sext(unsigned width) const {
943 assert(width > BitWidth && "Invalid APInt SignExtend request");
948 return APInt(width, val >> (APINT_BITS_PER_WORD - width));
951 APInt Result(getMemory(getNumWords(width)), width);
983 APInt APInt::zext(unsigned width) const {
984 assert(width > BitWidth && "Invalid APInt ZeroExtend request");
987 return APInt(width, VAL);
989 APInt Result(getMemory(getNumWords(width)), width);
1002 APInt APInt::zextOrTrunc(unsigned width) const {
1010 APInt APInt::sextOrTrunc(unsigned width) const {
1018 APInt APInt::zextOrSelf(unsigned width) const {
1024 APInt APInt::sextOrSelf(unsigned width) const {
1030 /// Arithmetic right-shift this APInt by shiftAmt.
1032 APInt APInt::ashr(const APInt &shiftAmt) const {
1036 /// Arithmetic right-shift this APInt by shiftAmt.
1038 APInt APInt::ashr(unsigned shiftAmt) const {
1047 return APInt(BitWidth, 0); // undefined
1050 return APInt(BitWidth,
1060 return APInt(BitWidth, -1ULL, true);
1062 return APInt(BitWidth, 0);
1116 return APInt(val, BitWidth).clearUnusedBits();
1119 /// Logical right-shift this APInt by shiftAmt.
1121 APInt APInt::lshr(const APInt &shiftAmt) const {
1125 /// Logical right-shift this APInt by shiftAmt.
1127 APInt APInt::lshr(unsigned shiftAmt) const {
1130 return APInt(BitWidth, 0);
1132 return APInt(BitWidth, this->VAL >> shiftAmt);
1139 return APInt(BitWidth, 0);
1153 return APInt(val, BitWidth).clearUnusedBits();
1166 return APInt(val,BitWidth).clearUnusedBits();
1180 return APInt(val, BitWidth).clearUnusedBits();
1183 /// Left-shift this APInt by shiftAmt.
1185 APInt APInt::shl(const APInt &shiftAmt) const {
1190 APInt APInt::shlSlowCase(unsigned shiftAmt) const {
1195 return APInt(BitWidth, 0);
1213 return APInt(val, BitWidth).clearUnusedBits();
1226 return APInt(val,BitWidth).clearUnusedBits();
1237 return APInt(val, BitWidth).clearUnusedBits();
1240 APInt APInt::rotl(const APInt &rotateAmt) const {
1244 APInt APInt::rotl(unsigned rotateAmt) const {
1251 APInt APInt::rotr(const APInt &rotateAmt) const {
1255 APInt APInt::rotr(unsigned rotateAmt) const {
1269 APInt APInt::sqrt() const {
1286 return APInt(BitWidth, results[ (isSingleWord() ? VAL : pVal[0]) ]);
1295 return APInt(BitWidth,
1298 return APInt(BitWidth,
1305 // was adapted to APINt from a wikipedia article on such computations.
1309 APInt testy(BitWidth, 16);
1310 APInt x_old(BitWidth, 1);
1311 APInt x_new(BitWidth, 0);
1312 APInt two(BitWidth, 2);
1335 APInt square(x_old * x_old);
1336 APInt nextSquare((x_old + 1) * (x_old +1));
1339 assert(this->ule(nextSquare) && "Error in APInt::sqrt computation");
1340 APInt midpoint((nextSquare - square).udiv(two));
1341 APInt offset(*this - square);
1347 /// Computes the multiplicative inverse of this APInt for a given modulo. The
1352 APInt APInt::multiplicativeInverse(const APInt& modulo) const {
1353 assert(ult(modulo) && "This APInt must be smaller than the modulo");
1363 APInt r[2] = { modulo, *this };
1364 APInt t[2] = { APInt(BitWidth, 0), APInt(BitWidth, 1) };
1365 APInt q(BitWidth, 0);
1377 // If this APInt and the modulo are not coprime, there is no multiplicative
1382 return APInt(BitWidth, 0);
1395 APInt::ms APInt::magic() const {
1396 const APInt& d = *this;
1398 APInt ad, anc, delta, q1, r1, q2, r2, t;
1399 APInt signedMin = APInt::getSignedMinValue(d.getBitWidth());
1439 APInt::mu APInt::magicu(unsigned LeadingZeros) const {
1440 const APInt& d = *this;
1442 APInt nc, delta, q1, r1, q2, r2;
1445 APInt allOnes = APInt::getAllOnesValue(d.getBitWidth()).lshr(LeadingZeros);
1446 APInt signedMin = APInt::getSignedMinValue(d.getBitWidth());
1447 APInt signedMax = APInt::getSignedMaxValue(d.getBitWidth());
1666 void APInt::divide(const APInt LHS, unsigned lhsWords,
1667 const APInt &RHS, unsigned rhsWords,
1668 APInt *Quotient, APInt *Remainder)
1795 assert(!Quotient->isSingleWord() && "Quotient APInt not large enough");
1826 assert(!Remainder->isSingleWord() && "Remainder APInt not large enough");
1842 APInt APInt::udiv(const APInt& RHS) const {
1848 return APInt(BitWidth, VAL / RHS.VAL);
1853 unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
1856 unsigned lhsWords = !lhsBits ? 0 : (APInt::whichWord(lhsBits - 1) + 1);
1861 return APInt(BitWidth, 0);
1864 return APInt(BitWidth, 0);
1867 return APInt(BitWidth, 1);
1870 return APInt(BitWidth, this->pVal[0] / RHS.pVal[0]);
1874 APInt Quotient(1,0); // to hold result.
1879 APInt APInt::urem(const APInt& RHS) const {
1883 return APInt(BitWidth, VAL % RHS.VAL);
1892 unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
1898 return APInt(BitWidth, 0);
1904 return APInt(BitWidth, 0);
1907 return APInt(BitWidth, pVal[0] % RHS.pVal[0]);
1911 APInt Remainder(1,0);
1916 void APInt::udivrem(const APInt &LHS, const APInt &RHS,
1917 APInt &Quotient, APInt &Remainder) {
1920 unsigned lhsWords = !lhsBits ? 0 : (APInt::whichWord(lhsBits - 1) + 1);
1922 unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
1947 Quotient = APInt(LHS.getBitWidth(), lhsValue / rhsValue);
1948 Remainder = APInt(LHS.getBitWidth(), lhsValue % rhsValue);
1956 APInt APInt::sadd_ov(const APInt &RHS, bool &Overflow) const {
1957 APInt Res = *this+RHS;
1963 APInt APInt::uadd_ov(const APInt &RHS, bool &Overflow) const {
1964 APInt Res = *this+RHS;
1969 APInt APInt::ssub_ov(const APInt &RHS, bool &Overflow) const {
1970 APInt Res = *this - RHS;
1976 APInt APInt::usub_ov(const APInt &RHS, bool &Overflow) const {
1977 APInt Res = *this-RHS;
1982 APInt APInt::sdiv_ov(const APInt &RHS, bool &Overflow) const {
1988 APInt APInt::smul_ov(const APInt &RHS, bool &Overflow) const {
1989 APInt Res = *this * RHS;
1998 APInt APInt::umul_ov(const APInt &RHS, bool &Overflow) const {
1999 APInt Res = *this * RHS;
2008 APInt APInt::sshl_ov(unsigned ShAmt, bool &Overflow) const {
2024 void APInt::fromString(unsigned numbits, StringRef str, uint8_t radix) {
2052 // Set up an APInt for the digit to add outside the loop so we don't
2054 APInt apdigit(getBitWidth(), 0);
2055 APInt apradix(getBitWidth(), radix);
2084 void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
2153 APInt Tmp(*this);
2186 APInt divisor(Radix == 10? 4 : 8, Radix);
2188 APInt APdigit(1, 0);
2189 APInt tmp2(Tmp.getBitWidth(), 0);
2203 /// toString - This returns the APInt as a std::string. Note that this is an
2206 std::string APInt::toString(unsigned Radix = 10, bool Signed = true) const {
2213 void APInt::dump() const {
2217 dbgs() << "APInt(" << BitWidth << "b, "
2221 void APInt::print(raw_ostream &OS, bool isSigned) const {
2316 APInt::tcSet(integerPart *dst, integerPart part, unsigned int parts)
2329 APInt::tcAssign(integerPart *dst, const integerPart *src, unsigned int parts)
2339 APInt::tcIsZero(const integerPart *src, unsigned int parts)
2352 APInt::tcExtractBit(const integerPart *parts, unsigned int bit)
2360 APInt::tcSetBit(integerPart *parts, unsigned int bit)
2367 APInt::tcClearBit(integerPart *parts, unsigned int bit)
2376 APInt::tcLSB(const integerPart *parts, unsigned int n)
2394 APInt::tcMSB(const integerPart *parts, unsigned int n)
2416 APInt::tcExtract(integerPart *dst, unsigned int dstCount,const integerPart *src,
2450 APInt::tcAdd(integerPart *dst, const integerPart *rhs,
2475 APInt::tcSubtract(integerPart *dst, const integerPart *rhs,
2500 APInt::tcNegate(integerPart *dst, unsigned int parts)
2518 APInt::tcMultiplyPart(integerPart *dst, const integerPart *src,
2611 APInt::tcMultiply(integerPart *dst, const integerPart *lhs,
2634 APInt::tcFullMultiply(integerPart *dst, const integerPart *lhs,
2668 APInt::tcDivide(integerPart *lhs, const integerPart *rhs,
2715 APInt::tcShiftLeft(integerPart *dst, unsigned int parts, unsigned int count)
2749 APInt::tcShiftRight(integerPart *dst, unsigned int parts, unsigned int count)
2781 APInt::tcAnd(integerPart *dst, const integerPart *rhs, unsigned int parts)
2791 APInt::tcOr(integerPart *dst, const integerPart *rhs, unsigned int parts)
2801 APInt::tcXor(integerPart *dst, const integerPart *rhs, unsigned int parts)
2811 APInt::tcComplement(integerPart *dst, unsigned int parts)
2821 APInt::tcCompare(const integerPart *lhs, const integerPart *rhs,
2840 APInt::tcIncrement(integerPart *dst, unsigned int parts)
2854 APInt::tcSetLeastSignificantBits(integerPart *dst, unsigned int parts,