mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-25 12:49:50 +00:00
PackedVector: Make the BitVector implementation configurable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164826 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
deda7b6e75
commit
07b4d5592a
@ -19,32 +19,32 @@
|
|||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
template <typename T, unsigned BitNum, bool isSigned>
|
template <typename T, unsigned BitNum, typename BitVectorTy, bool isSigned>
|
||||||
class PackedVectorBase;
|
class PackedVectorBase;
|
||||||
|
|
||||||
// This won't be necessary if we can specialize members without specializing
|
// This won't be necessary if we can specialize members without specializing
|
||||||
// the parent template.
|
// the parent template.
|
||||||
template <typename T, unsigned BitNum>
|
template <typename T, unsigned BitNum, typename BitVectorTy>
|
||||||
class PackedVectorBase<T, BitNum, false> {
|
class PackedVectorBase<T, BitNum, BitVectorTy, false> {
|
||||||
protected:
|
protected:
|
||||||
static T getValue(const llvm::BitVector &Bits, unsigned Idx) {
|
static T getValue(const BitVectorTy &Bits, unsigned Idx) {
|
||||||
T val = T();
|
T val = T();
|
||||||
for (unsigned i = 0; i != BitNum; ++i)
|
for (unsigned i = 0; i != BitNum; ++i)
|
||||||
val = T(val | ((Bits[(Idx << (BitNum-1)) + i] ? 1UL : 0UL) << i));
|
val = T(val | ((Bits[(Idx << (BitNum-1)) + i] ? 1UL : 0UL) << i));
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setValue(llvm::BitVector &Bits, unsigned Idx, T val) {
|
static void setValue(BitVectorTy &Bits, unsigned Idx, T val) {
|
||||||
assert((val >> BitNum) == 0 && "value is too big");
|
assert((val >> BitNum) == 0 && "value is too big");
|
||||||
for (unsigned i = 0; i != BitNum; ++i)
|
for (unsigned i = 0; i != BitNum; ++i)
|
||||||
Bits[(Idx << (BitNum-1)) + i] = val & (T(1) << i);
|
Bits[(Idx << (BitNum-1)) + i] = val & (T(1) << i);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, unsigned BitNum>
|
template <typename T, unsigned BitNum, typename BitVectorTy>
|
||||||
class PackedVectorBase<T, BitNum, true> {
|
class PackedVectorBase<T, BitNum, BitVectorTy, true> {
|
||||||
protected:
|
protected:
|
||||||
static T getValue(const llvm::BitVector &Bits, unsigned Idx) {
|
static T getValue(const BitVectorTy &Bits, unsigned Idx) {
|
||||||
T val = T();
|
T val = T();
|
||||||
for (unsigned i = 0; i != BitNum-1; ++i)
|
for (unsigned i = 0; i != BitNum-1; ++i)
|
||||||
val = T(val | ((Bits[(Idx << (BitNum-1)) + i] ? 1UL : 0UL) << i));
|
val = T(val | ((Bits[(Idx << (BitNum-1)) + i] ? 1UL : 0UL) << i));
|
||||||
@ -53,7 +53,7 @@ protected:
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setValue(llvm::BitVector &Bits, unsigned Idx, T val) {
|
static void setValue(BitVectorTy &Bits, unsigned Idx, T val) {
|
||||||
if (val < 0) {
|
if (val < 0) {
|
||||||
val = ~val;
|
val = ~val;
|
||||||
Bits.set((Idx << (BitNum-1)) + BitNum-1);
|
Bits.set((Idx << (BitNum-1)) + BitNum-1);
|
||||||
@ -71,11 +71,12 @@ protected:
|
|||||||
/// @endcode
|
/// @endcode
|
||||||
/// will create a vector accepting values -2, -1, 0, 1. Any other value will hit
|
/// will create a vector accepting values -2, -1, 0, 1. Any other value will hit
|
||||||
/// an assertion.
|
/// an assertion.
|
||||||
template <typename T, unsigned BitNum>
|
template <typename T, unsigned BitNum, typename BitVectorTy = BitVector>
|
||||||
class PackedVector : public PackedVectorBase<T, BitNum,
|
class PackedVector : public PackedVectorBase<T, BitNum, BitVectorTy,
|
||||||
std::numeric_limits<T>::is_signed> {
|
std::numeric_limits<T>::is_signed> {
|
||||||
llvm::BitVector Bits;
|
BitVectorTy Bits;
|
||||||
typedef PackedVectorBase<T, BitNum, std::numeric_limits<T>::is_signed> base;
|
typedef PackedVectorBase<T, BitNum, BitVectorTy,
|
||||||
|
std::numeric_limits<T>::is_signed> base;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class reference {
|
class reference {
|
||||||
|
Loading…
Reference in New Issue
Block a user