llvm.org GIT mirror llvm / d53f653
[APInt] Add negate helper method to implement twos complement. Use it to shorten code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302716 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 3 years ago
2 changed file(s) with 10 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
14361436 /// as "bitPosition".
14371437 void flipBit(unsigned bitPosition);
14381438
1439 /// Negate this APInt in place.
1440 void negate() {
1441 flipAllBits();
1442 ++(*this);
1443 }
1444
14391445 /// Insert the bits from a smaller APInt starting at bitPosition.
14401446 void insertBits(const APInt &SubBits, unsigned bitPosition);
14411447
19952001 }
19962002
19972003 inline APInt operator-(APInt v) {
1998 v.flipAllBits();
1999 ++v;
2004 v.negate();
20002005 return v;
20012006 }
20022007
18451845 *this += digit;
18461846 }
18471847 // If its negative, put it in two's complement form
1848 if (isNeg) {
1849 --(*this);
1850 this->flipAllBits();
1851 }
1848 if (isNeg)
1849 this->negate();
18521850 }
18531851
18541852 void APInt::toString(SmallVectorImpl &Str, unsigned Radix,
19261924 // They want to print the signed version and it is a negative value
19271925 // Flip the bits and add one to turn it into the equivalent positive
19281926 // value and put a '-' in the result.
1929 Tmp.flipAllBits();
1930 ++Tmp;
1927 Tmp.negate();
19311928 Str.push_back('-');
19321929 }
19331930