diff options
Diffstat (limited to 'zencore')
| -rw-r--r-- | zencore/include/zencore/intmath.h | 4 | ||||
| -rw-r--r-- | zencore/intmath.cpp | 56 | ||||
| -rw-r--r-- | zencore/zencore.cpp | 1 | ||||
| -rw-r--r-- | zencore/zencore.vcxproj | 1 | ||||
| -rw-r--r-- | zencore/zencore.vcxproj.filters | 1 |
5 files changed, 63 insertions, 0 deletions
diff --git a/zencore/include/zencore/intmath.h b/zencore/include/zencore/intmath.h index 90b7cf9f6..85447c17a 100644 --- a/zencore/include/zencore/intmath.h +++ b/zencore/include/zencore/intmath.h @@ -177,4 +177,8 @@ Max(auto x, auto y) return x > y ? x : y; } +////////////////////////////////////////////////////////////////////////// + +void intmath_forcelink(); // internal + } // namespace zen diff --git a/zencore/intmath.cpp b/zencore/intmath.cpp new file mode 100644 index 000000000..4039a3b39 --- /dev/null +++ b/zencore/intmath.cpp @@ -0,0 +1,56 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include <zencore/intmath.h> + +#include <doctest/doctest.h> + +namespace zen { + +////////////////////////////////////////////////////////////////////////// +// +// Testing related code follows... +// + +void +intmath_forcelink() +{ +} + +TEST_CASE("intmath") +{ + CHECK(FloorLog2(0x00) == 0); + CHECK(FloorLog2(0x01) == 0); + CHECK(FloorLog2(0x0f) == 3); + CHECK(FloorLog2(0x10) == 4); + CHECK(FloorLog2(0x11) == 4); + CHECK(FloorLog2(0x12) == 4); + CHECK(FloorLog2(0x22) == 5); + CHECK(FloorLog2(0x0001'0000) == 16); + CHECK(FloorLog2(0x0001'000f) == 16); + CHECK(FloorLog2(0x8000'0000) == 31); + + CHECK(FloorLog2_64(0x00ull) == 0); + CHECK(FloorLog2_64(0x01ull) == 0); + CHECK(FloorLog2_64(0x0full) == 3); + CHECK(FloorLog2_64(0x10ull) == 4); + CHECK(FloorLog2_64(0x11ull) == 4); + CHECK(FloorLog2_64(0x0001'0000ull) == 16); + CHECK(FloorLog2_64(0x0001'000full) == 16); + CHECK(FloorLog2_64(0x8000'0000ull) == 31); + CHECK(FloorLog2_64(0x0000'0001'0000'0000ull) == 32); + CHECK(FloorLog2_64(0x8000'0000'0000'0000ull) == 63); + + CHECK(CountLeadingZeros64(0x8000'0000'0000'0000ull) == 0); + CHECK(CountLeadingZeros64(0x0000'0000'0000'0000ull) == 64); + CHECK(CountLeadingZeros64(0x0000'0000'0000'0001ull) == 63); + CHECK(CountLeadingZeros64(0x0000'0000'8000'0000ull) == 32); + CHECK(CountLeadingZeros64(0x0000'0001'0000'0000ull) == 31); + + CHECK(CountTrailingZeros64(0x8000'0000'0000'0000ull) == 63); + CHECK(CountTrailingZeros64(0x0000'0000'0000'0000ull) == 64); + CHECK(CountTrailingZeros64(0x0000'0000'0000'0001ull) == 0); + CHECK(CountTrailingZeros64(0x0000'0000'8000'0000ull) == 31); + CHECK(CountTrailingZeros64(0x0000'0001'0000'0000ull) == 32); +} + +} // namespace zen diff --git a/zencore/zencore.cpp b/zencore/zencore.cpp index 27ac779b0..c53fd218f 100644 --- a/zencore/zencore.cpp +++ b/zencore/zencore.cpp @@ -85,6 +85,7 @@ zencore_forcelinktests() zen::blake3_forcelink(); zen::compositebuffer_forcelink(); zen::compress_forcelink(); + zen::intmath_forcelink(); zen::iobuffer_forcelink(); zen::memory_forcelink(); zen::refcount_forcelink(); diff --git a/zencore/zencore.vcxproj b/zencore/zencore.vcxproj index bf35f8f5a..4040d5ae1 100644 --- a/zencore/zencore.vcxproj +++ b/zencore/zencore.vcxproj @@ -165,6 +165,7 @@ <ClCompile Include="filesystem.cpp" /> <ClCompile Include="httpclient.cpp" /> <ClCompile Include="httpserver.cpp" /> + <ClCompile Include="intmath.cpp" /> <ClCompile Include="iohash.cpp" /> <ClCompile Include="iothreadpool.cpp" /> <ClCompile Include="logging.cpp" /> diff --git a/zencore/zencore.vcxproj.filters b/zencore/zencore.vcxproj.filters index b1b1b9359..3a291e967 100644 --- a/zencore/zencore.vcxproj.filters +++ b/zencore/zencore.vcxproj.filters @@ -77,6 +77,7 @@ <ClCompile Include="compositebuffer.cpp" /> <ClCompile Include="crc32.cpp" /> <ClCompile Include="logging.cpp" /> + <ClCompile Include="intmath.cpp" /> </ItemGroup> <ItemGroup> <Filter Include="CAS"> |