mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added unit test for half to/from float.
This commit is contained in:
@@ -6,47 +6,66 @@
|
||||
#include "test.h"
|
||||
#include <bx/uint32_t.h>
|
||||
|
||||
TEST(StrideAlign)
|
||||
TEST_CASE("StrideAlign")
|
||||
{
|
||||
CHECK(0 == bx::strideAlign(0, 12) );
|
||||
REQUIRE(0 == bx::strideAlign(0, 12) );
|
||||
for (uint32_t ii = 0; ii < 12; ++ii)
|
||||
{
|
||||
CHECK(12 == bx::strideAlign(ii+1, 12) );
|
||||
REQUIRE(12 == bx::strideAlign(ii+1, 12) );
|
||||
}
|
||||
|
||||
CHECK(0 == bx::strideAlign16(0, 12) );
|
||||
REQUIRE(0 == bx::strideAlign16(0, 12) );
|
||||
for (uint32_t ii = 0; ii < 12; ++ii)
|
||||
{
|
||||
CHECK(48 == bx::strideAlign16(ii+1, 12) );
|
||||
REQUIRE(48 == bx::strideAlign16(ii+1, 12) );
|
||||
}
|
||||
}
|
||||
|
||||
TEST(uint32_cnt)
|
||||
TEST_CASE("uint32_cnt")
|
||||
{
|
||||
CHECK( 0 == bx::uint32_cnttz(UINT32_C(1) ) );
|
||||
CHECK( 0 == bx::uint32_cnttz_ref(UINT32_C(1) ) );
|
||||
REQUIRE( 0 == bx::uint32_cnttz(UINT32_C(1) ) );
|
||||
REQUIRE( 0 == bx::uint32_cnttz_ref(UINT32_C(1) ) );
|
||||
|
||||
CHECK(31 == bx::uint32_cntlz(UINT32_C(1) ) );
|
||||
CHECK(31 == bx::uint32_cntlz_ref(UINT32_C(1) ) );
|
||||
REQUIRE(31 == bx::uint32_cntlz(UINT32_C(1) ) );
|
||||
REQUIRE(31 == bx::uint32_cntlz_ref(UINT32_C(1) ) );
|
||||
|
||||
CHECK( 0 == bx::uint64_cnttz(UINT64_C(1) ) );
|
||||
CHECK( 0 == bx::uint64_cnttz_ref(UINT64_C(1) ) );
|
||||
REQUIRE( 0 == bx::uint64_cnttz(UINT64_C(1) ) );
|
||||
REQUIRE( 0 == bx::uint64_cnttz_ref(UINT64_C(1) ) );
|
||||
|
||||
CHECK(63 == bx::uint64_cntlz(UINT64_C(1) ) );
|
||||
CHECK(63 == bx::uint64_cntlz_ref(UINT64_C(1) ) );
|
||||
REQUIRE(63 == bx::uint64_cntlz(UINT64_C(1) ) );
|
||||
REQUIRE(63 == bx::uint64_cntlz_ref(UINT64_C(1) ) );
|
||||
|
||||
CHECK( 1 == bx::uint32_cntbits(1) );
|
||||
CHECK( 1 == bx::uint32_cntbits_ref(1) );
|
||||
REQUIRE( 1 == bx::uint32_cntbits(1) );
|
||||
REQUIRE( 1 == bx::uint32_cntbits_ref(1) );
|
||||
|
||||
CHECK(16 == bx::uint32_cntbits(UINT16_MAX) );
|
||||
CHECK(16 == bx::uint32_cntbits_ref(UINT16_MAX) );
|
||||
REQUIRE(16 == bx::uint32_cntbits(UINT16_MAX) );
|
||||
REQUIRE(16 == bx::uint32_cntbits_ref(UINT16_MAX) );
|
||||
|
||||
CHECK(32 == bx::uint32_cntbits(UINT32_MAX) );
|
||||
CHECK(32 == bx::uint32_cntbits_ref(UINT32_MAX) );
|
||||
REQUIRE(32 == bx::uint32_cntbits(UINT32_MAX) );
|
||||
REQUIRE(32 == bx::uint32_cntbits_ref(UINT32_MAX) );
|
||||
}
|
||||
|
||||
TEST(uint32_part)
|
||||
TEST_CASE("uint32_part")
|
||||
{
|
||||
CHECK(UINT32_C(0x55555555) == bx::uint32_part1by1(UINT16_MAX) );
|
||||
CHECK(UINT32_C(0x09249249) == bx::uint32_part1by2(0x3ff) );
|
||||
REQUIRE(UINT32_C(0x55555555) == bx::uint32_part1by1(UINT16_MAX) );
|
||||
REQUIRE(UINT32_C(0x09249249) == bx::uint32_part1by2(0x3ff) );
|
||||
}
|
||||
|
||||
TEST_CASE("halfTo/FromFloat", "")
|
||||
{
|
||||
for (uint32_t ii = 0; ii < 0x7c00; ++ii)
|
||||
{
|
||||
const uint16_t orig = uint16_t(ii);
|
||||
const float htf = bx::halfToFloat(orig);
|
||||
const uint16_t hff = bx::halfFromFloat(htf);
|
||||
REQUIRE(orig == hff);
|
||||
}
|
||||
|
||||
for (uint32_t ii = 0x8000; ii < 0xfc00; ++ii)
|
||||
{
|
||||
const uint16_t orig = uint16_t(ii);
|
||||
const float htf = bx::halfToFloat(orig);
|
||||
const uint16_t hff = bx::halfFromFloat(htf);
|
||||
REQUIRE(orig == hff);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user