diff options
| author | Craig Topper <craig.topper@gmail.com> | 2017-05-10 20:01:38 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@gmail.com> | 2017-05-10 20:01:38 +0000 |
| commit | ef0114c4f0a1612cdafb71711cafda0653afebde (patch) | |
| tree | c6bf771413f4fc959d015d58daa7ddf98147374a /llvm/include | |
| parent | f41f274bf84712ef7057e532109bd0aa43e2c532 (diff) | |
| download | bcm5719-llvm-ef0114c4f0a1612cdafb71711cafda0653afebde.tar.gz bcm5719-llvm-ef0114c4f0a1612cdafb71711cafda0653afebde.zip | |
[APInt] Add negate helper method to implement twos complement. Use it to shorten code.
llvm-svn: 302716
Diffstat (limited to 'llvm/include')
| -rw-r--r-- | llvm/include/llvm/ADT/APInt.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index 934fe912f01..f1b039e16dc 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -1437,6 +1437,12 @@ public: /// as "bitPosition". void flipBit(unsigned bitPosition); + /// Negate this APInt in place. + void negate() { + flipAllBits(); + ++(*this); + } + /// Insert the bits from a smaller APInt starting at bitPosition. void insertBits(const APInt &SubBits, unsigned bitPosition); @@ -1996,8 +2002,7 @@ inline raw_ostream &operator<<(raw_ostream &OS, const APInt &I) { } inline APInt operator-(APInt v) { - v.flipAllBits(); - ++v; + v.negate(); return v; } |

