diff --git a/CMakeLists.txt b/CMakeLists.txt index a0400c71..803d0b9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,16 @@ if(COMMAND cmake_policy) endif() endif() -message("CMAKE Build type: ${CMAKE_BUILD_TYPE}") + +message(STATUS "CMAKE Build type: ${CMAKE_BUILD_TYPE}") +# Set a default build type if none was specified +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'Debug' as none was specified.") + set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") +endif() include (CheckFunctionExists) include (CheckIncludeFile) @@ -366,7 +375,8 @@ if (CLANG) if(ENABLE_SIMD) if (X86 OR X86_64) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3 -mfpmath=sse") + set(CMAKE_C_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse") + set(CMAKE_CXX_FLAGS_RELEASE "-O3 -msse2 -mfpmath=sse") endif() endif() endif() diff --git a/simgear/math/SGVec3.hxx b/simgear/math/SGVec3.hxx index 904ec1a8..9323063d 100644 --- a/simgear/math/SGVec3.hxx +++ b/simgear/math/SGVec3.hxx @@ -451,14 +451,14 @@ template inline T dist(const SGVec3& v1, const SGVec3& v2) -{ return norm(v1 - v2); } +{ return simd4::magnitude(v1.simd3() - v2.simd3()); } /// The squared euclidean distance of the two vectors template inline T distSqr(SGVec3 v1, const SGVec3& v2) -{ v1 -= v2; return dot(v1, v1); } +{ return simd4::magnitude2(v1.simd3() - v2.simd3()); } // calculate the projection of u along the direction of d. template @@ -466,7 +466,7 @@ inline SGVec3 projection(const SGVec3& u, const SGVec3& d) { - T denom = dot(d, d); + T denom = simd4::magnitude2(d); T ud = dot(u, d); if (SGLimits::min() < denom) return u; else return d * (dot(u, d) / denom); diff --git a/simgear/math/simd.hxx b/simgear/math/simd.hxx index b65dbf5e..e5710930 100644 --- a/simgear/math/simd.hxx +++ b/simgear/math/simd.hxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -330,10 +331,12 @@ public: simd_aligned16() {} ~simd_aligned16() {} - void *operator new (size_t size) { - return _mm_malloc(size, 16); + static void *operator new (size_t size) throw (std::bad_alloc) { + void *p = _mm_malloc(size, 16); + if (!p) throw std::bad_alloc(); + return p; } - void operator delete (void *p) { + static void operator delete (void *p) { _mm_free(p); } } ALIGN16C; @@ -487,22 +490,12 @@ inline float dot(simd4_t v1, const simd4_t& v2) { template<> inline simd4_t cross(const simd4_t& v1, const simd4_t& v2) { -#if 1 // http://threadlocalmutex.com/?p=8 __m128 v41 = v1.v4(), v42 = v2.v4(); __m128 a = _mm_shuffle_ps(v41, v41, _MM_SHUFFLE(3, 0, 2, 1)); __m128 b = _mm_shuffle_ps(v42, v42, _MM_SHUFFLE(3, 0, 2, 1)); __m128 c = _mm_sub_ps(_mm_mul_ps(v41, b), _mm_mul_ps(a, v42)); return _mm_shuffle_ps(c, c, _MM_SHUFFLE(3, 0, 2, 1)); -#else - v1 = _mm_sub_ps( - _mm_mul_ps(_mm_shuffle_ps(v1.v4(),v1.v4(),_MM_SHUFFLE(3, 0, 2, 1)), - _mm_shuffle_ps(v2.v4(),v2.v4(),_MM_SHUFFLE(3, 1, 0, 2))), - _mm_mul_ps(_mm_shuffle_ps(v1.v4(),v1.v4(),_MM_SHUFFLE(3, 1, 0, 2)), - _mm_shuffle_ps(v2.v4(),v2.v4(),_MM_SHUFFLE(3, 0, 2, 1))) - ); - return v1; -#endif } template @@ -529,10 +522,8 @@ inline simd4_tabs(simd4_t v) { # endif -# ifdef __AVX__ -# include +# ifdef __AVX_unsupported__ # include -// # include "avxintrin-emu.h" ALIGN32 class simd_aligned32 @@ -541,10 +532,12 @@ public: simd_aligned32() {} ~simd_aligned32() {} - void *operator new (size_t size) { - return _mm_malloc(size, 32); + static void *operator new (size_t size) throw (std::bad_alloc) { + void *p = _mm_malloc(size, 32); + if (!p) throw std::bad_alloc(); + return p; } - void operator delete (void *p) { + static void operator delete (void *p) { _mm_free(p); } } ALIGN32C; @@ -666,7 +659,7 @@ inline simd4_t::simd4_t(double d) { namespace simd4 { // http://berenger.eu/blog/sseavxsimd-horizontal-sum-sum-simd-vector-intrinsic/ -inline static float hsum_pd_avx(__m256d v) { +inline static double hsum_pd_avx(__m256d v) { const __m128d valupper = _mm256_extractf128_pd(v, 1); const __m128d vallower = _mm256_castpd256_pd128(v); _mm256_zeroupper(); @@ -685,7 +678,8 @@ inline double dot(simd4_t v1, const simd4_t& v2) { return hsum_pd_avx(_mm256_mul_pd(v1.v4(),v2.v4())); } -#ifdef __AVX2__ +# ifdef __AVX2__ +# include template<> inline simd4_t cross(const simd4_t& v1, const simd4_t& v2) { @@ -699,7 +693,7 @@ inline simd4_t cross(const simd4_t& v1, const simd4_t inline simd4_t min(simd4_t v1, const simd4_t& v2) { diff --git a/simgear/math/simd4x4.hxx b/simgear/math/simd4x4.hxx index 104c1ff2..b88604fa 100644 --- a/simgear/math/simd4x4.hxx +++ b/simgear/math/simd4x4.hxx @@ -514,10 +514,9 @@ inline simd4_t transform(const simd4x4_t& m, const simd # endif -# ifdef __AVX__ +# ifdef __AVX_unsupported__ # include # include -// # include "avxintrin-emu.h" template<> class simd4x4_t : public simd_aligned32