From 7981809f3639c6c323dbe7091b02c4ccf20d395a Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Tue, 15 Jan 2019 10:36:23 +0100 Subject: [PATCH] Split up SIMD support in ENABLE_SIMD which enables sse2 support for the compiler and ENABLE_SIMD_CODE which enables the hand crafted SIMD math functions which defaults to OFF now since compilers have catched up on generating optimized vectorized SIMD code. --- CMakeLists.txt | 15 ++++++++++----- simgear/math/simd.hxx | 4 ++-- simgear/math/simd4x4.hxx | 4 ++-- simgear/simgear_config_cmake.h.in | 1 + 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3562e791..8a2f59f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,9 +125,14 @@ option(ENABLE_SOUND "Set to OFF to disable building SimGear's sound support" option(USE_AEONWAVE "Set to ON to use AeonWave instead of OpenAL" ON) option(ENABLE_PKGUTIL "Set to ON to build the sg_pkgutil application (default)" ON) option(ENABLE_DNS "Set to ON to use udns library and DNS service resolver" ON) -option(ENABLE_SIMD "Enable SSE/SSE2 support for x86 compilers" ON) +option(ENABLE_SIMD "Enable SSE/SSE2 support for compilers" ON) +option(ENABLE_SIMD_CODE "Enable SSE/SSE2 support code for compilers" OFF) option(ENABLE_OPENMP "Enable OpenMP compiler support" OFF) +if (NOT ENABLE_SIMD AND ENABLE_SIMD_CODE) + set(ENABLE_SIMD_CODE OFF) +endif() + include (DetectArch) # until the fstream fix is applied and generally available in OSG, @@ -412,8 +417,8 @@ if(CMAKE_COMPILER_IS_GNUCXX) "${CMAKE_CXX_FLAGS} -O0 -fno-omit-frame-pointer -fno-inline") elseif (ENABLE_SIMD) if (X86 OR X86_64) - set(CMAKE_C_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse") - set(CMAKE_CXX_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse") + set(CMAKE_C_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse -ftree-vectorize -ftree-slp-vectorize") + set(CMAKE_CXX_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse -ftree-vectorize -ftree-slp-vectorize") endif() endif() @@ -440,8 +445,8 @@ if (CLANG) "${CMAKE_CXX_FLAGS} -O0 -fno-omit-frame-pointer -fno-inline-functions") elseif (ENABLE_SIMD) if (X86 OR X86_64) - set(CMAKE_C_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse") - set(CMAKE_CXX_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse") + set(CMAKE_C_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse -ftree-vectorize -ftree-slp-vectorize") + set(CMAKE_CXX_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse -ftree-vectorize -ftree-slp-vectorize") endif() endif() endif() diff --git a/simgear/math/simd.hxx b/simgear/math/simd.hxx index a2847775..162820ac 100644 --- a/simgear/math/simd.hxx +++ b/simgear/math/simd.hxx @@ -309,7 +309,7 @@ inline simd4_t operator*(simd4_t v, T f) { return v; } -#ifdef ENABLE_SIMD +#ifdef ENABLE_SIMD_CODE # ifdef __SSE__ namespace simd4 @@ -1305,7 +1305,7 @@ inline simd4_t max(simd4_t v1, const simd4_t& v2) { # endif -#endif /* ENABLE_SIMD */ +#endif /* ENABLE_SIMD_CODE */ #endif /* __SIMD_H__ */ diff --git a/simgear/math/simd4x4.hxx b/simgear/math/simd4x4.hxx index 69203511..26db560f 100644 --- a/simgear/math/simd4x4.hxx +++ b/simgear/math/simd4x4.hxx @@ -289,7 +289,7 @@ inline simd4x4_t operator*(const simd4x4_t& m1, const simd4x4_t& } -#ifdef ENABLE_SIMD +#ifdef ENABLE_SIMD_CODE # ifdef __SSE__ template<> @@ -1191,7 +1191,7 @@ inline simd4_t transform(const simd4x4_t& m, const simd4_t