Expose svbr rotated encoding as static member of LLVM bit reader

This commit is contained in:
baldurk
2020-06-18 17:22:40 +01:00
parent bfea4427aa
commit 0000916e75
3 changed files with 14 additions and 27 deletions
@@ -243,11 +243,7 @@ void ParseConstant(const LLVMBC::BlockOrRecord &constant, const Type *&curType,
{
Value v;
v.type = curType;
v.val.u64v[0] = constant.ops[0];
if(v.val.u64v[0] & 0x1)
v.val.s64v[0] = -int64_t(v.val.u64v[0] >> 1);
else
v.val.u64v[0] >>= 1;
v.val.s64v[0] = LLVMBC::BitReader::svbr(constant.ops[0]);
addValue(v);
}
else if(IS_KNOWN(constant.id, ConstantsRecord::FLOAT))
+3 -12
View File
@@ -116,22 +116,13 @@ public:
return T(ret);
}
template <typename T>
T svbr(size_t groupBitSize)
static int64_t svbr(uint64_t var)
{
// the value will fit in a uint64_t because the any negative values with the high bit set, which
// would overflow when shifted, no longer have the high bit set after being negated.
uint64_t var = vbr<uint64_t>(groupBitSize);
// if the low bit is set, it's negative
if(var & 0x1)
{
return T(-int64_t(var >> 1));
}
return -int64_t(var >> 1);
else
{
return T(var >> 1);
}
return int64_t(var >> 1);
}
template <typename T>
+10 -10
View File
@@ -759,34 +759,34 @@ TEST_CASE("Check LLVM bitreader", "[llvm]")
int64_t val;
val = b.svbr<int64_t>(4);
val = LLVMBC::BitReader::svbr(b.vbr<uint64_t>(4));
CHECK(val == 2);
val = b.svbr<int64_t>(4);
val = LLVMBC::BitReader::svbr(b.vbr<uint64_t>(4));
CHECK(val == 0);
val = b.svbr<int64_t>(4);
val = LLVMBC::BitReader::svbr(b.vbr<uint64_t>(4));
CHECK(val == -2);
val = b.svbr<int64_t>(4);
val = LLVMBC::BitReader::svbr(b.vbr<uint64_t>(4));
CHECK(val == 0);
val = b.svbr<int64_t>(4);
val = LLVMBC::BitReader::svbr(b.vbr<uint64_t>(4));
CHECK(val == 98765);
val = b.svbr<int64_t>(4);
val = LLVMBC::BitReader::svbr(b.vbr<uint64_t>(4));
CHECK(val == -98765);
val = b.svbr<int64_t>(4);
val = LLVMBC::BitReader::svbr(b.vbr<uint64_t>(4));
CHECK(val == INT64_MAX);
val = b.svbr<int64_t>(4);
val = LLVMBC::BitReader::svbr(b.vbr<uint64_t>(4));
CHECK(val == -INT64_MAX);
val = b.svbr<int64_t>(4);
val = LLVMBC::BitReader::svbr(b.vbr<uint64_t>(4));
CHECK(val == 3);
val = b.svbr<int64_t>(4);
val = LLVMBC::BitReader::svbr(b.vbr<uint64_t>(4));
CHECK(val == 0);
// should be exactly at the end of the stream