Userspace: Use BAN::Math instead of builtins
This commit is contained in:
@@ -96,8 +96,6 @@ struct BitmapAllocator
|
|||||||
// NOTE: We could optimize other bitmap functions than this
|
// NOTE: We could optimize other bitmap functions than this
|
||||||
// but this one is the bottle neck so it doesn't matter
|
// but this one is the bottle neck so it doesn't matter
|
||||||
|
|
||||||
static_assert(sizeof(unsigned long long) == sizeof(uint64_t));
|
|
||||||
|
|
||||||
if (index >= total_chunks)
|
if (index >= total_chunks)
|
||||||
return index;
|
return index;
|
||||||
|
|
||||||
@@ -105,7 +103,7 @@ struct BitmapAllocator
|
|||||||
{
|
{
|
||||||
const uint64_t qword = *reinterpret_cast<const uint64_t*>(base + (index - rem) / 8) >> rem;
|
const uint64_t qword = *reinterpret_cast<const uint64_t*>(base + (index - rem) / 8) >> rem;
|
||||||
if (qword != UINT64_MAX >> rem)
|
if (qword != UINT64_MAX >> rem)
|
||||||
return index + __builtin_ctzll(~qword);
|
return index + BAN::Math::ctz(~qword);
|
||||||
index += 64 - rem;
|
index += 64 - rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +111,7 @@ struct BitmapAllocator
|
|||||||
{
|
{
|
||||||
const uint64_t qword = *reinterpret_cast<const uint64_t*>(base + index / 8);
|
const uint64_t qword = *reinterpret_cast<const uint64_t*>(base + index / 8);
|
||||||
if (qword != UINT64_MAX)
|
if (qword != UINT64_MAX)
|
||||||
return index + __builtin_ctzll(~qword);
|
return index + BAN::Math::ctz(~qword);
|
||||||
index += 64;
|
index += 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -771,9 +771,9 @@ namespace LibQR
|
|||||||
const auto mod2_remainder =
|
const auto mod2_remainder =
|
||||||
[](uint32_t data, uint32_t generator, uint32_t degree)
|
[](uint32_t data, uint32_t generator, uint32_t degree)
|
||||||
{
|
{
|
||||||
constexpr auto bits = [](uint32_t val) -> uint32_t { return 31 - __builtin_clz(val | 1); };
|
uint32_t bits;
|
||||||
while (bits(data) >= degree)
|
while ((bits = BAN::Math::ilog2(data | 1)) >= degree)
|
||||||
data ^= generator << (bits(data) - degree);
|
data ^= generator << (bits - degree);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user