mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-18 21:24:32 -04:00
[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
This commit is contained in:
@@ -1846,10 +1846,8 @@ void APInt::fromString(unsigned numbits, StringRef str, uint8_t radix) {
|
||||
*this += digit;
|
||||
}
|
||||
// If its negative, put it in two's complement form
|
||||
if (isNeg) {
|
||||
--(*this);
|
||||
this->flipAllBits();
|
||||
}
|
||||
if (isNeg)
|
||||
this->negate();
|
||||
}
|
||||
|
||||
void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
|
||||
@@ -1927,8 +1925,7 @@ void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
|
||||
// They want to print the signed version and it is a negative value
|
||||
// Flip the bits and add one to turn it into the equivalent positive
|
||||
// value and put a '-' in the result.
|
||||
Tmp.flipAllBits();
|
||||
++Tmp;
|
||||
Tmp.negate();
|
||||
Str.push_back('-');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user