2021-04-10 19:24:44 +00:00
|
|
|
// Copyright 2021 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-04-10 19:24:44 +00:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Common/Arm64Emitter.h"
|
|
|
|
#include "Common/BitUtils.h"
|
|
|
|
#include "Common/CommonTypes.h"
|
2023-08-16 21:28:33 +00:00
|
|
|
#include "Common/ScopeGuard.h"
|
|
|
|
#include "Core/Core.h"
|
2021-04-10 19:24:44 +00:00
|
|
|
#include "Core/PowerPC/Interpreter/Interpreter_FPUtils.h"
|
|
|
|
#include "Core/PowerPC/JitArm64/Jit.h"
|
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2023-03-20 00:30:29 +00:00
|
|
|
#include "Core/System.h"
|
2021-04-10 19:24:44 +00:00
|
|
|
|
|
|
|
#include "../TestValues.h"
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace Arm64Gen;
|
|
|
|
|
|
|
|
class TestFPRF : public JitArm64
|
|
|
|
{
|
|
|
|
public:
|
2023-03-20 00:30:29 +00:00
|
|
|
explicit TestFPRF(Core::System& system) : JitArm64(system)
|
2021-04-10 19:24:44 +00:00
|
|
|
{
|
2021-06-19 17:05:35 +00:00
|
|
|
const Common::ScopedJITPageWriteAndNoExecute enable_jit_page_writes;
|
|
|
|
|
2021-04-10 19:24:44 +00:00
|
|
|
AllocCodeSpace(4096);
|
|
|
|
|
|
|
|
const u8* raw_fprf_single = GetCodePtr();
|
|
|
|
GenerateFPRF(true);
|
|
|
|
const u8* raw_fprf_double = GetCodePtr();
|
|
|
|
GenerateFPRF(false);
|
|
|
|
|
2023-03-28 22:42:27 +00:00
|
|
|
auto& ppc_state = system.GetPPCState();
|
|
|
|
|
2021-04-10 19:24:44 +00:00
|
|
|
fprf_single = Common::BitCast<void (*)(u32)>(GetCodePtr());
|
|
|
|
MOV(ARM64Reg::X15, ARM64Reg::X30);
|
|
|
|
MOV(ARM64Reg::X14, PPC_REG);
|
2023-03-28 22:42:27 +00:00
|
|
|
MOVP2R(PPC_REG, &ppc_state);
|
2021-04-10 19:24:44 +00:00
|
|
|
BL(raw_fprf_single);
|
|
|
|
MOV(ARM64Reg::X30, ARM64Reg::X15);
|
|
|
|
MOV(PPC_REG, ARM64Reg::X14);
|
|
|
|
RET();
|
|
|
|
|
|
|
|
fprf_double = Common::BitCast<void (*)(u64)>(GetCodePtr());
|
|
|
|
MOV(ARM64Reg::X15, ARM64Reg::X30);
|
|
|
|
MOV(ARM64Reg::X14, PPC_REG);
|
2023-03-28 22:42:27 +00:00
|
|
|
MOVP2R(PPC_REG, &ppc_state);
|
2021-04-10 19:24:44 +00:00
|
|
|
BL(raw_fprf_double);
|
|
|
|
MOV(ARM64Reg::X30, ARM64Reg::X15);
|
|
|
|
MOV(PPC_REG, ARM64Reg::X14);
|
|
|
|
RET();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::function<void(u32)> fprf_single;
|
|
|
|
std::function<void(u64)> fprf_double;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-03-28 22:42:27 +00:00
|
|
|
static u32 RunUpdateFPRF(PowerPC::PowerPCState& ppc_state, const std::function<void()>& f)
|
2021-04-10 19:24:44 +00:00
|
|
|
{
|
2023-03-28 22:42:27 +00:00
|
|
|
ppc_state.fpscr.Hex = 0x12345678;
|
2021-04-10 19:24:44 +00:00
|
|
|
f();
|
2023-03-28 22:42:27 +00:00
|
|
|
return ppc_state.fpscr.Hex;
|
2021-04-10 19:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(JitArm64, FPRF)
|
|
|
|
{
|
2023-08-16 21:28:33 +00:00
|
|
|
Core::DeclareAsCPUThread();
|
|
|
|
Common::ScopeGuard cpu_thread_guard([] { Core::UndeclareAsCPUThread(); });
|
|
|
|
|
2023-03-28 22:42:27 +00:00
|
|
|
auto& system = Core::System::GetInstance();
|
|
|
|
auto& ppc_state = system.GetPPCState();
|
|
|
|
TestFPRF test(system);
|
2021-04-10 19:24:44 +00:00
|
|
|
|
|
|
|
for (const u64 double_input : double_test_values)
|
|
|
|
{
|
2023-01-10 01:05:48 +00:00
|
|
|
const u32 expected_double = RunUpdateFPRF(
|
2023-03-28 22:42:27 +00:00
|
|
|
ppc_state, [&] { ppc_state.UpdateFPRFDouble(Common::BitCast<double>(double_input)); });
|
|
|
|
const u32 actual_double = RunUpdateFPRF(ppc_state, [&] { test.fprf_double(double_input); });
|
2021-04-10 19:24:44 +00:00
|
|
|
EXPECT_EQ(expected_double, actual_double);
|
|
|
|
|
|
|
|
const u32 single_input = ConvertToSingle(double_input);
|
|
|
|
|
2023-01-10 01:05:48 +00:00
|
|
|
const u32 expected_single = RunUpdateFPRF(
|
2023-03-28 22:42:27 +00:00
|
|
|
ppc_state, [&] { ppc_state.UpdateFPRFSingle(Common::BitCast<float>(single_input)); });
|
|
|
|
const u32 actual_single = RunUpdateFPRF(ppc_state, [&] { test.fprf_single(single_input); });
|
2021-04-10 19:24:44 +00:00
|
|
|
EXPECT_EQ(expected_single, actual_single);
|
|
|
|
}
|
|
|
|
}
|