mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-29 08:42:28 +00:00
Introduce support for trapping math
The feenableexcept() and fedisableexcept() APIs are now provided which let you detect when NaNs appear the moment it happens from anywhere in your program. Tests have also been added for the mission critical math functions expf() and erff(), whose perfect operation has been assured. See examples/trapping.c to see how to use this powerful functionality.
This commit is contained in:
parent
403bc25412
commit
5c6877b02b
13 changed files with 576 additions and 2 deletions
|
@ -75,6 +75,19 @@ cosmo: push %rbp
|
|||
#ifdef __FAST_MATH__
|
||||
push %rax
|
||||
stmxcsr (%rsp)
|
||||
//
|
||||
// Enable hardware optimizations in violation of the IEEE standard.
|
||||
//
|
||||
// - 0x0040 enables "DAZ: Denormals Are Zeros" in MXCSR. This causes the
|
||||
// processor to turn denormal inputs into zero, before computing them.
|
||||
// See Intel Manual Vol. 1 §10.2.3.4
|
||||
//
|
||||
// - 0x8000 enables "FTZ: Flush To Zero" in MXCSR. This means a floating
|
||||
// point operation that results in underflow will be set to zero, with
|
||||
// the same sign, rather than producing a denormalized output. It will
|
||||
// happen only if underflow trapping hasnt been enabled. See the Intel
|
||||
// Manual Vol. 1 §10.2.3.3.
|
||||
//
|
||||
orl $0x8040,(%rsp)
|
||||
ldmxcsr (%rsp)
|
||||
pop %rax
|
||||
|
|
|
@ -81,6 +81,8 @@ int fesetenv(const fenv_t *);
|
|||
int fesetexceptflag(const fexcept_t *, int);
|
||||
int fesetround(int);
|
||||
int fetestexcept(int);
|
||||
int feenableexcept(int);
|
||||
int fedisableexcept(int);
|
||||
int feupdateenv(const fenv_t *);
|
||||
int __flt_rounds(void);
|
||||
int __fesetround(int);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue