e01.org

Subnormal number

In computer science, subnormal numbers are the subset of denormalized numbers (sometimes called denormals) that fill the underflow gap around zero in floating-point arithmetic. Any non-zero number with magnitude smaller than the smallest positive normal number is subnormal, while denormal can also refer to numbers outside that range. Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.

In computer science, subnormal numbers are the subset of denormalized numbers (sometimes called denormals) that fill the underflow gap around zero in floating-point arithmetic. Any non-zero number with magnitude smaller than the smallest positive normal number is subnormal, while denormal can also refer to numbers outside that range. include pragma STDC FENV_ACCESS ON // Sets DAZ and FTZ, clobbering other CSR settings. fesetenv(FE_DFL_DISABLE_SSE_DENORMS_ENV); // fesetenv(FE_DFL_ENV) // Disable both, clobbering other CSR settings. For other x86-SSE platforms where the C library has not yet implemented this flag, the following may work: include _mm_setcsr(_mm_getcsr() | 0x0040); // DAZ _mm_setcsr(_mm_getcsr() | 0x8000); // FTZ _mm_setcsr(_mm_getcsr() | 0x8040); // Both _mm_setcsr(_mm_getcsr() & ~0x8040); // Disable both The and macros wrap a more readable interface for the code above. // To enable DAZ include _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); // To enable FTZ include _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); Most compilers will already provide the previous macro by default, otherwise the following code snippet can be used (the definition for FTZ is analogous): define _MM_DENORMALS_ZERO_MASK 0x0040 define _MM_DENORMALS_ZERO_ON 0x0040 define _MM_DENORMALS_ZERO_OFF 0x0000 define _MM_SET_DENORMALS_ZERO_MODE(mode) _mm_setcsr((_mm_getcsr() & ~_MM_DENORMALS_ZERO_MASK) | (mode)) define _MM_GET_DENORMALS_ZERO_MODE() (_mm_getcsr() & _MM_DENORMALS_ZERO_MASK) The default denormalization behavior is mandated by the ABI, and therefore well-behaved software should save and restore the denormalization mode before returning to the caller or calling code in other libraries. if defined(__arm64__) || defined(__aarch64__) uint64_t fpcr; asm( "mrs %0, fpcr" : "=r"( fpcr )); //Load the FPCR register asm( "msr fpcr, %0" :: "r"( fpcr | (1 Some ARM processors have hardware handling of subnormals.

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Subnormal number". 1791158933. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1378575792

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·