2018-06-29 19:34:46 +01:00
|
|
|
/* This file is part of the dynarmic project.
|
|
|
|
* Copyright (c) 2018 MerryMage
|
2020-04-23 15:25:11 +01:00
|
|
|
* SPDX-License-Identifier: 0BSD
|
2018-06-29 19:34:46 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-12-31 16:26:55 +00:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2022-04-19 15:36:26 +01:00
|
|
|
#include <mcl/stdint.hpp>
|
2018-06-29 19:34:46 +01:00
|
|
|
|
2021-05-19 17:28:35 +01:00
|
|
|
#include "../rand_int.h"
|
|
|
|
#include "dynarmic/common/fp/fpcr.h"
|
|
|
|
#include "dynarmic/common/fp/fpsr.h"
|
|
|
|
#include "dynarmic/common/fp/op.h"
|
|
|
|
#include "dynarmic/common/fp/rounding_mode.h"
|
2018-06-29 19:34:46 +01:00
|
|
|
|
|
|
|
using namespace Dynarmic;
|
|
|
|
using namespace Dynarmic::FP;
|
|
|
|
|
|
|
|
TEST_CASE("FPToFixed", "[fp]") {
|
2021-05-22 14:51:20 +01:00
|
|
|
const std::vector<std::tuple<u32, size_t, u64, u32>> test_cases{
|
2018-06-29 19:34:46 +01:00
|
|
|
{0x447A0000, 64, 0x000003E8, 0x00},
|
|
|
|
{0xC47A0000, 32, 0xFFFFFC18, 0x00},
|
|
|
|
{0x4479E000, 64, 0x000003E8, 0x10},
|
|
|
|
{0x50800000, 32, 0x7FFFFFFF, 0x01},
|
|
|
|
{0xD0800000, 32, 0x80000000, 0x01},
|
|
|
|
{0xCF000000, 32, 0x80000000, 0x00},
|
|
|
|
{0x80002B94, 64, 0x00000000, 0x10},
|
|
|
|
{0x80636D24, 64, 0x00000000, 0x10},
|
|
|
|
};
|
|
|
|
|
|
|
|
const FPCR fpcr;
|
|
|
|
for (auto [input, ibits, expected_output, expected_fpsr] : test_cases) {
|
|
|
|
FPSR fpsr;
|
|
|
|
const u64 output = FPToFixed<u32>(ibits, input, 0, false, fpcr, RoundingMode::ToNearest_TieEven, fpsr);
|
|
|
|
REQUIRE(output == expected_output);
|
|
|
|
REQUIRE(fpsr.Value() == expected_fpsr);
|
|
|
|
}
|
|
|
|
}
|
2023-01-15 23:59:27 +00:00
|
|
|
|
|
|
|
TEST_CASE("FPToFixed edge cases", "[fp]") {
|
|
|
|
const std::vector<std::tuple<u64, u64, bool, FP::RoundingMode>> test_cases{
|
|
|
|
{0x41dffffffffffffe, 0x7fffffff, false, FP::RoundingMode::ToNearest_TieEven},
|
|
|
|
{0x41dffffffffffffe, 0x7fffffff, false, FP::RoundingMode::TowardsPlusInfinity},
|
|
|
|
{0x41dffffffffffffe, 0x7fffffff, false, FP::RoundingMode::TowardsMinusInfinity},
|
|
|
|
{0x41dffffffffffffe, 0x7fffffff, false, FP::RoundingMode::TowardsZero},
|
|
|
|
{0x41dffffffffffffe, 0x7fffffff, false, FP::RoundingMode::ToNearest_TieAwayFromZero},
|
|
|
|
};
|
|
|
|
|
|
|
|
const FPCR fpcr;
|
|
|
|
FPSR fpsr;
|
|
|
|
for (auto [input, expected_output, unsigned_, rounding_mode] : test_cases) {
|
|
|
|
const u64 output = FPToFixed<u64>(32, input, 0, unsigned_, fpcr, rounding_mode, fpsr);
|
|
|
|
REQUIRE(output == expected_output);
|
|
|
|
}
|
|
|
|
}
|