30#ifndef APF_DENORMALPREVENTION_H
31#define APF_DENORMALPREVENTION_H
56 void prevent_denormals(T&) {}
59template<
typename>
struct dc;
65 static void prevent_denormals(
float& val) { val += 1e-18f; }
72 static void prevent_denormals(
double& val) { val += 1e-30; }
75template<
typename>
struct ac;
82 ac() : _anti_denorm(1e-18f) {}
84 void prevent_denormals(
float& val)
86 _anti_denorm = -_anti_denorm;
99 ac() : _anti_denorm(1e-30) {}
101 void prevent_denormals(
double& val)
103 _anti_denorm = -_anti_denorm;
111template<
typename>
struct quantization;
115struct quantization<float>
117 static void prevent_denormals(
float& val)
126struct quantization<double>
128 static void prevent_denormals(
double& val)
139 static void prevent_denormals(T& val)
141 if (std::abs(val) < std::numeric_limits<T>::min() && (val != 0)) val = 0;
149 static void prevent_denormals(T& val)
151 if ((val != 0) && std::abs(val) < std::numeric_limits<T>::min()) val = 0;
159 static void prevent_denormals(T& val)
161 if (std::abs(val) < std::numeric_limits<T>::min()) val = 0;
170template<
typename>
struct NoisePrevention;
173struct NoisePrevention<float>
176 NoisePrevention() : _rand_state(1) {}
178 void prevent_denormals(
float& val)
180 _rand_state = _rand_state * 1234567UL + 890123UL;
181 int mantissa = _rand_state & 0x807F0000;
182 int flt_rnd = mantissa | 0x1E000000;
183 val += *
reinterpret_cast<const float*
>(&flt_rnd);
187 unsigned int _rand_state;
199 _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
206 _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF);
223 _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
230 _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_OFF);
void ftz_off()
Unset Flush-To-Zero (FTZ).
void daz_off()
Unset Denormals-Are-Zero (DAZ).
void daz_on()
Set Denormals-Are-Zero (DAZ).
void ftz_on()
Set Flush-To-Zero (FTZ).
Audio Processing Framework.
Disable denormal prevention.
Detect denormals and set 0.
Detect denormals and set 0.
Detect denormals and set 0.