diff --git a/CMakeLists.txt b/CMakeLists.txt index fd06fc404d..4d07a76cc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ add_subdirectory(pcsx2) # tests if(ACTUALLY_ENABLE_TESTS) + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) add_subdirectory(3rdparty/gtest EXCLUDE_FROM_ALL) add_subdirectory(tests/ctest) endif() diff --git a/tests/ctest/CMakeLists.txt b/tests/ctest/CMakeLists.txt index 1b4b00002f..27d6c5c708 100644 --- a/tests/ctest/CMakeLists.txt +++ b/tests/ctest/CMakeLists.txt @@ -1,17 +1,27 @@ option(ENABLE_UNSUPPORTED_TESTS "Include tests that require instructions not supported by this computer" OFF) set(avxdetect_code " - int main() - { - #if defined(__AVX2__) - return 51; - #elif defined(__AVX__) - return 50; - #elif defined(__SSE4_1__) - return 41; + #ifdef __GNUC__ + #include + void cpuid(int result[4], int leaf, int subleaf) { + __cpuid_count(leaf, subleaf, result[0], result[1], result[2], result[3]); + } #else - return 0; + #include + #define cpuid __cpuidex #endif + int test(int leaf, int subleaf, int reg, int bit) { + int res[4]; + cpuid(res, 0, 0); + if (res[0] < leaf) { return 0; } + cpuid(res, leaf, subleaf); + return !!(res[reg] & (1 << bit)); + } + int main() { + if (test(7, 0, 1, 5) /* AVX2 */) return 51; + if (test(1, 0, 2, 28) /* AVX */) return 50; + if (test(1, 0, 2, 19) /* SSE41 */) return 41; + return 0; } ") @@ -27,11 +37,27 @@ else() compile_result_unused "${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}/avxdetect.c" - CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=-march=native" ) set(CMAKE_CROSSCOMPILING ${cc_backup}) endif() +if (MSVC) + if(_M_X86_32) + set(compile_options_sse4 /arch:SSE2) + endif() + set(compile_options_avx /arch:AVX) + set(compile_options_avx2 /arch:AVX2) + set(definitions_sse4 _M_SSE=0x401) + set(definitions_avx _M_SSE=0x500) + set(definitions_avx2 _M_SSE=0x501) +else() + set(compile_options_sse4 -msse4.1) + set(compile_options_avx -mavx) + set(compile_options_avx2 -mavx2 -mbmi -mbmi2) +endif() +set(isa_number_sse4 41) +set(isa_number_avx 50) +set(isa_number_avx2 51) enable_testing() add_custom_target(unittests) diff --git a/tests/ctest/GS/CMakeLists.txt b/tests/ctest/GS/CMakeLists.txt index 38c9c2c2de..3f181c0c08 100644 --- a/tests/ctest/GS/CMakeLists.txt +++ b/tests/ctest/GS/CMakeLists.txt @@ -1,15 +1,14 @@ foreach(isa "sse4" "avx" "avx2") set(GSDir ${CMAKE_SOURCE_DIR}/pcsx2/GS) - if((${isa} STREQUAL "sse4" AND ${native_vector_isa} LESS 41) - OR (${isa} STREQUAL "avx" AND ${native_vector_isa} LESS 50) - OR (${isa} STREQUAL "avx2" AND ${native_vector_isa} LESS 51)) + if(${native_vector_isa} LESS ${isa_number_${isa}}) # Skip unsupported tests continue() endif() add_pcsx2_test(swizzle_test_${isa} swizzle_test_main.cpp + swizzle_test_nops.cpp ${GSDir}/GSBlock.cpp ${GSDir}/GSBlock.h ${GSDir}/GSClut.cpp @@ -18,20 +17,10 @@ foreach(isa "sse4" "avx" "avx2") ${GSDir}/GSTables.h) target_include_directories(swizzle_test_${isa} PRIVATE ${GSDir} ${CMAKE_SOURCE_DIR}/pcsx2/ ${CMAKE_SOURCE_DIR}/pcsx2/gui) - - # Prevent linker errors for functions in e.g. GSClut that we don't actually use depending on things we didn't include - if(UNIX AND NOT APPLE) - target_compile_options(swizzle_test_${isa} PRIVATE -ffunction-sections) - target_link_options(swizzle_test_${isa} PRIVATE -Wl,-gc-sections) - elseif(APPLE) - target_link_options(swizzle_test_${isa} PRIVATE -Wl,-dead_strip) + if(WIN32) + target_include_directories(swizzle_test_${isa} PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty) endif() - if(${isa} STREQUAL "avx2") - target_compile_options(swizzle_test_${isa} PRIVATE -mavx2 -mbmi -mbmi2) - elseif(${isa} STREQUAL "avx") - target_compile_options(swizzle_test_${isa} PRIVATE -mavx) - else() - target_compile_options(swizzle_test_${isa} PRIVATE -msse4.1) - endif() + target_compile_options(swizzle_test_${isa} PRIVATE ${compile_options_${isa}}) + target_compile_definitions(swizzle_test_${isa} PRIVATE ${definitions_${isa}}) endforeach() diff --git a/tests/ctest/GS/swizzle_test_nops.cpp b/tests/ctest/GS/swizzle_test_nops.cpp new file mode 100644 index 0000000000..f06fea28ef --- /dev/null +++ b/tests/ctest/GS/swizzle_test_nops.cpp @@ -0,0 +1,37 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2021 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with PCSX2. + * If not, see . + */ + +// This file defines functions that are linked to by files used in swizzle tests but not actually used in swizzle tests, in order to make linkers happy + +#include "PrecompiledHeader.h" +#include "GSBlock.h" +#include "GSClut.h" +#include "GSLocalMemory.h" + +GSLocalMemory::psm_t GSLocalMemory::m_psm[64]; +GSOffset* GSLocalMemory::GetOffset(uint32 bp, uint32 bw, uint32 psm) +{ + abort(); +} + +void* vmalloc(size_t size, bool code) +{ + abort(); +} + +void vmfree(void* ptr, size_t size) +{ + abort(); +} diff --git a/tests/ctest/x86emitter/codegen_tests.cpp b/tests/ctest/x86emitter/codegen_tests.cpp index 84f5fd9ba4..4baed86c61 100644 --- a/tests/ctest/x86emitter/codegen_tests.cpp +++ b/tests/ctest/x86emitter/codegen_tests.cpp @@ -13,20 +13,29 @@ * If not, see . */ +#include "codegen_tests.h" #include #include +#include using namespace x86Emitter; thread_local const char *currentTest; -void pxOnAssert(const DiagnosticOrigin &origin, const wxString &msg) { - FAIL() << "Assertion failed: " << msg +static void assertHandlerInternal(const DiagnosticOrigin& origin, const wxChar* msg) { + FAIL() << "Assertion failed: " << wxString(msg) << "\n at " << origin.srcfile << ":" << origin.line << "" << "\n when trying to assemble " << currentTest; } +static bool assertHandler(const DiagnosticOrigin& origin, const wxChar* msg) { + assertHandlerInternal(origin, msg); + return false; +} + void runCodegenTest(void (*exec)(void *base), const char* description, const char* expected) { + pxDoAssert = assertHandler; + u8 code[4096]; memset(code, 0xcc, sizeof(code)); char str[4096] = {0}; diff --git a/tests/ctest/x86emitter/codegen_tests.h b/tests/ctest/x86emitter/codegen_tests.h index e785666562..5b42d53c4e 100644 --- a/tests/ctest/x86emitter/codegen_tests.h +++ b/tests/ctest/x86emitter/codegen_tests.h @@ -13,6 +13,8 @@ * If not, see . */ +#include "Utilities/Dependencies.h" + void runCodegenTest(void (*exec)(void *base), const char* description, const char* expected); // Use null to skip, empty string to expect no output