aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-24 23:27:48 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-24 23:27:48 +0000
commit8f969ee62c3fed26f835a37c41f7c009f99ea3bf (patch)
treee6219bfe75a1dd67feb2066b0ea2d8d27bd7062b /include
parent3f3ee6e58859bde398af6191bee49fe6331911b3 (diff)
downloadexternal_llvm-8f969ee62c3fed26f835a37c41f7c009f99ea3bf.zip
external_llvm-8f969ee62c3fed26f835a37c41f7c009f99ea3bf.tar.gz
external_llvm-8f969ee62c3fed26f835a37c41f7c009f99ea3bf.tar.bz2
Implement the getBitsSet function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35310 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/APInt.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h
index 31fac96..4ceef2d 100644
--- a/include/llvm/ADT/APInt.h
+++ b/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