Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #9423 from MerryMage/arm64-movi2r-test
UnitTests: Add MOVI2R test
- Loading branch information
Showing
4 changed files
with
163 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } |