diff --git a/include/Mixer.h b/include/Mixer.h index f8f9cf313..03a815975 100644 --- a/include/Mixer.h +++ b/include/Mixer.h @@ -25,13 +25,7 @@ #ifndef MIXER_H #define MIXER_H -// denormals stripping -#ifdef __SSE__ -#include -#endif -#ifdef __SSE3__ -#include -#endif +#include "denormals.h" #include "lmmsconfig.h" diff --git a/include/denormals.h b/include/denormals.h new file mode 100644 index 000000000..f89325ac1 --- /dev/null +++ b/include/denormals.h @@ -0,0 +1,32 @@ +// Denormals stripping. +// These snippets should be common enough to be considered public domain. + +#ifndef DENORMALS_H +#define DENORMALS_H + + +#ifdef __SSE__ +#include +#endif +#ifdef __SSE3__ +#include +#endif + + +// Set denormal protection for this thread. +// To be on the safe side, don't set the DAZ flag for SSE2 builds, +// even if most SSE2 CPUs can handle it. +void inline disable_denormals() { +#ifdef __SSE3__ + /* DAZ flag */ + _MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON ); +#endif + +#ifdef __SSE__ + /* FTZ flag */ + _MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON ); +#endif +} + +#endif + diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index 845abbf93..686e2c5c7 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -930,15 +930,7 @@ void Mixer::fifoWriter::finish() void Mixer::fifoWriter::run() { -// set denormal protection for this thread -#ifdef __SSE3__ -/* DAZ flag */ - _MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON ); -#endif -#ifdef __SSE__ -/* FTZ flag */ - _MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON ); -#endif + disable_denormals(); #if 0 #ifdef LMMS_BUILD_LINUX diff --git a/src/core/MixerWorkerThread.cpp b/src/core/MixerWorkerThread.cpp index ef011f55f..45554708c 100644 --- a/src/core/MixerWorkerThread.cpp +++ b/src/core/MixerWorkerThread.cpp @@ -29,12 +29,7 @@ #include "ThreadableJob.h" #include "Mixer.h" -#ifdef __SSE__ -#include -#endif -#ifdef __SSE3__ -#include -#endif +#include "denormals.h" MixerWorkerThread::JobQueue MixerWorkerThread::globalJobQueue; QWaitCondition * MixerWorkerThread::queueReadyWaitCond = NULL; @@ -159,15 +154,8 @@ void MixerWorkerThread::startAndWaitForJobs() void MixerWorkerThread::run() { -// set denormal protection for this thread -#ifdef __SSE3__ -/* DAZ flag */ - _MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON ); -#endif -#ifdef __SSE__ -/* FTZ flag */ - _MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON ); -#endif + disable_denormals(); + QMutex m; while( m_quit == false ) { diff --git a/src/core/main.cpp b/src/core/main.cpp index bf5d8d2ef..bba357b01 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -27,13 +27,7 @@ #include "lmmsversion.h" #include "versioninfo.h" -// denormals stripping -#ifdef __SSE__ -#include -#endif -#ifdef __SSE3__ -#include -#endif +#include "denormals.h" #include #include @@ -103,15 +97,7 @@ int main( int argc, char * * argv ) // intialize RNG srand( getpid() + time( 0 ) ); - // set denormal protection for this thread - #ifdef __SSE3__ - /* DAZ flag */ - _MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON ); - #endif - #ifdef __SSE__ - /* FTZ flag */ - _MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON ); - #endif + disable_denormals(); bool core_only = false; bool fullscreen = true;