Skip to content

Commit

Permalink
Allow disabling of SIMD for some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohlstand committed Oct 31, 2023
1 parent 7f7c11f commit f859270
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ else()
set(ENABLE_FPIC OFF)
endif()

option(DISABLE_SIMD "Disable all SIMD optimizations as possible" OFF)

# --- TODO: implement building or usage of pre-built libSDL here ---
# set(SNDIO OFF) # Disable sndio that is not needed to us
# add_subdirectory(libSDL2)
Expand Down
1 change: 1 addition & 0 deletions FluidLite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ include(TestBigEndian)

set(CMAKE_C_STANDARD 99)

set(AUDIO_CODECS_KEEP_SSE ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/../audio_codec_common.cmake)

test_big_endian(WORDS_BIGENDIAN)
Expand Down
26 changes: 26 additions & 0 deletions audio_codec_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ macro(ac_disable_cxx_warning_flag WARNINGFLAG WARNING_VAR)
endmacro()

# Add compiler argument(s)
macro(ac_add_opt_flag COMPILERFLAG COMPILERFLAG_VAR)
check_c_compiler_flag("${COMPILERFLAG}" HAVE_C_${COMPILERFLAG_VAR})
if(HAVE_C_${COMPILERFLAG_VAR})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILERFLAG}")
endif()

check_cxx_compiler_flag("${COMPILERFLAG}" HAVE_CXX_${COMPILERFLAG_VAR})
if(HAVE_CXX_${COMPILERFLAG_VAR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILERFLAG}")
endif()
endmacro()

macro(ac_add_c_compiler_flag COMPILERFLAG COMPILERFLAG_VAR)
check_c_compiler_flag("${COMPILERFLAG}" HAVE_C_${COMPILERFLAG_VAR})
if(HAVE_C_${COMPILERFLAG_VAR})
Expand Down Expand Up @@ -148,3 +160,17 @@ endif()
if(WIN32)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif()

if(DISABLE_SIMD)
if(NOT AUDIO_CODECS_KEEP_SSE)
ac_add_opt_flag("-mno-sse" NO_SSE)
endif()
ac_add_opt_flag("-mno-sse2" NO_SSE2)
ac_add_opt_flag("-mno-sse3" NO_SSE3)
ac_add_opt_flag("-mno-ssse3" NO_SSSE3)
ac_add_opt_flag("-mno-sse4.1" NO_SSE41)
ac_add_opt_flag("-mno-sse4.2" NO_SSE42)
ac_add_opt_flag("-mno-avx" NO_AVX)
ac_add_opt_flag("-mno-avx2" NO_AVX2)
ac_add_opt_flag("-mno-avx512f" NO_AVX512F)
endif()
16 changes: 16 additions & 0 deletions download_sdl2_hg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ if(ANDROID)
)
endif()

set(SDL2_CMAKE_NOSIMD_FLAGS)
if(DISABLE_SIMD)
set(SDL2_CMAKE_NOSIMD_FLAGS
"-DSDL_SSEMATH=OFF"
"-DSDL_SSE=OFF"
"-DSDL_SSE2=OFF"
"-DSDL_SSE3=OFF"
"-DSDL_MMX=OFF"
"-DSDL_3DNOW=OFF"
"-DSDL_ALTIVEC=OFF"
"-DSDL_ARMSIMD=OFF"
"-DSDL_ARMNEON=OFF"
)
endif()

if(USE_USE_NDK_MAKE)
if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
set(SDL2_DEBUG_SUFFIX "d")
Expand Down Expand Up @@ -135,6 +150,7 @@ elseif(USE_LOCAL_SDL2)
-DCMAKE_DEBUG_POSTFIX=${CMAKE_DEBUG_POSTFIX}
${SDL2_CMAKE_FPIC_FLAG}
${SDL2_WASAPI_FLAG}
${SDL2_CMAKE_NOSIMD_FLAGS}
${APPLE_FLAGS}
${ANDROID_FLAGS}
${EMSCRIPTEN_FLAGS}
Expand Down
1 change: 1 addition & 0 deletions libFLAC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project(libFLAC VERSION 1.3.4 LANGUAGES C)
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(TestBigEndian)
set(AUDIO_CODECS_KEEP_SSE ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/../audio_codec_common.cmake)

TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
Expand Down
1 change: 1 addition & 0 deletions libgme/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.2...3.5)
project(libGME VERSION 0.6.2 LANGUAGES CXX)

set(AUDIO_CODECS_KEEP_SSE ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/../audio_codec_common.cmake)
include(TestBigEndian)

Expand Down
1 change: 1 addition & 0 deletions libmodplug/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ include(CheckIncludeFile)
include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
include(TestBigEndian)
set(AUDIO_CODECS_KEEP_SSE ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/../audio_codec_common.cmake)

TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
Expand Down
1 change: 1 addition & 0 deletions libopus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckLibraryExists)

set(AUDIO_CODECS_KEEP_SSE ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/../audio_codec_common.cmake)

if(NOT MSVC)
Expand Down
1 change: 1 addition & 0 deletions libtimidity-sdl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.2...3.5)
project(libTimiditySDL VERSION 0.2 LANGUAGES C)

set(AUDIO_CODECS_KEEP_SSE ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/../audio_codec_common.cmake)

# Turn on warnings and legacy C/C++ standards to support more compilers
Expand Down
1 change: 1 addition & 0 deletions libvorbis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include(CheckIncludeFile)

set(CMAKE_C_STANDARD 99)

set(AUDIO_CODECS_KEEP_SSE ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/../audio_codec_common.cmake)

add_definitions(
Expand Down

0 comments on commit f859270

Please sign in to comment.