2021-05-05 19:10:48 +00:00
|
|
|
// Copyright 2021 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-05-05 19:10:48 +00:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
#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-05-05 19:10:48 +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-05-05 19:10:48 +00:00
|
|
|
|
|
|
|
#include "../TestValues.h"
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace Arm64Gen;
|
|
|
|
|
|
|
|
class TestFrsqrte : public JitArm64
|
|
|
|
{
|
|
|
|
public:
|
2023-03-20 00:30:29 +00:00
|
|
|
explicit TestFrsqrte(Core::System& system) : JitArm64(system)
|
2021-05-05 19:10:48 +00:00
|
|
|
{
|
2021-06-19 17:05:35 +00:00
|
|
|
const Common::ScopedJITPageWriteAndNoExecute enable_jit_page_writes;
|
|
|
|
|
2021-05-05 19:10:48 +00:00
|
|
|
AllocCodeSpace(4096);
|
|
|
|
|
|
|
|
const u8* raw_frsqrte = GetCodePtr();
|
|
|
|
GenerateFrsqrte();
|
|
|
|
|
|
|
|
frsqrte = Common::BitCast<u64 (*)(u64)>(GetCodePtr());
|
|
|
|
MOV(ARM64Reg::X15, ARM64Reg::X30);
|
|
|
|
MOV(ARM64Reg::X14, PPC_REG);
|
2023-03-28 22:42:27 +00:00
|
|
|
MOVP2R(PPC_REG, &system.GetPPCState());
|
2021-05-05 19:10:48 +00:00
|
|
|
MOV(ARM64Reg::X1, ARM64Reg::X0);
|
|
|
|
m_float_emit.FMOV(ARM64Reg::D0, ARM64Reg::X0);
|
|
|
|
m_float_emit.FRSQRTE(ARM64Reg::D0, ARM64Reg::D0);
|
|
|
|
BL(raw_frsqrte);
|
|
|
|
MOV(ARM64Reg::X30, ARM64Reg::X15);
|
|
|
|
MOV(PPC_REG, ARM64Reg::X14);
|
|
|
|
RET();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::function<u64(u64)> frsqrte;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(JitArm64, Frsqrte)
|
|
|
|
{
|
2023-08-16 21:28:33 +00:00
|
|
|
Core::DeclareAsCPUThread();
|
|
|
|
Common::ScopeGuard cpu_thread_guard([] { Core::UndeclareAsCPUThread(); });
|
|
|
|
|
2023-03-20 00:30:29 +00:00
|
|
|
TestFrsqrte test(Core::System::GetInstance());
|
2021-05-05 19:10:48 +00:00
|
|
|
|
|
|
|
for (const u64 ivalue : double_test_values)
|
|
|
|
{
|
|
|
|
const double dvalue = Common::BitCast<double>(ivalue);
|
|
|
|
|
|
|
|
const u64 expected = Common::BitCast<u64>(Common::ApproximateReciprocalSquareRoot(dvalue));
|
|
|
|
const u64 actual = test.frsqrte(ivalue);
|
|
|
|
|
|
|
|
if (expected != actual)
|
|
|
|
fmt::print("{:016x} -> {:016x} == {:016x}\n", ivalue, actual, expected);
|
|
|
|
|
|
|
|
EXPECT_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
}
|