diff --git a/CMakeLists.txt b/CMakeLists.txt index 05d04201..4f11b2f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -344,7 +344,6 @@ endif() set(SSE2_SWITCH "") -set(FPU_NEON_SWITCH "") set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) if(NOT MSVC) @@ -355,10 +354,6 @@ check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH) if(HAVE_MSSE2_SWITCH) set(SSE2_SWITCH "-msse2") endif() -check_c_compiler_flag(-mfpu=neon HAVE_MFPU_NEON_SWITCH) -if(HAVE_MFPU_NEON_SWITCH) - set(FPU_NEON_SWITCH "-mfpu=neon") -endif() set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS}) unset(OLD_REQUIRED_FLAGS) @@ -368,12 +363,79 @@ check_include_file(pmmintrin.h HAVE_PMMINTRIN_H) check_include_file(smmintrin.h HAVE_SMMINTRIN_H) check_include_file(arm_neon.h HAVE_ARM_NEON_H) +set(HAVE_SSE 0) +set(HAVE_SSE2 0) +set(HAVE_SSE3 0) +set(HAVE_SSE4_1 0) +set(HAVE_NEON 0) + +# Check for SSE+SSE2 support +option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF) +option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF) +if(HAVE_XMMINTRIN_H AND HAVE_EMMINTRIN_H) + option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON) + option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON) + if(ALSOFT_CPUEXT_SSE AND ALSOFT_CPUEXT_SSE2) + set(HAVE_SSE 1) + set(HAVE_SSE2 1) + endif() +endif() +if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE) + message(FATAL_ERROR "Failed to enabled required SSE CPU extensions") +endif() +if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2) + message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions") +endif() + +option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF) +if(HAVE_PMMINTRIN_H) + option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON) + if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3) + set(HAVE_SSE3 1) + endif() +endif() +if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3) + message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions") +endif() + +option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF) +if(HAVE_SMMINTRIN_H) + option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON) + if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1) + set(HAVE_SSE4_1 1) + endif() +endif() +if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1) + message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions") +endif() + +# Check for ARM Neon support +option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF) +if(HAVE_ARM_NEON_H) + option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON) + if(ALSOFT_CPUEXT_NEON) + check_c_source_compiles("#include + int main() + { + int32x4_t ret4 = vdupq_n_s32(0); + return vgetq_lane_s32(ret4, 0); + }" HAVE_NEON_INTRINSICS) + if(HAVE_NEON_INTRINSICS) + set(HAVE_NEON 1) + endif() + endif() +endif() +if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON) + message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions") +endif() + + set(SSE_FLAGS ) set(FPMATH_SET "0") -if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND (SSE2_SWITCH OR MSVC)) +if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2) option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE) if(ALSOFT_ENABLE_SSE2_CODEGEN) - if(SSE2_SWITCH) + if(SSE2_SWITCH OR NOT MSVC) check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2) if(HAVE_MFPMATH_SSE_2) set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse) @@ -396,14 +458,14 @@ if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND (SSE2_SWITCH OR MSVC)) endif() endif() -if(HAVE_EMMINTRIN_H) +if(HAVE_SSE2) set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) foreach(flag_var ${SSE_FLAGS}) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}") endforeach() check_c_source_compiles("#include - int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS) + int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS) set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS}) endif() @@ -701,72 +763,23 @@ set(ALC_OBJS alc/voice.h alc/voice_change.h) - +# Include SIMD mixers set(CPU_EXTS "Default") -set(HAVE_SSE 0) -set(HAVE_SSE2 0) -set(HAVE_SSE3 0) -set(HAVE_SSE4_1 0) -set(HAVE_NEON 0) - -# Check for SSE+SSE2 support -option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF) -option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF) -if(HAVE_XMMINTRIN_H AND HAVE_EMMINTRIN_H) - option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON) - option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON) - if(ALSOFT_CPUEXT_SSE AND ALSOFT_CPUEXT_SSE2) - set(HAVE_SSE 1) - set(HAVE_SSE2 1) - set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse.cpp core/mixer/mixer_sse2.cpp) - set(CPU_EXTS "${CPU_EXTS}, SSE, SSE2") - endif() +if(HAVE_SSE2) + set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse.cpp core/mixer/mixer_sse2.cpp) + set(CPU_EXTS "${CPU_EXTS}, SSE, SSE2") endif() -if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE) - message(FATAL_ERROR "Failed to enabled required SSE CPU extensions") +if(HAVE_SSE3) + set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse3.cpp) + set(CPU_EXTS "${CPU_EXTS}, SSE3") endif() -if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2) - message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions") +if(HAVE_SSE4_1) + set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse41.cpp) + set(CPU_EXTS "${CPU_EXTS}, SSE4.1") endif() - -option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF) -if(HAVE_PMMINTRIN_H) - option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON) - if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3) - set(HAVE_SSE3 1) - set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse3.cpp) - set(CPU_EXTS "${CPU_EXTS}, SSE3") - endif() -endif() -if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3) - message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions") -endif() - -option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF) -if(HAVE_SMMINTRIN_H) - option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON) - if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1) - set(HAVE_SSE4_1 1) - set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse41.cpp) - set(CPU_EXTS "${CPU_EXTS}, SSE4.1") - endif() -endif() -if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1) - message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions") -endif() - -# Check for ARM Neon support -option(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF) -if(HAVE_ARM_NEON_H) - option(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON) - if(ALSOFT_CPUEXT_NEON) - set(HAVE_NEON 1) - set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_neon.cpp) - set(CPU_EXTS "${CPU_EXTS}, Neon") - endif() -endif() -if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON) - message(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions") +if(HAVE_NEON) + set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_neon.cpp) + set(CPU_EXTS "${CPU_EXTS}, Neon") endif()