2019-05-25 21:43:04 +00:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-05-25 21:43:04 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
2023-08-16 21:28:33 +00:00
|
|
|
#include "Common/ScopeGuard.h"
|
2019-05-25 21:43:04 +00:00
|
|
|
#include "Common/x64ABI.h"
|
2023-08-16 21:28:33 +00:00
|
|
|
#include "Core/Core.h"
|
2019-05-25 21:43:04 +00:00
|
|
|
#include "Core/PowerPC/Gekko.h"
|
|
|
|
#include "Core/PowerPC/Interpreter/Interpreter_FPUtils.h"
|
|
|
|
#include "Core/PowerPC/Jit64/Jit.h"
|
|
|
|
#include "Core/PowerPC/Jit64Common/Jit64AsmCommon.h"
|
|
|
|
#include "Core/PowerPC/Jit64Common/Jit64PowerPCState.h"
|
2023-03-20 00:30:29 +00:00
|
|
|
#include "Core/System.h"
|
2019-05-25 21:43:04 +00:00
|
|
|
|
2021-05-02 15:14:06 +00:00
|
|
|
#include "../TestValues.h"
|
|
|
|
|
2020-11-25 17:59:47 +00:00
|
|
|
#include <fmt/format.h>
|
2019-05-25 21:43:04 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class TestCommonAsmRoutines : public CommonAsmRoutines
|
|
|
|
{
|
|
|
|
public:
|
2023-03-20 00:30:29 +00:00
|
|
|
explicit TestCommonAsmRoutines(Core::System& system) : CommonAsmRoutines(jit), jit(system)
|
2019-05-25 21:43:04 +00:00
|
|
|
{
|
|
|
|
using namespace Gen;
|
|
|
|
|
|
|
|
AllocCodeSpace(4096);
|
|
|
|
m_const_pool.Init(AllocChildCodeSpace(1024), 1024);
|
|
|
|
|
|
|
|
const auto raw_cdts = reinterpret_cast<double (*)(double)>(AlignCode4());
|
|
|
|
GenConvertDoubleToSingle();
|
|
|
|
|
|
|
|
wrapped_cdts = reinterpret_cast<u32 (*)(u64)>(AlignCode4());
|
|
|
|
ABI_PushRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8, 16);
|
|
|
|
|
|
|
|
// Call
|
|
|
|
MOVQ_xmm(XMM0, R(ABI_PARAM1));
|
|
|
|
ABI_CallFunction(raw_cdts);
|
2019-05-25 21:51:02 +00:00
|
|
|
MOV(32, R(ABI_RETURN), R(RSCRATCH));
|
2019-05-25 21:43:04 +00:00
|
|
|
|
|
|
|
ABI_PopRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8, 16);
|
|
|
|
RET();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 (*wrapped_cdts)(u64);
|
|
|
|
Jit64 jit;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(Jit64, ConvertDoubleToSingle)
|
|
|
|
{
|
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
|
|
|
TestCommonAsmRoutines routines(Core::System::GetInstance());
|
2019-05-25 21:43:04 +00:00
|
|
|
|
2021-05-02 15:14:06 +00:00
|
|
|
for (const u64 input : double_test_values)
|
2019-05-25 21:43:04 +00:00
|
|
|
{
|
|
|
|
const u32 expected = ConvertToSingle(input);
|
|
|
|
const u32 actual = routines.wrapped_cdts(input);
|
|
|
|
|
2020-11-25 17:59:47 +00:00
|
|
|
fmt::print("{:016x} -> {:08x} == {:08x}\n", input, actual, expected);
|
2019-05-25 21:43:04 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
}
|