LMMS
Loading...
Searching...
No Matches
denormals.h
Go to the documentation of this file.
1// Denormals stripping.
2// These snippets should be common enough to be considered public domain.
3
4#ifndef LMMS_DENORMALS_H
5#define LMMS_DENORMALS_H
6
7#ifdef __SSE__
8#include <immintrin.h>
9#ifdef __GNUC__
10#include <x86intrin.h>
11#endif // __GNUC__
12#endif // __SSE__
13
14
15namespace lmms
16{
17
18#ifdef __SSE__
19
20// Intel® 64 and IA-32 Architectures Software Developer’s Manual,
21// Volume 1: Basic Architecture,
22// 11.6.3 Checking for the DAZ Flag in the MXCSR Register
23int inline can_we_daz()
24{
25 alignas(16) unsigned char buffer[512] = {0};
26#if defined(LMMS_HOST_X86)
27 _fxsave(buffer);
28#elif defined(LMMS_HOST_X86_64)
29 _fxsave64(buffer);
30#endif // defined(LLMS_HOST_X86)
31 // Bit 6 of the MXCSR_MASK, i.e. in the lowest byte,
32 // tells if we can use the DAZ flag.
33 return ((buffer[28] & (1 << 6)) != 0);
34}
35
36#endif // __SSE__
37
38// Set denormal protection for this thread.
39void inline disable_denormals()
40{
41#ifdef __SSE__
42 /* Setting DAZ might freeze systems not supporting it */
43 if (can_we_daz()) {
44 _MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON );
45 }
46 /* FTZ flag */
47 _MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON );
48#endif // __SSE__
49}
50
51} // namespace lmms
52
53#endif // LMMS_DENORMALS_H
Definition AudioAlsa.cpp:35
void disable_denormals()
Definition denormals.h:39