From 1d1b79d5f02070348c708dfa5132c8d3decac4a0 Mon Sep 17 00:00:00 2001 From: Enrique Martinez <73340871+emartinez-dev@users.noreply.github.com> Date: Sat, 7 Feb 2026 00:12:36 +0100 Subject: [PATCH] Added ARM64 (Apple Silicon) support using sse2neon (#50) * feat: implemented arm64 support for builds * feat: explicitly add compiler flags when needed --- CMakeLists.txt | 37 ++++++++++++++++++++++++ ps2xRuntime/include/ps2_runtime.h | 10 +++++-- ps2xRuntime/include/ps2_runtime_macros.h | 2 ++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f57ce0d..0ef4d2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,43 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) option(PS2X_RUNTIME OFF) +# ARM64 support using sse2neon +if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|ARM64") + message(STATUS "ARM64 detected, fetching sse2neon") + + include(FetchContent) + FetchContent_Declare( + sse2neon + GIT_REPOSITORY https://github.com/DLTcollab/sse2neon.git + GIT_TAG v1.9.1 + GIT_SHALLOW TRUE + ) + FetchContent_MakeAvailable(sse2neon) + + include_directories(${sse2neon_SOURCE_DIR}) + add_compile_definitions(USE_SSE2NEON) + + if(APPLE) + # macOS ARM64 already uses optimal defaults + message(STATUS "macOS ARM64 - using default compiler flags") + elseif(MSVC) + # Windows ARM64 - MSVC already uses optimal defaults + message(STATUS "Windows ARM64 (MSVC) - using default compiler flags") + else() + # Linux ARM64 - add NEON flags + message(STATUS "Non-Apple ARM64 - adding NEON compiler flags") + add_compile_options(-march=armv8-a+fp+simd) + + # Try to enable crypto and CRC extensions if supported + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag("-march=armv8-a+fp+simd+crypto+crc" COMPILER_SUPPORTS_CRYPTO_CRC) + if(COMPILER_SUPPORTS_CRYPTO_CRC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+fp+simd+crypto+crc") + message(STATUS "Crypto and CRC extensions enabled") + endif() + endif() +endif() + add_subdirectory("ps2xRecomp") add_subdirectory("ps2xRuntime") diff --git a/ps2xRuntime/include/ps2_runtime.h b/ps2xRuntime/include/ps2_runtime.h index db73007..4c3d82e 100644 --- a/ps2xRuntime/include/ps2_runtime.h +++ b/ps2xRuntime/include/ps2_runtime.h @@ -6,8 +6,14 @@ #include #include #include -#include // For SSE/AVX instructions -#include +#if defined(_MSC_VER) + #include +#elif defined(USE_SSE2NEON) + #include "sse2neon.h" +#else + #include // For SSE/AVX instructions + #include // For SSE4.1 instructions +#endif #include #include #include diff --git a/ps2xRuntime/include/ps2_runtime_macros.h b/ps2xRuntime/include/ps2_runtime_macros.h index 1576f1f..8f33073 100644 --- a/ps2xRuntime/include/ps2_runtime_macros.h +++ b/ps2xRuntime/include/ps2_runtime_macros.h @@ -3,6 +3,8 @@ #include #if defined(_MSC_VER) #include +#elif defined(USE_SSE2NEON) + #include "sse2neon.h" #else #include // For SSE/AVX intrinsics #endif