nish 0.42.0 → 0.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/docs/AI.md +287 -129
- package/package.json +9 -9
- package/runtime/core/numbers.mjs +3 -1
- package/runtime/core/strings.mjs +90 -38
- package/runtime/core.d.ts +24 -0
- package/runtime/core.mjs +21 -0
- package/runtime/nish.d.ts +167 -24
- package/runtime/nish.mjs +7 -1
- package/runtime/runtime-cross.c +9 -0
- package/runtime/runtime-net.c +51 -13
- package/runtime/runtime-region.c +13 -0
- package/runtime/runtime-text.c +11 -0
- package/runtime/runtime-uring.c +83 -25
- package/runtime/runtime-wasm.c +3 -0
- package/runtime/runtime.c +329 -6
- package/runtime/sqlite/README.md +16 -3
- package/runtime/sqlite/nish-sqlite.c +940 -29
- package/scripts/build.sh +111 -29
- package/skills/writing-nish/SKILL.md +12 -4
- package/std/README.md +6 -6
- package/std/array.ts +10 -2
- package/std/bytes.ts +239 -26
- package/std/cli-args.ts +1072 -606
- package/std/cli-flags.ts +180 -98
- package/std/cli.ts +21 -13
- package/std/collections.ts +245 -127
- package/std/compress/checksum.ts +32 -37
- package/std/compress/deflate.ts +1102 -542
- package/std/compress/gzip.ts +290 -145
- package/std/compress/zlib.ts +57 -21
- package/std/crypto/aes.ts +153 -75
- package/std/crypto/base64url.ts +163 -39
- package/std/crypto/bcrypt-batch.ts +164 -90
- package/std/crypto/bcrypt.ts +185 -107
- package/std/crypto/chacha20poly1305.ts +84 -68
- package/std/crypto/ct.ts +9 -7
- package/std/crypto/ed25519.ts +64 -27
- package/std/crypto/hkdf.ts +105 -63
- package/std/crypto/hmac.ts +95 -89
- package/std/crypto/jwt.ts +248 -126
- package/std/crypto/p256.ts +758 -444
- package/std/crypto/p384.ts +20 -13
- package/std/crypto/pki-roots.ts +95 -38
- package/std/crypto/pki.ts +164 -60
- package/std/crypto/rsa.ts +266 -223
- package/std/crypto/scram.ts +141 -0
- package/std/crypto/sha1.ts +157 -57
- package/std/crypto/sha256.ts +502 -422
- package/std/crypto/sha512.ts +204 -135
- package/std/crypto/x509-random.ts +9 -3
- package/std/crypto/x509.ts +331 -171
- package/std/host/ring.ts +1 -1
- package/std/host/text.ts +1 -1
- package/std/json-equal.ts +35 -19
- package/std/json-format.ts +215 -108
- package/std/json-number.ts +126 -72
- package/std/json-pointer.ts +42 -13
- package/std/json-tokenizer.ts +498 -307
- package/std/json-typed.ts +115 -36
- package/std/json-value.ts +341 -152
- package/std/json.ts +300 -158
- package/std/net/buffer-pool.ts +17 -7
- package/std/net/dns-config.ts +427 -236
- package/std/net/dns-message.ts +114 -47
- package/std/net/dns-resolver.ts +736 -237
- package/std/net/dns.ts +205 -52
- package/std/net/fetch.ts +320 -184
- package/std/net/grpc.ts +948 -0
- package/std/net/handler.ts +1276 -218
- package/std/net/hpack.ts +395 -180
- package/std/net/http-compress.ts +502 -65
- package/std/net/http-fields.ts +85 -49
- package/std/net/http-server.ts +1764 -603
- package/std/net/http1-client-codec.ts +372 -161
- package/std/net/http1-codec.ts +665 -331
- package/std/net/http1-server.ts +881 -269
- package/std/net/http2-cleartext.ts +165 -95
- package/std/net/http2-frame.ts +232 -89
- package/std/net/http2-tls.ts +42 -12
- package/std/net/http2.ts +327 -101
- package/std/net/http3-frame.ts +68 -33
- package/std/net/http3-server.ts +672 -206
- package/std/net/http3.ts +669 -191
- package/std/net/oidc.ts +63 -24
- package/std/net/outbound.ts +207 -142
- package/std/net/postgres-async.ts +1223 -470
- package/std/net/postgres-carrier.ts +575 -372
- package/std/net/postgres.ts +1521 -632
- package/std/net/prefork.ts +254 -98
- package/std/net/protobuf.ts +1017 -0
- package/std/net/qpack.ts +143 -92
- package/std/net/quic-conn-ack.ts +104 -22
- package/std/net/quic-conn-cid.ts +66 -26
- package/std/net/quic-conn-params.ts +13 -7
- package/std/net/quic-datagram.ts +90 -27
- package/std/net/quic-frame.ts +324 -121
- package/std/net/quic-listener.ts +206 -91
- package/std/net/quic-packet.ts +289 -163
- package/std/net/quic-recovery.ts +279 -128
- package/std/net/quic-stream.ts +466 -167
- package/std/net/quic.ts +584 -258
- package/std/net/router.ts +450 -99
- package/std/net/serve.ts +661 -240
- package/std/net/static.ts +1458 -0
- package/std/net/tls/client.ts +140 -45
- package/std/net/tls/codec.ts +510 -260
- package/std/net/tls/record-client.ts +268 -76
- package/std/net/tls/record-server.ts +236 -79
- package/std/net/tls/record.ts +173 -47
- package/std/net/tls/schedule.ts +58 -39
- package/std/net/tls/ticket.ts +295 -103
- package/std/net/tls/verify.ts +1 -1
- package/std/net/tls-tcp.ts +218 -75
- package/std/net/tls.ts +260 -152
- package/std/net/upstream.ts +283 -86
- package/std/net/url.ts +277 -102
- package/std/net/websocket.ts +532 -209
- package/std/net/webtransport.ts +755 -436
- package/std/regex.ts +1659 -829
- package/std/sqlite.ts +325 -0
- package/std/sync/ring.ts +320 -156
- package/std/sync/shm.ts +53 -6
- package/std/text.ts +285 -135
- package/std/threads.ts +22 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nish",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.1",
|
|
4
4
|
"description": "Nish: an ahead-of-time compiler from a static subset of TypeScript to LLVM IR",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
"postinstall": "node scripts/postinstall.mjs",
|
|
65
65
|
"bootstrap": "bash scripts/bootstrap.sh",
|
|
66
66
|
"compile": "build/nish",
|
|
67
|
-
"example": "build/nish examples/add.ts -o build/add.ll && cat build/add.ll",
|
|
67
|
+
"example": "build/nish examples/add.ts --allow-panics -o build/add.ll && cat build/add.ll",
|
|
68
68
|
"test": "node tests/run.js",
|
|
69
|
-
"size-report": "build/nish examples/add.ts -o build/add.ll && bash scripts/size-report.sh build/add.ll examples/main.c",
|
|
69
|
+
"size-report": "build/nish examples/add.ts --allow-panics -o build/add.ll && bash scripts/size-report.sh build/add.ll examples/main.c",
|
|
70
70
|
"smoke": "bash scripts/smoke.sh",
|
|
71
71
|
"check": "tsc -p tsconfig.json",
|
|
72
72
|
"test:update": "UPDATE_GOLDENS=1 node tests/run.js",
|
|
73
73
|
"test:diff": "node tests/differential/run.js",
|
|
74
|
-
"test:nish": "
|
|
75
|
-
"test:cli": "
|
|
74
|
+
"test:nish": "bash scripts/nish-harness.sh tests/nish/run.ts build/nish-runner",
|
|
75
|
+
"test:cli": "bash scripts/nish-harness.sh tests/nish/cli.ts build/nish-cli",
|
|
76
76
|
"test:node": "node tests/differential/unmodified.js",
|
|
77
77
|
"lint": "node scripts/check-filenames.mjs && node scripts/check-install-scripts.mjs && biome check .",
|
|
78
78
|
"lint:fix": "biome check --write .",
|
|
@@ -114,9 +114,9 @@
|
|
|
114
114
|
"typescript": "^5.6.0"
|
|
115
115
|
},
|
|
116
116
|
"optionalDependencies": {
|
|
117
|
-
"@amritk/nish-aarch64-darwin": "0.
|
|
118
|
-
"@amritk/nish-aarch64-linux": "0.
|
|
119
|
-
"@amritk/nish-x86_64-darwin": "0.
|
|
120
|
-
"@amritk/nish-x86_64-linux": "0.
|
|
117
|
+
"@amritk/nish-aarch64-darwin": "0.45.1",
|
|
118
|
+
"@amritk/nish-aarch64-linux": "0.45.1",
|
|
119
|
+
"@amritk/nish-x86_64-darwin": "0.45.1",
|
|
120
|
+
"@amritk/nish-x86_64-linux": "0.45.1"
|
|
121
121
|
}
|
|
122
122
|
}
|
package/runtime/core/numbers.mjs
CHANGED
|
@@ -250,7 +250,9 @@ export function convert(x, from, to) {
|
|
|
250
250
|
// The hot paths of u64 arithmetic written over i64 (`toU64(a) * toU64(b)`)
|
|
251
251
|
// stay in a function small enough for V8 to inline at the call: the two
|
|
252
252
|
// 64-bit kinds reinterpret each other's bits, and a zext of an unsigned
|
|
253
|
-
// 32-bit-or-narrower value to u64 keeps the value as it is.
|
|
253
|
+
// 32-bit-or-narrower value to u64 keeps the value as it is. Keep it this
|
|
254
|
+
// small: answering the integer `number` cases here, inline or through a
|
|
255
|
+
// helper, made ct_asm_x25519 under --emit-ts 1.1x to 1.8x slower.
|
|
254
256
|
if (typeof x === "bigint") {
|
|
255
257
|
if (to === "u64") return BigInt.asUintN(64, x);
|
|
256
258
|
if (to === "i64") return BigInt.asIntN(64, x);
|
package/runtime/core/strings.mjs
CHANGED
|
@@ -11,31 +11,65 @@ import { panicIndex, panicSlice, toIndex } from "./checks.mjs";
|
|
|
11
11
|
const ENCODER = new TextEncoder();
|
|
12
12
|
const DECODER = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
let lastBytes = new Uint8Array(0);
|
|
14
|
+
/** A UTF-16 unit that is not ASCII, so its UTF-8 bytes are not its units. */
|
|
15
|
+
const NON_ASCII = /[^\x00-\x7f]/;
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* How many strings `bytesOf` keeps. A loop alternates between strings: std's
|
|
19
|
+
* `indexOfAnyFrom` and `yamlByte` read a byte of the document, then of a
|
|
20
|
+
* needle or a word, per step, so a cache of one encodes the document on every
|
|
21
|
+
* read. Eight covers the most std's loops keep live at once.
|
|
22
|
+
*/
|
|
23
|
+
const SLOTS = 8;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The strings `bytesOf` saw last, most recent first, and their bytes: `null`
|
|
27
|
+
* for an ASCII string, whose units are its bytes and which is never encoded.
|
|
28
|
+
* A hit moves its entry to the front and a miss drops the last one, so a
|
|
29
|
+
* string stays while it is read and leaves when it is not. A lookup compares
|
|
30
|
+
* at most `SLOTS` strings with `===`, which answers at once for the same
|
|
31
|
+
* string or a different length and otherwise stops at the first unit that
|
|
32
|
+
* differs.
|
|
33
|
+
*/
|
|
34
|
+
const keys = new Array(SLOTS).fill("");
|
|
35
|
+
const values = new Array(SLOTS).fill(null);
|
|
36
|
+
let used = 0;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The UTF-8 bytes of `s`, which is what an Nish string holds, or `null` when
|
|
40
|
+
* `s` is ASCII and its UTF-16 units are those bytes. Nothing here writes to
|
|
22
41
|
* the bytes it is handed.
|
|
23
42
|
*/
|
|
24
43
|
function bytesOf(s) {
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
if (keys[0] === s) return values[0];
|
|
45
|
+
let at = 1;
|
|
46
|
+
while (at < used && keys[at] !== s) at++;
|
|
47
|
+
let bytes;
|
|
48
|
+
if (at < used) {
|
|
49
|
+
bytes = values[at];
|
|
50
|
+
} else {
|
|
51
|
+
bytes = NON_ASCII.test(s) ? ENCODER.encode(s) : null;
|
|
52
|
+
if (used < SLOTS) used++;
|
|
53
|
+
at = used - 1;
|
|
54
|
+
}
|
|
55
|
+
for (; at > 0; at--) {
|
|
56
|
+
keys[at] = keys[at - 1];
|
|
57
|
+
values[at] = values[at - 1];
|
|
28
58
|
}
|
|
29
|
-
|
|
59
|
+
keys[0] = s;
|
|
60
|
+
values[0] = bytes;
|
|
61
|
+
return bytes;
|
|
30
62
|
}
|
|
31
63
|
|
|
32
64
|
/**
|
|
33
65
|
* `s.length`: UTF-8 byte length for strings (arrays keep their own `.length`).
|
|
34
|
-
* The
|
|
35
|
-
* `
|
|
66
|
+
* The loop condition `i < s.length` then leaves the bytes for the
|
|
67
|
+
* `s.charCodeAt(i)` it guards.
|
|
36
68
|
*/
|
|
37
69
|
export function strLen(x) {
|
|
38
|
-
|
|
70
|
+
if (typeof x !== "string") return x.length;
|
|
71
|
+
const bytes = bytesOf(x);
|
|
72
|
+
return bytes === null ? x.length : bytes.length;
|
|
39
73
|
}
|
|
40
74
|
|
|
41
75
|
/**
|
|
@@ -52,6 +86,10 @@ export function strLenOpt(x) {
|
|
|
52
86
|
export function charCodeAt(s, i) {
|
|
53
87
|
const bytes = bytesOf(s);
|
|
54
88
|
const k = toIndex(i);
|
|
89
|
+
if (bytes === null) {
|
|
90
|
+
if (!(k >= 0 && k < s.length)) panicIndex(k, s.length);
|
|
91
|
+
return s.charCodeAt(k);
|
|
92
|
+
}
|
|
55
93
|
if (!(k >= 0 && k < bytes.length)) panicIndex(k, bytes.length);
|
|
56
94
|
return bytes[k];
|
|
57
95
|
}
|
|
@@ -59,9 +97,13 @@ export function charCodeAt(s, i) {
|
|
|
59
97
|
/** `s.substring(a, b)`: JavaScript's clamp and swap, over byte offsets. */
|
|
60
98
|
export function substring(s, a, b) {
|
|
61
99
|
const bytes = bytesOf(s);
|
|
62
|
-
const
|
|
100
|
+
const len = bytes === null ? s.length : bytes.length;
|
|
101
|
+
const clamp = (v) => Math.max(0, Math.min(toIndex(v), len));
|
|
63
102
|
const from = clamp(a);
|
|
64
|
-
const to = b === undefined ?
|
|
103
|
+
const to = b === undefined ? len : clamp(b);
|
|
104
|
+
// A NaN index cuts nothing, as native's does; JavaScript's would read it as 0.
|
|
105
|
+
if (from !== from || to !== to) return "";
|
|
106
|
+
if (bytes === null) return s.substring(from, to);
|
|
65
107
|
return DECODER.decode(bytes.subarray(Math.min(from, to), Math.max(from, to)));
|
|
66
108
|
}
|
|
67
109
|
|
|
@@ -73,17 +115,22 @@ export function substring(s, a, b) {
|
|
|
73
115
|
*/
|
|
74
116
|
export function slice(s, a, b) {
|
|
75
117
|
const bytes = bytesOf(s);
|
|
118
|
+
const len = bytes === null ? s.length : bytes.length;
|
|
76
119
|
const from = toIndex(a);
|
|
77
|
-
const to = b === undefined ?
|
|
78
|
-
if (!(from >= 0 && from <= to && to <=
|
|
79
|
-
return DECODER.decode(bytes.subarray(from, to));
|
|
120
|
+
const to = b === undefined ? len : toIndex(b);
|
|
121
|
+
if (!(from >= 0 && from <= to && to <= len)) panicSlice(from, to, len);
|
|
122
|
+
return bytes === null ? s.slice(from, to) : DECODER.decode(bytes.subarray(from, to));
|
|
80
123
|
}
|
|
81
124
|
|
|
82
|
-
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Whether `sub` sits in `bytes` at byte offset `at`; `needle` is `sub`'s
|
|
127
|
+
* bytes, or `null` when `sub` is ASCII and its units are compared instead.
|
|
128
|
+
*/
|
|
129
|
+
function bytesAt(bytes, at, sub, needle) {
|
|
130
|
+
const n = needle === null ? sub.length : needle.length;
|
|
131
|
+
if (!(at >= 0 && at + n <= bytes.length)) return false;
|
|
132
|
+
for (let j = 0; j < n; j++) {
|
|
133
|
+
if (bytes[at + j] !== (needle === null ? sub.charCodeAt(j) : needle[j])) return false;
|
|
87
134
|
}
|
|
88
135
|
return true;
|
|
89
136
|
}
|
|
@@ -92,35 +139,40 @@ function bytesAt(bytes, at, needle) {
|
|
|
92
139
|
* `s.indexOf(sub, from)`: the first *byte* offset at or after `from`, or -1.
|
|
93
140
|
* `from` is converted as JavaScript's `ToIntegerOrInfinity` converts it (NaN
|
|
94
141
|
* is 0) and clamped into `[0, len]`, so an empty `sub` is found at `from`.
|
|
95
|
-
*
|
|
96
|
-
*
|
|
142
|
+
* In an ASCII `s` the engine's own `indexOf` answers: offsets are bytes there,
|
|
143
|
+
* and a `sub` that is not ASCII is in it nowhere, as none of its bytes are.
|
|
144
|
+
* Otherwise the engine's `indexOf` over the bytes finds each candidate for
|
|
145
|
+
* `sub`'s first byte, and only those are compared in full.
|
|
97
146
|
*/
|
|
98
147
|
export function indexOf(s, sub, from) {
|
|
99
148
|
const haystack = bytesOf(s);
|
|
149
|
+
const len = haystack === null ? s.length : haystack.length;
|
|
100
150
|
const at = from === undefined ? 0 : toIndex(from);
|
|
101
|
-
const start = Number.isNaN(at) ? 0 : Math.max(0, Math.min(at,
|
|
151
|
+
const start = Number.isNaN(at) ? 0 : Math.max(0, Math.min(at, len));
|
|
102
152
|
if (sub.length === 0) return start;
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
153
|
+
if (haystack === null) return s.indexOf(sub, start);
|
|
154
|
+
const needle = bytesOf(sub);
|
|
155
|
+
const first = needle === null ? sub.charCodeAt(0) : needle[0];
|
|
156
|
+
const last = len - (needle === null ? sub.length : needle.length);
|
|
157
|
+
for (let i = haystack.indexOf(first, start); i >= 0 && i <= last; i = haystack.indexOf(first, i + 1)) {
|
|
158
|
+
if (bytesAt(haystack, i, sub, needle)) return i;
|
|
107
159
|
}
|
|
108
160
|
return -1;
|
|
109
161
|
}
|
|
110
162
|
|
|
111
|
-
/** `
|
|
112
|
-
function occursAt(s, at, sub) {
|
|
113
|
-
return bytesAt(bytesOf(s), at, ENCODER.encode(sub));
|
|
114
|
-
}
|
|
115
|
-
|
|
163
|
+
/** `s.startsWith(sub)`: whether `sub`'s bytes begin `s`'s; an ASCII `s` asks the engine. */
|
|
116
164
|
export function startsWith(s, sub) {
|
|
117
|
-
|
|
165
|
+
const bytes = bytesOf(s);
|
|
166
|
+
if (bytes === null) return s.startsWith(sub);
|
|
167
|
+
return bytesAt(bytes, 0, sub, bytesOf(sub));
|
|
118
168
|
}
|
|
119
169
|
|
|
170
|
+
/** `s.endsWith(sub)`: whether `sub`'s bytes end `s`'s; an ASCII `s` asks the engine. */
|
|
120
171
|
export function endsWith(s, sub) {
|
|
121
172
|
const bytes = bytesOf(s);
|
|
122
|
-
|
|
123
|
-
|
|
173
|
+
if (bytes === null) return s.endsWith(sub);
|
|
174
|
+
const needle = bytesOf(sub);
|
|
175
|
+
return bytesAt(bytes, bytes.length - (needle === null ? sub.length : needle.length), sub, needle);
|
|
124
176
|
}
|
|
125
177
|
|
|
126
178
|
/**
|
package/runtime/core.d.ts
CHANGED
|
@@ -8,6 +8,22 @@ export * from "./core/numbers.js";
|
|
|
8
8
|
export * from "./core/result.js";
|
|
9
9
|
export * from "./core/strings.js";
|
|
10
10
|
|
|
11
|
+
// `nish:compact`: what `--emit-ts` writes for a program's `import ... from "nish:compact"`.
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The marker a class implements to store its links as 32-bit offsets in a
|
|
15
|
+
* native build. It has no members, so `implements Compact` adds nothing a
|
|
16
|
+
* TypeScript checker sees.
|
|
17
|
+
*/
|
|
18
|
+
export interface Compact {}
|
|
19
|
+
/** The value `core.mjs` exports under the marker's name, so an emitted import of it resolves. */
|
|
20
|
+
export declare const Compact: Compact;
|
|
21
|
+
|
|
22
|
+
/** Reserved for WP48 stage 3, which lets a class refuse the compiler's choice. */
|
|
23
|
+
export interface Wide {}
|
|
24
|
+
/** The value `core.mjs` exports under the reserved marker's name. */
|
|
25
|
+
export declare const Wide: Wide;
|
|
26
|
+
|
|
11
27
|
// `nish:simd`: what `--emit-ts` writes for a program's `import ... from "nish:simd"`.
|
|
12
28
|
import type { f32, f64, i32, u16, u32, u8 } from "./core/numbers.js";
|
|
13
29
|
|
|
@@ -131,3 +147,11 @@ export declare function asI32x4(v: SimdVector): i32x4;
|
|
|
131
147
|
export declare function asU32x4(v: SimdVector): u32x4;
|
|
132
148
|
export declare function asF32x4(v: SimdVector): f32x4;
|
|
133
149
|
export declare function asF64x2(v: SimdVector): f64x2;
|
|
150
|
+
|
|
151
|
+
// `mulHigh` and `mulHighIsNative`: builtins, written out under these names.
|
|
152
|
+
import type { u64 } from "./core/numbers.js";
|
|
153
|
+
|
|
154
|
+
/** The high 64 bits of the 128-bit product of `a` and `b` (WP41): `(a * b) >> 64n`. */
|
|
155
|
+
export declare function mulHigh(a: u64, b: u64): u64;
|
|
156
|
+
/** `false` under Node, where `mulHigh` is a BigInt multiply rather than one instruction. */
|
|
157
|
+
export declare function mulHighIsNative(): boolean;
|
package/runtime/core.mjs
CHANGED
|
@@ -84,6 +84,27 @@ const simdLoad = (Lanes) => (xs, i) => {
|
|
|
84
84
|
return out;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
+
// `nish:compact`: the marker interfaces pick a native layout and mean nothing
|
|
88
|
+
// under Node, where every reference is the engine's own.
|
|
89
|
+
export const Compact = Object.freeze({});
|
|
90
|
+
export const Wide = Object.freeze({});
|
|
91
|
+
|
|
92
|
+
// `mulHigh` / `mulHighIsNative` (WP41). A `u64` is a BigInt here, so the high
|
|
93
|
+
// half is the exact product shifted down. A `number` operand is the mix the
|
|
94
|
+
// native checker refuses (NL2823), and throws rather than answering from a
|
|
95
|
+
// double. `mulHighIsNative` is `false`, so std keeps its narrow-limb code under
|
|
96
|
+
// Node, where `mulHigh` is a BigInt multiply and no faster than four products.
|
|
97
|
+
export function mulHigh(a, b) {
|
|
98
|
+
if (typeof a !== "bigint" || typeof b !== "bigint") {
|
|
99
|
+
throw new TypeError("mulHigh: takes u64 (BigInt) operands");
|
|
100
|
+
}
|
|
101
|
+
return (BigInt.asUintN(64, a) * BigInt.asUintN(64, b)) >> 64n;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function mulHighIsNative() {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
|
|
87
108
|
export const u8x16 = simdMake(Uint8Array);
|
|
88
109
|
export const u16x8 = simdMake(Uint16Array);
|
|
89
110
|
export const i32x4 = simdMake(Int32Array);
|