mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-12-16 04:09:39 +00:00
Merge de07124df9 into ed2fe134aa
This commit is contained in:
commit
92ffd66f53
@ -22,6 +22,7 @@ if(_M_X86_64)
|
||||
add_dolphin_test(PowerPCTest
|
||||
PowerPC/DivUtilsTest.cpp
|
||||
PowerPC/Jit64Common/ConvertDoubleToSingle.cpp
|
||||
PowerPC/Jit64Common/Fres.cpp
|
||||
PowerPC/Jit64Common/Frsqrte.cpp
|
||||
)
|
||||
elseif(_M_ARM_64)
|
||||
|
||||
@ -64,7 +64,8 @@ TEST(Jit64, ConvertDoubleToSingle)
|
||||
const u32 expected = ConvertToSingle(input);
|
||||
const u32 actual = routines.wrapped_cdts(input);
|
||||
|
||||
fmt::print("{:016x} -> {:08x} == {:08x}\n", input, actual, expected);
|
||||
if (expected != actual)
|
||||
fmt::print("{:016x} -> {:08x} == {:08x}\n", input, actual, expected);
|
||||
|
||||
EXPECT_EQ(expected, actual);
|
||||
}
|
||||
|
||||
81
Source/UnitTests/Core/PowerPC/Jit64Common/Fres.cpp
Normal file
81
Source/UnitTests/Core/PowerPC/Jit64Common/Fres.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
// Copyright 2025 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <bit>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FloatUtils.h"
|
||||
#include "Common/ScopeGuard.h"
|
||||
#include "Common/x64ABI.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/PowerPC/Jit64/Jit.h"
|
||||
#include "Core/PowerPC/Jit64Common/Jit64AsmCommon.h"
|
||||
#include "Core/PowerPC/Jit64Common/Jit64PowerPCState.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
#include "../TestValues.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
class TestFres : public CommonAsmRoutines
|
||||
{
|
||||
public:
|
||||
explicit TestFres(Core::System& system) : CommonAsmRoutines(jit), jit(system)
|
||||
{
|
||||
using namespace Gen;
|
||||
|
||||
AllocCodeSpace(4096);
|
||||
m_const_pool.Init(AllocChildCodeSpace(1024), 1024);
|
||||
|
||||
const auto raw_fres = reinterpret_cast<double (*)(double)>(AlignCode4());
|
||||
GenFres();
|
||||
|
||||
wrapped_fres = reinterpret_cast<u64 (*)(u64, const UReg_FPSCR&)>(AlignCode4());
|
||||
ABI_PushRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8, 16);
|
||||
|
||||
// We know that the only part of PowerPCState that the fres routine accesses is the fpscr.
|
||||
// We manufacture a PPCSTATE pointer so it reads from our provided fpscr instead.
|
||||
MOV(64, R(RPPCSTATE), R(ABI_PARAM2));
|
||||
SUB(64, R(RPPCSTATE), Imm32(PPCSTATE_OFF(fpscr)));
|
||||
|
||||
// Call
|
||||
MOVQ_xmm(XMM0, R(ABI_PARAM1));
|
||||
ABI_CallFunction(raw_fres);
|
||||
MOVQ_xmm(R(ABI_RETURN), XMM0);
|
||||
|
||||
ABI_PopRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8, 16);
|
||||
RET();
|
||||
}
|
||||
|
||||
u64 (*wrapped_fres)(u64, const UReg_FPSCR&);
|
||||
Jit64 jit;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(Jit64, Fres)
|
||||
{
|
||||
Core::DeclareAsCPUThread();
|
||||
Common::ScopeGuard cpu_thread_guard([] { Core::UndeclareAsCPUThread(); });
|
||||
|
||||
TestFres test(Core::System::GetInstance());
|
||||
|
||||
// FPSCR with NI set
|
||||
const UReg_FPSCR fpscr = UReg_FPSCR(0x00000004);
|
||||
|
||||
for (const u64 ivalue : double_test_values)
|
||||
{
|
||||
const double dvalue = std::bit_cast<double>(ivalue);
|
||||
|
||||
const u64 expected = std::bit_cast<u64>(Common::ApproximateReciprocal(dvalue));
|
||||
const u64 actual = test.wrapped_fres(ivalue, fpscr);
|
||||
|
||||
if (expected != actual)
|
||||
fmt::print("{:016x} -> {:016x} == {:016x}\n", ivalue, actual, expected);
|
||||
|
||||
EXPECT_EQ(expected, actual);
|
||||
}
|
||||
}
|
||||
@ -38,12 +38,10 @@ public:
|
||||
wrapped_frsqrte = reinterpret_cast<u64 (*)(u64, UReg_FPSCR&)>(AlignCode4());
|
||||
ABI_PushRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8, 16);
|
||||
|
||||
// We know the frsqrte implementation only accesses the fpscr. We manufacture a
|
||||
// PPCSTATE pointer so we read/write to our provided fpscr argument instead.
|
||||
XOR(32, R(RPPCSTATE), R(RPPCSTATE));
|
||||
LEA(64, RSCRATCH, PPCSTATE(fpscr));
|
||||
SUB(64, R(ABI_PARAM2), R(RSCRATCH));
|
||||
// We know that the only part of PowerPCState that the frsqrte routine accesses is the fpscr.
|
||||
// We manufacture a PPCSTATE pointer so it reads/writes to our provided fpscr instead.
|
||||
MOV(64, R(RPPCSTATE), R(ABI_PARAM2));
|
||||
SUB(64, R(RPPCSTATE), Imm32(PPCSTATE_OFF(fpscr)));
|
||||
|
||||
// Call
|
||||
MOVQ_xmm(XMM0, R(ABI_PARAM1));
|
||||
@ -76,7 +74,8 @@ TEST(Jit64, Frsqrte)
|
||||
|
||||
u64 actual = routines.wrapped_frsqrte(ivalue, fpscr);
|
||||
|
||||
fmt::print("{:016x} -> {:016x} == {:016x}\n", ivalue, actual, expected);
|
||||
if (expected != actual)
|
||||
fmt::print("{:016x} -> {:016x} == {:016x}\n", ivalue, actual, expected);
|
||||
|
||||
EXPECT_EQ(expected, actual);
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
#include "Common/Arm64Emitter.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FloatUtils.h"
|
||||
#include "Common/ScopeGuard.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/PowerPC/Interpreter/Interpreter_FPUtils.h"
|
||||
@ -15,6 +16,7 @@
|
||||
|
||||
#include "../TestValues.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
#include <functional>
|
||||
|
||||
#include "Common/Arm64Emitter.h"
|
||||
#include "Common/BitUtils.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FloatUtils.h"
|
||||
#include "Common/ScopeGuard.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/PowerPC/Interpreter/Interpreter_FPUtils.h"
|
||||
|
||||
@ -81,6 +81,7 @@
|
||||
<ItemGroup Condition="'$(Platform)'=='x64'">
|
||||
<ClCompile Include="Common\x64EmitterTest.cpp" />
|
||||
<ClCompile Include="Core\PowerPC\Jit64Common\ConvertDoubleToSingle.cpp" />
|
||||
<ClCompile Include="Core\PowerPC\Jit64Common\Fres.cpp" />
|
||||
<ClCompile Include="Core\PowerPC\Jit64Common\Frsqrte.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(Platform)'=='ARM64'">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user