#floating-point #dsp #float #flags #off #temporarily #denormals

no_denormals

Temporarily turn off floating point denormals

5 releases

0.2.0 Dec 20, 2024
0.1.3 Oct 7, 2024
0.1.2 Jul 14, 2023
0.1.1 Jun 11, 2023
0.1.0 Jun 11, 2023

#148 in Audio

Download history 390/week @ 2024-09-16 480/week @ 2024-09-23 402/week @ 2024-09-30 448/week @ 2024-10-07 177/week @ 2024-10-14 314/week @ 2024-10-21 218/week @ 2024-10-28 326/week @ 2024-11-04 82/week @ 2024-11-11 146/week @ 2024-11-18 129/week @ 2024-11-25 202/week @ 2024-12-02 423/week @ 2024-12-09 507/week @ 2024-12-16 121/week @ 2024-12-23 126/week @ 2024-12-30

1,199 downloads per month
Used in 8 crates (4 directly)

MIT license

8KB
109 lines

no_denormals

build Crates.io MIT licensed

Temporarily turn off floating point denormals.

Internally, this uses a RAII-style guard to manage the state of certain processor flags. On x86 and x86_64, this sets the flush-to-zero and denormals-are-zero flags in the MXCSR register. On aarch64 this sets the flush-to-zero flag in the FPCR register. In all cases, the register will be reset to its initial state when the guard is dropped.

Note that according to the Rust docs "modifying the masking flags, rounding mode, or denormals-are-zero mode flags leads to immediate Undefined Behavior: Rust assumes that these are always in their default state and will optimize accordingly." So use this at your own risk.

Usage

use no_denormals::no_denormals;

unsafe {
    no_denormals(|| {
        // your DSP code here.
    })
};

No runtime deps