@amritk/nish-x86_64-linux 0.37.0 → 0.38.0

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.
@@ -0,0 +1,1068 @@
1
+ /* Nish runtime, the text half: strings and the digits of numbers.
2
+ *
3
+ * Building a string (`nish_str_new`, `a + b`, a template), comparing and
4
+ * searching one, and spelling an integer or a double the way JavaScript's
5
+ * `String(x)` does (Zmij, below). Moved here from runtime.c (WP50 stage 4,
6
+ * docs/wp50-wasm-host.md §7) so that the freestanding wasm link can take the
7
+ * same code a native program runs: nothing in this file needs libc beyond
8
+ * the mem* routines, and a wasm32 build without WASI spells those as the
9
+ * builtins `-mbulk-memory` lowers to memory.copy and memory.fill, and the two
10
+ * searches as loops. A module that formats a number for a page therefore
11
+ * prints the digits a native program prints, which tests/run.js holds to a
12
+ * corpus (`host-import`).
13
+ *
14
+ * What it needs from the rest of the runtime is the allocator,
15
+ * `nish_alloc_struct`, and on a native link the failure `nish_oom`, runtime.c's,
16
+ * which writes to stderr and exits. A wasm build asks runtime-wasm.c's allocator
17
+ * for a size no arena holds instead, which is its out-of-memory panic: the page's
18
+ * `nish.panic` import under wasm-host, then a trap.
19
+ * scripts/build.sh adds this file to a wasm link whose IR calls into it; the
20
+ * native links name it beside runtime.c. Its `.text*` has its own ceiling,
21
+ * RUNTIME_TEXT_UNIT_BUDGET in tests/runtime-budgets.js.
22
+ */
23
+ #include <stddef.h>
24
+ #include <stdint.h>
25
+
26
+ #if defined(__wasm__) && !defined(__wasi__)
27
+ /* No libc. memcpy, memset and memmove are the bulk-memory instructions; the
28
+ comparison and the byte search are the loops below. */
29
+ #define memcpy __builtin_memcpy
30
+ #define memset __builtin_memset
31
+ #define memmove __builtin_memmove
32
+ static int nish_text_cmp(const char *a, const char *b, uint64_t n) {
33
+ for (uint64_t i = 0; i < n; i++)
34
+ if (a[i] != b[i]) return 1;
35
+ return 0;
36
+ }
37
+ #define memcmp nish_text_cmp
38
+ #define NISH_TEXT_FREESTANDING 1
39
+ #else
40
+ #include <string.h>
41
+ #endif
42
+
43
+ void *nish_alloc_struct(uint64_t size);
44
+ #if !defined(NISH_TEXT_FREESTANDING) && !defined(NISH_ASAN) && !defined(__OPTIMIZE_SIZE__)
45
+ /* runtime.c's bump fast path, repeated here so that this file's compile sees
46
+ it, as it did while strings lived in runtime.c. Behind a call the LTO link
47
+ does inline the allocator, but too late: `a + b` was then too big to inline
48
+ into the program, and strbuild ran 15% more instructions. The arena's layout
49
+ is ABI (nish.h), and the asserts below hold the copy to it. An ASan build keeps the
50
+ call, whose `nish_asan_alloc` poisons the rounding; a wasm build has its own
51
+ allocator, runtime-wasm.c's; and an -Os or -Oz build keeps the call too, since
52
+ the two inlined copies cost 41 bytes the size profile and this file's budget
53
+ do not have. */
54
+ #ifdef NISH_THREADS
55
+ #define NISH_TEXT_TLS _Thread_local
56
+ #else
57
+ #define NISH_TEXT_TLS
58
+ #endif
59
+ struct nish_arena { char *buf; uint64_t off; uint64_t cap; void *chunks; };
60
+ /* A copy of nish.h's definition, kept rather than included because nish.h's
61
+ `nish_str` is a tagged struct and this file's is not. runtime.c asserts the
62
+ same layout: a copy that drifted from it would bump the wrong field and
63
+ corrupt the heap. */
64
+ _Static_assert(offsetof(struct nish_arena, buf) == 0, "runtime.c's struct nish_arena: buf first");
65
+ _Static_assert(sizeof(struct nish_arena) == 32, "runtime.c's struct nish_arena: four 8-byte fields");
66
+ _Static_assert(offsetof(struct nish_arena, off) == 8, "runtime.c's struct nish_arena: off second");
67
+ _Static_assert(offsetof(struct nish_arena, cap) == 16, "runtime.c's struct nish_arena: cap third");
68
+ _Static_assert(offsetof(struct nish_arena, chunks) == 24, "runtime.c's struct nish_arena: chunks last");
69
+ extern NISH_TEXT_TLS struct nish_arena nish_arena;
70
+ void *nish_arena_grow(uint64_t size);
71
+ static inline void *nish_text_alloc(uint64_t size) {
72
+ size = (size + 7) & ~(uint64_t)7;
73
+ if (nish_arena.off + size <= nish_arena.cap) {
74
+ void *p = nish_arena.buf + nish_arena.off;
75
+ nish_arena.off += size;
76
+ return p;
77
+ }
78
+ return nish_arena_grow(size);
79
+ }
80
+ #else
81
+ #define nish_text_alloc nish_alloc_struct
82
+ #endif
83
+ #ifdef NISH_TEXT_FREESTANDING
84
+ /* runtime-wasm.c refuses any size past 2^64 - 8 as out of memory. Spelled this
85
+ way rather than as a `nish_oom` there, because `--profile wasm` exports every
86
+ symbol it links: a function for strings alone would change the bytes of every
87
+ program that links runtime-wasm.c and builds no string. */
88
+ #define nish_oom() (nish_alloc_struct(UINT64_MAX), __builtin_unreachable())
89
+ #else
90
+ __attribute__((noreturn)) void nish_oom(void);
91
+ #endif
92
+
93
+ /* The most bytes a string may hold: runtime.c's `NISH_ARRAY_MAX`, for the
94
+ reason given at `nish_str_concat`. */
95
+ #define NISH_ARRAY_MAX 2147483647u
96
+
97
+ /* ---- Strings: { i64 len, bytes[len], '\0' }, immutable; 8 = the len header */
98
+ typedef struct { uint64_t len; char data[]; } nish_str;
99
+
100
+ nish_str *nish_str_new(const char *bytes, uint64_t len) {
101
+ nish_str *s = nish_text_alloc(8 + len + 1);
102
+ s->len = len;
103
+ if (len) memcpy(s->data, bytes, len);
104
+ s->data[len] = 0;
105
+ return s;
106
+ }
107
+
108
+ /* A string never passes 2^31 - 1 bytes, for the reason an array never passes
109
+ that many elements (`NISH_ARRAY_MAX`, above): under --number-mode i32 a
110
+ longer one's `length` reads back negative and bounds-check elimination
111
+ trusts it (docs/security/runtime.md, RT-2). `a + b` past it fails as an
112
+ allocation does. */
113
+ nish_str *nish_str_concat(const nish_str *a, const nish_str *b) {
114
+ uint64_t len = a->len + b->len;
115
+ if (len > NISH_ARRAY_MAX) nish_oom();
116
+ nish_str *s = nish_text_alloc(8 + len + 1);
117
+ s->len = len;
118
+ memcpy(s->data, a->data, a->len);
119
+ memcpy(s->data + a->len, b->data, b->len);
120
+ s->data[len] = 0;
121
+ return s;
122
+ }
123
+
124
+ _Bool nish_str_eq(const nish_str *a, const nish_str *b) {
125
+ return a == b || (a->len == b->len && memcmp(a->data, b->data, a->len) == 0);
126
+ }
127
+
128
+ uint64_t nish_str_len(const nish_str *s) { return s->len; }
129
+
130
+ /* `s.startsWith(sub)` is at 0, `s.endsWith(sub)` at len - sub->len, which is
131
+ negative when `sub` is the longer string. */
132
+ _Bool nish_str_at(const nish_str *s, int64_t at, const nish_str *sub) {
133
+ return at >= 0 && (uint64_t)at + sub->len <= s->len && !memcmp(s->data + at, sub->data, sub->len);
134
+ }
135
+ /* `s.indexOf(sub)`: the first byte offset where `sub` occurs, or -1. An empty
136
+ needle answers 0 and a needle longer than the haystack -1, both of which are
137
+ what JavaScript says and what the inline loop this replaces did.
138
+
139
+ This was lowered inline, one `nish_str_at` per offset, to keep `runtime.c`
140
+ small. That cost a byte-at-a-time scan — 53.7 ms over 52 MB of haystack —
141
+ and WP15 section 7's rule is that the budget yields to a measured win, so the
142
+ search moved into the runtime: `memchr` finds a candidate first byte and `memcmp`
143
+ confirms it, both the libc's vectorised routines. 2.9 ms, or 3.1 ms when the
144
+ needle starts with a byte the haystack is full of.
145
+
146
+ `memmem` is deliberately not used, and costs little: 2.5 ms on the same two
147
+ measurements. It is a GNU extension glibc hides behind `_GNU_SOURCE`, and
148
+ defining that here makes `<string.h>` pull in `<strings.h>` — which any `-I`
149
+ directory holding a file of that name then shadows. This project generates
150
+ exactly such a header from `examples/strings.ts`, and the interop tests
151
+ caught runtime.c picking it up and inheriting `nish.h` through it. A C host
152
+ would hit the same. A fifth of the time is not worth making the runtime
153
+ sensitive to its includer's `-I` paths. A freestanding wasm build has no
154
+ `memchr`, and scans for the first byte with a loop instead.
155
+
156
+ `s.indexOf(sub, from)` is the same search from byte `from`, and
157
+ `s.indexOf(sub)` is it from 0: one loop, not two. The compiler clamps `from`
158
+ into [0, s.length] first, as JavaScript does, with `llvm.smin`/`smax` where
159
+ LLVM can fold them, so the clamp costs this file nothing; an empty needle
160
+ answers that clamped `from`. The clamp is a precondition: a caller that
161
+ skips it never reads outside the string, but gets -1 for a non-empty needle
162
+ (a negative `from` reads as one past the end) and `from` itself, unchanged,
163
+ for an empty one. */
164
+ int64_t nish_str_index_of_from(const nish_str *s, const nish_str *sub, int64_t from) {
165
+ uint64_t at = (uint64_t)from;
166
+ if (sub->len == 0) return from;
167
+ while (at <= s->len && sub->len <= s->len - at) {
168
+ #ifdef NISH_TEXT_FREESTANDING
169
+ const char *c = s->data + at, *last = s->data + s->len - sub->len;
170
+ while (c <= last && *c != sub->data[0]) c++;
171
+ if (c > last) break;
172
+ #else
173
+ const char *c = memchr(s->data + at, sub->data[0], s->len - at - sub->len + 1);
174
+ if (!c) break;
175
+ #endif
176
+ at = (uint64_t)(c - s->data);
177
+ if (memcmp(c + 1, sub->data + 1, sub->len - 1) == 0) return (int64_t)at;
178
+ at++;
179
+ }
180
+ return -1;
181
+ }
182
+ int64_t nish_str_index_of(const nish_str *s, const nish_str *sub) { return nish_str_index_of_from(s, sub, 0); }
183
+
184
+ /* Decimal digits of `u`, with a '-' in front when `neg`. 20 digits is the
185
+ widest a uint64_t can be, plus the sign. */
186
+ static nish_str *str_from_digits(uint64_t u, int neg) {
187
+ char tmp[21], *p = tmp + 21;
188
+ do { *--p = '0' + u % 10; u /= 10; } while (u);
189
+ if (neg) *--p = '-';
190
+ return nish_str_new(p, tmp + 21 - p);
191
+ }
192
+
193
+ nish_str *nish_str_from_i64(int64_t v) {
194
+ return str_from_digits(v < 0 ? -(uint64_t)v : (uint64_t)v, v < 0);
195
+ }
196
+ nish_str *nish_str_from_i32(int32_t v) { return nish_str_from_i64(v); }
197
+ /* The one unsigned formatter (WP15): u8/u16/u32 are zero-extended by the
198
+ caller, so 0xFFFFFFFF prints as 4294967295 rather than -1. */
199
+ nish_str *nish_str_from_u64(uint64_t v) { return str_from_digits(v, 0); }
200
+
201
+
202
+ /* ---- Shortest round-trip digits (Zmij)
203
+
204
+ Adapted from Zmij (https://github.com/vitaut/zmij), zmij.c. Copyright (c)
205
+ 2025 - present, Victor Zverovich. Used under the Boost Software License,
206
+ Version 1.0 (upstream offers MIT or BSL-1.0); see runtime/LICENSE-zmij. The
207
+ code from here to the end of `nish_shortest_digits` follows upstream's
208
+ `umul192_hi128`, `umul128_add_hi64`, `compute_dec_exp`, `compute_exp_shift`
209
+ and the scalar `to_decimal_double`, which is why it keeps their constants;
210
+ the table is regenerated by scripts/gen-pow10-table.py rather than copied.
211
+ Only the digit computation is taken: no SIMD, and none of upstream's own
212
+ formatting, since the layout below is ECMAScript's rather than printf's.
213
+
214
+ `String(x)` in JavaScript prints the *fewest* digits that read back as the
215
+ same double, and the language promises that spelling. Reaching it by asking
216
+ snprintf for k digits and strtod whether they round-trip is both slow and,
217
+ less obviously, *wrong*: printf can only hand back the correctly-rounded
218
+ k-digit string, and for some values the shortest string that round-trips at
219
+ that length is a different one (7.120236347223045e-307 is the pinned case).
220
+
221
+ Zmij (a Schubfach descendant) gets there with one 64x128-bit multiply: it
222
+ scales the value by a power of ten chosen so the integer part is the shorter
223
+ of the two candidate lengths, decides from the fractional part whether that
224
+ candidate already lies inside the rounding interval, and otherwise reads one
225
+ more digit off the fraction. Ryu, which this replaced, needed three
226
+ multiplies and a loop of divisions. Read upstream before touching the
227
+ arithmetic: `315653 >> 20`, `217707 >> 16` and the `+6` bias are exact over
228
+ the exponents a double can have and verified there, not in general. */
229
+ /* Generated by scripts/gen-pow10-table.py; do not hand-edit. 10^-293 to 10^323. */
230
+ #define NISH_POW10_MIN (-293)
231
+ static const uint64_t NISH_POW10_SIG[617][2] = {
232
+ { 0xcc5fc196fefd7d0cu, 0x1e53ed49a96272c8u },
233
+ { 0xff77b1fcbebcdc4fu, 0x25e8e89c13bb0f7au },
234
+ { 0x9faacf3df73609b1u, 0x77b191618c54e9acu },
235
+ { 0xc795830d75038c1du, 0xd59df5b9ef6a2417u },
236
+ { 0xf97ae3d0d2446f25u, 0x4b0573286b44ad1du },
237
+ { 0x9becce62836ac577u, 0x4ee367f9430aec32u },
238
+ { 0xc2e801fb244576d5u, 0x229c41f793cda73fu },
239
+ { 0xf3a20279ed56d48au, 0x6b43527578c1110fu },
240
+ { 0x9845418c345644d6u, 0x830a13896b78aaa9u },
241
+ { 0xbe5691ef416bd60cu, 0x23cc986bc656d553u },
242
+ { 0xedec366b11c6cb8fu, 0x2cbfbe86b7ec8aa8u },
243
+ { 0x94b3a202eb1c3f39u, 0x7bf7d71432f3d6a9u },
244
+ { 0xb9e08a83a5e34f07u, 0xdaf5ccd93fb0cc53u },
245
+ { 0xe858ad248f5c22c9u, 0xd1b3400f8f9cff68u },
246
+ { 0x91376c36d99995beu, 0x23100809b9c21fa1u },
247
+ { 0xb58547448ffffb2du, 0xabd40a0c2832a78au },
248
+ { 0xe2e69915b3fff9f9u, 0x16c90c8f323f516cu },
249
+ { 0x8dd01fad907ffc3bu, 0xae3da7d97f6792e3u },
250
+ { 0xb1442798f49ffb4au, 0x99cd11cfdf41779cu },
251
+ { 0xdd95317f31c7fa1du, 0x40405643d711d583u },
252
+ { 0x8a7d3eef7f1cfc52u, 0x482835ea666b2572u },
253
+ { 0xad1c8eab5ee43b66u, 0xda3243650005eecfu },
254
+ { 0xd863b256369d4a40u, 0x90bed43e40076a82u },
255
+ { 0x873e4f75e2224e68u, 0x5a7744a6e804a291u },
256
+ { 0xa90de3535aaae202u, 0x711515d0a205cb36u },
257
+ { 0xd3515c2831559a83u, 0x0d5a5b44ca873e03u },
258
+ { 0x8412d9991ed58091u, 0xe858790afe9486c2u },
259
+ { 0xa5178fff668ae0b6u, 0x626e974dbe39a872u },
260
+ { 0xce5d73ff402d98e3u, 0xfb0a3d212dc8128fu },
261
+ { 0x80fa687f881c7f8eu, 0x7ce66634bc9d0b99u },
262
+ { 0xa139029f6a239f72u, 0x1c1fffc1ebc44e80u },
263
+ { 0xc987434744ac874eu, 0xa327ffb266b56220u },
264
+ { 0xfbe9141915d7a922u, 0x4bf1ff9f0062baa8u },
265
+ { 0x9d71ac8fada6c9b5u, 0x6f773fc3603db4a9u },
266
+ { 0xc4ce17b399107c22u, 0xcb550fb4384d21d3u },
267
+ { 0xf6019da07f549b2bu, 0x7e2a53a146606a48u },
268
+ { 0x99c102844f94e0fbu, 0x2eda7444cbfc426du },
269
+ { 0xc0314325637a1939u, 0xfa911155fefb5308u },
270
+ { 0xf03d93eebc589f88u, 0x793555ab7eba27cau },
271
+ { 0x96267c7535b763b5u, 0x4bc1558b2f3458deu },
272
+ { 0xbbb01b9283253ca2u, 0x9eb1aaedfb016f16u },
273
+ { 0xea9c227723ee8bcbu, 0x465e15a979c1cadcu },
274
+ { 0x92a1958a7675175fu, 0x0bfacd89ec191ec9u },
275
+ { 0xb749faed14125d36u, 0xcef980ec671f667bu },
276
+ { 0xe51c79a85916f484u, 0x82b7e12780e7401au },
277
+ { 0x8f31cc0937ae58d2u, 0xd1b2ecb8b0908810u },
278
+ { 0xb2fe3f0b8599ef07u, 0x861fa7e6dcb4aa15u },
279
+ { 0xdfbdcece67006ac9u, 0x67a791e093e1d49au },
280
+ { 0x8bd6a141006042bdu, 0xe0c8bb2c5c6d24e0u },
281
+ { 0xaecc49914078536du, 0x58fae9f773886e18u },
282
+ { 0xda7f5bf590966848u, 0xaf39a475506a899eu },
283
+ { 0x888f99797a5e012du, 0x6d8406c952429603u },
284
+ { 0xaab37fd7d8f58178u, 0xc8e5087ba6d33b83u },
285
+ { 0xd5605fcdcf32e1d6u, 0xfb1e4a9a90880a64u },
286
+ { 0x855c3be0a17fcd26u, 0x5cf2eea09a55067fu },
287
+ { 0xa6b34ad8c9dfc06fu, 0xf42faa48c0ea481eu },
288
+ { 0xd0601d8efc57b08bu, 0xf13b94daf124da26u },
289
+ { 0x823c12795db6ce57u, 0x76c53d08d6b70858u },
290
+ { 0xa2cb1717b52481edu, 0x54768c4b0c64ca6eu },
291
+ { 0xcb7ddcdda26da268u, 0xa9942f5dcf7dfd09u },
292
+ { 0xfe5d54150b090b02u, 0xd3f93b35435d7c4cu },
293
+ { 0x9efa548d26e5a6e1u, 0xc47bc5014a1a6dafu },
294
+ { 0xc6b8e9b0709f109au, 0x359ab6419ca1091bu },
295
+ { 0xf867241c8cc6d4c0u, 0xc30163d203c94b62u },
296
+ { 0x9b407691d7fc44f8u, 0x79e0de63425dcf1du },
297
+ { 0xc21094364dfb5636u, 0x985915fc12f542e4u },
298
+ { 0xf294b943e17a2bc4u, 0x3e6f5b7b17b2939du },
299
+ { 0x979cf3ca6cec5b5au, 0xa705992ceecf9c42u },
300
+ { 0xbd8430bd08277231u, 0x50c6ff782a838353u },
301
+ { 0xece53cec4a314ebdu, 0xa4f8bf5635246428u },
302
+ { 0x940f4613ae5ed136u, 0x871b7795e136be99u },
303
+ { 0xb913179899f68584u, 0x28e2557b59846e3fu },
304
+ { 0xe757dd7ec07426e5u, 0x331aeada2fe589cfu },
305
+ { 0x9096ea6f3848984fu, 0x3ff0d2c85def7621u },
306
+ { 0xb4bca50b065abe63u, 0x0fed077a756b53a9u },
307
+ { 0xe1ebce4dc7f16dfbu, 0xd3e8495912c62894u },
308
+ { 0x8d3360f09cf6e4bdu, 0x64712dd7abbbd95cu },
309
+ { 0xb080392cc4349decu, 0xbd8d794d96aacfb3u },
310
+ { 0xdca04777f541c567u, 0xecf0d7a0fc5583a0u },
311
+ { 0x89e42caaf9491b60u, 0xf41686c49db57244u },
312
+ { 0xac5d37d5b79b6239u, 0x311c2875c522ced5u },
313
+ { 0xd77485cb25823ac7u, 0x7d633293366b828bu },
314
+ { 0x86a8d39ef77164bcu, 0xae5dff9c02033197u },
315
+ { 0xa8530886b54dbdebu, 0xd9f57f830283fdfcu },
316
+ { 0xd267caa862a12d66u, 0xd072df63c324fd7bu },
317
+ { 0x8380dea93da4bc60u, 0x4247cb9e59f71e6du },
318
+ { 0xa46116538d0deb78u, 0x52d9be85f074e608u },
319
+ { 0xcd795be870516656u, 0x67902e276c921f8bu },
320
+ { 0x806bd9714632dff6u, 0x00ba1cd8a3db53b6u },
321
+ { 0xa086cfcd97bf97f3u, 0x80e8a40eccd228a4u },
322
+ { 0xc8a883c0fdaf7df0u, 0x6122cd128006b2cdu },
323
+ { 0xfad2a4b13d1b5d6cu, 0x796b805720085f81u },
324
+ { 0x9cc3a6eec6311a63u, 0xcbe3303674053bb0u },
325
+ { 0xc3f490aa77bd60fcu, 0xbedbfc4411068a9cu },
326
+ { 0xf4f1b4d515acb93bu, 0xee92fb5515482d44u },
327
+ { 0x991711052d8bf3c5u, 0x751bdd152d4d1c4au },
328
+ { 0xbf5cd54678eef0b6u, 0xd262d45a78a0635du },
329
+ { 0xef340a98172aace4u, 0x86fb897116c87c34u },
330
+ { 0x9580869f0e7aac0eu, 0xd45d35e6ae3d4da0u },
331
+ { 0xbae0a846d2195712u, 0x8974836059cca109u },
332
+ { 0xe998d258869facd7u, 0x2bd1a438703fc94bu },
333
+ { 0x91ff83775423cc06u, 0x7b6306a34627ddcfu },
334
+ { 0xb67f6455292cbf08u, 0x1a3bc84c17b1d542u },
335
+ { 0xe41f3d6a7377eecau, 0x20caba5f1d9e4a93u },
336
+ { 0x8e938662882af53eu, 0x547eb47b7282ee9cu },
337
+ { 0xb23867fb2a35b28du, 0xe99e619a4f23aa43u },
338
+ { 0xdec681f9f4c31f31u, 0x6405fa00e2ec94d4u },
339
+ { 0x8b3c113c38f9f37eu, 0xde83bc408dd3dd04u },
340
+ { 0xae0b158b4738705eu, 0x9624ab50b148d445u },
341
+ { 0xd98ddaee19068c76u, 0x3badd624dd9b0957u },
342
+ { 0x87f8a8d4cfa417c9u, 0xe54ca5d70a80e5d6u },
343
+ { 0xa9f6d30a038d1dbcu, 0x5e9fcf4ccd211f4cu },
344
+ { 0xd47487cc8470652bu, 0x7647c3200069671fu },
345
+ { 0x84c8d4dfd2c63f3bu, 0x29ecd9f40041e073u },
346
+ { 0xa5fb0a17c777cf09u, 0xf468107100525890u },
347
+ { 0xcf79cc9db955c2ccu, 0x7182148d4066eeb4u },
348
+ { 0x81ac1fe293d599bfu, 0xc6f14cd848405530u },
349
+ { 0xa21727db38cb002fu, 0xb8ada00e5a506a7cu },
350
+ { 0xca9cf1d206fdc03bu, 0xa6d90811f0e4851cu },
351
+ { 0xfd442e4688bd304au, 0x908f4a166d1da663u },
352
+ { 0x9e4a9cec15763e2eu, 0x9a598e4e043287feu },
353
+ { 0xc5dd44271ad3cdbau, 0x40eff1e1853f29fdu },
354
+ { 0xf7549530e188c128u, 0xd12bee59e68ef47cu },
355
+ { 0x9a94dd3e8cf578b9u, 0x82bb74f8301958ceu },
356
+ { 0xc13a148e3032d6e7u, 0xe36a52363c1faf01u },
357
+ { 0xf18899b1bc3f8ca1u, 0xdc44e6c3cb279ac1u },
358
+ { 0x96f5600f15a7b7e5u, 0x29ab103a5ef8c0b9u },
359
+ { 0xbcb2b812db11a5deu, 0x7415d448f6b6f0e7u },
360
+ { 0xebdf661791d60f56u, 0x111b495b3464ad21u },
361
+ { 0x936b9fcebb25c995u, 0xcab10dd900beec34u },
362
+ { 0xb84687c269ef3bfbu, 0x3d5d514f40eea742u },
363
+ { 0xe65829b3046b0afau, 0x0cb4a5a3112a5112u },
364
+ { 0x8ff71a0fe2c2e6dcu, 0x47f0e785eaba72abu },
365
+ { 0xb3f4e093db73a093u, 0x59ed216765690f56u },
366
+ { 0xe0f218b8d25088b8u, 0x306869c13ec3532cu },
367
+ { 0x8c974f7383725573u, 0x1e414218c73a13fbu },
368
+ { 0xafbd2350644eeacfu, 0xe5d1929ef90898fau },
369
+ { 0xdbac6c247d62a583u, 0xdf45f746b74abf39u },
370
+ { 0x894bc396ce5da772u, 0x6b8bba8c328eb783u },
371
+ { 0xab9eb47c81f5114fu, 0x066ea92f3f326564u },
372
+ { 0xd686619ba27255a2u, 0xc80a537b0efefebdu },
373
+ { 0x8613fd0145877585u, 0xbd06742ce95f5f36u },
374
+ { 0xa798fc4196e952e7u, 0x2c48113823b73704u },
375
+ { 0xd17f3b51fca3a7a0u, 0xf75a15862ca504c5u },
376
+ { 0x82ef85133de648c4u, 0x9a984d73dbe722fbu },
377
+ { 0xa3ab66580d5fdaf5u, 0xc13e60d0d2e0ebbau },
378
+ { 0xcc963fee10b7d1b3u, 0x318df905079926a8u },
379
+ { 0xffbbcfe994e5c61fu, 0xfdf17746497f7052u },
380
+ { 0x9fd561f1fd0f9bd3u, 0xfeb6ea8bedefa633u },
381
+ { 0xc7caba6e7c5382c8u, 0xfe64a52ee96b8fc0u },
382
+ { 0xf9bd690a1b68637bu, 0x3dfdce7aa3c673b0u },
383
+ { 0x9c1661a651213e2du, 0x06bea10ca65c084eu },
384
+ { 0xc31bfa0fe5698db8u, 0x486e494fcff30a62u },
385
+ { 0xf3e2f893dec3f126u, 0x5a89dba3c3efccfau },
386
+ { 0x986ddb5c6b3a76b7u, 0xf89629465a75e01cu },
387
+ { 0xbe89523386091465u, 0xf6bbb397f1135823u },
388
+ { 0xee2ba6c0678b597fu, 0x746aa07ded582e2cu },
389
+ { 0x94db483840b717efu, 0xa8c2a44eb4571cdcu },
390
+ { 0xba121a4650e4ddebu, 0x92f34d62616ce413u },
391
+ { 0xe896a0d7e51e1566u, 0x77b020baf9c81d17u },
392
+ { 0x915e2486ef32cd60u, 0x0ace1474dc1d122eu },
393
+ { 0xb5b5ada8aaff80b8u, 0x0d819992132456bau },
394
+ { 0xe3231912d5bf60e6u, 0x10e1fff697ed6c69u },
395
+ { 0x8df5efabc5979c8fu, 0xca8d3ffa1ef463c1u },
396
+ { 0xb1736b96b6fd83b3u, 0xbd308ff8a6b17cb2u },
397
+ { 0xddd0467c64bce4a0u, 0xac7cb3f6d05ddbdeu },
398
+ { 0x8aa22c0dbef60ee4u, 0x6bcdf07a423aa96bu },
399
+ { 0xad4ab7112eb3929du, 0x86c16c98d2c953c6u },
400
+ { 0xd89d64d57a607744u, 0xe871c7bf077ba8b7u },
401
+ { 0x87625f056c7c4a8bu, 0x11471cd764ad4972u },
402
+ { 0xa93af6c6c79b5d2du, 0xd598e40d3dd89bcfu },
403
+ { 0xd389b47879823479u, 0x4aff1d108d4ec2c3u },
404
+ { 0x843610cb4bf160cbu, 0xcedf722a585139bau },
405
+ { 0xa54394fe1eedb8feu, 0xc2974eb4ee658828u },
406
+ { 0xce947a3da6a9273eu, 0x733d226229feea32u },
407
+ { 0x811ccc668829b887u, 0x0806357d5a3f525fu },
408
+ { 0xa163ff802a3426a8u, 0xca07c2dcb0cf26f7u },
409
+ { 0xc9bcff6034c13052u, 0xfc89b393dd02f0b5u },
410
+ { 0xfc2c3f3841f17c67u, 0xbbac2078d443ace2u },
411
+ { 0x9d9ba7832936edc0u, 0xd54b944b84aa4c0du },
412
+ { 0xc5029163f384a931u, 0x0a9e795e65d4df11u },
413
+ { 0xf64335bcf065d37du, 0x4d4617b5ff4a16d5u },
414
+ { 0x99ea0196163fa42eu, 0x504bced1bf8e4e45u },
415
+ { 0xc06481fb9bcf8d39u, 0xe45ec2862f71e1d6u },
416
+ { 0xf07da27a82c37088u, 0x5d767327bb4e5a4cu },
417
+ { 0x964e858c91ba2655u, 0x3a6a07f8d510f86fu },
418
+ { 0xbbe226efb628afeau, 0x890489f70a55368bu },
419
+ { 0xeadab0aba3b2dbe5u, 0x2b45ac74ccea842eu },
420
+ { 0x92c8ae6b464fc96fu, 0x3b0b8bc90012929du },
421
+ { 0xb77ada0617e3bbcbu, 0x09ce6ebb40173744u },
422
+ { 0xe55990879ddcaabdu, 0xcc420a6a101d0515u },
423
+ { 0x8f57fa54c2a9eab6u, 0x9fa946824a12232du },
424
+ { 0xb32df8e9f3546564u, 0x47939822dc96abf9u },
425
+ { 0xdff9772470297ebdu, 0x59787e2b93bc56f7u },
426
+ { 0x8bfbea76c619ef36u, 0x57eb4edb3c55b65au },
427
+ { 0xaefae51477a06b03u, 0xede622920b6b23f1u },
428
+ { 0xdab99e59958885c4u, 0xe95fab368e45ecedu },
429
+ { 0x88b402f7fd75539bu, 0x11dbcb0218ebb414u },
430
+ { 0xaae103b5fcd2a881u, 0xd652bdc29f26a119u },
431
+ { 0xd59944a37c0752a2u, 0x4be76d3346f0495fu },
432
+ { 0x857fcae62d8493a5u, 0x6f70a4400c562ddbu },
433
+ { 0xa6dfbd9fb8e5b88eu, 0xcb4ccd500f6bb952u },
434
+ { 0xd097ad07a71f26b2u, 0x7e2000a41346a7a7u },
435
+ { 0x825ecc24c873782fu, 0x8ed400668c0c28c8u },
436
+ { 0xa2f67f2dfa90563bu, 0x728900802f0f32fau },
437
+ { 0xcbb41ef979346bcau, 0x4f2b40a03ad2ffb9u },
438
+ { 0xfea126b7d78186bcu, 0xe2f610c84987bfa8u },
439
+ { 0x9f24b832e6b0f436u, 0x0dd9ca7d2df4d7c9u },
440
+ { 0xc6ede63fa05d3143u, 0x91503d1c79720dbbu },
441
+ { 0xf8a95fcf88747d94u, 0x75a44c6397ce912au },
442
+ { 0x9b69dbe1b548ce7cu, 0xc986afbe3ee11abau },
443
+ { 0xc24452da229b021bu, 0xfbe85badce996168u },
444
+ { 0xf2d56790ab41c2a2u, 0xfae27299423fb9c3u },
445
+ { 0x97c560ba6b0919a5u, 0xdccd879fc967d41au },
446
+ { 0xbdb6b8e905cb600fu, 0x5400e987bbc1c920u },
447
+ { 0xed246723473e3813u, 0x290123e9aab23b68u },
448
+ { 0x9436c0760c86e30bu, 0xf9a0b6720aaf6521u },
449
+ { 0xb94470938fa89bceu, 0xf808e40e8d5b3e69u },
450
+ { 0xe7958cb87392c2c2u, 0xb60b1d1230b20e04u },
451
+ { 0x90bd77f3483bb9b9u, 0xb1c6f22b5e6f48c2u },
452
+ { 0xb4ecd5f01a4aa828u, 0x1e38aeb6360b1af3u },
453
+ { 0xe2280b6c20dd5232u, 0x25c6da63c38de1b0u },
454
+ { 0x8d590723948a535fu, 0x579c487e5a38ad0eu },
455
+ { 0xb0af48ec79ace837u, 0x2d835a9df0c6d851u },
456
+ { 0xdcdb1b2798182244u, 0xf8e431456cf88e65u },
457
+ { 0x8a08f0f8bf0f156bu, 0x1b8e9ecb641b58ffu },
458
+ { 0xac8b2d36eed2dac5u, 0xe272467e3d222f3fu },
459
+ { 0xd7adf884aa879177u, 0x5b0ed81dcc6abb0fu },
460
+ { 0x86ccbb52ea94baeau, 0x98e947129fc2b4e9u },
461
+ { 0xa87fea27a539e9a5u, 0x3f2398d747b36224u },
462
+ { 0xd29fe4b18e88640eu, 0x8eec7f0d19a03aadu },
463
+ { 0x83a3eeeef9153e89u, 0x1953cf68300424acu },
464
+ { 0xa48ceaaab75a8e2bu, 0x5fa8c3423c052dd7u },
465
+ { 0xcdb02555653131b6u, 0x3792f412cb06794du },
466
+ { 0x808e17555f3ebf11u, 0xe2bbd88bbee40bd0u },
467
+ { 0xa0b19d2ab70e6ed6u, 0x5b6aceaeae9d0ec4u },
468
+ { 0xc8de047564d20a8bu, 0xf245825a5a445275u },
469
+ { 0xfb158592be068d2eu, 0xeed6e2f0f0d56712u },
470
+ { 0x9ced737bb6c4183du, 0x55464dd69685606bu },
471
+ { 0xc428d05aa4751e4cu, 0xaa97e14c3c26b886u },
472
+ { 0xf53304714d9265dfu, 0xd53dd99f4b3066a8u },
473
+ { 0x993fe2c6d07b7fabu, 0xe546a8038efe4029u },
474
+ { 0xbf8fdb78849a5f96u, 0xde98520472bdd033u },
475
+ { 0xef73d256a5c0f77cu, 0x963e66858f6d4440u },
476
+ { 0x95a8637627989aadu, 0xdde7001379a44aa8u },
477
+ { 0xbb127c53b17ec159u, 0x5560c018580d5d52u },
478
+ { 0xe9d71b689dde71afu, 0xaab8f01e6e10b4a6u },
479
+ { 0x9226712162ab070du, 0xcab3961304ca70e8u },
480
+ { 0xb6b00d69bb55c8d1u, 0x3d607b97c5fd0d22u },
481
+ { 0xe45c10c42a2b3b05u, 0x8cb89a7db77c506au },
482
+ { 0x8eb98a7a9a5b04e3u, 0x77f3608e92adb242u },
483
+ { 0xb267ed1940f1c61cu, 0x55f038b237591ed3u },
484
+ { 0xdf01e85f912e37a3u, 0x6b6c46dec52f6688u },
485
+ { 0x8b61313bbabce2c6u, 0x2323ac4b3b3da015u },
486
+ { 0xae397d8aa96c1b77u, 0xabec975e0a0d081au },
487
+ { 0xd9c7dced53c72255u, 0x96e7bd358c904a21u },
488
+ { 0x881cea14545c7575u, 0x7e50d64177da2e54u },
489
+ { 0xaa242499697392d2u, 0xdde50bd1d5d0b9e9u },
490
+ { 0xd4ad2dbfc3d07787u, 0x955e4ec64b44e864u },
491
+ { 0x84ec3c97da624ab4u, 0xbd5af13bef0b113eu },
492
+ { 0xa6274bbdd0fadd61u, 0xecb1ad8aeacdd58eu },
493
+ { 0xcfb11ead453994bau, 0x67de18eda5814af2u },
494
+ { 0x81ceb32c4b43fcf4u, 0x80eacf948770ced7u },
495
+ { 0xa2425ff75e14fc31u, 0xa1258379a94d028du },
496
+ { 0xcad2f7f5359a3b3eu, 0x096ee45813a04330u },
497
+ { 0xfd87b5f28300ca0du, 0x8bca9d6e188853fcu },
498
+ { 0x9e74d1b791e07e48u, 0x775ea264cf55347du },
499
+ { 0xc612062576589ddau, 0x95364afe032a819du },
500
+ { 0xf79687aed3eec551u, 0x3a83ddbd83f52204u },
501
+ { 0x9abe14cd44753b52u, 0xc4926a9672793542u },
502
+ { 0xc16d9a0095928a27u, 0x75b7053c0f178293u },
503
+ { 0xf1c90080baf72cb1u, 0x5324c68b12dd6338u },
504
+ { 0x971da05074da7beeu, 0xd3f6fc16ebca5e03u },
505
+ { 0xbce5086492111aeau, 0x88f4bb1ca6bcf584u },
506
+ { 0xec1e4a7db69561a5u, 0x2b31e9e3d06c32e5u },
507
+ { 0x9392ee8e921d5d07u, 0x3aff322e62439fcfu },
508
+ { 0xb877aa3236a4b449u, 0x09befeb9fad487c2u },
509
+ { 0xe69594bec44de15bu, 0x4c2ebe687989a9b3u },
510
+ { 0x901d7cf73ab0acd9u, 0x0f9d37014bf60a10u },
511
+ { 0xb424dc35095cd80fu, 0x538484c19ef38c94u },
512
+ { 0xe12e13424bb40e13u, 0x2865a5f206b06fb9u },
513
+ { 0x8cbccc096f5088cbu, 0xf93f87b7442e45d3u },
514
+ { 0xafebff0bcb24aafeu, 0xf78f69a51539d748u },
515
+ { 0xdbe6fecebdedd5beu, 0xb573440e5a884d1bu },
516
+ { 0x89705f4136b4a597u, 0x31680a88f8953030u },
517
+ { 0xabcc77118461cefcu, 0xfdc20d2b36ba7c3du },
518
+ { 0xd6bf94d5e57a42bcu, 0x3d32907604691b4cu },
519
+ { 0x8637bd05af6c69b5u, 0xa63f9a49c2c1b10fu },
520
+ { 0xa7c5ac471b478423u, 0x0fcf80dc33721d53u },
521
+ { 0xd1b71758e219652bu, 0xd3c36113404ea4a8u },
522
+ { 0x83126e978d4fdf3bu, 0x645a1cac083126e9u },
523
+ { 0xa3d70a3d70a3d70au, 0x3d70a3d70a3d70a3u },
524
+ { 0xccccccccccccccccu, 0xccccccccccccccccu },
525
+ { 0x8000000000000000u, 0x0000000000000000u },
526
+ { 0xa000000000000000u, 0x0000000000000000u },
527
+ { 0xc800000000000000u, 0x0000000000000000u },
528
+ { 0xfa00000000000000u, 0x0000000000000000u },
529
+ { 0x9c40000000000000u, 0x0000000000000000u },
530
+ { 0xc350000000000000u, 0x0000000000000000u },
531
+ { 0xf424000000000000u, 0x0000000000000000u },
532
+ { 0x9896800000000000u, 0x0000000000000000u },
533
+ { 0xbebc200000000000u, 0x0000000000000000u },
534
+ { 0xee6b280000000000u, 0x0000000000000000u },
535
+ { 0x9502f90000000000u, 0x0000000000000000u },
536
+ { 0xba43b74000000000u, 0x0000000000000000u },
537
+ { 0xe8d4a51000000000u, 0x0000000000000000u },
538
+ { 0x9184e72a00000000u, 0x0000000000000000u },
539
+ { 0xb5e620f480000000u, 0x0000000000000000u },
540
+ { 0xe35fa931a0000000u, 0x0000000000000000u },
541
+ { 0x8e1bc9bf04000000u, 0x0000000000000000u },
542
+ { 0xb1a2bc2ec5000000u, 0x0000000000000000u },
543
+ { 0xde0b6b3a76400000u, 0x0000000000000000u },
544
+ { 0x8ac7230489e80000u, 0x0000000000000000u },
545
+ { 0xad78ebc5ac620000u, 0x0000000000000000u },
546
+ { 0xd8d726b7177a8000u, 0x0000000000000000u },
547
+ { 0x878678326eac9000u, 0x0000000000000000u },
548
+ { 0xa968163f0a57b400u, 0x0000000000000000u },
549
+ { 0xd3c21bcecceda100u, 0x0000000000000000u },
550
+ { 0x84595161401484a0u, 0x0000000000000000u },
551
+ { 0xa56fa5b99019a5c8u, 0x0000000000000000u },
552
+ { 0xcecb8f27f4200f3au, 0x0000000000000000u },
553
+ { 0x813f3978f8940984u, 0x4000000000000000u },
554
+ { 0xa18f07d736b90be5u, 0x5000000000000000u },
555
+ { 0xc9f2c9cd04674edeu, 0xa400000000000000u },
556
+ { 0xfc6f7c4045812296u, 0x4d00000000000000u },
557
+ { 0x9dc5ada82b70b59du, 0xf020000000000000u },
558
+ { 0xc5371912364ce305u, 0x6c28000000000000u },
559
+ { 0xf684df56c3e01bc6u, 0xc732000000000000u },
560
+ { 0x9a130b963a6c115cu, 0x3c7f400000000000u },
561
+ { 0xc097ce7bc90715b3u, 0x4b9f100000000000u },
562
+ { 0xf0bdc21abb48db20u, 0x1e86d40000000000u },
563
+ { 0x96769950b50d88f4u, 0x1314448000000000u },
564
+ { 0xbc143fa4e250eb31u, 0x17d955a000000000u },
565
+ { 0xeb194f8e1ae525fdu, 0x5dcfab0800000000u },
566
+ { 0x92efd1b8d0cf37beu, 0x5aa1cae500000000u },
567
+ { 0xb7abc627050305adu, 0xf14a3d9e40000000u },
568
+ { 0xe596b7b0c643c719u, 0x6d9ccd05d0000000u },
569
+ { 0x8f7e32ce7bea5c6fu, 0xe4820023a2000000u },
570
+ { 0xb35dbf821ae4f38bu, 0xdda2802c8a800000u },
571
+ { 0xe0352f62a19e306eu, 0xd50b2037ad200000u },
572
+ { 0x8c213d9da502de45u, 0x4526f422cc340000u },
573
+ { 0xaf298d050e4395d6u, 0x9670b12b7f410000u },
574
+ { 0xdaf3f04651d47b4cu, 0x3c0cdd765f114000u },
575
+ { 0x88d8762bf324cd0fu, 0xa5880a69fb6ac800u },
576
+ { 0xab0e93b6efee0053u, 0x8eea0d047a457a00u },
577
+ { 0xd5d238a4abe98068u, 0x72a4904598d6d880u },
578
+ { 0x85a36366eb71f041u, 0x47a6da2b7f864750u },
579
+ { 0xa70c3c40a64e6c51u, 0x999090b65f67d924u },
580
+ { 0xd0cf4b50cfe20765u, 0xfff4b4e3f741cf6du },
581
+ { 0x82818f1281ed449fu, 0xbff8f10e7a8921a4u },
582
+ { 0xa321f2d7226895c7u, 0xaff72d52192b6a0du },
583
+ { 0xcbea6f8ceb02bb39u, 0x9bf4f8a69f764490u },
584
+ { 0xfee50b7025c36a08u, 0x02f236d04753d5b4u },
585
+ { 0x9f4f2726179a2245u, 0x01d762422c946590u },
586
+ { 0xc722f0ef9d80aad6u, 0x424d3ad2b7b97ef5u },
587
+ { 0xf8ebad2b84e0d58bu, 0xd2e0898765a7deb2u },
588
+ { 0x9b934c3b330c8577u, 0x63cc55f49f88eb2fu },
589
+ { 0xc2781f49ffcfa6d5u, 0x3cbf6b71c76b25fbu },
590
+ { 0xf316271c7fc3908au, 0x8bef464e3945ef7au },
591
+ { 0x97edd871cfda3a56u, 0x97758bf0e3cbb5acu },
592
+ { 0xbde94e8e43d0c8ecu, 0x3d52eeed1cbea317u },
593
+ { 0xed63a231d4c4fb27u, 0x4ca7aaa863ee4bddu },
594
+ { 0x945e455f24fb1cf8u, 0x8fe8caa93e74ef6au },
595
+ { 0xb975d6b6ee39e436u, 0xb3e2fd538e122b44u },
596
+ { 0xe7d34c64a9c85d44u, 0x60dbbca87196b616u },
597
+ { 0x90e40fbeea1d3a4au, 0xbc8955e946fe31cdu },
598
+ { 0xb51d13aea4a488ddu, 0x6babab6398bdbe41u },
599
+ { 0xe264589a4dcdab14u, 0xc696963c7eed2dd1u },
600
+ { 0x8d7eb76070a08aecu, 0xfc1e1de5cf543ca2u },
601
+ { 0xb0de65388cc8ada8u, 0x3b25a55f43294bcbu },
602
+ { 0xdd15fe86affad912u, 0x49ef0eb713f39ebeu },
603
+ { 0x8a2dbf142dfcc7abu, 0x6e3569326c784337u },
604
+ { 0xacb92ed9397bf996u, 0x49c2c37f07965404u },
605
+ { 0xd7e77a8f87daf7fbu, 0xdc33745ec97be906u },
606
+ { 0x86f0ac99b4e8dafdu, 0x69a028bb3ded71a3u },
607
+ { 0xa8acd7c0222311bcu, 0xc40832ea0d68ce0cu },
608
+ { 0xd2d80db02aabd62bu, 0xf50a3fa490c30190u },
609
+ { 0x83c7088e1aab65dbu, 0x792667c6da79e0fau },
610
+ { 0xa4b8cab1a1563f52u, 0x577001b891185938u },
611
+ { 0xcde6fd5e09abcf26u, 0xed4c0226b55e6f86u },
612
+ { 0x80b05e5ac60b6178u, 0x544f8158315b05b4u },
613
+ { 0xa0dc75f1778e39d6u, 0x696361ae3db1c721u },
614
+ { 0xc913936dd571c84cu, 0x03bc3a19cd1e38e9u },
615
+ { 0xfb5878494ace3a5fu, 0x04ab48a04065c723u },
616
+ { 0x9d174b2dcec0e47bu, 0x62eb0d64283f9c76u },
617
+ { 0xc45d1df942711d9au, 0x3ba5d0bd324f8394u },
618
+ { 0xf5746577930d6500u, 0xca8f44ec7ee36479u },
619
+ { 0x9968bf6abbe85f20u, 0x7e998b13cf4e1ecbu },
620
+ { 0xbfc2ef456ae276e8u, 0x9e3fedd8c321a67eu },
621
+ { 0xefb3ab16c59b14a2u, 0xc5cfe94ef3ea101eu },
622
+ { 0x95d04aee3b80ece5u, 0xbba1f1d158724a12u },
623
+ { 0xbb445da9ca61281fu, 0x2a8a6e45ae8edc97u },
624
+ { 0xea1575143cf97226u, 0xf52d09d71a3293bdu },
625
+ { 0x924d692ca61be758u, 0x593c2626705f9c56u },
626
+ { 0xb6e0c377cfa2e12eu, 0x6f8b2fb00c77836cu },
627
+ { 0xe498f455c38b997au, 0x0b6dfb9c0f956447u },
628
+ { 0x8edf98b59a373fecu, 0x4724bd4189bd5eacu },
629
+ { 0xb2977ee300c50fe7u, 0x58edec91ec2cb657u },
630
+ { 0xdf3d5e9bc0f653e1u, 0x2f2967b66737e3edu },
631
+ { 0x8b865b215899f46cu, 0xbd79e0d20082ee74u },
632
+ { 0xae67f1e9aec07187u, 0xecd8590680a3aa11u },
633
+ { 0xda01ee641a708de9u, 0xe80e6f4820cc9495u },
634
+ { 0x884134fe908658b2u, 0x3109058d147fdcddu },
635
+ { 0xaa51823e34a7eedeu, 0xbd4b46f0599fd415u },
636
+ { 0xd4e5e2cdc1d1ea96u, 0x6c9e18ac7007c91au },
637
+ { 0x850fadc09923329eu, 0x03e2cf6bc604ddb0u },
638
+ { 0xa6539930bf6bff45u, 0x84db8346b786151cu },
639
+ { 0xcfe87f7cef46ff16u, 0xe612641865679a63u },
640
+ { 0x81f14fae158c5f6eu, 0x4fcb7e8f3f60c07eu },
641
+ { 0xa26da3999aef7749u, 0xe3be5e330f38f09du },
642
+ { 0xcb090c8001ab551cu, 0x5cadf5bfd3072cc5u },
643
+ { 0xfdcb4fa002162a63u, 0x73d9732fc7c8f7f6u },
644
+ { 0x9e9f11c4014dda7eu, 0x2867e7fddcdd9afau },
645
+ { 0xc646d63501a1511du, 0xb281e1fd541501b8u },
646
+ { 0xf7d88bc24209a565u, 0x1f225a7ca91a4226u },
647
+ { 0x9ae757596946075fu, 0x3375788de9b06958u },
648
+ { 0xc1a12d2fc3978937u, 0x0052d6b1641c83aeu },
649
+ { 0xf209787bb47d6b84u, 0xc0678c5dbd23a49au },
650
+ { 0x9745eb4d50ce6332u, 0xf840b7ba963646e0u },
651
+ { 0xbd176620a501fbffu, 0xb650e5a93bc3d898u },
652
+ { 0xec5d3fa8ce427affu, 0xa3e51f138ab4cebeu },
653
+ { 0x93ba47c980e98cdfu, 0xc66f336c36b10137u },
654
+ { 0xb8a8d9bbe123f017u, 0xb80b0047445d4184u },
655
+ { 0xe6d3102ad96cec1du, 0xa60dc059157491e5u },
656
+ { 0x9043ea1ac7e41392u, 0x87c89837ad68db2fu },
657
+ { 0xb454e4a179dd1877u, 0x29babe4598c311fbu },
658
+ { 0xe16a1dc9d8545e94u, 0xf4296dd6fef3d67au },
659
+ { 0x8ce2529e2734bb1du, 0x1899e4a65f58660cu },
660
+ { 0xb01ae745b101e9e4u, 0x5ec05dcff72e7f8fu },
661
+ { 0xdc21a1171d42645du, 0x76707543f4fa1f73u },
662
+ { 0x899504ae72497ebau, 0x6a06494a791c53a8u },
663
+ { 0xabfa45da0edbde69u, 0x0487db9d17636892u },
664
+ { 0xd6f8d7509292d603u, 0x45a9d2845d3c42b6u },
665
+ { 0x865b86925b9bc5c2u, 0x0b8a2392ba45a9b2u },
666
+ { 0xa7f26836f282b732u, 0x8e6cac7768d7141eu },
667
+ { 0xd1ef0244af2364ffu, 0x3207d795430cd926u },
668
+ { 0x8335616aed761f1fu, 0x7f44e6bd49e807b8u },
669
+ { 0xa402b9c5a8d3a6e7u, 0x5f16206c9c6209a6u },
670
+ { 0xcd036837130890a1u, 0x36dba887c37a8c0fu },
671
+ { 0x802221226be55a64u, 0xc2494954da2c9789u },
672
+ { 0xa02aa96b06deb0fdu, 0xf2db9baa10b7bd6cu },
673
+ { 0xc83553c5c8965d3du, 0x6f92829494e5acc7u },
674
+ { 0xfa42a8b73abbf48cu, 0xcb772339ba1f17f9u },
675
+ { 0x9c69a97284b578d7u, 0xff2a760414536efbu },
676
+ { 0xc38413cf25e2d70du, 0xfef5138519684abau },
677
+ { 0xf46518c2ef5b8cd1u, 0x7eb258665fc25d69u },
678
+ { 0x98bf2f79d5993802u, 0xef2f773ffbd97a61u },
679
+ { 0xbeeefb584aff8603u, 0xaafb550ffacfd8fau },
680
+ { 0xeeaaba2e5dbf6784u, 0x95ba2a53f983cf38u },
681
+ { 0x952ab45cfa97a0b2u, 0xdd945a747bf26183u },
682
+ { 0xba756174393d88dfu, 0x94f971119aeef9e4u },
683
+ { 0xe912b9d1478ceb17u, 0x7a37cd5601aab85du },
684
+ { 0x91abb422ccb812eeu, 0xac62e055c10ab33au },
685
+ { 0xb616a12b7fe617aau, 0x577b986b314d6009u },
686
+ { 0xe39c49765fdf9d94u, 0xed5a7e85fda0b80bu },
687
+ { 0x8e41ade9fbebc27du, 0x14588f13be847307u },
688
+ { 0xb1d219647ae6b31cu, 0x596eb2d8ae258fc8u },
689
+ { 0xde469fbd99a05fe3u, 0x6fca5f8ed9aef3bbu },
690
+ { 0x8aec23d680043beeu, 0x25de7bb9480d5854u },
691
+ { 0xada72ccc20054ae9u, 0xaf561aa79a10ae6au },
692
+ { 0xd910f7ff28069da4u, 0x1b2ba1518094da04u },
693
+ { 0x87aa9aff79042286u, 0x90fb44d2f05d0842u },
694
+ { 0xa99541bf57452b28u, 0x353a1607ac744a53u },
695
+ { 0xd3fa922f2d1675f2u, 0x42889b8997915ce8u },
696
+ { 0x847c9b5d7c2e09b7u, 0x69956135febada11u },
697
+ { 0xa59bc234db398c25u, 0x43fab9837e699095u },
698
+ { 0xcf02b2c21207ef2eu, 0x94f967e45e03f4bbu },
699
+ { 0x8161afb94b44f57du, 0x1d1be0eebac278f5u },
700
+ { 0xa1ba1ba79e1632dcu, 0x6462d92a69731732u },
701
+ { 0xca28a291859bbf93u, 0x7d7b8f7503cfdcfeu },
702
+ { 0xfcb2cb35e702af78u, 0x5cda735244c3d43eu },
703
+ { 0x9defbf01b061adabu, 0x3a0888136afa64a7u },
704
+ { 0xc56baec21c7a1916u, 0x088aaa1845b8fdd0u },
705
+ { 0xf6c69a72a3989f5bu, 0x8aad549e57273d45u },
706
+ { 0x9a3c2087a63f6399u, 0x36ac54e2f678864bu },
707
+ { 0xc0cb28a98fcf3c7fu, 0x84576a1bb416a7ddu },
708
+ { 0xf0fdf2d3f3c30b9fu, 0x656d44a2a11c51d5u },
709
+ { 0x969eb7c47859e743u, 0x9f644ae5a4b1b325u },
710
+ { 0xbc4665b596706114u, 0x873d5d9f0dde1feeu },
711
+ { 0xeb57ff22fc0c7959u, 0xa90cb506d155a7eau },
712
+ { 0x9316ff75dd87cbd8u, 0x09a7f12442d588f2u },
713
+ { 0xb7dcbf5354e9beceu, 0x0c11ed6d538aeb2fu },
714
+ { 0xe5d3ef282a242e81u, 0x8f1668c8a86da5fau },
715
+ { 0x8fa475791a569d10u, 0xf96e017d694487bcu },
716
+ { 0xb38d92d760ec4455u, 0x37c981dcc395a9acu },
717
+ { 0xe070f78d3927556au, 0x85bbe253f47b1417u },
718
+ { 0x8c469ab843b89562u, 0x93956d7478ccec8eu },
719
+ { 0xaf58416654a6babbu, 0x387ac8d1970027b2u },
720
+ { 0xdb2e51bfe9d0696au, 0x06997b05fcc0319eu },
721
+ { 0x88fcf317f22241e2u, 0x441fece3bdf81f03u },
722
+ { 0xab3c2fddeeaad25au, 0xd527e81cad7626c3u },
723
+ { 0xd60b3bd56a5586f1u, 0x8a71e223d8d3b074u },
724
+ { 0x85c7056562757456u, 0xf6872d5667844e49u },
725
+ { 0xa738c6bebb12d16cu, 0xb428f8ac016561dbu },
726
+ { 0xd106f86e69d785c7u, 0xe13336d701beba52u },
727
+ { 0x82a45b450226b39cu, 0xecc0024661173473u },
728
+ { 0xa34d721642b06084u, 0x27f002d7f95d0190u },
729
+ { 0xcc20ce9bd35c78a5u, 0x31ec038df7b441f4u },
730
+ { 0xff290242c83396ceu, 0x7e67047175a15271u },
731
+ { 0x9f79a169bd203e41u, 0x0f0062c6e984d386u },
732
+ { 0xc75809c42c684dd1u, 0x52c07b78a3e60868u },
733
+ { 0xf92e0c3537826145u, 0xa7709a56ccdf8a82u },
734
+ { 0x9bbcc7a142b17ccbu, 0x88a66076400bb691u },
735
+ { 0xc2abf989935ddbfeu, 0x6acff893d00ea435u },
736
+ { 0xf356f7ebf83552feu, 0x0583f6b8c4124d43u },
737
+ { 0x98165af37b2153deu, 0xc3727a337a8b704au },
738
+ { 0xbe1bf1b059e9a8d6u, 0x744f18c0592e4c5cu },
739
+ { 0xeda2ee1c7064130cu, 0x1162def06f79df73u },
740
+ { 0x9485d4d1c63e8be7u, 0x8addcb5645ac2ba8u },
741
+ { 0xb9a74a0637ce2ee1u, 0x6d953e2bd7173692u },
742
+ { 0xe8111c87c5c1ba99u, 0xc8fa8db6ccdd0437u },
743
+ { 0x910ab1d4db9914a0u, 0x1d9c9892400a22a2u },
744
+ { 0xb54d5e4a127f59c8u, 0x2503beb6d00cab4bu },
745
+ { 0xe2a0b5dc971f303au, 0x2e44ae64840fd61du },
746
+ { 0x8da471a9de737e24u, 0x5ceaecfed289e5d2u },
747
+ { 0xb10d8e1456105dadu, 0x7425a83e872c5f47u },
748
+ { 0xdd50f1996b947518u, 0xd12f124e28f77719u },
749
+ { 0x8a5296ffe33cc92fu, 0x82bd6b70d99aaa6fu },
750
+ { 0xace73cbfdc0bfb7bu, 0x636cc64d1001550bu },
751
+ { 0xd8210befd30efa5au, 0x3c47f7e05401aa4eu },
752
+ { 0x8714a775e3e95c78u, 0x65acfaec34810a71u },
753
+ { 0xa8d9d1535ce3b396u, 0x7f1839a741a14d0du },
754
+ { 0xd31045a8341ca07cu, 0x1ede48111209a050u },
755
+ { 0x83ea2b892091e44du, 0x934aed0aab460432u },
756
+ { 0xa4e4b66b68b65d60u, 0xf81da84d5617853fu },
757
+ { 0xce1de40642e3f4b9u, 0x36251260ab9d668eu },
758
+ { 0x80d2ae83e9ce78f3u, 0xc1d72b7c6b426019u },
759
+ { 0xa1075a24e4421730u, 0xb24cf65b8612f81fu },
760
+ { 0xc94930ae1d529cfcu, 0xdee033f26797b627u },
761
+ { 0xfb9b7cd9a4a7443cu, 0x169840ef017da3b1u },
762
+ { 0x9d412e0806e88aa5u, 0x8e1f289560ee864eu },
763
+ { 0xc491798a08a2ad4eu, 0xf1a6f2bab92a27e2u },
764
+ { 0xf5b5d7ec8acb58a2u, 0xae10af696774b1dbu },
765
+ { 0x9991a6f3d6bf1765u, 0xacca6da1e0a8ef29u },
766
+ { 0xbff610b0cc6edd3fu, 0x17fd090a58d32af3u },
767
+ { 0xeff394dcff8a948eu, 0xddfc4b4cef07f5b0u },
768
+ { 0x95f83d0a1fb69cd9u, 0x4abdaf101564f98eu },
769
+ { 0xbb764c4ca7a4440fu, 0x9d6d1ad41abe37f1u },
770
+ { 0xea53df5fd18d5513u, 0x84c86189216dc5edu },
771
+ { 0x92746b9be2f8552cu, 0x32fd3cf5b4e49bb4u },
772
+ { 0xb7118682dbb66a77u, 0x3fbc8c33221dc2a1u },
773
+ { 0xe4d5e82392a40515u, 0x0fabaf3feaa5334au },
774
+ { 0x8f05b1163ba6832du, 0x29cb4d87f2a7400eu },
775
+ { 0xb2c71d5bca9023f8u, 0x743e20e9ef511012u },
776
+ { 0xdf78e4b2bd342cf6u, 0x914da9246b255416u },
777
+ { 0x8bab8eefb6409c1au, 0x1ad089b6c2f7548eu },
778
+ { 0xae9672aba3d0c320u, 0xa184ac2473b529b1u },
779
+ { 0xda3c0f568cc4f3e8u, 0xc9e5d72d90a2741eu },
780
+ { 0x8865899617fb1871u, 0x7e2fa67c7a658892u },
781
+ { 0xaa7eebfb9df9de8du, 0xddbb901b98feeab7u },
782
+ { 0xd51ea6fa85785631u, 0x552a74227f3ea565u },
783
+ { 0x8533285c936b35deu, 0xd53a88958f87275fu },
784
+ { 0xa67ff273b8460356u, 0x8a892abaf368f137u },
785
+ { 0xd01fef10a657842cu, 0x2d2b7569b0432d85u },
786
+ { 0x8213f56a67f6b29bu, 0x9c3b29620e29fc73u },
787
+ { 0xa298f2c501f45f42u, 0x8349f3ba91b47b8fu },
788
+ { 0xcb3f2f7642717713u, 0x241c70a936219a73u },
789
+ { 0xfe0efb53d30dd4d7u, 0xed238cd383aa0110u },
790
+ { 0x9ec95d1463e8a506u, 0xf4363804324a40aau },
791
+ { 0xc67bb4597ce2ce48u, 0xb143c6053edcd0d5u },
792
+ { 0xf81aa16fdc1b81dau, 0xdd94b7868e94050au },
793
+ { 0x9b10a4e5e9913128u, 0xca7cf2b4191c8326u },
794
+ { 0xc1d4ce1f63f57d72u, 0xfd1c2f611f63a3f0u },
795
+ { 0xf24a01a73cf2dccfu, 0xbc633b39673c8cecu },
796
+ { 0x976e41088617ca01u, 0xd5be0503e085d813u },
797
+ { 0xbd49d14aa79dbc82u, 0x4b2d8644d8a74e18u },
798
+ { 0xec9c459d51852ba2u, 0xddf8e7d60ed1219eu },
799
+ { 0x93e1ab8252f33b45u, 0xcabb90e5c942b503u },
800
+ { 0xb8da1662e7b00a17u, 0x3d6a751f3b936243u },
801
+ { 0xe7109bfba19c0c9du, 0x0cc512670a783ad4u },
802
+ { 0x906a617d450187e2u, 0x27fb2b80668b24c5u },
803
+ { 0xb484f9dc9641e9dau, 0xb1f9f660802dedf6u },
804
+ { 0xe1a63853bbd26451u, 0x5e7873f8a0396973u },
805
+ { 0x8d07e33455637eb2u, 0xdb0b487b6423e1e8u },
806
+ { 0xb049dc016abc5e5fu, 0x91ce1a9a3d2cda62u },
807
+ { 0xdc5c5301c56b75f7u, 0x7641a140cc7810fbu },
808
+ { 0x89b9b3e11b6329bau, 0xa9e904c87fcb0a9du },
809
+ { 0xac2820d9623bf429u, 0x546345fa9fbdcd44u },
810
+ { 0xd732290fbacaf133u, 0xa97c177947ad4095u },
811
+ { 0x867f59a9d4bed6c0u, 0x49ed8eabcccc485du },
812
+ { 0xa81f301449ee8c70u, 0x5c68f256bfff5a74u },
813
+ { 0xd226fc195c6a2f8cu, 0x73832eec6fff3111u },
814
+ { 0x83585d8fd9c25db7u, 0xc831fd53c5ff7eabu },
815
+ { 0xa42e74f3d032f525u, 0xba3e7ca8b77f5e55u },
816
+ { 0xcd3a1230c43fb26fu, 0x28ce1bd2e55f35ebu },
817
+ { 0x80444b5e7aa7cf85u, 0x7980d163cf5b81b3u },
818
+ { 0xa0555e361951c366u, 0xd7e105bcc332621fu },
819
+ { 0xc86ab5c39fa63440u, 0x8dd9472bf3fefaa7u },
820
+ { 0xfa856334878fc150u, 0xb14f98f6f0feb951u },
821
+ { 0x9c935e00d4b9d8d2u, 0x6ed1bf9a569f33d3u },
822
+ { 0xc3b8358109e84f07u, 0x0a862f80ec4700c8u },
823
+ { 0xf4a642e14c6262c8u, 0xcd27bb612758c0fau },
824
+ { 0x98e7e9cccfbd7dbdu, 0x8038d51cb897789cu },
825
+ { 0xbf21e44003acdd2cu, 0xe0470a63e6bd56c3u },
826
+ { 0xeeea5d5004981478u, 0x1858ccfce06cac74u },
827
+ { 0x95527a5202df0ccbu, 0x0f37801e0c43ebc8u },
828
+ { 0xbaa718e68396cffdu, 0xd30560258f54e6bau },
829
+ { 0xe950df20247c83fdu, 0x47c6b82ef32a2069u },
830
+ { 0x91d28b7416cdd27eu, 0x4cdc331d57fa5441u },
831
+ { 0xb6472e511c81471du, 0xe0133fe4adf8e952u },
832
+ { 0xe3d8f9e563a198e5u, 0x58180fddd97723a6u },
833
+ { 0x8e679c2f5e44ff8fu, 0x570f09eaa7ea7648u },
834
+ { 0xb201833b35d63f73u, 0x2cd2cc6551e513dau },
835
+ { 0xde81e40a034bcf4fu, 0xf8077f7ea65e58d1u },
836
+ { 0x8b112e86420f6191u, 0xfb04afaf27faf782u },
837
+ { 0xadd57a27d29339f6u, 0x79c5db9af1f9b563u },
838
+ { 0xd94ad8b1c7380874u, 0x18375281ae7822bcu },
839
+ { 0x87cec76f1c830548u, 0x8f2293910d0b15b5u },
840
+ { 0xa9c2794ae3a3c69au, 0xb2eb3875504ddb22u },
841
+ { 0xd433179d9c8cb841u, 0x5fa60692a46151ebu },
842
+ { 0x849feec281d7f328u, 0xdbc7c41ba6bcd333u },
843
+ { 0xa5c7ea73224deff3u, 0x12b9b522906c0800u },
844
+ { 0xcf39e50feae16befu, 0xd768226b34870a00u },
845
+ { 0x81842f29f2cce375u, 0xe6a1158300d46640u },
846
+ { 0xa1e53af46f801c53u, 0x60495ae3c1097fd0u },
847
+ { 0xca5e89b18b602368u, 0x385bb19cb14bdfc4u },
848
+ { 0xfcf62c1dee382c42u, 0x46729e03dd9ed7b5u },
849
+ };
850
+
851
+ /* The 128-bit product of `x` and `y`: the low half returned, the high in
852
+ `*hi`. A 64-bit target has the one instruction for it. wasm32 has none, and
853
+ `__uint128_t` there is a call to compiler-rt's `__multi3`, which a
854
+ freestanding link does not have, so the four 32-bit partial products are
855
+ summed here instead: the most each column can carry is below 2^64. */
856
+ static uint64_t nish_umul128(uint64_t x, uint64_t y, uint64_t *hi) {
857
+ #ifdef NISH_TEXT_FREESTANDING
858
+ uint64_t xl = (uint32_t)x, xh = x >> 32, yl = (uint32_t)y, yh = y >> 32;
859
+ uint64_t ll = xl * yl, lh = xl * yh, hl = xh * yl, hh = xh * yh;
860
+ uint64_t mid = (ll >> 32) + (uint32_t)lh + (uint32_t)hl;
861
+ *hi = hh + (lh >> 32) + (hl >> 32) + (mid >> 32);
862
+ return (mid << 32) | (uint32_t)ll;
863
+ #else
864
+ __uint128_t p = (__uint128_t)x * y;
865
+ *hi = (uint64_t)(p >> 64);
866
+ return (uint64_t)p;
867
+ #endif
868
+ }
869
+
870
+ /* The high 128 bits of the 192-bit product of `x_hi:x_lo` and `y`, dropping
871
+ the low word's carry exactly as upstream does: the table rounds down, and
872
+ the error that leaves is what the `+6` below absorbs. */
873
+ static void nish_umul192_hi128(uint64_t x_hi, uint64_t x_lo, uint64_t y,
874
+ uint64_t *hi, uint64_t *lo) {
875
+ uint64_t p_hi, p_lo = nish_umul128(x_hi, y, &p_hi), q_hi;
876
+ nish_umul128(x_lo, y, &q_hi);
877
+ uint64_t l = p_lo + q_hi;
878
+ *hi = p_hi + (l < p_lo);
879
+ *lo = l;
880
+ }
881
+
882
+ /* (x * y + c) >> 64: one decimal digit off a 64-bit fraction, biased by `c`. */
883
+ static uint64_t nish_umul128_add_hi64(uint64_t x, uint64_t y, uint64_t c) {
884
+ uint64_t hi, lo = nish_umul128(x, y, &hi);
885
+ return hi + (lo + c < lo);
886
+ }
887
+
888
+ /* The shortest digits of a finite, positive double, given as its bits, as an
889
+ integer `sig` with no trailing zeros and `*exp10` set so the value is
890
+ `sig * 10^*exp10`. `sig` has 1 to 17 digits. */
891
+ static uint64_t nish_shortest_digits(uint64_t bits, int *exp10) {
892
+ uint64_t bin_sig = bits & ((1ull << 52) - 1);
893
+ int raw_exp = (int)(bits >> 52);
894
+ /* A power of two has a lower neighbour half as far away as its upper one,
895
+ so its rounding interval is lopsided ("irregular"). 2^-1022 is the one
896
+ power that is not: the largest subnormal sits a full ulp below it. V8 and
897
+ Ryu both treat it as regular, and so does this; upstream does not, which
898
+ would need one more table row and prints the same digits. */
899
+ int regular = bin_sig != 0 || raw_exp <= 1;
900
+ if (raw_exp == 0) raw_exp = 1; /* a subnormal has 2^-1022's spacing */
901
+ else bin_sig |= 1ull << 52;
902
+ int bin_exp = raw_exp - 1075;
903
+
904
+ /* floor(log10(2^bin_exp)), or of 3/4 of it when irregular, and the shift
905
+ that puts every exponent's decimal point at the same bit. Scaling by
906
+ 10^(-dec_exp-1) rather than 10^-dec_exp lands on the shorter candidate
907
+ directly, so the extra digit comes off the fraction, not out of a div10. */
908
+ int dec_exp = (bin_exp * 315653 - (regular ? 0 : 131072)) >> 20;
909
+ int shift = bin_exp + ((-(dec_exp + 1) * 217707) >> 16) + 1 + 6;
910
+ const uint64_t *pow10 = NISH_POW10_SIG[-dec_exp - 1 - NISH_POW10_MIN];
911
+ uint64_t hi, lo;
912
+ nish_umul192_hi128(pow10[0], pow10[1], bin_sig << shift, &hi, &lo);
913
+ uint64_t integral = hi >> 6;
914
+ uint64_t fractional = (hi << 58) | (lo >> 6);
915
+
916
+ /* Half the distance to each neighbour, in the fraction's units. An even
917
+ significand's interval is closed, which is the round-half-to-even tie
918
+ rule for reading the digits back. */
919
+ uint64_t half_ulp = pow10[0] >> (7 - shift);
920
+ int round_up, round_down;
921
+ uint64_t digit;
922
+ if (regular) {
923
+ half_ulp += 1 - (bin_sig & 1);
924
+ round_up = fractional + half_ulp < fractional;
925
+ round_down = half_ulp > fractional;
926
+ /* The nearest next digit, ties to even: 0.25 is the one fraction whose
927
+ tenfold is an exact .5 that rounds the wrong way. */
928
+ digit = nish_umul128_add_hi64(fractional, 10, (1ull << 63) + 6);
929
+ if (fractional == 1ull << 62) digit = 2;
930
+ } else {
931
+ round_up = half_ulp > ~0ull - fractional;
932
+ round_down = (half_ulp >> 1) > fractional;
933
+ /* The lower neighbour is closer, so the nearest digit may fall below the
934
+ interval: take the smallest one inside it instead. */
935
+ digit = nish_umul128_add_hi64(fractional, 10, (1ull << 63) - 1);
936
+ uint64_t least = nish_umul128_add_hi64(fractional - (half_ulp >> 1), 10, ~0ull);
937
+ if (digit < least) digit = least;
938
+ }
939
+
940
+ /* When either end of the interval reaches past the shorter candidate, that
941
+ candidate (rounded toward the end that holds it) is the answer; otherwise
942
+ it takes one more digit. */
943
+ uint64_t sig = (integral + round_up) * 10 + (round_up | round_down ? 0 : digit);
944
+ int e = dec_exp;
945
+ /* At most 16 trailing zeros: `sig` is below 2^53 * 10 + 10 < 10^17. */
946
+ if (sig % 10 == 0) {
947
+ sig /= 10; e += 1;
948
+ if (sig % 100000000 == 0) { sig /= 100000000; e += 8; }
949
+ if (sig % 10000 == 0) { sig /= 10000; e += 4; }
950
+ if (sig % 100 == 0) { sig /= 100; e += 2; }
951
+ if (sig % 10 == 0) { sig /= 10; e += 1; }
952
+ }
953
+ *exp10 = e;
954
+ return sig;
955
+ }
956
+
957
+ /* "00" to "99", so the digits go out two to a lookup and two to a store. */
958
+ static const char NISH_DIGITS2[200] =
959
+ "0001020304050607080910111213141516171819"
960
+ "2021222324252627282930313233343536373839"
961
+ "4041424344454647484950515253545556575859"
962
+ "6061626364656667686970717273747576777879"
963
+ "8081828384858687888990919293949596979899";
964
+
965
+ static const uint64_t NISH_POW10_U64[18] = {
966
+ 1ull, 10ull, 100ull, 1000ull, 10000ull, 100000ull, 1000000ull, 10000000ull,
967
+ 100000000ull, 1000000000ull, 10000000000ull, 100000000000ull,
968
+ 1000000000000ull, 10000000000000ull, 100000000000000ull,
969
+ 1000000000000000ull, 10000000000000000ull, 100000000000000000ull,
970
+ };
971
+
972
+ /* The decimal digits of `v` into the bytes just before `end`, as many as it
973
+ has, written backward a pair at a time. The caller knows the count. */
974
+ static void nish_put_digits(char *end, uint64_t v) {
975
+ while (v >= 100) {
976
+ uint64_t q = v / 100;
977
+ end -= 2;
978
+ memcpy(end, NISH_DIGITS2 + 2 * (v - q * 100), 2);
979
+ v = q;
980
+ }
981
+ if (v >= 10) memcpy(end - 2, NISH_DIGITS2 + 2 * v, 2);
982
+ else end[-1] = (char)('0' + v);
983
+ }
984
+
985
+ /* runtime/nish.h and tests/runtime-test.c state the same size; tests/run.js
986
+ (`f64_format_oracle`) fails if the three disagree. */
987
+ #define NISH_F64_MAX 32
988
+
989
+ /* JS Number#toString: shortest round-trip digits, e-form outside (-6, 21].
990
+ Writes no NUL and returns the length. The longest output is 25 bytes,
991
+ -0.0000012345678901234567: a sign, "0.", five zeros and seventeen digits.
992
+ Every other layout is shorter: 22 for a 21-digit integer and its sign, 24
993
+ for -1.2345678901234567e-308, 9 for -Infinity. No layout writes scratch
994
+ past its own final length. */
995
+ int nish_f64_format(double v, char out[NISH_F64_MAX]) {
996
+ uint64_t bits;
997
+ char *o = out;
998
+ memcpy(&bits, &v, 8);
999
+ if ((bits << 1) >> 53 == 0x7ff) {
1000
+ if (bits << 12) { memcpy(o, "NaN", 3); return 3; }
1001
+ if (bits >> 63) *o++ = '-';
1002
+ memcpy(o, "Infinity", 8);
1003
+ return (int)(o - out) + 8;
1004
+ }
1005
+ if ((bits << 1) == 0) { *o = '0'; return 1; } /* -0 prints as 0 */
1006
+ if (bits >> 63) *o++ = '-';
1007
+
1008
+ int e;
1009
+ uint64_t sig = nish_shortest_digits(bits & ~(1ull << 63), &e);
1010
+ /* The digit count: 1233 / 4096 is log10(2) from below, which can only be
1011
+ one short, and the table settles it. */
1012
+ int k = ((64 - __builtin_clzll(sig)) * 1233) >> 12;
1013
+ k += sig >= NISH_POW10_U64[k];
1014
+ int n = k + e; /* value = 0.<digits> * 10^n */
1015
+
1016
+ if (n > 21 || n <= -6) {
1017
+ /* d.ddde+x: the digits one byte right, then the first moved left past
1018
+ where the point goes. */
1019
+ nish_put_digits(o + 1 + k, sig);
1020
+ o[0] = o[1];
1021
+ if (k > 1) { o[1] = '.'; o += k + 1; }
1022
+ else o += 1;
1023
+ int x = n - 1;
1024
+ *o++ = 'e';
1025
+ *o++ = x < 0 ? '-' : '+';
1026
+ if (x < 0) x = -x;
1027
+ if (x >= 100) { *o++ = (char)('0' + x / 100); x %= 100; memcpy(o, NISH_DIGITS2 + 2 * x, 2); o += 2; }
1028
+ else if (x >= 10) { memcpy(o, NISH_DIGITS2 + 2 * x, 2); o += 2; }
1029
+ else *o++ = (char)('0' + x);
1030
+ } else if (n <= 0) {
1031
+ o[0] = '0'; o[1] = '.';
1032
+ memset(o + 2, '0', (size_t)-n);
1033
+ o += 2 - n;
1034
+ nish_put_digits(o + k, sig);
1035
+ o += k;
1036
+ } else if (n >= k) {
1037
+ nish_put_digits(o + k, sig);
1038
+ memset(o + k, '0', (size_t)(n - k));
1039
+ o += n;
1040
+ } else {
1041
+ /* The integer part shifts left one byte to open the point's slot. */
1042
+ nish_put_digits(o + 1 + k, sig);
1043
+ memmove(o, o + 1, (size_t)n);
1044
+ o[n] = '.';
1045
+ o += k + 1;
1046
+ }
1047
+ return (int)(o - out);
1048
+ }
1049
+
1050
+ nish_str *nish_str_from_f64(double v) {
1051
+ char out[NISH_F64_MAX];
1052
+ return nish_str_new(out, (uint64_t)nish_f64_format(v, out));
1053
+ }
1054
+
1055
+ /* `JsonWriter.f64`'s digits straight into the writer's buffer (std/json.ts,
1056
+ `jsonPutF64Walk`; the emitter makes the call, src/kernels.ts): `v`'s
1057
+ spelling at `buf[at]`, all of it or none. Answers the new end, or -1 when
1058
+ `at` is negative or the bytes do not fit before `len`, and then writes
1059
+ nothing, as `jsonWriterPutText` does. `len` is the array's length as the
1060
+ Nish code's `toI32` reads it, which is never more than the array holds; the
1061
+ comparison is in 64 bits, so no `len` or `at` wraps it. */
1062
+ int32_t nish_json_put_f64(uint8_t *buf, int32_t len, int32_t at, double v) {
1063
+ char out[NISH_F64_MAX];
1064
+ int n = nish_f64_format(v, out);
1065
+ if (at < 0 || (int64_t)at > (int64_t)len - n) return -1;
1066
+ memcpy(buf + at, out, (size_t)n);
1067
+ return at + n;
1068
+ }