llvm.org GIT mirror llvm / 07b4d55
PackedVector: Make the BitVector implementation configurable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164826 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 7 years ago
1 changed file(s) with 14 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
1818
1919 namespace llvm {
2020
21 template bool isSigned>
21 template typename BitVectorTy, bool isSigned>
2222 class PackedVectorBase;
2323
2424 // This won't be necessary if we can specialize members without specializing
2525 // the parent template.
26 template
27 class PackedVectorBase {
26 template
27 class PackedVectorBase {
2828 protected:
29 static T getValue(const llvm::BitVector &Bits, unsigned Idx) {
29 static T getValue(const BitVectorTy &Bits, unsigned Idx) {
3030 T val = T();
3131 for (unsigned i = 0; i != BitNum; ++i)
3232 val = T(val | ((Bits[(Idx << (BitNum-1)) + i] ? 1UL : 0UL) << i));
3333 return val;
3434 }
3535
36 static void setValue(llvm::BitVector &Bits, unsigned Idx, T val) {
36 static void setValue(BitVectorTy &Bits, unsigned Idx, T val) {
3737 assert((val >> BitNum) == 0 && "value is too big");
3838 for (unsigned i = 0; i != BitNum; ++i)
3939 Bits[(Idx << (BitNum-1)) + i] = val & (T(1) << i);
4040 }
4141 };
4242
43 template
44 class PackedVectorBase {
43 template
44 class PackedVectorBase {
4545 protected:
46 static T getValue(const llvm::BitVector &Bits, unsigned Idx) {
46 static T getValue(const BitVectorTy &Bits, unsigned Idx) {
4747 T val = T();
4848 for (unsigned i = 0; i != BitNum-1; ++i)
4949 val = T(val | ((Bits[(Idx << (BitNum-1)) + i] ? 1UL : 0UL) << i));
5252 return val;
5353 }
5454
55 static void setValue(llvm::BitVector &Bits, unsigned Idx, T val) {
55 static void setValue(BitVectorTy &Bits, unsigned Idx, T val) {
5656 if (val < 0) {
5757 val = ~val;
5858 Bits.set((Idx << (BitNum-1)) + BitNum-1);
7070 /// @endcode
7171 /// will create a vector accepting values -2, -1, 0, 1. Any other value will hit
7272 /// an assertion.
73 template
74 class PackedVector : public PackedVectorBase
73 template
74 class PackedVector : public PackedVectorBase
7575 std::numeric_limits::is_signed> {
76 llvm::BitVector Bits;
77 typedef PackedVectorBase::is_signed> base;
76 BitVectorTy Bits;
77 typedef PackedVectorBase
78 std::numeric_limits::is_signed> base;
7879
7980 public:
8081 class reference {