summaryrefslogtreecommitdiff
path: root/Source/UnitTests/Core
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2021-02-08 10:58:09 +0100
committerGitHub <noreply@github.com>2021-02-08 10:58:09 +0100
commit3e4bf57c696ed1e4f465075ae311653de2cd33b0 (patch)
treef83f232833cf78b1bcb737c6d201b124c832eac0 /Source/UnitTests/Core
parent9a2d908aba78e83d600c90349b6ca334707cbc51 (diff)
parent1ab7657120cbd9552f89660e23b2d618cc03c4c7 (diff)
Merge pull request #9423 from MerryMage/arm64-movi2r-test
UnitTests: Add MOVI2R test
Diffstat (limited to 'Source/UnitTests/Core')
-rw-r--r--Source/UnitTests/Core/CMakeLists.txt4
-rw-r--r--Source/UnitTests/Core/PowerPC/JitArm64/MovI2R.cpp97
2 files changed, 101 insertions, 0 deletions
diff --git a/Source/UnitTests/Core/CMakeLists.txt b/Source/UnitTests/Core/CMakeLists.txt
index c6c9ac4463..01bfd99fbe 100644
--- a/Source/UnitTests/Core/CMakeLists.txt
+++ b/Source/UnitTests/Core/CMakeLists.txt
@@ -19,4 +19,8 @@ if(_M_X86)
PowerPC/Jit64Common/ConvertDoubleToSingle.cpp
PowerPC/Jit64Common/Frsqrte.cpp
)
+elseif(_M_ARM_64)
+ add_dolphin_test(PowerPCTest
+ PowerPC/JitArm64/MovI2R.cpp
+ )
endif()
diff --git a/Source/UnitTests/Core/PowerPC/JitArm64/MovI2R.cpp b/Source/UnitTests/Core/PowerPC/JitArm64/MovI2R.cpp
new file mode 100644
index 0000000000..8f44259f8d
--- /dev/null
+++ b/Source/UnitTests/Core/PowerPC/JitArm64/MovI2R.cpp
@@ -0,0 +1,97 @@
+// Copyright 2021 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include <cstddef>
+#include <type_traits>
+
+#include "Common/Arm64Emitter.h"
+#include "Common/Assert.h"
+#include "Common/BitUtils.h"
+#include "Common/Random.h"
+
+#include <gtest/gtest.h>
+
+namespace
+{
+using namespace Arm64Gen;
+
+class TestMovI2R : public ARM64CodeBlock
+{
+public:
+ TestMovI2R() { AllocCodeSpace(4096); }
+
+ void Check32(u32 value)
+ {
+ ResetCodePtr();
+
+ const u8* fn = GetCodePtr();
+ MOVI2R(W0, value);
+ RET();
+
+ FlushIcacheSection(const_cast<u8*>(fn), const_cast<u8*>(GetCodePtr()));
+
+ const u64 result = Common::BitCast<u64 (*)()>(fn)();
+ EXPECT_EQ(value, result);
+ }
+
+ void Check64(u64 value)
+ {
+ ResetCodePtr();
+
+ const u8* fn = GetCodePtr();
+ MOVI2R(X0, value);
+ RET();
+
+ FlushIcacheSection(const_cast<u8*>(fn), const_cast<u8*>(GetCodePtr()));
+
+ const u64 result = Common::BitCast<u64 (*)()>(fn)();
+ EXPECT_EQ(value, result);
+ }
+};
+
+} // namespace
+
+TEST(JitArm64, MovI2R_32BitValues)
+{
+ Common::Random::PRNG rng{0};
+ TestMovI2R test;
+ for (u64 i = 0; i < 0x100000; i++)
+ {
+ const u32 value = rng.GenerateValue<u32>();
+ test.Check32(value);
+ test.Check64(value);
+ }
+}
+
+TEST(JitArm64, MovI2R_Rand)
+{
+ Common::Random::PRNG rng{0};
+ TestMovI2R test;
+ for (u64 i = 0; i < 0x100000; i++)
+ {
+ test.Check64(rng.GenerateValue<u64>());
+ }
+}
+
+TEST(JitArm64, MovI2R_ADP)
+{
+ TestMovI2R test;
+ const u64 base = Common::BitCast<u64>(test.GetCodePtr());
+ for (s64 i = -0x20000; i < 0x20000; i++)
+ {
+ const u64 offset = static_cast<u64>(i);
+ test.Check64(base + offset);
+ }
+}
+
+TEST(JitArm64, MovI2R_ADRP)
+{
+ TestMovI2R test;
+ const u64 base = Common::BitCast<u64>(test.GetCodePtr()) & ~0xFFF;
+ for (s64 i = -0x20000; i < 0x20000; i++)
+ {
+ const u64 offset = static_cast<u64>(i) << 12;
+ test.Check64(base + offset);
+ }
+}