From 226bae250b285930da75accc7a7ee0045942d807 Mon Sep 17 00:00:00 2001 From: Sinan KARAKAYA Date: Mon, 17 Aug 2026 22:57:21 +0200 Subject: [PATCH] Set the x86 SIMD baseline that the code already requires ps2_runtime.h includes unconditionally, and the recompiler emits SSE4.1-only intrinsics (_mm_blendv_ps and friends) for the COP2 and FPU select idioms. SSE4.1 is therefore a hard requirement of the codebase, not a tuning option. Nothing sets it for GCC or Clang. MSVC does not need it -- its intrinsics are not gated behind a target feature -- and the only place any x86 feature is named is /arch:AVX2 inside EnableFastReleaseMode, which is MSVC-only and applies to Release and RelWithDebInfo only. GCC and Clang default to the plain x86-64 baseline, which is SSE2, so on a stock Linux or macOS toolchain the affected translation units fail with "always_inline function ... requires target feature 'sse4.1'". Adds EnableX86SimdBaseline and applies it to ps2_runtime in every configuration rather than in EnableFastReleaseMode, since a Debug build needs it just as much. PUBLIC, so recompiled game code linking against ps2_runtime inherits it -- that code is where most of the SSE4.1 intrinsics actually are. Guarded on the target processor so ARM builds are unaffected. Co-Authored-By: Claude Opus 5 --- ps2xRuntime/CMakeLists.txt | 5 +++++ ps2xRuntime/cmake/ReleaseMode.cmake | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/ps2xRuntime/CMakeLists.txt b/ps2xRuntime/CMakeLists.txt index e4dc195..aad5fb8 100644 --- a/ps2xRuntime/CMakeLists.txt +++ b/ps2xRuntime/CMakeLists.txt @@ -552,6 +552,11 @@ if(PS2X_IS_VITA) endif() endif() +# Every configuration, not just Release: SSE4.1 is required to compile, not an +# optimisation. PUBLIC so recompiled game code linking against ps2_runtime +# inherits it -- that code is where most of the SSE4.1 intrinsics actually are. +EnableX86SimdBaseline(ps2_runtime) + if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") EnableFastReleaseMode(ps2_runtime) EnableFastReleaseMode(ps2EntryRunner) diff --git a/ps2xRuntime/cmake/ReleaseMode.cmake b/ps2xRuntime/cmake/ReleaseMode.cmake index 92ef0d5..0b97e90 100644 --- a/ps2xRuntime/cmake/ReleaseMode.cmake +++ b/ps2xRuntime/cmake/ReleaseMode.cmake @@ -2,6 +2,26 @@ include(CheckIPOSupported) check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT IPO_ERROR) +# ps2_runtime.h unconditionally includes and the recompiler emits +# SSE4.1-only intrinsics (_mm_blendv_ps and friends) for the COP2/FPU select +# idioms, so SSE4.1 is a hard requirement of the codebase rather than a tuning +# knob. MSVC enables it implicitly (its intrinsics are not gated by a target +# feature), but GCC and Clang default to the plain x86-64 baseline, which is +# SSE2 -- so on any stock Linux or macOS toolchain those translation units fail +# to compile with "always_inline function ... requires target feature 'sse4.1'". +# +# This must not live in EnableFastReleaseMode: that is only applied for Release +# and RelWithDebInfo, whereas the requirement applies to every configuration. +function(EnableX86SimdBaseline TargetName) + if(MSVC) + return() + endif() + if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|amd64|i[3-6]86|x86)$") + return() + endif() + target_compile_options(${TargetName} PUBLIC -msse4.1) +endfunction() + function(EnableFastReleaseMode TargetName) message("> Enabling optimization for: ${TargetName}") if(MSVC)