diff --git a/build/bootstrap/compile.com b/build/bootstrap/compile.com index 347df93b0..0073592d8 100755 Binary files a/build/bootstrap/compile.com and b/build/bootstrap/compile.com differ diff --git a/build/config.mk b/build/config.mk index e04ca5584..141977aef 100644 --- a/build/config.mk +++ b/build/config.mk @@ -69,6 +69,9 @@ CONFIG_CCFLAGS += \ $(BACKTRACES) \ -O2 +TARGET_ARCH ?= \ + -msse3 + endif # Debug Mode @@ -88,7 +91,7 @@ CONFIG_CPPFLAGS += \ CONFIG_CCFLAGS += \ $(BACKTRACES) \ $(FTRACE) \ - -O2 + -Og CONFIG_COPTS += \ $(SECURITY_BLANKETS) \ diff --git a/examples/walk.c b/examples/walk.c new file mode 100644 index 000000000..31f5fc405 --- /dev/null +++ b/examples/walk.c @@ -0,0 +1,52 @@ +#if 0 +/*─────────────────────────────────────────────────────────────────╗ +│ To the extent possible under law, Justine Tunney has waived │ +│ all copyright and related or neighboring rights to this file, │ +│ as it is written in the following disclaimers: │ +│ • http://unlicense.org/ │ +│ • http://creativecommons.org/publicdomain/zero/1.0/ │ +╚─────────────────────────────────────────────────────────────────*/ +#endif +#include "libc/calls/calls.h" +#include "libc/calls/struct/stat.h" +#include "libc/log/log.h" +#include "libc/runtime/runtime.h" +#include "libc/sysv/consts/exit.h" +#include "third_party/musl/ftw.h" + +/** + * @fileoverview Directory walker example. + * Copied from IEEE Std 1003.1-2017 + */ + +static int display_info(const char *fpath, const struct stat *sb, int tflag, + struct FTW *ftwbuf) { + printf("%-3s %2d %7jd %-40s %d %s\n", + (tflag == FTW_D) ? "d" + : (tflag == FTW_DNR) ? "dnr" + : (tflag == FTW_DP) ? "dp" + : (tflag == FTW_F) ? (S_ISBLK(sb->st_mode) ? "f b" + : S_ISCHR(sb->st_mode) ? "f c" + : S_ISFIFO(sb->st_mode) ? "f p" + : S_ISREG(sb->st_mode) ? "f r" + : S_ISSOCK(sb->st_mode) ? "f s" + : "f ?") + : (tflag == FTW_NS) ? "ns" + : (tflag == FTW_SL) ? "sl" + : (tflag == FTW_SLN) ? "sln" + : "?", + ftwbuf->level, (intmax_t)sb->st_size, fpath, ftwbuf->base, + fpath + ftwbuf->base); + return 0; /* To tell nftw() to continue */ +} + +int main(int argc, char *argv[]) { + int flags = 0; + if (argc > 2 && strchr(argv[2], 'd') != NULL) flags |= FTW_DEPTH; + if (argc > 2 && strchr(argv[2], 'p') != NULL) flags |= FTW_PHYS; + if (nftw((argc < 2) ? "." : argv[1], display_info, 20, flags) == -1) { + perror("nftw"); + exit(EXIT_FAILURE); + } + exit(EXIT_SUCCESS); +} diff --git a/libc/runtime/fesetround.c b/libc/runtime/fesetround.c index f55465f35..3b8896c4e 100644 --- a/libc/runtime/fesetround.c +++ b/libc/runtime/fesetround.c @@ -18,8 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/runtime/fenv.h" -/* TODO(jart): This needs tests. */ - /** * Sets rounding mode. * diff --git a/libc/runtime/fltrounds.c b/libc/runtime/fltrounds.c index 3b90c0f41..c3a8920b8 100644 --- a/libc/runtime/fltrounds.c +++ b/libc/runtime/fltrounds.c @@ -19,16 +19,18 @@ #include "libc/runtime/fenv.h" int __flt_rounds(void) { - switch (fegetround()) { - case FE_TOWARDZERO: + int x87cw; + asm("fnstcw\t%0" : "=m"(x87cw)); + switch ((x87cw & 0x0c00) >> 10) { + case FE_TOWARDZERO >> 10: return 0; - case FE_TONEAREST: + case FE_TONEAREST >> 10: return 1; - case FE_UPWARD: + case FE_UPWARD >> 10: return 2; - case FE_DOWNWARD: + case FE_DOWNWARD >> 10: return 3; default: - return -1; + unreachable; } } diff --git a/libc/testlib/formatfloat.c b/libc/testlib/formatfloat.c index d515c66ba..0056a8ded 100644 --- a/libc/testlib/formatfloat.c +++ b/libc/testlib/formatfloat.c @@ -19,12 +19,9 @@ #include "libc/fmt/fmt.h" #include "libc/mem/mem.h" #include "libc/testlib/testlib.h" +#include "libc/x/x.h" #include "third_party/gdtoa/gdtoa.h" testonly char *testlib_formatfloat(long double x) { - char buf[32]; - char *str = malloc(256); - g_xfmt_p(buf, &x, 15, sizeof(buf), 0); - sprintf(str, "%Lf (%s)", x, buf); - return str; + return xasprintf("%.15Lg", x); } diff --git a/libc/tinymath/atanh.c b/libc/tinymath/atanh.c index 7927aa709..3548943d4 100644 --- a/libc/tinymath/atanh.c +++ b/libc/tinymath/atanh.c @@ -22,5 +22,5 @@ * Returns inverse hyperbolic tangent of 𝑥. */ double atanh(double x) { - return log((1 + x) / (1 - x)) / 2; + return x ? log((1 + x) / (1 - x)) / 2 : x; } diff --git a/libc/tinymath/atanhf.c b/libc/tinymath/atanhf.c index 702a4ae34..ef27074bf 100644 --- a/libc/tinymath/atanhf.c +++ b/libc/tinymath/atanhf.c @@ -22,5 +22,5 @@ * Returns inverse hyperbolic tangent of 𝑥. */ float atanhf(float x) { - return logf((1 + x) / (1 - x)) / 2; + return x ? logf((1 + x) / (1 - x)) / 2 : x; } diff --git a/libc/tinymath/atanhl.c b/libc/tinymath/atanhl.c index 54baf9bc4..a88347d18 100644 --- a/libc/tinymath/atanhl.c +++ b/libc/tinymath/atanhl.c @@ -22,5 +22,5 @@ * Returns inverse hyperbolic tangent of 𝑥. */ long double atanhl(long double x) { - return logl((1 + x) / (1 - x)) / 2; + return x ? logl((1 + x) / (1 - x)) / 2 : x; } diff --git a/libc/tinymath/expm1l.S b/libc/tinymath/expm1l.S index d12f779d6..f5852d861 100644 --- a/libc/tinymath/expm1l.S +++ b/libc/tinymath/expm1l.S @@ -19,7 +19,7 @@ #include "libc/runtime/pc.internal.h" #include "libc/macros.internal.h" -// Returns 𝑒^x-1. +// Returns 𝑒^𝑥-𝟷. // // @param 𝑥 is an 80-bit long double passed on stack in 16-bytes // @return result of exponentiation on FPU stack in %st @@ -27,11 +27,13 @@ expm1l: push %rbp mov %rsp,%rbp .profilable fldt 16(%rbp) - fxam # isinf(x) + fxam fstsw %ax mov %ah,%al - and $0x45,%ah - cmp $5,%ah + and $(FPU_C3|FPU_C2|FPU_C0)>>8,%ah + cmp $(FPU_C3)>>8,%ah # !x + je 0f + cmp $(FPU_C2|FPU_C0)>>8,%ah # isinf(x) je 1f fldl2e fmulp %st,%st(1) @@ -50,7 +52,7 @@ expm1l: push %rbp faddp %st,%st(1) 0: pop %rbp ret -1: test $2,%al # signbit(x) +1: test $FPU_C1>>8,%al # signbit(x) jz 0b fstp %st fld1 diff --git a/libc/tinymath/powl.c b/libc/tinymath/powl.c index 9ecdc23dd..e2a58a23b 100644 --- a/libc/tinymath/powl.c +++ b/libc/tinymath/powl.c @@ -46,7 +46,11 @@ long double powl(long double x, long double y) { return 1; } } else if (y > 0) { - return y == 1 ? x : 0; + if (signbit(x) && y == truncl(y) && ((int64_t)y & 1)) { + return -0.; + } else { + return 0; + } } else if (!y) { return 1; } else { diff --git a/libc/tinymath/sinh.c b/libc/tinymath/sinh.c index 6cab29aa8..f0e998b7e 100644 --- a/libc/tinymath/sinh.c +++ b/libc/tinymath/sinh.c @@ -22,5 +22,6 @@ * Returns hyperbolic sine of 𝑥. */ double sinh(double x) { + if (!x) return x; return (exp(x) - exp(-x)) / 2; } diff --git a/libc/tinymath/sinhf.c b/libc/tinymath/sinhf.c index db7088279..73a013c22 100644 --- a/libc/tinymath/sinhf.c +++ b/libc/tinymath/sinhf.c @@ -22,5 +22,6 @@ * Returns hyperbolic sine of 𝑥. */ float sinhf(float x) { + if (!x) return x; return (expf(x) - expf(-x)) / 2; } diff --git a/libc/tinymath/sinhl.c b/libc/tinymath/sinhl.c index 16c79e330..c2a09d892 100644 --- a/libc/tinymath/sinhl.c +++ b/libc/tinymath/sinhl.c @@ -22,5 +22,6 @@ * Returns hyperbolic sine of 𝑥. */ long double sinhl(long double x) { + if (!x) return x; return (expl(x) - expl(-x)) / 2; } diff --git a/libc/tinymath/tanh.c b/libc/tinymath/tanh.c index 8139d00f0..5ae19c19f 100644 --- a/libc/tinymath/tanh.c +++ b/libc/tinymath/tanh.c @@ -22,6 +22,7 @@ * Returns hyperbolic tangent of 𝑥. */ double tanh(double x) { + if (!x) return x; if (isinf(x)) return copysign(1, x); return sinh(x) / cosh(x); } diff --git a/libc/tinymath/tanhf.c b/libc/tinymath/tanhf.c index aef44313f..d9f491de7 100644 --- a/libc/tinymath/tanhf.c +++ b/libc/tinymath/tanhf.c @@ -22,6 +22,7 @@ * Returns hyperbolic tangent of 𝑥. */ float tanhf(float x) { + if (!x) return x; if (isinf(x)) return copysignf(1, x); return sinhf(x) / coshf(x); } diff --git a/libc/tinymath/tanhl.c b/libc/tinymath/tanhl.c index 3c76761bf..7d0a41e01 100644 --- a/libc/tinymath/tanhl.c +++ b/libc/tinymath/tanhl.c @@ -22,6 +22,7 @@ * Returns hyperbolic tangent of 𝑥. */ long double tanhl(long double x) { + if (!x) return x; if (isinf(x)) return copysignl(1, x); return sinhl(x) / coshl(x); } diff --git a/test/libc/tinymath/atan2_test.c b/test/libc/tinymath/atan2_test.c index 82350d494..976ff5f2f 100644 --- a/test/libc/tinymath/atan2_test.c +++ b/test/libc/tinymath/atan2_test.c @@ -282,6 +282,11 @@ TEST(atan2, test) { gc(xasprintf("%.15g", atan2(__DBL_MAX__, __DBL_MIN__)))); EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", atan2(__DBL_MAX__, __DBL_MAX__)))); + EXPECT_STREQ("-0", + gc(xasprintf("%.15g", atan2(-0.000000000000001, INFINITY)))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-1, INFINITY)))); + EXPECT_STREQ( + "-0", gc(xasprintf("%.15g", atan2(-1.7976931348623157e308, INFINITY)))); } BENCH(atan2, bench) { diff --git a/test/libc/tinymath/atanh_test.c b/test/libc/tinymath/atanh_test.c index 2f7de8c53..f096cc212 100644 --- a/test/libc/tinymath/atanh_test.c +++ b/test/libc/tinymath/atanh_test.c @@ -27,6 +27,7 @@ TEST(atanh, test) { EXPECT_STREQ("0", gc(xdtoa(atanh(0)))); + EXPECT_STREQ("-0", gc(xdtoa(atanh(-0.)))); EXPECT_STREQ(".549306144334055", gc(xdtoa(atanh(.5)))); EXPECT_STREQ("-.549306144334055", gc(xdtoa(atanh(-.5)))); EXPECT_STREQ("INFINITY", gc(xdtoa(atanh(+1)))); @@ -37,6 +38,7 @@ TEST(atanh, test) { TEST(atanhl, test) { EXPECT_STREQ("0", gc(xdtoal(atanhl(0)))); + EXPECT_STREQ("-0", gc(xdtoal(atanhl(-0.)))); EXPECT_STREQ(".5493061443340548", gc(xdtoal(atanhl(.5)))); EXPECT_STREQ("-.5493061443340548", gc(xdtoal(atanhl(-.5)))); EXPECT_STREQ("INFINITY", gc(xdtoal(atanhl(+1)))); @@ -47,6 +49,7 @@ TEST(atanhl, test) { TEST(atanhf, test) { EXPECT_STREQ("0", gc(xdtoaf(atanhf(0)))); + EXPECT_STREQ("-0", gc(xdtoaf(atanhf(-0.)))); EXPECT_STREQ(".549306", gc(xdtoaf(atanhf(.5)))); EXPECT_STREQ("-.549306", gc(xdtoaf(atanhf(-.5)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(atanhf(+1)))); diff --git a/test/libc/tinymath/expm1_test.c b/test/libc/tinymath/expm1_test.c index 2da3221c6..2d218a26f 100644 --- a/test/libc/tinymath/expm1_test.c +++ b/test/libc/tinymath/expm1_test.c @@ -25,11 +25,37 @@ #define expm1(x) expm1(VEIL("x", (double)(x))) #define expm1f(x) expm1f(VEIL("x", (float)(x))) +TEST(expm1, test) { + EXPECT_STREQ("0", gc(xdtoa(expm1(0)))); + EXPECT_STREQ("-0", gc(xdtoa(expm1(-0.)))); + EXPECT_STREQ("NAN", gc(xdtoa(expm1(NAN)))); + EXPECT_STREQ("-1", gc(xdtoa(expm1(-INFINITY)))); + EXPECT_STREQ("INFINITY", gc(xdtoa(expm1(INFINITY)))); + /* EXPECT_STREQ("-INFINITY", gc(xdtoa(expm1(-132098844872390)))); */ + /* EXPECT_STREQ("INFINITY", gc(xdtoa(expm1(132098844872390)))); */ + EXPECT_STREQ("0", gc(xasprintf("%.15g", expm1(0.)))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", expm1(-0.)))); + EXPECT_STREQ("0.648721270700128", gc(xasprintf("%.15g", expm1(.5)))); + EXPECT_STREQ("-0.393469340287367", gc(xasprintf("%.15g", expm1(-.5)))); + EXPECT_STREQ("1.71828182845905", gc(xasprintf("%.15g", expm1(1.)))); + EXPECT_STREQ("-0.632120558828558", gc(xasprintf("%.15g", expm1(-1.)))); + EXPECT_STREQ("3.48168907033806", gc(xasprintf("%.15g", expm1(1.5)))); + EXPECT_STREQ("-0.77686983985157", gc(xasprintf("%.15g", expm1(-1.5)))); + EXPECT_STREQ("6.38905609893065", gc(xasprintf("%.15g", expm1(2.)))); + EXPECT_TRUE(isnan(expm1(NAN))); + EXPECT_TRUE(isnan(expm1(-NAN))); + EXPECT_STREQ("inf", gc(xasprintf("%.15g", expm1(INFINITY)))); + EXPECT_STREQ("-1", gc(xasprintf("%.15g", expm1(-INFINITY)))); + EXPECT_STREQ("2.2250738585072e-308", + gc(xasprintf("%.15g", expm1(__DBL_MIN__)))); + EXPECT_STREQ("inf", gc(xasprintf("%.15g", expm1(__DBL_MAX__)))); +} + TEST(expm1l, test) { EXPECT_STREQ("1.718281828459045", gc(xdtoal(expm1l(1)))); EXPECT_STREQ("1.718281828459045", gc(xdtoal(expl(1) - 1))); EXPECT_STREQ("0", gc(xdtoal(expm1l(0)))); - EXPECT_STREQ("0", gc(xdtoal(expm1l(-0.)))); + EXPECT_STREQ("-0", gc(xdtoal(expm1l(-0.)))); EXPECT_STREQ("NAN", gc(xdtoal(expm1l(NAN)))); EXPECT_STREQ("-1", gc(xdtoal(expm1l(-INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(expm1l(INFINITY)))); @@ -37,19 +63,9 @@ TEST(expm1l, test) { /* EXPECT_STREQ("INFINITY", gc(xdtoal(expm1l(132098844872390)))); */ } -TEST(expm1, test) { - EXPECT_STREQ("0", gc(xdtoa(expm1(0)))); - EXPECT_STREQ("0", gc(xdtoa(expm1(-0.)))); - EXPECT_STREQ("NAN", gc(xdtoa(expm1(NAN)))); - EXPECT_STREQ("-1", gc(xdtoa(expm1(-INFINITY)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(expm1(INFINITY)))); - /* EXPECT_STREQ("-INFINITY", gc(xdtoa(expm1(-132098844872390)))); */ - /* EXPECT_STREQ("INFINITY", gc(xdtoa(expm1(132098844872390)))); */ -} - TEST(expm1f, test) { EXPECT_STREQ("0", gc(xdtoaf(expm1f(0)))); - EXPECT_STREQ("0", gc(xdtoaf(expm1f(-0.)))); + EXPECT_STREQ("-0", gc(xdtoaf(expm1f(-0.)))); EXPECT_STREQ("NAN", gc(xdtoaf(expm1f(NAN)))); EXPECT_STREQ("-1", gc(xdtoaf(expm1f(-INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(expm1f(INFINITY)))); diff --git a/test/libc/tinymath/powl_test.c b/test/libc/tinymath/powl_test.c index 971ecf22b..2922692f0 100644 --- a/test/libc/tinymath/powl_test.c +++ b/test/libc/tinymath/powl_test.c @@ -100,6 +100,8 @@ TEST(powl, test) { EXPECT_TRUE(isnan(powl(-3, -(1. / MAX(rando, 2))))); EXPECT_STREQ("-.3333333333333333", gc(xdtoal(powl(-3, -1)))); EXPECT_STREQ(".1111111111111111", gc(xdtoal(powl(-3, -2)))); + EXPECT_STREQ("-0", gc(xdtoal(powl(-0., MAX(1, rando) | 1)))); + EXPECT_STREQ("0", gc(xdtoal(powl(-0., MAX(1, rando) & ~1)))); } TEST(pow, test) { @@ -150,6 +152,8 @@ TEST(pow, test) { EXPECT_STREQ("inf", fmtd(pow(-0., -(rando & -2)))); EXPECT_STREQ("-0.333333333333333", fmtd(pow(-3, -1))); EXPECT_STREQ("0.111111111111111", fmtd(pow(-3, -2))); + EXPECT_STREQ("-0", gc(xdtoa(pow(-0., MAX(1, rando) | 1)))); + EXPECT_STREQ("0", gc(xdtoa(pow(-0., MAX(1, rando) & ~1)))); } TEST(powf, test) { @@ -200,6 +204,8 @@ TEST(powf, test) { EXPECT_STREQ("inf", fmtf(powf(-0., -(rando & -2)))); EXPECT_STREQ("-0.333333", fmtf(powf(-3, -1))); EXPECT_STREQ("0.111111", fmtf(powf(-3, -2))); + EXPECT_STREQ("-0", gc(xdtoaf(powf(-0., MAX(1, rando) | 1)))); + EXPECT_STREQ("0", gc(xdtoaf(powf(-0., MAX(1, rando) & ~1)))); } TEST(powl, errors) { @@ -537,6 +543,15 @@ TEST(powl, errors) { errno = 0; EXPECT_STREQ("inf", fmtd(pow(__DBL_MAX__, __DBL_MAX__))); /* EXPECT_EQ(ERANGE, errno); */ + EXPECT_STREQ("1", gc(xasprintf("%.15g", pow(0., 0)))); + EXPECT_STREQ("1", gc(xasprintf("%.15g", pow(-0., 0)))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", pow(-0., 1)))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", pow(-0., 11)))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", pow(-0., 111)))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", pow(-0., 2)))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", pow(-0., 22)))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", pow(-0., 222)))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", pow(-0., 2.5)))); } BENCH(powl, bench) { diff --git a/test/libc/tinymath/sinh_test.c b/test/libc/tinymath/sinh_test.c index 6cdbe9845..653bb560b 100644 --- a/test/libc/tinymath/sinh_test.c +++ b/test/libc/tinymath/sinh_test.c @@ -31,6 +31,7 @@ TEST(sinh, test) { EXPECT_STREQ("INFINITY", gc(xdtoa(sinh(30000)))); EXPECT_STREQ("-INFINITY", gc(xdtoa(sinh(-30000)))); EXPECT_STREQ("0", gc(xdtoa(sinh(0)))); + EXPECT_STREQ("-0", gc(xdtoa(sinh(-0.)))); EXPECT_STREQ("NAN", gc(xdtoa(sinh(NAN)))); EXPECT_STREQ("INFINITY", gc(xdtoa(sinh(INFINITY)))); EXPECT_STREQ("-INFINITY", gc(xdtoa(sinh(-INFINITY)))); @@ -42,6 +43,7 @@ TEST(sinhl, test) { EXPECT_STREQ("INFINITY", gc(xdtoal(sinhl(30000)))); EXPECT_STREQ("-INFINITY", gc(xdtoal(sinhl(-30000)))); EXPECT_STREQ("0", gc(xdtoal(sinhl(0)))); + EXPECT_STREQ("-0", gc(xdtoal(sinhl(-0.)))); EXPECT_STREQ("NAN", gc(xdtoal(sinhl(NAN)))); EXPECT_STREQ("INFINITY", gc(xdtoal(sinhl(INFINITY)))); EXPECT_STREQ("-INFINITY", gc(xdtoal(sinhl(-INFINITY)))); @@ -53,6 +55,7 @@ TEST(sinhf, test) { EXPECT_STREQ("INFINITY", gc(xdtoaf(sinhf(30000)))); EXPECT_STREQ("-INFINITY", gc(xdtoaf(sinhf(-30000)))); EXPECT_STREQ("0", gc(xdtoaf(sinhf(0)))); + EXPECT_STREQ("-0", gc(xdtoaf(sinhf(-0.)))); EXPECT_STREQ("NAN", gc(xdtoaf(sinhf(NAN)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(sinhf(INFINITY)))); EXPECT_STREQ("-INFINITY", gc(xdtoaf(sinhf(-INFINITY)))); diff --git a/test/libc/tinymath/strtod_test.c b/test/libc/tinymath/strtod_test.c new file mode 100644 index 000000000..f6ee4fdc8 --- /dev/null +++ b/test/libc/tinymath/strtod_test.c @@ -0,0 +1,57 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/runtime/fenv.h" +#include "libc/runtime/gc.internal.h" +#include "libc/testlib/testlib.h" +#include "libc/x/x.h" +#include "third_party/gdtoa/gdtoa.h" + +int oldround; + +void SetUp(void) { + oldround = fegetround(); +} + +void TearDown(void) { + fesetround(oldround); +} + +TEST(strtod, testNearest) { + fesetround(FE_TONEAREST); + EXPECT_STREQ("-1.79769313486231e+308", + gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); +} + +TEST(strtod, testDownward) { + fesetround(FE_DOWNWARD); + EXPECT_STREQ("-1.79769313486232e+308", + gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); +} + +TEST(strtod, testUpward) { + fesetround(FE_UPWARD); + EXPECT_STREQ("-1.7976931348623e+308", + gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); +} + +TEST(strtod, testTowardzero) { + fesetround(FE_TOWARDZERO); + EXPECT_STREQ("-1.7976931348623e+308", + gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); +} diff --git a/test/libc/tinymath/tanh_test.c b/test/libc/tinymath/tanh_test.c index b1a59544d..65f922d0f 100644 --- a/test/libc/tinymath/tanh_test.c +++ b/test/libc/tinymath/tanh_test.c @@ -29,6 +29,7 @@ TEST(tanhl, test) { EXPECT_STREQ(".09966799462495582", gc(xdtoal(tanhl(+.1)))); EXPECT_STREQ("-.09966799462495582", gc(xdtoal(tanhl(-.1)))); EXPECT_STREQ("0", gc(xdtoal(tanhl(0)))); + EXPECT_STREQ("-0", gc(xdtoal(tanhl(-0.)))); EXPECT_TRUE(isnan(tanhl(NAN))); EXPECT_STREQ("1", gc(xdtoal(tanhl(INFINITY)))); EXPECT_STREQ("-1", gc(xdtoal(tanhl(-INFINITY)))); @@ -38,6 +39,7 @@ TEST(tanh, test) { EXPECT_STREQ(".0996679946249559", gc(xdtoa(tanh(+.1)))); EXPECT_STREQ("-.0996679946249559", gc(xdtoa(tanh(-.1)))); EXPECT_STREQ("0", gc(xdtoa(tanh(0)))); + EXPECT_STREQ("-0", gc(xdtoa(tanh(-0.)))); EXPECT_TRUE(isnan(tanh(NAN))); EXPECT_STREQ("1", gc(xdtoa(tanh(INFINITY)))); EXPECT_STREQ("-1", gc(xdtoa(tanh(-INFINITY)))); @@ -47,6 +49,7 @@ TEST(tanhf, test) { EXPECT_STREQ(".099668", gc(xdtoaf(tanhf(+.1)))); EXPECT_STREQ("-.099668", gc(xdtoaf(tanhf(-.1)))); EXPECT_STREQ("0", gc(xdtoaf(tanhf(0)))); + EXPECT_STREQ("-0", gc(xdtoaf(tanhf(-0.)))); EXPECT_TRUE(isnan(tanhf(NAN))); EXPECT_STREQ("1", gc(xdtoaf(tanhf(INFINITY)))); EXPECT_STREQ("-1", gc(xdtoaf(tanhf(-INFINITY)))); diff --git a/test/libc/tinymath/test.mk b/test/libc/tinymath/test.mk index 641693130..4feea7a30 100644 --- a/test/libc/tinymath/test.mk +++ b/test/libc/tinymath/test.mk @@ -37,7 +37,8 @@ TEST_LIBC_TINYMATH_DIRECTDEPS = \ LIBC_TESTLIB \ LIBC_TINYMATH \ LIBC_UNICODE \ - LIBC_X + LIBC_X \ + THIRD_PARTY_GDTOA TEST_LIBC_TINYMATH_DEPS := \ $(call uniq,$(foreach x,$(TEST_LIBC_TINYMATH_DIRECTDEPS),$($(x)))) diff --git a/third_party/gdtoa/gdtoa.internal.h b/third_party/gdtoa/gdtoa.internal.h index 0a74b0556..970015a47 100644 --- a/third_party/gdtoa/gdtoa.internal.h +++ b/third_party/gdtoa/gdtoa.internal.h @@ -18,6 +18,9 @@ asm(".include \"libc/disclaimer.inc\""); #define d_QNAN0 0x7ff80000 #define d_QNAN1 0x0 +#define Check_FLT_ROUNDS 1 +#define Trust_FLT_ROUNDS 1 + /**************************************************************** The author of this software is David M. Gay. diff --git a/third_party/gdtoa/gdtoa.mk b/third_party/gdtoa/gdtoa.mk index d9e15e57b..c253ef9a6 100644 --- a/third_party/gdtoa/gdtoa.mk +++ b/third_party/gdtoa/gdtoa.mk @@ -46,13 +46,6 @@ $(THIRD_PARTY_GDTOA_A).pkg: \ $(THIRD_PARTY_GDTOA_A_OBJS) \ $(foreach x,$(THIRD_PARTY_GDTOA_A_DIRECTDEPS),$($(x)_A).pkg) -$(THIRD_PARTY_GDTOA_A_OBJS): \ - OVERRIDE_CFLAGS += \ - $(OLD_CODE) \ - $(IEEE_MATH) \ - -ffunction-sections \ - -fdata-sections - THIRD_PARTY_GDTOA_LIBS = $(foreach x,$(THIRD_PARTY_GDTOA_ARTIFACTS),$($(x))) THIRD_PARTY_GDTOA_SRCS = $(foreach x,$(THIRD_PARTY_GDTOA_ARTIFACTS),$($(x)_SRCS)) THIRD_PARTY_GDTOA_HDRS = $(foreach x,$(THIRD_PARTY_GDTOA_ARTIFACTS),$($(x)_HDRS)) diff --git a/third_party/gdtoa/strtod.c b/third_party/gdtoa/strtod.c index 1080b6b34..19f2de989 100644 --- a/third_party/gdtoa/strtod.c +++ b/third_party/gdtoa/strtod.c @@ -729,7 +729,7 @@ strtod(CONST char *s00, char **se) } #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow*/ - dval(&adj) *= ulp(&rv); + dval(&adj) *= ulp(&rv); /* XXX */ if (dsign) { if (word0(&rv) == Big0 && word1(&rv) == Big1) goto ovfl; diff --git a/third_party/lua/lua.mk b/third_party/lua/lua.mk index b2628de9b..50a78b0ec 100644 --- a/third_party/lua/lua.mk +++ b/third_party/lua/lua.mk @@ -41,7 +41,7 @@ THIRD_PARTY_LUA_DEPS := \ $(THIRD_PARTY_LUA_A): \ third_party/lua/ \ $(THIRD_PARTY_LUA_A).pkg \ - $(filter-out %/lua.c,$(THIRD_PARTY_LUA_OBJS)) + $(filter-out %/lua.o,$(THIRD_PARTY_LUA_OBJS)) $(THIRD_PARTY_LUA_A).pkg: \ $(THIRD_PARTY_LUA_OBJS) \ diff --git a/third_party/musl/ftw.c b/third_party/musl/ftw.c index ee4c54b22..51622cb51 100644 --- a/third_party/musl/ftw.c +++ b/third_party/musl/ftw.c @@ -34,6 +34,12 @@ asm(".include \"libc/disclaimer.inc\""); /* clang-format off */ +/** + * Walks file tree. + * + * @see examples/walk.c for example + * @see nftw() + */ int ftw(const char *path, int (*fn)(const char *, const struct stat *, int), int fd_limit) { /* The following cast assumes that calling a function with one diff --git a/third_party/musl/nftw.c b/third_party/musl/nftw.c index 15a491df8..21d31ff51 100644 --- a/third_party/musl/nftw.c +++ b/third_party/musl/nftw.c @@ -38,7 +38,13 @@ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -#define pthread_setcancelstate(...) /* no cosmo pthreads support atm */ +/* no reason to impose windows limit + small enough to fit in stack frame + should be changed to use realloc */ +#define PATH_MAX2 2048 + +/* no cosmo pthreads support atm */ +#define pthread_setcancelstate(...) /* clang-format off */ @@ -123,7 +129,7 @@ static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int, && (!de->d_name[1] || (de->d_name[1]=='.' && !de->d_name[2]))) continue; - if (strlen(de->d_name) >= PATH_MAX-l) { + if (strlen(de->d_name) >= PATH_MAX2-l) { errno = ENAMETOOLONG; closedir(d); return -1; @@ -149,16 +155,21 @@ static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int, return 0; } +/** + * Walks file tree. + * + * @see examples/walk.c for example + */ int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int fd_limit, int flags) { int r, cs; size_t l; - char pathbuf[PATH_MAX+1]; + char pathbuf[PATH_MAX2+1]; if (fd_limit <= 0) return 0; l = strlen(path); - if (l > PATH_MAX) { + if (l > PATH_MAX2) { errno = ENAMETOOLONG; return -1; } diff --git a/third_party/quickjs/README.cosmo b/third_party/quickjs/README.cosmo index 072d819e9..c8f7ab916 100644 --- a/third_party/quickjs/README.cosmo +++ b/third_party/quickjs/README.cosmo @@ -1,2 +1,7 @@ Source: -https://bellard.org/quickjs/quickjs-2021-03-27.tar.xz +- https://bellard.org/quickjs/quickjs-2021-03-27.tar.xz + +Local Changes: +- Replace snprintf with xasprintf in find_unique_cname +- Squash uninitialized read of harnessbuf in run-test262.c +- Change run-test262.c to not rebase configured paths diff --git a/third_party/quickjs/quickjs-libc.c b/third_party/quickjs/quickjs-libc.c index 32dcc53f8..cea3b1bad 100644 --- a/third_party/quickjs/quickjs-libc.c +++ b/third_party/quickjs/quickjs-libc.c @@ -2764,61 +2764,6 @@ static char **build_envp(JSContext *ctx, JSValueConst obj) goto done; } -/* execvpe is not available on non GNU systems */ -static int my_execvpe(const char *filename, char **argv, char **envp) -{ - char *path, *p, *p_next, *p1; - char buf[PATH_MAX]; - size_t filename_len, path_len; - BOOL eacces_error; - - filename_len = strlen(filename); - if (filename_len == 0) { - errno = ENOENT; - return -1; - } - if (strchr(filename, '/')) - return execve(filename, argv, envp); - - path = getenv("PATH"); - if (!path) - path = (char *)"/bin:/usr/bin"; - eacces_error = FALSE; - p = path; - for(p = path; p != NULL; p = p_next) { - p1 = strchr(p, ':'); - if (!p1) { - p_next = NULL; - path_len = strlen(p); - } else { - p_next = p1 + 1; - path_len = p1 - p; - } - /* path too long */ - if ((path_len + 1 + filename_len + 1) > PATH_MAX) - continue; - memcpy(buf, p, path_len); - buf[path_len] = '/'; - memcpy(buf + path_len + 1, filename, filename_len); - buf[path_len + 1 + filename_len] = '\0'; - - execve(buf, argv, envp); - - if (errno == EACCES) { - eacces_error = TRUE; - } else if (errno == ENOENT) { - /* do nothing */ - } else if (errno == ENOTDIR) { - /* do nothing */ - } else { - return -1; - } - } - if (eacces_error) - errno = EACCES; - return -1; -} - /* exec(args[, options]) -> exitcode */ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) @@ -2973,7 +2918,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val, if (!file) file = exec_argv[0]; if (use_path) - ret = my_execvpe(file, (char **)exec_argv, envp); + ret = execvpe(file, (char **)exec_argv, envp); else ret = execve(file, (char **)exec_argv, envp); _exit(127); diff --git a/third_party/quickjs/quickjs.c b/third_party/quickjs/quickjs.c index bcec9cc48..1935e0cec 100644 --- a/third_party/quickjs/quickjs.c +++ b/third_party/quickjs/quickjs.c @@ -11296,11 +11296,11 @@ static char *i64toa(char *buf_end, int64_t n, unsigned int base) static void js_ecvt1(double d, int n_digits, int *decpt, int *sign, char *buf, int rounding_mode, char *buf1, int buf1_size) { - /* if (rounding_mode != FE_TONEAREST) */ - /* fesetround(rounding_mode); */ + if (rounding_mode != FE_TONEAREST) + fesetround(rounding_mode); snprintf(buf1, buf1_size, "%+.*e", n_digits - 1, d); - /* if (rounding_mode != FE_TONEAREST) */ - /* fesetround(FE_TONEAREST); */ + if (rounding_mode != FE_TONEAREST) + fesetround(FE_TONEAREST); *sign = (buf1[0] == '-'); /* mantissa */ buf[0] = buf1[1]; @@ -53608,12 +53608,12 @@ static JSValue js_atomics_op(JSContext *ctx, a = func_name((_Atomic(uint32_t) *)ptr, v); \ break; #endif - /* OP(ADD, atomic_fetch_add) */ - /* OP(AND, atomic_fetch_and) */ - /* OP(OR, atomic_fetch_or) */ - /* OP(SUB, atomic_fetch_sub) */ - /* OP(XOR, atomic_fetch_xor) */ - /* OP(EXCHANGE, atomic_exchange) */ + OP(ADD, atomic_fetch_add) + OP(AND, atomic_fetch_and) + OP(OR, atomic_fetch_or) + OP(SUB, atomic_fetch_sub) + OP(XOR, atomic_fetch_xor) + OP(EXCHANGE, atomic_exchange) #undef OP case ATOMICS_OP_LOAD | (0 << 3): diff --git a/third_party/quickjs/quickjs.mk b/third_party/quickjs/quickjs.mk index 494e1d93f..f278b6eb5 100644 --- a/third_party/quickjs/quickjs.mk +++ b/third_party/quickjs/quickjs.mk @@ -3,83 +3,151 @@ PKGS += THIRD_PARTY_QUICKJS -THIRD_PARTY_QUICKJS_FILES := $(wildcard third_party/quickjs/*) -THIRD_PARTY_QUICKJS_SRCS = $(filter %.c,$(THIRD_PARTY_QUICKJS_FILES)) -THIRD_PARTY_QUICKJS_HDRS = $(filter %.h,$(THIRD_PARTY_QUICKJS_FILES)) +THIRD_PARTY_QUICKJS_ARTIFACTS += THIRD_PARTY_QUICKJS_A THIRD_PARTY_QUICKJS_BINS = $(THIRD_PARTY_QUICKJS_COMS) $(THIRD_PARTY_QUICKJS_COMS:%=%.dbg) -THIRD_PARTY_QUICKJS = $(THIRD_PARTY_QUICKJS_DEPS) $(THIRD_PARTY_QUICKJS_A) +THIRD_PARTY_QUICKJS = $(THIRD_PARTY_QUICKJS_A_DEPS) $(THIRD_PARTY_QUICKJS_A) THIRD_PARTY_QUICKJS_A = o/$(MODE)/third_party/quickjs/quickjs.a +THIRD_PARTY_QUICKJS_HDRS = $(foreach x,$(THIRD_PARTY_QUICKJS_ARTIFACTS),$($(x)_HDRS)) -THIRD_PARTY_QUICKJS_OBJS = \ - $(THIRD_PARTY_QUICKJS_SRCS:%.c=o/$(MODE)/%.o) +THIRD_PARTY_QUICKJS_A_SRCS = \ + third_party/quickjs/cutils.c \ + third_party/quickjs/libbf.c \ + third_party/quickjs/libregexp.c \ + third_party/quickjs/libunicode.c \ + third_party/quickjs/quickjs-libc.c \ + third_party/quickjs/quickjs.c \ + third_party/quickjs/wut.c -THIRD_PARTY_QUICKJS_COMS = \ - o/$(MODE)/third_party/quickjs/qjs.com +THIRD_PARTY_QUICKJS_A_HDRS = \ + third_party/quickjs/cutils.h \ + third_party/quickjs/libbf.h \ + third_party/quickjs/libregexp.h \ + third_party/quickjs/libunicode.h \ + third_party/quickjs/list.h \ + third_party/quickjs/quickjs-libc.h \ + third_party/quickjs/quickjs.h -THIRD_PARTY_QUICKJS_CHECKS = \ - $(THIRD_PARTY_QUICKJS_A).pkg \ - $(THIRD_PARTY_QUICKJS_HDRS:%=o/$(MODE)/%.ok) +THIRD_PARTY_QUICKJS_A_OBJS = \ + o/$(MODE)/third_party/quickjs/cutils.o \ + o/$(MODE)/third_party/quickjs/libbf.o \ + o/$(MODE)/third_party/quickjs/libregexp.o \ + o/$(MODE)/third_party/quickjs/libunicode.o \ + o/$(MODE)/third_party/quickjs/quickjs-libc.o \ + o/$(MODE)/third_party/quickjs/quickjs.o \ + o/$(MODE)/third_party/quickjs/wut.o -THIRD_PARTY_QUICKJS_DIRECTDEPS = \ - LIBC_ALG \ - LIBC_CALLS \ - LIBC_FMT \ - LIBC_INTRIN \ - LIBC_LOG \ - LIBC_MEM \ - LIBC_NEXGEN32E \ - LIBC_RUNTIME \ - LIBC_SOCK \ - LIBC_STDIO \ - LIBC_STR \ - LIBC_SYSV \ - LIBC_SYSV_CALLS \ - LIBC_TIME \ - LIBC_TINYMATH \ - LIBC_UNICODE \ - LIBC_X \ - THIRD_PARTY_COMPILER_RT \ - THIRD_PARTY_GDTOA \ - THIRD_PARTY_GETOPT \ +THIRD_PARTY_QUICKJS_A_DIRECTDEPS = \ + LIBC_ALG \ + LIBC_CALLS \ + LIBC_FMT \ + LIBC_INTRIN \ + LIBC_LOG \ + LIBC_MEM \ + LIBC_NEXGEN32E \ + LIBC_RUNTIME \ + LIBC_SOCK \ + LIBC_STDIO \ + LIBC_STR \ + LIBC_SYSV \ + LIBC_SYSV_CALLS \ + LIBC_TIME \ + LIBC_TINYMATH \ + LIBC_UNICODE \ + LIBC_X \ + THIRD_PARTY_COMPILER_RT \ + THIRD_PARTY_GDTOA \ + THIRD_PARTY_GETOPT \ THIRD_PARTY_MUSL -THIRD_PARTY_QUICKJS_DEPS := \ - $(call uniq,$(foreach x,$(THIRD_PARTY_QUICKJS_DIRECTDEPS),$($(x)))) +THIRD_PARTY_QUICKJS_A_DEPS := \ + $(call uniq,$(foreach x,$(THIRD_PARTY_QUICKJS_A_DIRECTDEPS),$($(x)))) -$(THIRD_PARTY_QUICKJS_A): \ - third_party/quickjs/ \ - $(THIRD_PARTY_QUICKJS_A).pkg \ - $(filter-out %/quickjs.c,$(THIRD_PARTY_QUICKJS_OBJS)) +$(THIRD_PARTY_QUICKJS_A): \ + third_party/quickjs/ \ + $(THIRD_PARTY_QUICKJS_A).pkg \ + $(THIRD_PARTY_QUICKJS_A_OBJS) -$(THIRD_PARTY_QUICKJS_A).pkg: \ - $(THIRD_PARTY_QUICKJS_OBJS) \ - $(foreach x,$(THIRD_PARTY_QUICKJS_DIRECTDEPS),$($(x)_A).pkg) +$(THIRD_PARTY_QUICKJS_A).pkg: \ + $(THIRD_PARTY_QUICKJS_A_OBJS) \ + $(foreach x,$(THIRD_PARTY_QUICKJS_A_DIRECTDEPS),$($(x)_A).pkg) -o/$(MODE)/third_party/quickjs/qjs.com.dbg: \ - $(THIRD_PARTY_QUICKJS_DEPS) \ - $(THIRD_PARTY_QUICKJS_A) \ - $(THIRD_PARTY_QUICKJS_A).pkg \ - o/$(MODE)/third_party/quickjs/qjs.o \ - $(CRT) \ +THIRD_PARTY_QUICKJS_SRCS = \ + third_party/quickjs/qjs.c \ + third_party/quickjs/qjsc.c \ + third_party/quickjs/run-test262.c \ + $(foreach x,$(THIRD_PARTY_QUICKJS_ARTIFACTS),$($(x)_SRCS)) + +THIRD_PARTY_QUICKJS_OBJS = \ + o/$(MODE)/third_party/quickjs/qjs.o \ + o/$(MODE)/third_party/quickjs/qjsc.o \ + o/$(MODE)/third_party/quickjs/run-test262.o \ + $(THIRD_PARTY_QUICKJS_A_OBJS) + +THIRD_PARTY_QUICKJS_COMS = \ + o/$(MODE)/third_party/quickjs/qjs.com \ + o/$(MODE)/third_party/quickjs/qjsc.com \ + o/$(MODE)/third_party/quickjs/run-test262.com \ + o/$(MODE)/third_party/quickjs/unicode_gen.com + +THIRD_PARTY_QUICKJS_CHECKS = \ + $(THIRD_PARTY_QUICKJS_A).pkg \ + $(THIRD_PARTY_QUICKJS_A_HDRS:%=o/$(MODE)/%.ok) + +o/$(MODE)/third_party/quickjs/qjs.com.dbg: \ + $(THIRD_PARTY_QUICKJS_A_DEPS) \ + $(THIRD_PARTY_QUICKJS_A) \ + $(THIRD_PARTY_QUICKJS_A).pkg \ + o/$(MODE)/third_party/quickjs/qjs.o \ + $(CRT) \ $(APE) -@$(APELINK) -$(THIRD_PARTY_QUICKJS_OBJS): \ - OVERRIDE_CPPFLAGS += \ - -DCONFIG_BIGNUM \ +o/$(MODE)/third_party/quickjs/qjsc.com.dbg: \ + $(THIRD_PARTY_QUICKJS_A_DEPS) \ + $(THIRD_PARTY_QUICKJS_A) \ + $(THIRD_PARTY_QUICKJS_A).pkg \ + o/$(MODE)/third_party/quickjs/qjsc.o \ + $(CRT) \ + $(APE) + -@$(APELINK) + +# git clone git@github.com:tc39/test262 /opt/test262 +# make -j8 MODE=dbg o/dbg/third_party/quickjs/run-test262.com +# o/dbg/third_party/quickjs/run-test262.com -m -c third_party/quickjs/test262.conf -a +o/$(MODE)/third_party/quickjs/run-test262.com.dbg: \ + $(THIRD_PARTY_QUICKJS_A_DEPS) \ + $(THIRD_PARTY_QUICKJS_A) \ + $(THIRD_PARTY_QUICKJS_A).pkg \ + o/$(MODE)/third_party/quickjs/run-test262.o \ + $(CRT) \ + $(APE) + -@$(APELINK) + +o/$(MODE)/third_party/quickjs/unicode_gen.com.dbg: \ + $(THIRD_PARTY_QUICKJS_A_DEPS) \ + $(THIRD_PARTY_QUICKJS_A) \ + $(THIRD_PARTY_QUICKJS_A).pkg \ + o/$(MODE)/third_party/quickjs/unicode_gen.o \ + $(CRT) \ + $(APE) + -@$(APELINK) + +$(THIRD_PARTY_QUICKJS_OBJS): \ + OVERRIDE_CPPFLAGS += \ + -DCONFIG_BIGNUM \ -DCONFIG_VERSION=\"$(shell cat third_party/quickjs/VERSION)\" -o/$(MODE)/third_party/quickjs/unicode_gen.o: \ - OVERRIDE_CPPFLAGS += \ +o/$(MODE)/third_party/quickjs/unicode_gen.o: \ + OVERRIDE_CPPFLAGS += \ -DSTACK_FRAME_UNLIMITED # TODO(jart): Replace alloca() calls with malloc(). -o/$(MODE)/third_party/quickjs/libregexp.o \ -o/$(MODE)/third_party/quickjs/quickjs.o: \ - OVERRIDE_CPPFLAGS += \ +o/$(MODE)/third_party/quickjs/libregexp.o \ +o/$(MODE)/third_party/quickjs/quickjs.o: \ + OVERRIDE_CPPFLAGS += \ -DSTACK_FRAME_UNLIMITED .PHONY: o/$(MODE)/third_party/quickjs -o/$(MODE)/third_party/quickjs: \ - $(THIRD_PARTY_QUICKJS_BINS) \ +o/$(MODE)/third_party/quickjs: \ + $(THIRD_PARTY_QUICKJS_BINS) \ $(THIRD_PARTY_QUICKJS_CHECKS) diff --git a/third_party/quickjs/run-test262.c b/third_party/quickjs/run-test262.c index f69a28f48..756d43aa8 100644 --- a/third_party/quickjs/run-test262.c +++ b/third_party/quickjs/run-test262.c @@ -931,7 +931,8 @@ void load_config(const char *filename) if (!f) { perror_exit(1, filename); } - base_name = get_basename(filename); + /* base_name = get_basename(filename); */ + base_name = strdup(""); while (fgets(buf, sizeof(buf), f) != NULL) { char *p, *q; @@ -1672,6 +1673,8 @@ int run_test(const char *filename, int index) if (p) { snprintf(harnessbuf, sizeof(harnessbuf), "%.*s%s", (int)(p - filename), filename, "test/harness"); + } else { + strcpy(harnessbuf, ""); /* XXX */ } harness = harnessbuf; } @@ -1947,6 +1950,8 @@ int main(int argc, char **argv) BOOL is_test262_harness = FALSE; BOOL is_module = FALSE; + showcrashreports(); + #if !defined(_WIN32) /* Date tests assume California local time */ setenv("TZ", "America/Los_Angeles", 1); diff --git a/third_party/quickjs/test262.conf b/third_party/quickjs/test262.conf index 6fbb5793a..0a181ef30 100644 --- a/third_party/quickjs/test262.conf +++ b/third_party/quickjs/test262.conf @@ -26,22 +26,22 @@ module=yes verbose=yes # load harness files from this directory -harnessdir=test262/harness +harnessdir=/opt/test262/harness # names of harness include files to skip #harnessexclude= # name of the error file for known errors -errorfile=test262_errors.txt +errorfile=third_party/quickjs/test262_errors.txt # exclude tests enumerated in this file (see also [exclude] section) #excludefile=test262_exclude.txt # report test results to this file -reportfile=test262_report.txt +reportfile=o/test262_report.txt # enumerate tests from this directory -testdir=test262/test +testdir=/opt/test262/test [features] # Standard language features and proposed extensions @@ -184,16 +184,19 @@ __setter__ # list excluded tests and directories here # intl not supported -test262/test/intl402/ +/opt/test262/test/intl402/ # incompatible with the "caller" feature -test262/test/built-ins/Function/prototype/restricted-property-caller.js -test262/test/built-ins/Function/prototype/restricted-property-arguments.js -test262/test/built-ins/ThrowTypeError/unique-per-realm-function-proto.js +/opt/test262/test/built-ins/Function/prototype/restricted-property-caller.js +/opt/test262/test/built-ins/Function/prototype/restricted-property-arguments.js +/opt/test262/test/built-ins/ThrowTypeError/unique-per-realm-function-proto.js # slow tests -#test262/test/built-ins/RegExp/CharacterClassEscapes/ -#test262/test/built-ins/RegExp/property-escapes/ +#/opt/test262/test/built-ins/RegExp/CharacterClassEscapes/ +#/opt/test262/test/built-ins/RegExp/property-escapes/ + +# No threads in Cosmopolitan ATM +/opt/test262/test/built-ins/Atomics/ [tests] # list test files or use config.testdir diff --git a/tool/build/compile.c b/tool/build/compile.c index 647396df4..b52435c5f 100644 --- a/tool/build/compile.c +++ b/tool/build/compile.c @@ -421,6 +421,11 @@ int main(int argc, char *argv[]) { } else if (isclang && startswith(argv[i], "--debug-prefix-map")) { /* llvm doesn't provide a gas interface so simulate w/ clang */ AddArg(xasprintf("-f%s", argv[i] + 2)); + } else if (isgcc && (!strcmp(argv[i], "-Os") || !strcmp(argv[i], "-O2") || + !strcmp(argv[i], "-O3"))) { + /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97623 */ + AddArg(argv[i]); + AddArg("-fno-code-hoisting"); } else { AddArg(argv[i]); }