Files
lmms/include/denormals.h
Levin Oehlmann 7227c89847 Namespace lmms (#6174)
This PR places all LMMS symbols into namespaces to eliminate any potential future name collisions between LMMS and third-party modules.

Also, this PR changes back `LmmsCore` to `Engine`, reverting c519921306 .

Co-authored-by: allejok96 <allejok96@gmail.com>
2022-06-19 20:08:46 +02:00

55 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Denormals stripping.
// These snippets should be common enough to be considered public domain.
#ifndef DENORMALS_H
#define DENORMALS_H
#ifdef __SSE__
#include <immintrin.h>
#ifdef __GNUC__
#include <x86intrin.h>
#endif // __GNUC__
#endif // __SSE__
namespace lmms
{
#ifdef __SSE__
// Intel® 64 and IA-32 Architectures Software Developers Manual,
// Volume 1: Basic Architecture,
// 11.6.3 Checking for the DAZ Flag in the MXCSR Register
int inline can_we_daz()
{
alignas(16) unsigned char buffer[512] = {0};
#if defined(LMMS_HOST_X86)
_fxsave(buffer);
#elif defined(LMMS_HOST_X86_64)
_fxsave64(buffer);
#endif // defined(LLMS_HOST_X86)
// Bit 6 of the MXCSR_MASK, i.e. in the lowest byte,
// tells if we can use the DAZ flag.
return ((buffer[28] & (1 << 6)) != 0);
}
#endif // __SSE__
// Set denormal protection for this thread.
void inline disable_denormals()
{
#ifdef __SSE__
/* Setting DAZ might freeze systems not supporting it */
if (can_we_daz()) {
_MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON );
}
/* FTZ flag */
_MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON );
#endif // __SSE__
}
} // namespace lmms
#endif // DENORMALS_H