[llvm] r299342 - [APInt] Make use of whichWord and maskBit to simplify some code. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 2 12:35:19 PDT 2017


Author: ctopper
Date: Sun Apr  2 14:35:18 2017
New Revision: 299342

URL: http://llvm.org/viewvc/llvm-project?rev=299342&view=rev
Log:
[APInt] Make use of whichWord and maskBit to simplify some code. NFC

Modified:
    llvm/trunk/lib/Support/APInt.cpp

Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=299342&r1=299341&r2=299342&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Sun Apr  2 14:35:18 2017
@@ -2375,19 +2375,17 @@ bool APInt::tcIsZero(const WordType *src
 
 /* Extract the given bit of a bignum; returns 0 or 1.  */
 int APInt::tcExtractBit(const WordType *parts, unsigned bit) {
-  return (parts[bit / APINT_BITS_PER_WORD] &
-          ((WordType) 1 << bit % APINT_BITS_PER_WORD)) != 0;
+  return (parts[whichWord(bit)] & maskBit(bit)) != 0;
 }
 
 /* Set the given bit of a bignum. */
 void APInt::tcSetBit(WordType *parts, unsigned bit) {
-  parts[bit / APINT_BITS_PER_WORD] |= (WordType) 1 << (bit % APINT_BITS_PER_WORD);
+  parts[whichWord(bit)] |= maskBit(bit);
 }
 
 /* Clears the given bit of a bignum. */
 void APInt::tcClearBit(WordType *parts, unsigned bit) {
-  parts[bit / APINT_BITS_PER_WORD] &=
-    ~((WordType) 1 << (bit % APINT_BITS_PER_WORD));
+  parts[whichWord(bit)] &= ~maskBit(bit);
 }
 
 /* Returns the bit number of the least significant set bit of a




More information about the llvm-commits mailing list