2024-11-18 17:30:30 -05:00
|
|
|
#
|
|
|
|
# Copyright (c) 2024 Alex Spataru <https://github.com/alex-spataru>
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
# THE SOFTWARE.
|
|
|
|
#
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.19)
|
|
|
|
|
|
|
|
add_library(simde INTERFACE)
|
|
|
|
target_include_directories(simde INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
|
2024-11-18 18:42:02 -05:00
|
|
|
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64)")
|
|
|
|
message(STATUS "Detected ARM architecture")
|
|
|
|
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
check_cxx_compiler_flag("-mfpu=neon" COMPILER_SUPPORTS_NEON)
|
|
|
|
check_cxx_compiler_flag("-march=armv8-a+simd" COMPILER_SUPPORTS_ARMV8_SIMD)
|
|
|
|
|
|
|
|
if(COMPILER_SUPPORTS_ARMV8_SIMD)
|
2024-11-18 19:17:31 -05:00
|
|
|
add_compile_options(-march=armv8-a+simd)
|
2024-11-18 18:42:02 -05:00
|
|
|
message(STATUS "Using ARMv8 Advanced SIMD optimizations")
|
|
|
|
elseif(COMPILER_SUPPORTS_NEON)
|
2024-11-18 19:17:31 -05:00
|
|
|
add_compile_options(-mfpu=neon)
|
2024-11-18 18:42:02 -05:00
|
|
|
message(STATUS "Using ARM NEON optimizations")
|
|
|
|
else()
|
|
|
|
message(WARNING "No SIMD support detected on ARM; falling back to portable mode")
|
2024-11-18 19:17:31 -05:00
|
|
|
add_compile_definitions(SIMDE_NO_NATIVE)
|
2024-11-18 18:42:02 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86|x86_64)")
|
|
|
|
message(STATUS "Detected x86 architecture")
|
|
|
|
|
|
|
|
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
2024-11-18 19:17:31 -05:00
|
|
|
add_compile_options(-msse2 -mavx -mavx2)
|
2024-11-18 18:42:02 -05:00
|
|
|
message(STATUS "Enabled SSE2, AVX, and AVX2 optimizations for GCC/Clang")
|
|
|
|
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
2024-11-18 19:17:31 -05:00
|
|
|
add_compile_options(/arch:AVX2)
|
2024-11-18 18:42:02 -05:00
|
|
|
message(STATUS "Enabled AVX2 optimizations for MSVC")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
else()
|
|
|
|
message(WARNING "Unknown architecture; enabling portable fallback")
|
2024-11-18 19:17:31 -05:00
|
|
|
add_compile_definitions(SIMDE_NO_NATIVE)
|
2024-11-18 17:30:30 -05:00
|
|
|
endif()
|
|
|
|
|
2024-11-18 19:17:31 -05:00
|
|
|
# Enable OpenMP SIMD support globally
|
2024-11-18 18:42:02 -05:00
|
|
|
find_package(OpenMP QUIET)
|
|
|
|
if(OpenMP_CXX_FOUND)
|
2024-11-18 19:17:31 -05:00
|
|
|
add_compile_definitions(SIMDE_ENABLE_OPENMP)
|
|
|
|
add_compile_options(${OpenMP_CXX_FLAGS})
|
|
|
|
message(STATUS "OpenMP SIMD support enabled globally")
|
2024-11-18 18:42:02 -05:00
|
|
|
else()
|
|
|
|
message(WARNING "OpenMP not found; SIMD performance may be suboptimal")
|
|
|
|
endif()
|