Skip to content

Commit

Permalink
Merge pull request #4504 from jrsurge/topic/fix-windows-denormals
Browse files Browse the repository at this point in the history
[scsynth][supernova] fix Windows not guarding denormals
  • Loading branch information
mossheim committed Feb 15, 2020
2 parents bc32f32 + ff2c03d commit 2f42c47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
24 changes: 8 additions & 16 deletions server/scsynth/SC_World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@

#include "malloc_aligned.hpp"

#include <boost/predef/hardware.h>

#ifdef BOOST_HW_SIMD_AVAILABLE >= BOOST_HW_SIMD_X86_SSE_VERSION
# include <xmmintrin.h>
#endif

// undefine the shadowed scfft functions
#undef scfft_create
#undef scfft_dofft
Expand Down Expand Up @@ -148,26 +154,12 @@ void zfree(void* ptr) { return free_alig(ptr); }
////////////////////////////////////////////////////////////////////////////////

// Set denormal FTZ mode on CPUs that need/support it.
void sc_SetDenormalFlags();

#ifdef __SSE2__
# include <xmmintrin.h>

void sc_SetDenormalFlags() {
#if BOOST_HW_SIMD_X86 >= BOOST_HW_SIMD_X86_SSE_VERSION
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_mm_setcsr(_mm_getcsr() | 0x40); // DAZ
}

#elif defined(__SSE__)
# include <xmmintrin.h>

void sc_SetDenormalFlags() { _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); }

#else

void sc_SetDenormalFlags() {}

#endif
}

////////////////////////////////////////////////////////////////////////////////

Expand Down
4 changes: 3 additions & 1 deletion server/supernova/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
# include <CoreAudio/CoreAudioTypes.h>
#endif

#include <boost/predef/hardware.h>

namespace nova {

class nova_server* instance = nullptr;
Expand Down Expand Up @@ -207,7 +209,7 @@ static void name_current_thread(int thread_index) {
}

static void set_daz_ftz(void) {
#ifdef __SSE__
#if BOOST_HW_SIMD_X86 >= BOOST_X86_SSE_VERSION
/* denormal handling */
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_mm_setcsr(_mm_getcsr() | 0x40);
Expand Down

0 comments on commit 2f42c47

Please sign in to comment.