[llvm] r304854 - [APInt] Add a isOneValue method that can determine if a number is 1 by only using getActiveBits/countLeadingZeros
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 6 17:57:57 PDT 2017
Author: ctopper
Date: Tue Jun 6 19:57:57 2017
New Revision: 304854
URL: http://llvm.org/viewvc/llvm-project?rev=304854&view=rev
Log:
[APInt] Add a isOneValue method that can determine if a number is 1 by only using getActiveBits/countLeadingZeros
Previously you would have to use operator==(uint64_t) which does the getActiveBits call and a uint64_t comparison. But we can get all we need to know from the getActiveBits call.
This method will be used in another commit.
Modified:
llvm/trunk/include/llvm/ADT/APInt.h
Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=304854&r1=304853&r2=304854&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Tue Jun 6 19:57:57 2017
@@ -392,6 +392,12 @@ public:
/// not.
bool isNullValue() const { return !*this; }
+ /// \brief Determine if all bits are clear
+ ///
+ /// This checks to see if the value has all bits of the APInt are clear or
+ /// not.
+ bool isOneValue() const { return getActiveBits() == 1; }
+
/// \brief Determine if this is the largest unsigned value.
///
/// This checks to see if the value of this APInt is the maximum unsigned
More information about the llvm-commits
mailing list