diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-24 23:27:48 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-24 23:27:48 +0000 |
commit | b334e8ac573ecfe92a20bdf1dadeac205a6843df (patch) | |
tree | 2e4e0c80a1577147106f025126c63d893897bc96 | |
parent | e3d00119e6ab209a12efd43473919540f3ee3e03 (diff) | |
download | bcm5719-llvm-b334e8ac573ecfe92a20bdf1dadeac205a6843df.tar.gz bcm5719-llvm-b334e8ac573ecfe92a20bdf1dadeac205a6843df.zip |
Implement the getBitsSet function.
llvm-svn: 35310
-rw-r--r-- | llvm/include/llvm/ADT/APInt.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index 31fac9608f8..4ceef2df3ca 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -340,7 +340,16 @@ public: /// @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 |