Skip to content

Commit 8a91518

Browse files
committed
Fix issues revealed by ECMAScript test262
Cosmopolitan's QuickJS is now equally conformant and performant, with the exception of Atomics, which have been disabled since Cosmopolitan currently doesn't support pthreads. QuickJS memory usage -- BigNum 2021-03-27 version, 64-bit, malloc limit: -1 NAME COUNT SIZE memory allocated 937 131764 (140.6 per block) memory used 938 116103 (8 overhead, 16.7 average slack) atoms 513 21408 (41.7 per atom) objects 170 12279 (72.2 per object) properties 864 15531 (5.1 per object) shapes 58 12995 (224.1 per shape) bytecode functions 13 1512 bytecode 13 867 (66.7 per function) C functions 99 arrays 1 fast arrays 1 elements 1 16 (1.0 per fast array) Result: 35/74740 errors, 1279 excluded, 485 skipped, 19 new, 2 fixed real 2m40.828s user 2m29.764s sys 0m10.939s
1 parent 8f52c0d commit 8a91518

38 files changed

+398
-187
lines changed

build/bootstrap/compile.com

0 Bytes
Binary file not shown.

build/config.mk

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ CONFIG_CCFLAGS += \
6969
$(BACKTRACES) \
7070
-O2
7171

72+
TARGET_ARCH ?= \
73+
-msse3
74+
7275
endif
7376

7477
# Debug Mode
@@ -88,7 +91,7 @@ CONFIG_CPPFLAGS += \
8891
CONFIG_CCFLAGS += \
8992
$(BACKTRACES) \
9093
$(FTRACE) \
91-
-O2
94+
-Og
9295

9396
CONFIG_COPTS += \
9497
$(SECURITY_BLANKETS) \

examples/walk.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#if 0
2+
/*─────────────────────────────────────────────────────────────────╗
3+
│ To the extent possible under law, Justine Tunney has waived │
4+
│ all copyright and related or neighboring rights to this file, │
5+
│ as it is written in the following disclaimers: │
6+
│ • http://unlicense.org/ │
7+
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
8+
╚─────────────────────────────────────────────────────────────────*/
9+
#endif
10+
#include "libc/calls/calls.h"
11+
#include "libc/calls/struct/stat.h"
12+
#include "libc/log/log.h"
13+
#include "libc/runtime/runtime.h"
14+
#include "libc/sysv/consts/exit.h"
15+
#include "third_party/musl/ftw.h"
16+
17+
/**
18+
* @fileoverview Directory walker example.
19+
* Copied from IEEE Std 1003.1-2017
20+
*/
21+
22+
static int display_info(const char *fpath, const struct stat *sb, int tflag,
23+
struct FTW *ftwbuf) {
24+
printf("%-3s %2d %7jd %-40s %d %s\n",
25+
(tflag == FTW_D) ? "d"
26+
: (tflag == FTW_DNR) ? "dnr"
27+
: (tflag == FTW_DP) ? "dp"
28+
: (tflag == FTW_F) ? (S_ISBLK(sb->st_mode) ? "f b"
29+
: S_ISCHR(sb->st_mode) ? "f c"
30+
: S_ISFIFO(sb->st_mode) ? "f p"
31+
: S_ISREG(sb->st_mode) ? "f r"
32+
: S_ISSOCK(sb->st_mode) ? "f s"
33+
: "f ?")
34+
: (tflag == FTW_NS) ? "ns"
35+
: (tflag == FTW_SL) ? "sl"
36+
: (tflag == FTW_SLN) ? "sln"
37+
: "?",
38+
ftwbuf->level, (intmax_t)sb->st_size, fpath, ftwbuf->base,
39+
fpath + ftwbuf->base);
40+
return 0; /* To tell nftw() to continue */
41+
}
42+
43+
int main(int argc, char *argv[]) {
44+
int flags = 0;
45+
if (argc > 2 && strchr(argv[2], 'd') != NULL) flags |= FTW_DEPTH;
46+
if (argc > 2 && strchr(argv[2], 'p') != NULL) flags |= FTW_PHYS;
47+
if (nftw((argc < 2) ? "." : argv[1], display_info, 20, flags) == -1) {
48+
perror("nftw");
49+
exit(EXIT_FAILURE);
50+
}
51+
exit(EXIT_SUCCESS);
52+
}

libc/runtime/fesetround.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
╚─────────────────────────────────────────────────────────────────────────────*/
1919
#include "libc/runtime/fenv.h"
2020

21-
/* TODO(jart): This needs tests. */
22-
2321
/**
2422
* Sets rounding mode.
2523
*

libc/runtime/fltrounds.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@
1919
#include "libc/runtime/fenv.h"
2020

2121
int __flt_rounds(void) {
22-
switch (fegetround()) {
23-
case FE_TOWARDZERO:
22+
int x87cw;
23+
asm("fnstcw\t%0" : "=m"(x87cw));
24+
switch ((x87cw & 0x0c00) >> 10) {
25+
case FE_TOWARDZERO >> 10:
2426
return 0;
25-
case FE_TONEAREST:
27+
case FE_TONEAREST >> 10:
2628
return 1;
27-
case FE_UPWARD:
29+
case FE_UPWARD >> 10:
2830
return 2;
29-
case FE_DOWNWARD:
31+
case FE_DOWNWARD >> 10:
3032
return 3;
3133
default:
32-
return -1;
34+
unreachable;
3335
}
3436
}

libc/testlib/formatfloat.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
#include "libc/fmt/fmt.h"
2020
#include "libc/mem/mem.h"
2121
#include "libc/testlib/testlib.h"
22+
#include "libc/x/x.h"
2223
#include "third_party/gdtoa/gdtoa.h"
2324

2425
testonly char *testlib_formatfloat(long double x) {
25-
char buf[32];
26-
char *str = malloc(256);
27-
g_xfmt_p(buf, &x, 15, sizeof(buf), 0);
28-
sprintf(str, "%Lf (%s)", x, buf);
29-
return str;
26+
return xasprintf("%.15Lg", x);
3027
}

libc/tinymath/atanh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
* Returns inverse hyperbolic tangent of 𝑥.
2323
*/
2424
double atanh(double x) {
25-
return log((1 + x) / (1 - x)) / 2;
25+
return x ? log((1 + x) / (1 - x)) / 2 : x;
2626
}

libc/tinymath/atanhf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
* Returns inverse hyperbolic tangent of 𝑥.
2323
*/
2424
float atanhf(float x) {
25-
return logf((1 + x) / (1 - x)) / 2;
25+
return x ? logf((1 + x) / (1 - x)) / 2 : x;
2626
}

libc/tinymath/atanhl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
* Returns inverse hyperbolic tangent of 𝑥.
2323
*/
2424
long double atanhl(long double x) {
25-
return logl((1 + x) / (1 - x)) / 2;
25+
return x ? logl((1 + x) / (1 - x)) / 2 : x;
2626
}

libc/tinymath/expm1l.S

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@
1919
#include "libc/runtime/pc.internal.h"
2020
#include "libc/macros.internal.h"
2121

22-
// Returns 𝑒^x-1.
22+
// Returns 𝑒^𝑥-𝟷.
2323
//
2424
// @param 𝑥 is an 80-bit long double passed on stack in 16-bytes
2525
// @return result of exponentiation on FPU stack in %st
2626
expm1l: push %rbp
2727
mov %rsp,%rbp
2828
.profilable
2929
fldt 16(%rbp)
30-
fxam # isinf(x)
30+
fxam
3131
fstsw %ax
3232
mov %ah,%al
33-
and $0x45,%ah
34-
cmp $5,%ah
33+
and $(FPU_C3|FPU_C2|FPU_C0)>>8,%ah
34+
cmp $(FPU_C3)>>8,%ah # !x
35+
je 0f
36+
cmp $(FPU_C2|FPU_C0)>>8,%ah # isinf(x)
3537
je 1f
3638
fldl2e
3739
fmulp %st,%st(1)
@@ -50,7 +52,7 @@ expm1l: push %rbp
5052
faddp %st,%st(1)
5153
0: pop %rbp
5254
ret
53-
1: test $2,%al # signbit(x)
55+
1: test $FPU_C1>>8,%al # signbit(x)
5456
jz 0b
5557
fstp %st
5658
fld1

0 commit comments

Comments
 (0)