aboutsummaryrefslogtreecommitdiff
path: root/src/dynarmic/tests/fp/unpacked_tests.cpp
diff options
context:
space:
mode:
authorcrueter <crueter@eden-emu.dev>2025-08-04 04:50:14 +0200
committercrueter <crueter@eden-emu.dev>2025-08-04 04:50:14 +0200
commit51b170b470ed587f99a7c2a773e4464687f0d07a (patch)
tree4c03c510cfb17a5f5d6233df490d78f06dcfa7f7 /src/dynarmic/tests/fp/unpacked_tests.cpp
parent04e5e6453875ffa5c79cdb421a29bc19985b1049 (diff)
[cmake] refactor: Use CPM over submodules (#143)
Transfers the majority of submodules and large externals to CPM, using source archives rather than full Git clones. Not only does this save massive amounts of clone and configure time, but dependencies are grabbed on-demand rather than being required by default. Additionally, CPM will (generally) automatically search for system dependencies, though certain dependencies have options to control this. Testing shows gains ranging from 5x to 10x in terms of overall clone/configure time. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/143 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Diffstat (limited to 'src/dynarmic/tests/fp/unpacked_tests.cpp')
-rw-r--r--src/dynarmic/tests/fp/unpacked_tests.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/dynarmic/tests/fp/unpacked_tests.cpp b/src/dynarmic/tests/fp/unpacked_tests.cpp
new file mode 100644
index 0000000000..919f21bf2f
--- /dev/null
+++ b/src/dynarmic/tests/fp/unpacked_tests.cpp
@@ -0,0 +1,98 @@
+// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+/* This file is part of the dynarmic project.
+ * Copyright (c) 2018 MerryMage
+ * SPDX-License-Identifier: 0BSD
+ */
+
+#include <tuple>
+#include <vector>
+
+#include <catch2/catch_test_macros.hpp>
+#include "dynarmic/common/common_types.h"
+
+#include "../rand_int.h"
+#include "dynarmic/common/fp/fpcr.h"
+#include "dynarmic/common/fp/fpsr.h"
+#include "dynarmic/common/fp/unpacked.h"
+
+using namespace Dynarmic;
+using namespace Dynarmic::FP;
+
+TEST_CASE("FPUnpack Tests", "[fp]") {
+ const static std::vector<std::tuple<u32, std::tuple<FPType, bool, FPUnpacked>, u32>> test_cases{
+ {0x00000000, {FPType::Zero, false, ToNormalized(false, 0, 0)}, 0},
+ {0x7F800000, {FPType::Infinity, false, ToNormalized(false, 1000000, 1)}, 0},
+ {0xFF800000, {FPType::Infinity, true, ToNormalized(true, 1000000, 1)}, 0},
+ {0x7F800001, {FPType::SNaN, false, ToNormalized(false, 0, 0)}, 0},
+ {0xFF800001, {FPType::SNaN, true, ToNormalized(true, 0, 0)}, 0},
+ {0x7FC00001, {FPType::QNaN, false, ToNormalized(false, 0, 0)}, 0},
+ {0xFFC00001, {FPType::QNaN, true, ToNormalized(true, 0, 0)}, 0},
+ {0x00000001, {FPType::Nonzero, false, ToNormalized(false, -149, 1)}, 0}, // Smallest single precision denormal is 2^-149.
+ {0x3F7FFFFF, {FPType::Nonzero, false, ToNormalized(false, -24, 0xFFFFFF)}, 0}, // 1.0 - epsilon
+ };
+
+ const FPCR fpcr;
+ for (const auto& [input, expected_output, expected_fpsr] : test_cases) {
+ FPSR fpsr;
+ const auto output = FPUnpack<u32>(input, fpcr, fpsr);
+
+ INFO("Input: " << std::hex << input);
+ INFO("Output Sign: " << std::get<2>(output).sign);
+ INFO("Output Exponent: " << std::get<2>(output).exponent);
+ INFO("Output Mantissa: " << std::hex << std::get<2>(output).mantissa);
+ INFO("Expected Sign: " << std::get<2>(expected_output).sign);
+ INFO("Expected Exponent: " << std::get<2>(expected_output).exponent);
+ INFO("Expected Mantissa: " << std::hex << std::get<2>(expected_output).mantissa);
+
+ REQUIRE(output == expected_output);
+ REQUIRE(fpsr.Value() == expected_fpsr);
+ }
+}
+
+TEST_CASE("FPRound Tests", "[fp]") {
+ const static std::vector<std::tuple<u32, std::tuple<FPType, bool, FPUnpacked>, u32>> test_cases{
+ {0x7F800000, {FPType::Infinity, false, ToNormalized(false, 1000000, 1)}, 0x14},
+ {0xFF800000, {FPType::Infinity, true, ToNormalized(true, 1000000, 1)}, 0x14},
+ {0x00000001, {FPType::Nonzero, false, ToNormalized(false, -149, 1)}, 0}, // Smallest single precision denormal is 2^-149.
+ {0x3F7FFFFF, {FPType::Nonzero, false, ToNormalized(false, -24, 0xFFFFFF)}, 0}, // 1.0 - epsilon
+ {0x3F800000, {FPType::Nonzero, false, ToNormalized(false, -28, 0xFFFFFFF)}, 0x10}, // rounds to 1.0
+ };
+
+ const FPCR fpcr;
+ for (const auto& [expected_output, input, expected_fpsr] : test_cases) {
+ FPSR fpsr;
+ const auto output = FPRound<u32>(std::get<2>(input), fpcr, fpsr);
+
+ INFO("Expected Output: " << std::hex << expected_output);
+ REQUIRE(output == expected_output);
+ REQUIRE(fpsr.Value() == expected_fpsr);
+ }
+}
+
+TEST_CASE("FPUnpack<->FPRound Round-trip Tests", "[fp]") {
+ const FPCR fpcr;
+ for (size_t count = 0; count < 100000; count++) {
+ FPSR fpsr;
+ const u32 input = RandInt(0, 1) == 0 ? RandInt<u32>(0x00000001, 0x7F800000) : RandInt<u32>(0x80000001, 0xFF800000);
+ const auto intermediate = std::get<2>(FPUnpack<u32>(input, fpcr, fpsr));
+ const u32 output = FPRound<u32>(intermediate, fpcr, fpsr);
+
+ INFO("Count: " << count);
+ INFO("Intermediate Values: " << std::hex << intermediate.sign << ';' << intermediate.exponent << ';' << intermediate.mantissa);
+ REQUIRE(input == output);
+ }
+}
+
+TEST_CASE("FPRound (near zero, round to posinf)", "[fp]") {
+ const FPUnpacked input = {false, -353, 0x0a98d25ace5b2000};
+
+ FPSR fpsr;
+ FPCR fpcr;
+ fpcr.RMode(RoundingMode::TowardsPlusInfinity);
+
+ const u32 output = FPRound<u32>(input, fpcr, fpsr);
+
+ REQUIRE(output == 0x00000001);
+}