From beac2e4b3a25494ac208449b0cf7ab0beb3c3383 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 1 Mar 2016 16:32:08 +0000 Subject: [PATCH] Removed some legacy support for non-SSE2 CPUs. Added function FloatVectorOperations::disableDenormalisedNumberSupport() --- .../buffers/juce_FloatVectorOperations.cpp | 31 ++++++------------- .../buffers/juce_FloatVectorOperations.h | 6 ++++ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp b/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp index f6548ce64f..881965e253 100644 --- a/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp +++ b/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp @@ -29,17 +29,6 @@ namespace FloatVectorHelpers #define JUCE_INCREMENT_DEST dest += (16 / sizeof (*dest)); #if JUCE_USE_SSE_INTRINSICS - static bool sse2Present = false; - - static bool isSSE2Available() noexcept - { - if (sse2Present) - return true; - - sse2Present = SystemStats::hasSSE2(); - return sse2Present; - } - inline static bool isAligned (const void* p) noexcept { return (((pointer_sized_int) p) & 15) == 0; @@ -113,7 +102,6 @@ namespace FloatVectorHelpers #define JUCE_BEGIN_VEC_OP \ typedef FloatVectorHelpers::ModeType::Mode Mode; \ - if (FloatVectorHelpers::isSSE2Available()) \ { \ const int numLongOps = num / Mode::numParallel; @@ -372,11 +360,7 @@ namespace FloatVectorHelpers { int numLongOps = num / Mode::numParallel; - #if JUCE_USE_SSE_INTRINSICS - if (numLongOps > 1 && isSSE2Available()) - #else if (numLongOps > 1) - #endif { ParallelType val; @@ -446,11 +430,7 @@ namespace FloatVectorHelpers { int numLongOps = num / Mode::numParallel; - #if JUCE_USE_SSE_INTRINSICS - if (numLongOps > 1 && isSSE2Available()) - #else if (numLongOps > 1) - #endif { ParallelType mn, mx; @@ -1002,12 +982,19 @@ double JUCE_CALLTYPE FloatVectorOperations::findMaximum (const double* src, int void JUCE_CALLTYPE FloatVectorOperations::enableFlushToZeroMode (bool shouldEnable) noexcept { #if JUCE_USE_SSE_INTRINSICS - if (FloatVectorHelpers::isSSE2Available()) - _MM_SET_FLUSH_ZERO_MODE (shouldEnable ? _MM_FLUSH_ZERO_ON : _MM_FLUSH_ZERO_OFF); + _MM_SET_FLUSH_ZERO_MODE (shouldEnable ? _MM_FLUSH_ZERO_ON : _MM_FLUSH_ZERO_OFF); #endif ignoreUnused (shouldEnable); } +void JUCE_CALLTYPE FloatVectorOperations::disableDenormalisedNumberSupport() noexcept +{ + #if JUCE_USE_SSE_INTRINSICS + const int mxcsr = _mm_getcsr(); + _mm_setcsr (mxcsr | 0x8040); // add the DAZ and FZ bits + #endif +} + //============================================================================== //============================================================================== #if JUCE_UNIT_TESTS diff --git a/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.h b/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.h index 0c85e60f43..f1a8d13b47 100644 --- a/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.h +++ b/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.h @@ -198,6 +198,12 @@ public: Effectively, this is a wrapper around a call to _MM_SET_FLUSH_ZERO_MODE */ static void JUCE_CALLTYPE enableFlushToZeroMode (bool shouldEnable) noexcept; + + /** On Intel CPUs, this method enables the SSE flush-to-zero and denormalised-are-zero modes. + This effectively sets the DAZ and FZ bits of the MXCSR register. It's a convenient thing to + call before audio processing code where you really want to avoid denormalisation performance hits. + */ + static void JUCE_CALLTYPE disableDenormalisedNumberSupport() noexcept; };