mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-04-29 23:41:19 -06:00
61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
// SPDX-FileCopyrightText: Copyright 2026 shadPS4 Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include <cmath>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "gcn_test_runner.hpp"
|
|
#include "instructions.hpp"
|
|
#include "translator.hpp"
|
|
|
|
class GcnTest : public ::testing::Test {
|
|
protected:
|
|
void SetUp() override {}
|
|
|
|
void TearDown() override {}
|
|
};
|
|
|
|
struct F32x2 {
|
|
float a;
|
|
float b;
|
|
};
|
|
|
|
// Example
|
|
// TEST_F(GcnTest, test_name) {
|
|
// // Runner sets the vulkan context
|
|
// auto runner = gcn_test::Runner::instance().value();
|
|
//
|
|
// // v_add_f32 v0, v0, v1
|
|
// auto spirv = TranslateToSpirv(VOP2(OpcodeVOP2::V_ADD_F32, VOperand8::V0, SOperand9::V0, VOperand8::V1).Get());
|
|
//
|
|
// // run<T> tells how to interpret the result (only 32bit as of now)
|
|
// // the second argument is templated, it can be at most 4 u32s
|
|
// // the data is accessible by the instruction in v0-4 and s0-4 (mirrored)
|
|
// // the result has to be placed in v0
|
|
// auto result = runner->run<float>(spirv, F32x2{1.5f, 6.0f});
|
|
//
|
|
// EXPECT_TRUE(result.has_value());
|
|
// EXPECT_EQ(*result, 7.5f);
|
|
// }
|
|
|
|
TEST_F(GcnTest, add_f32) {
|
|
auto runner = gcn_test::Runner::instance().value();
|
|
|
|
auto spirv = TranslateToSpirv(VOP2(OpcodeVOP2::V_ADD_F32, VOperand8::V0, SOperand9::V0, VOperand8::V1).Get());
|
|
auto result = runner->run<float>(spirv, F32x2{1.5f, 6.0f});
|
|
|
|
EXPECT_TRUE(result.has_value());
|
|
EXPECT_EQ(*result, 7.5f);
|
|
}
|
|
|
|
TEST_F(GcnTest, add_nan) {
|
|
auto runner = gcn_test::Runner::instance().value();
|
|
|
|
auto spirv = TranslateToSpirv(VOP2(OpcodeVOP2::V_ADD_F32, VOperand8::V0, SOperand9::V0, VOperand8::V1).Get());
|
|
auto result = runner->run<float>(spirv, F32x2{1.0f, std::numeric_limits<float>::quiet_NaN()});
|
|
|
|
EXPECT_TRUE(result.has_value());
|
|
EXPECT_TRUE(std::isnan(*result));
|
|
}
|