[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Reid Spencer
reid at x10sys.com
Sat Mar 24 16:28:05 PDT 2007
Changes in directory llvm/include/llvm/ADT:
APInt.h updated: 1.51 -> 1.52
---
Log message:
Implement the getBitsSet function.
---
Diffs of the changes: (+10 -1)
APInt.h | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletion(-)
Index: llvm/include/llvm/ADT/APInt.h
diff -u llvm/include/llvm/ADT/APInt.h:1.51 llvm/include/llvm/ADT/APInt.h:1.52
--- llvm/include/llvm/ADT/APInt.h:1.51 Sat Mar 24 18:05:35 2007
+++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 18:27:48 2007
@@ -340,7 +340,16 @@
/// @param loBit the index of the lowest bit set.
/// @returns An APInt value with the requested bits set.
/// @brief Get a value with a block of bits set.
- static APInt getBitsSet(uint32_t numBits, uint32_t hiBit, uint32_t loBit = 0);
+ static APInt getBitsSet(uint32_t numBits, uint32_t hiBit, uint32_t loBit = 0){
+ assert(hiBit < numBits && "hiBit out of range");
+ assert(loBit < numBits && "loBit out of range");
+ if (hiBit < loBit)
+ return getLowBitsSet(numBits, hiBit+1) |
+ getHighBitsSet(numBits, numBits-loBit+1);
+ else if (loBit == 0)
+ return getLowBitsSet(numBits, hiBit+1);
+ return getLowBitsSet(numBits, hiBit-loBit+1).shl(loBit);
+ }
/// Constructs an APInt value that has the top hiBitsSet bits set.
/// @param numBits the bitwidth of the result
More information about the llvm-commits
mailing list