]> granicus.if.org Git - llvm/commitdiff
[APInt] Move the setBit and clearBit methods inline.
authorCraig Topper <craig.topper@gmail.com>
Tue, 2 May 2017 05:49:40 +0000 (05:49 +0000)
committerCraig Topper <craig.topper@gmail.com>
Tue, 2 May 2017 05:49:40 +0000 (05:49 +0000)
This makes setBit/clearBit more consistent with setBits which is already inlined.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301900 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APInt.h
lib/Support/APInt.cpp

index 26d4bbcdb8d9a5f93d3ce9e903a0e77b166a3f30..dd12d51e7bded2cc2bc6edc36a9dd14a77a6c70d 100644 (file)
@@ -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() {
index 7103007d8ca5bef28a91cad30ccbe665fbc74f38..e01e6f5e79f3c13e3bb3d485346d108453906ba6 100644 (file)
@@ -392,13 +392,6 @@ int APInt::compareSigned(const APInt& RHS) const {
   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 loBit, unsigned hiBit) {
     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());