mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added testpow2 test, and use improved version. Issue #184.
This commit is contained in:
@@ -453,12 +453,10 @@ namespace bx
|
||||
|
||||
inline uint32_t uint32_testpow2(uint32_t _a)
|
||||
{
|
||||
const uint32_t tmp0 = uint32_not(_a);
|
||||
const uint32_t tmp1 = uint32_inc(tmp0);
|
||||
const uint32_t tmp2 = uint32_and(_a, tmp1);
|
||||
const uint32_t tmp3 = uint32_cmpeq(tmp2, _a);
|
||||
const uint32_t tmp4 = uint32_cmpneq(_a, 0);
|
||||
const uint32_t result = uint32_and(tmp3, tmp4);
|
||||
const uint32_t tmp0 = uint32_dec(_a);
|
||||
const uint32_t tmp1 = uint32_xor(_a, tmp0);
|
||||
const uint32_t tmp2 = uint32_srl(tmp1, 1);
|
||||
const uint32_t result = uint32_cmpeq(tmp2, tmp0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -69,3 +69,17 @@ TEST_CASE("halfTo/FromFloat", "")
|
||||
REQUIRE(orig == hff);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("uint32_testpow2", "")
|
||||
{
|
||||
uint32_t shift = 0;
|
||||
|
||||
for (uint32_t ii = 0; ii < UINT32_MAX; ++ii)
|
||||
{
|
||||
if (bx::uint32_testpow2(ii) )
|
||||
{
|
||||
REQUIRE(ii == 1 << shift);
|
||||
++shift;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user