diff --git a/Source/UnitTests/Common/FloatUtilsTest.cpp b/Source/UnitTests/Common/FloatUtilsTest.cpp index 4f98409911..e0172c5643 100644 --- a/Source/UnitTests/Common/FloatUtilsTest.cpp +++ b/Source/UnitTests/Common/FloatUtilsTest.cpp @@ -1,6 +1,7 @@ // Copyright 2018 Dolphin Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include #include #include @@ -9,6 +10,8 @@ #include "Common/BitUtils.h" #include "Common/FloatUtils.h" +#include "../Core/PowerPC/TestValues.h" + TEST(FloatUtils, IsQNAN) { EXPECT_TRUE(Common::IsQNAN(std::numeric_limits::quiet_NaN())); @@ -62,3 +65,35 @@ TEST(FloatUtils, FlushToZero) EXPECT_EQ(i_tmp, Common::BitCast(Common::FlushToZero(Common::BitCast(i_tmp)))); } } + +TEST(FloatUtils, ApproximateReciprocalSquareRoot) +{ + constexpr std::array expected_values{ + 0x7FF0'0000'0000'0000, 0x617F'FE80'0000'0000, 0x60BF'FE80'0000'0000, 0x5FE0'0008'2C00'0000, + 0x5FDF'FE80'0000'0000, 0x5FDF'FE80'0000'0000, 0x3FEF'FE80'0000'0000, 0x1FF0'0008'2C00'0000, + 0x0000'0000'0000'0000, 0x7FF8'0000'0000'0001, 0x7FFF'FFFF'FFFF'FFFF, 0x7FF8'0000'0000'0000, + 0x7FFF'FFFF'FFFF'FFFF, 0xFFF0'0000'0000'0000, 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, + 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, + 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, 0xFFF8'0000'0000'0001, 0xFFFF'FFFF'FFFF'FFFF, + 0xFFF8'0000'0000'0000, 0xFFFF'FFFF'FFFF'FFFF, 0x43E6'9FA0'0000'0000, 0x43DF'FE80'0000'0000, + 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, 0x43E6'9360'6000'0000, 0x43DF'ED30'7000'0000, + 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, 0x44A6'9FA0'0000'0000, 0x4496'9FA0'0000'0000, + 0x448F'FE80'0000'0000, 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, + 0x44A6'9360'6000'0000, 0x4496'9360'6000'0000, 0x448F'ED30'7000'0000, 0x7FF8'0000'0000'0000, + 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, 0x3C06'9FA0'0000'0000, 0x3BFF'FE80'0000'0000, + 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, 0x43EF'FE80'0000'0000, 0x43F6'9FA0'0000'0000, + 0x7FF8'0000'0000'0000, 0x7FF8'0000'0000'0000, 0x3FEA'2040'0000'0000, 0x3FA0'3108'0000'0000, + 0x7FF8'0000'0000'0000}; + + for (int i = 0; i < double_test_values.size(); ++i) + { + u64 ivalue = double_test_values[i]; + double dvalue = Common::BitCast(ivalue); + + u64 expected = expected_values[i]; + + u64 actual = Common::BitCast(Common::ApproximateReciprocalSquareRoot(dvalue)); + + EXPECT_EQ(expected, actual); + } +}