2016-11-10 21:53:08 +01:00
|
|
|
/*
|
2018-02-03 17:39:28 +01:00
|
|
|
* Copyright 2010-2018 Branimir Karadzic. All rights reserved.
|
2016-11-10 21:53:08 +01:00
|
|
|
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
#include <bx/uint32_t.h>
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
TEST_CASE("StrideAlign")
|
2016-11-10 21:53:08 +01:00
|
|
|
{
|
2017-04-11 08:16:10 +02:00
|
|
|
REQUIRE(0 == bx::strideAlign(0, 12) );
|
2016-11-10 21:53:08 +01:00
|
|
|
for (uint32_t ii = 0; ii < 12; ++ii)
|
|
|
|
{
|
2017-04-11 08:16:10 +02:00
|
|
|
REQUIRE(12 == bx::strideAlign(ii+1, 12) );
|
2016-11-10 21:53:08 +01:00
|
|
|
}
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
REQUIRE(0 == bx::strideAlign16(0, 12) );
|
2016-11-10 21:53:08 +01:00
|
|
|
for (uint32_t ii = 0; ii < 12; ++ii)
|
|
|
|
{
|
2017-04-11 08:16:10 +02:00
|
|
|
REQUIRE(48 == bx::strideAlign16(ii+1, 12) );
|
2016-11-10 21:53:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
TEST_CASE("uint32_cnt")
|
2016-11-10 21:53:08 +01:00
|
|
|
{
|
2017-04-11 08:16:10 +02:00
|
|
|
REQUIRE( 0 == bx::uint32_cnttz(UINT32_C(1) ) );
|
|
|
|
REQUIRE( 0 == bx::uint32_cnttz_ref(UINT32_C(1) ) );
|
2016-11-10 21:53:08 +01:00
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
REQUIRE(31 == bx::uint32_cntlz(UINT32_C(1) ) );
|
|
|
|
REQUIRE(31 == bx::uint32_cntlz_ref(UINT32_C(1) ) );
|
2016-11-10 21:53:08 +01:00
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
REQUIRE( 0 == bx::uint64_cnttz(UINT64_C(1) ) );
|
|
|
|
REQUIRE( 0 == bx::uint64_cnttz_ref(UINT64_C(1) ) );
|
2016-11-10 21:53:08 +01:00
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
REQUIRE(63 == bx::uint64_cntlz(UINT64_C(1) ) );
|
|
|
|
REQUIRE(63 == bx::uint64_cntlz_ref(UINT64_C(1) ) );
|
2016-11-10 21:53:08 +01:00
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
REQUIRE( 1 == bx::uint32_cntbits(1) );
|
|
|
|
REQUIRE( 1 == bx::uint32_cntbits_ref(1) );
|
2016-11-10 21:53:08 +01:00
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
REQUIRE(16 == bx::uint32_cntbits(UINT16_MAX) );
|
|
|
|
REQUIRE(16 == bx::uint32_cntbits_ref(UINT16_MAX) );
|
2016-11-10 21:53:08 +01:00
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
REQUIRE(32 == bx::uint32_cntbits(UINT32_MAX) );
|
|
|
|
REQUIRE(32 == bx::uint32_cntbits_ref(UINT32_MAX) );
|
2016-11-10 21:53:08 +01:00
|
|
|
}
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
TEST_CASE("uint32_part")
|
2016-11-10 21:53:08 +01:00
|
|
|
{
|
2017-04-11 08:16:10 +02:00
|
|
|
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);
|
|
|
|
}
|
2016-11-10 21:53:08 +01:00
|
|
|
}
|