|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
RAII scope guard to disable denormalised (subnormal) floating-point numbers. More...
#include <DenormalGuard.h>
Public Member Functions | |
| DenormalGuard () noexcept | |
| Constructs the guard, saving the current FP state and enabling FTZ (plus DAZ on x86). | |
| ~DenormalGuard () noexcept | |
| Destroys the guard, restoring the exact FP state captured at construction. | |
| DenormalGuard (const DenormalGuard &)=delete | |
| DenormalGuard & | operator= (const DenormalGuard &)=delete |
| DenormalGuard (DenormalGuard &&)=delete | |
| DenormalGuard & | operator= (DenormalGuard &&)=delete |
Static Public Member Functions | |
| static constexpr bool | isActive () noexcept |
| True when this build has a real flush-to-zero implementation. | |
RAII scope guard to disable denormalised (subnormal) floating-point numbers.
Denormals cause severe performance penalties (CPU spikes) in recursive DSP calculations (IIR filters, delays, reverbs) when signals decay towards zero. This guard configures the CPU to flush denormal results to zero (FTZ) and, on x86, to also treat denormal inputs as zero (DAZ) for the lifetime of the object, preventing the degradation without audible effect on sound quality.
The floating-point mode is a per-thread CPU register: construct the guard on the thread whose maths it must protect (typically at the top of the audio callback), and give it a name - a discarded temporary is destroyed immediately and protects nothing (the class is marked [[nodiscard]] so compilers flag that mistake). Guards nest safely: each one restores the exact state it captured, so the host's own floating-point configuration survives. Construction and destruction cost a handful of cycles.
Architecture support:
_mm_getcsr/_mm_setcsr. 32-bit GCC/Clang builds need -msse; without it the guard is a no-op.mrs/msr inline assembly._ReadStatusReg/_WriteStatusReg.vmrs/vmsr.Use isActive() to ask at compile time whether this build has a real implementation or the no-op.
Definition at line 85 of file DenormalGuard.h.
|
inlinenoexcept |
Constructs the guard, saving the current FP state and enabling FTZ (plus DAZ on x86).
Definition at line 91 of file DenormalGuard.h.
|
inlinenoexcept |
Destroys the guard, restoring the exact FP state captured at construction.
Definition at line 128 of file DenormalGuard.h.
|
delete |
|
delete |
|
inlinestaticconstexprnoexcept |
True when this build has a real flush-to-zero implementation.
False where the guard compiles as a documented no-op (WebAssembly, soft-float ARM, 32-bit x86 without SSE, unknown architectures). Lets tests and diagnostics assert flushing only where the hardware can do it.
Definition at line 153 of file DenormalGuard.h.
|
delete |
|
delete |