Make gdtoa less tunable (#104)

The -fno-math-errno flag shouldn't impact libraries since it's mostly
intended for permitting the compiler to generate sqrt() instructions.
This commit is contained in:
Justine Tunney 2021-03-07 16:34:16 -08:00
parent 8a6ac6dd63
commit a8945714e8
8 changed files with 485 additions and 124 deletions

View file

@ -58,8 +58,8 @@ syscon errno ESPIPE 29 29 29 29 29 25 # unix consensus & kNtErro
syscon errno EROFS 30 30 30 30 30 6009 # unix consensus & kNtErrorFileReadOnly
syscon errno EMLINK 31 31 31 31 31 4 # unix consensus & kNtErrorTooManyLinks
syscon errno EPIPE 32 32 32 32 32 109 # unix consensus & kNtErrorBrokenPipe
syscon errno EDOM 33 33 33 33 33 0 # bsd consensus
syscon errno ERANGE 34 34 34 34 34 0 # bsd consensus
syscon errno EDOM 33 33 33 33 33 33 # bsd consensus & fudged on NT
syscon errno ERANGE 34 34 34 34 34 34 # bsd consensus & fudged on NT
syscon errno EDEADLK 35 11 11 11 11 1131 # bsd consensus & kNtErrorPossibleDeadlock
syscon errno ENAMETOOLONG 36 63 63 63 63 0x274f # bsd consensus & WSAENAMETOOLONG
syscon errno ENOLCK 37 77 77 77 77 0 # bsd consensus

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EDOM,33,33,33,33,33,0
.syscon errno,EDOM,33,33,33,33,33,33

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,ERANGE,34,34,34,34,34,0
.syscon errno,ERANGE,34,34,34,34,34,34

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/math.h"
/**
@ -27,23 +28,34 @@ long double powl(long double x, long double y) {
if (!isinf(y)) {
if (!isinf(x)) {
if (x) {
asm("fyl2x" : "=t"(u) : "0"(fabsl(x)), "u"(y) : "st(1)");
asm("fprem" : "=t"(t) : "0"(u), "u"(1.L));
asm("f2xm1" : "=t"(t) : "0"(t));
asm("fscale" : "=t"(t) : "0"(t + 1), "u"(u));
if (signbit(x)) {
if (y != truncl(y)) return -NAN;
if (!signbit(y) || ((int64_t)y & 1)) t = -t;
if (y) {
if (x < 0 && y != truncl(y)) {
errno = EDOM;
return NAN;
}
asm("fyl2x" : "=t"(u) : "0"(fabsl(x)), "u"(y) : "st(1)");
asm("fprem" : "=t"(t) : "0"(u), "u"(1.L));
asm("f2xm1" : "=t"(t) : "0"(t));
asm("fscale" : "=t"(t) : "0"(t + 1), "u"(u));
if (signbit(x)) {
if (y != truncl(y)) return -NAN;
if ((int64_t)y & 1) t = -t;
}
return t;
} else {
return 1;
}
return t;
} else if (y > 0) {
return 0;
return y == 1 ? x : 0;
} else if (!y) {
return 1;
} else if (y == truncl(y) && ((int64_t)y & 1)) {
return copysignl(INFINITY, x);
} else {
return INFINITY;
errno = ERANGE;
if (y == truncl(y) && ((int64_t)y & 1)) {
return copysignl(INFINITY, x);
} else {
return INFINITY;
}
}
} else if (signbit(x)) {
if (!y) return 1;

View file

@ -26,7 +26,8 @@ LIBC_TINYMATH_A_CHECKS = \
LIBC_TINYMATH_A_DIRECTDEPS = \
LIBC_INTRIN \
LIBC_STUBS \
LIBC_NEXGEN32E
LIBC_NEXGEN32E \
LIBC_SYSV
LIBC_TINYMATH_A_DEPS := \
$(call uniq,$(foreach x,$(LIBC_TINYMATH_A_DIRECTDEPS),$($(x))))