uint32_test.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  4. */
  5. #include "test.h"
  6. #include <bx/uint32_t.h>
  7. TEST_CASE("StrideAlign")
  8. {
  9. REQUIRE(0 == bx::strideAlign(0, 12) );
  10. for (uint32_t ii = 0; ii < 12; ++ii)
  11. {
  12. REQUIRE(12 == bx::strideAlign(ii+1, 12) );
  13. }
  14. REQUIRE(0 == bx::strideAlign16(0, 12) );
  15. for (uint32_t ii = 0; ii < 12; ++ii)
  16. {
  17. REQUIRE(48 == bx::strideAlign16(ii+1, 12) );
  18. }
  19. }
  20. TEST_CASE("uint32_cnt")
  21. {
  22. REQUIRE( 0 == bx::uint32_cnttz(UINT32_C(1) ) );
  23. REQUIRE( 0 == bx::uint32_cnttz_ref(UINT32_C(1) ) );
  24. REQUIRE(31 == bx::uint32_cntlz(UINT32_C(1) ) );
  25. REQUIRE(31 == bx::uint32_cntlz_ref(UINT32_C(1) ) );
  26. REQUIRE( 0 == bx::uint64_cnttz(UINT64_C(1) ) );
  27. REQUIRE( 0 == bx::uint64_cnttz_ref(UINT64_C(1) ) );
  28. REQUIRE(63 == bx::uint64_cntlz(UINT64_C(1) ) );
  29. REQUIRE(63 == bx::uint64_cntlz_ref(UINT64_C(1) ) );
  30. REQUIRE( 1 == bx::uint32_cntbits(1) );
  31. REQUIRE( 1 == bx::uint32_cntbits_ref(1) );
  32. REQUIRE(16 == bx::uint32_cntbits(UINT16_MAX) );
  33. REQUIRE(16 == bx::uint32_cntbits_ref(UINT16_MAX) );
  34. REQUIRE(32 == bx::uint32_cntbits(UINT32_MAX) );
  35. REQUIRE(32 == bx::uint32_cntbits_ref(UINT32_MAX) );
  36. }
  37. TEST_CASE("uint32_part")
  38. {
  39. REQUIRE(UINT32_C(0x55555555) == bx::uint32_part1by1(UINT16_MAX) );
  40. REQUIRE(UINT32_C(0x09249249) == bx::uint32_part1by2(0x3ff) );
  41. }
  42. TEST_CASE("halfTo/FromFloat", "")
  43. {
  44. for (uint32_t ii = 0; ii < 0x7c00; ++ii)
  45. {
  46. const uint16_t orig = uint16_t(ii);
  47. const float htf = bx::halfToFloat(orig);
  48. const uint16_t hff = bx::halfFromFloat(htf);
  49. REQUIRE(orig == hff);
  50. }
  51. for (uint32_t ii = 0x8000; ii < 0xfc00; ++ii)
  52. {
  53. const uint16_t orig = uint16_t(ii);
  54. const float htf = bx::halfToFloat(orig);
  55. const uint16_t hff = bx::halfFromFloat(htf);
  56. REQUIRE(orig == hff);
  57. }
  58. }