[llvm] r301900 - [APInt] Move the setBit and clearBit methods inline.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon May 1 22:49:40 PDT 2017


Author: ctopper
Date: Tue May  2 00:49:40 2017
New Revision: 301900

URL: http://llvm.org/viewvc/llvm-project?rev=301900&view=rev
Log:
[APInt] Move the setBit and clearBit methods inline.

This makes setBit/clearBit more consistent with setBits which is already inlined.

Modified:
    llvm/trunk/include/llvm/ADT/APInt.h
    llvm/trunk/lib/Support/APInt.cpp

Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=301900&r1=301899&r2=301900&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Tue May  2 00:49:40 2017
@@ -1352,7 +1352,14 @@ public:
   /// \brief Set a given bit to 1.
   ///
   /// Set the given bit to 1 whose position is given as "bitPosition".
-  void setBit(unsigned bitPosition);
+  void setBit(unsigned BitPosition) {
+    assert(BitPosition <= BitWidth && "BitPosition out of range");
+    WordType Mask = maskBit(BitPosition);
+    if (isSingleWord())
+      VAL |= Mask;
+    else
+      pVal[whichWord(BitPosition)] |= Mask;
+  }
 
   /// Set the sign bit to 1.
   void setSignBit() {
@@ -1404,7 +1411,14 @@ public:
   /// \brief Set a given bit to 0.
   ///
   /// Set the given bit to 0 whose position is given as "bitPosition".
-  void clearBit(unsigned bitPosition);
+  void clearBit(unsigned BitPosition) {
+    assert(BitPosition <= BitWidth && "BitPosition out of range");
+    WordType Mask = ~maskBit(BitPosition);
+    if (isSingleWord())
+      VAL &= Mask;
+    else
+      pVal[whichWord(BitPosition)] &= Mask;
+  }
 
   /// Set the sign bit to 0.
   void clearSignBit() {

Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=301900&r1=301899&r2=301900&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Tue May  2 00:49:40 2017
@@ -392,13 +392,6 @@ int APInt::compareSigned(const APInt& RH
   return tcCompare(pVal, RHS.pVal, getNumWords());
 }
 
-void APInt::setBit(unsigned bitPosition) {
-  if (isSingleWord())
-    VAL |= maskBit(bitPosition);
-  else
-    pVal[whichWord(bitPosition)] |= maskBit(bitPosition);
-}
-
 void APInt::setBitsSlowCase(unsigned loBit, unsigned hiBit) {
   unsigned loWord = whichWord(loBit);
   unsigned hiWord = whichWord(hiBit);
@@ -426,15 +419,6 @@ void APInt::setBitsSlowCase(unsigned loB
     pVal[word] = WORD_MAX;
 }
 
-/// Set the given bit to 0 whose position is given as "bitPosition".
-/// @brief Set a given bit to 0.
-void APInt::clearBit(unsigned bitPosition) {
-  if (isSingleWord())
-    VAL &= ~maskBit(bitPosition);
-  else
-    pVal[whichWord(bitPosition)] &= ~maskBit(bitPosition);
-}
-
 /// @brief Toggle every bit to its opposite value.
 void APInt::flipAllBitsSlowCase() {
   tcComplement(pVal, getNumWords());




More information about the llvm-commits mailing list