@fluffylabs/anan-as 1.2.0-e8a5af8 → 1.2.0-ef04361

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.
Files changed (102) hide show
  1. package/dist/bin/src/trace-replay.js +2 -2
  2. package/dist/build/compiler-inline.js +1 -1
  3. package/dist/build/compiler.wasm +0 -0
  4. package/dist/build/debug-inline.js +1 -1
  5. package/dist/build/debug-raw-inline.js +1 -1
  6. package/dist/build/debug-raw.d.ts +34 -98
  7. package/dist/build/debug-raw.js +51 -105
  8. package/dist/build/debug-raw.wasm +0 -0
  9. package/dist/build/debug.d.ts +34 -98
  10. package/dist/build/debug.js +53 -112
  11. package/dist/build/debug.wasm +0 -0
  12. package/dist/build/js/assembly/api-debugger.d.ts +55 -0
  13. package/dist/build/js/assembly/api-debugger.js +245 -0
  14. package/dist/build/js/assembly/api-internal.d.ts +13 -0
  15. package/dist/build/js/assembly/api-internal.js +192 -0
  16. package/dist/build/js/assembly/api-types.d.ts +45 -0
  17. package/dist/build/js/assembly/api-types.js +53 -0
  18. package/dist/build/js/assembly/api-utils.d.ts +71 -0
  19. package/dist/build/js/assembly/api-utils.js +206 -0
  20. package/dist/build/js/assembly/arguments.d.ts +44 -0
  21. package/dist/build/js/assembly/arguments.js +164 -0
  22. package/dist/build/js/assembly/codec.d.ts +24 -0
  23. package/dist/build/js/assembly/codec.js +139 -0
  24. package/dist/build/js/assembly/gas-costs.d.ts +6 -0
  25. package/dist/build/js/assembly/gas-costs.js +39 -0
  26. package/dist/build/js/assembly/gas.d.ts +16 -0
  27. package/dist/build/js/assembly/gas.js +23 -0
  28. package/dist/build/js/assembly/index-shared.d.ts +4 -0
  29. package/dist/build/js/assembly/index-shared.js +4 -0
  30. package/dist/build/js/assembly/instructions/bit.d.ts +11 -0
  31. package/dist/build/js/assembly/instructions/bit.js +53 -0
  32. package/dist/build/js/assembly/instructions/branch.d.ts +17 -0
  33. package/dist/build/js/assembly/instructions/branch.js +120 -0
  34. package/dist/build/js/assembly/instructions/jump.d.ts +5 -0
  35. package/dist/build/js/assembly/instructions/jump.js +21 -0
  36. package/dist/build/js/assembly/instructions/load.d.ts +17 -0
  37. package/dist/build/js/assembly/instructions/load.js +134 -0
  38. package/dist/build/js/assembly/instructions/logic.d.ts +10 -0
  39. package/dist/build/js/assembly/instructions/logic.js +47 -0
  40. package/dist/build/js/assembly/instructions/math.d.ts +28 -0
  41. package/dist/build/js/assembly/instructions/math.js +225 -0
  42. package/dist/build/js/assembly/instructions/misc.d.ts +6 -0
  43. package/dist/build/js/assembly/instructions/misc.js +22 -0
  44. package/dist/build/js/assembly/instructions/mov.d.ts +6 -0
  45. package/dist/build/js/assembly/instructions/mov.js +35 -0
  46. package/dist/build/js/assembly/instructions/outcome.d.ts +30 -0
  47. package/dist/build/js/assembly/instructions/outcome.js +63 -0
  48. package/dist/build/js/assembly/instructions/rot.d.ts +15 -0
  49. package/dist/build/js/assembly/instructions/rot.js +66 -0
  50. package/dist/build/js/assembly/instructions/set.d.ts +7 -0
  51. package/dist/build/js/assembly/instructions/set.js +36 -0
  52. package/dist/build/js/assembly/instructions/shift.d.ts +19 -0
  53. package/dist/build/js/assembly/instructions/shift.js +121 -0
  54. package/dist/build/js/assembly/instructions/store.d.ts +17 -0
  55. package/dist/build/js/assembly/instructions/store.js +101 -0
  56. package/dist/build/js/assembly/instructions/utils.d.ts +23 -0
  57. package/dist/build/js/assembly/instructions/utils.js +75 -0
  58. package/dist/build/js/assembly/instructions-exe.d.ts +2 -0
  59. package/dist/build/js/assembly/instructions-exe.js +245 -0
  60. package/dist/build/js/assembly/instructions.d.ts +11 -0
  61. package/dist/build/js/assembly/instructions.js +252 -0
  62. package/dist/build/js/assembly/interpreter.d.ts +29 -0
  63. package/dist/build/js/assembly/interpreter.js +229 -0
  64. package/dist/build/js/assembly/math.d.ts +8 -0
  65. package/dist/build/js/assembly/math.js +14 -0
  66. package/dist/build/js/assembly/memory-page.d.ts +38 -0
  67. package/dist/build/js/assembly/memory-page.js +68 -0
  68. package/dist/build/js/assembly/memory.d.ts +82 -0
  69. package/dist/build/js/assembly/memory.js +386 -0
  70. package/dist/build/js/assembly/portable.d.ts +24 -0
  71. package/dist/build/js/assembly/portable.js +362 -0
  72. package/dist/build/js/assembly/program-build.d.ts +2 -0
  73. package/dist/build/js/assembly/program-build.js +104 -0
  74. package/dist/build/js/assembly/program.d.ts +78 -0
  75. package/dist/build/js/assembly/program.js +284 -0
  76. package/dist/build/js/assembly/registers.d.ts +6 -0
  77. package/dist/build/js/assembly/registers.js +9 -0
  78. package/dist/build/js/assembly/spi.d.ts +92 -0
  79. package/dist/build/js/assembly/spi.js +152 -0
  80. package/dist/build/js/portable/bootstrap.d.ts +1 -0
  81. package/dist/build/js/portable/bootstrap.js +5 -0
  82. package/dist/build/js/portable/index.d.ts +4 -0
  83. package/dist/build/js/portable/index.js +6 -0
  84. package/dist/build/js/portable-bundle.js +4309 -0
  85. package/dist/build/release-inline.js +1 -1
  86. package/dist/build/release-mini-inline.js +1 -1
  87. package/dist/build/release-mini.d.ts +34 -98
  88. package/dist/build/release-mini.js +53 -112
  89. package/dist/build/release-mini.wasm +0 -0
  90. package/dist/build/release-stub-inline.js +1 -1
  91. package/dist/build/release-stub.d.ts +34 -98
  92. package/dist/build/release-stub.js +53 -112
  93. package/dist/build/release-stub.wasm +0 -0
  94. package/dist/build/release.d.ts +34 -98
  95. package/dist/build/release.js +53 -112
  96. package/dist/build/release.wasm +0 -0
  97. package/dist/build/test-inline.js +1 -1
  98. package/dist/build/test.wasm +0 -0
  99. package/dist/test/test-w3f-common.js +126 -0
  100. package/dist/test/test-w3f-portable.js +5 -0
  101. package/dist/test/test-w3f.js +3 -120
  102. package/package.json +11 -4
@@ -0,0 +1,386 @@
1
+ import { u8SignExtend, u16SignExtend, u32SignExtend } from "./instructions/utils";
2
+ import { minU32 } from "./math";
3
+ import { Access, Arena, PAGE_SIZE, PAGE_SIZE_SHIFT, Page, RawPage, RESERVED_MEMORY, RESERVED_PAGES, } from "./memory-page";
4
+ import { portable } from "./portable";
5
+ // @unmanaged
6
+ export class MaybePageFault {
7
+ constructor() {
8
+ /** Accessing memory triggered a page fault. */
9
+ this.isFault = false;
10
+ /** The page fault was caused by invalid memory access (i.e. writing to read-only memory). */
11
+ this.isAccess = false;
12
+ /** Start memory index of a page that triggered the fault. */
13
+ this.fault = 0;
14
+ }
15
+ }
16
+ const EMPTY_UINT8ARRAY = new Uint8Array(0);
17
+ const EMPTY_PAGE = new Page(Access.None, new RawPage(-1, null));
18
+ class Chunks {
19
+ constructor() {
20
+ this.firstPageData = EMPTY_UINT8ARRAY;
21
+ this.firstPageOffset = 0;
22
+ this.secondPageData = EMPTY_UINT8ARRAY;
23
+ this.secondPageEnd = 0;
24
+ }
25
+ }
26
+ class PageResult {
27
+ constructor() {
28
+ this.page = EMPTY_PAGE;
29
+ this.relativeAddress = 0;
30
+ }
31
+ }
32
+ const MEMORY_SIZE = 4294967296;
33
+ const MAX_MEMORY_ADDRESS = 4294967295;
34
+ export class MemoryBuilder {
35
+ constructor(preAllocatePages = 0) {
36
+ this.pages = new Map();
37
+ this.arena = new Arena(preAllocatePages);
38
+ }
39
+ /** Allocates memory pages with given `access`, for given `address` and initialize with `zeroes` */
40
+ setEmpty(access, address, len) {
41
+ const endAddress = address + len;
42
+ for (let currentAddress = address; currentAddress < endAddress; currentAddress += PAGE_SIZE) {
43
+ this.getOrCreatePageForAddress(access, currentAddress);
44
+ }
45
+ return this;
46
+ }
47
+ /** Allocates memory pages with given `access`, for given `address` and writes there `data` */
48
+ setData(access, address, data) {
49
+ let currentAddress = address;
50
+ let currentData = data;
51
+ while (currentData.length > 0) {
52
+ const page = this.getOrCreatePageForAddress(access, currentAddress);
53
+ const relAddress = currentAddress % PAGE_SIZE;
54
+ const spaceInPage = PAGE_SIZE - relAddress;
55
+ const end = u32(currentData.length) < spaceInPage ? currentData.length : spaceInPage;
56
+ page.raw.data.set(currentData.subarray(0, end), relAddress);
57
+ // move to the next address to write
58
+ currentAddress = currentAddress + end;
59
+ currentData = currentData.subarray(end);
60
+ }
61
+ return this;
62
+ }
63
+ /** Returns memory page for given address (creates if not exists) */
64
+ getOrCreatePageForAddress(access, address) {
65
+ const pageIdx = u32(address >> PAGE_SIZE_SHIFT);
66
+ if (pageIdx < RESERVED_PAGES) {
67
+ throw new Error(`Attempting to allocate reserved page: ${pageIdx}`);
68
+ }
69
+ if (!this.pages.has(pageIdx)) {
70
+ const page = this.arena.acquire();
71
+ this.pages.set(pageIdx, new Page(access, page));
72
+ }
73
+ return this.pages.get(pageIdx);
74
+ }
75
+ build(sbrkAddress = RESERVED_MEMORY, maxHeapPointer = MAX_MEMORY_ADDRESS) {
76
+ return new Memory(this.arena, this.pages, sbrkAddress, maxHeapPointer);
77
+ }
78
+ }
79
+ export class Memory {
80
+ constructor(arena, pages = new Map(), sbrkAddress = 0, maxHeapPointer = MAX_MEMORY_ADDRESS) {
81
+ this.arena = arena;
82
+ this.pages = pages;
83
+ this.sbrkAddress = sbrkAddress;
84
+ this.pageResult = new PageResult();
85
+ this.chunksResult = new Chunks();
86
+ const sbrkPage = u32(sbrkAddress >> PAGE_SIZE_SHIFT);
87
+ if (sbrkPage < RESERVED_PAGES) {
88
+ throw new Error("sbrk within reserved memory is not allowed!");
89
+ }
90
+ this.lastAllocatedPage = pages.has(sbrkPage) ? sbrkPage : sbrkPage - 1;
91
+ this.maxHeapPointer = u64(maxHeapPointer);
92
+ }
93
+ pageDump(index) {
94
+ if (!this.pages.has(index)) {
95
+ return null;
96
+ }
97
+ return this.pages.get(index).raw.data;
98
+ }
99
+ /**
100
+ * Returns the WASM linear memory pointer (byte offset) for the backing buffer of the page at `pageIndex`.
101
+ *
102
+ * Returns `0` if the page does not exist or is not readable (page/access fault).
103
+ *
104
+ * This enables efficient memory reading on the JS side without extra WASM allocations:
105
+ * ```ts
106
+ * let pagesRead = 0;
107
+ * for (let address = start; address < end; address += PAGE_SIZE) {
108
+ * const page = address >> PAGE_SIZE_SHIFT;
109
+ * const ptr = getPagePointer(page);
110
+ * if (ptr === 0) {
111
+ * throw new Error(`Page fault at ${page << PAGE_SIZE_SHIFT}`);
112
+ * }
113
+ * destination.set(
114
+ * new Uint8Array(wasm.instance.exports.memory.buffer, ptr, Math.min(end - address, PAGE_SIZE)),
115
+ * pagesRead << PAGE_SIZE_SHIFT,
116
+ * );
117
+ * pagesRead += 1;
118
+ * }
119
+ * ```
120
+ */
121
+ getPagePointer(pageIndex) {
122
+ if (!this.pages.has(pageIndex)) {
123
+ return 0;
124
+ }
125
+ const page = this.pages.get(pageIndex);
126
+ if (!page.can(Access.Read)) {
127
+ return 0;
128
+ }
129
+ // Trigger lazy allocation if the backing buffer has not been created yet.
130
+ // @ts-ignore: dataStart is an AS-specific property on Uint8Array
131
+ return page.raw.data.dataStart;
132
+ }
133
+ free() {
134
+ // @ts-ignore: AS returns T[], JS returns iterator - asArray handles both
135
+ const pages = portable.asArray(this.pages.values());
136
+ for (let i = 0; i < pages.length; i++) {
137
+ this.arena.release(pages[i].raw);
138
+ }
139
+ this.pages.clear();
140
+ }
141
+ sbrk(faultRes, amount) {
142
+ const freeMemoryStart = u64(this.sbrkAddress);
143
+ if (amount === 0) {
144
+ faultRes.isFault = false;
145
+ return freeMemoryStart;
146
+ }
147
+ const newSbrk = portable.u64_add(freeMemoryStart, u64(amount));
148
+ if (newSbrk > this.maxHeapPointer) {
149
+ faultRes.isFault = true;
150
+ return freeMemoryStart;
151
+ }
152
+ this.sbrkAddress = u32(newSbrk);
153
+ const pageIdx = i32(portable.u64_sub(newSbrk, u64(1)) >> u64(PAGE_SIZE_SHIFT));
154
+ if (pageIdx === this.lastAllocatedPage) {
155
+ return freeMemoryStart;
156
+ }
157
+ for (let i = this.lastAllocatedPage + 1; i <= pageIdx; i++) {
158
+ const page = this.arena.acquire();
159
+ this.pages.set(i, new Page(Access.Write, page));
160
+ }
161
+ this.lastAllocatedPage = pageIdx;
162
+ return freeMemoryStart;
163
+ }
164
+ getU8(faultRes, address) {
165
+ return u64(u8(this.getBytesReversed(faultRes, Access.Read, address, 1)));
166
+ }
167
+ getU16(faultRes, address) {
168
+ return u64(portable.bswap_u16(u16(this.getBytesReversed(faultRes, Access.Read, address, 2))));
169
+ }
170
+ getU32(faultRes, address) {
171
+ return u64(portable.bswap_u32(u32(this.getBytesReversed(faultRes, Access.Read, address, 4))));
172
+ }
173
+ getU64(faultRes, address) {
174
+ return portable.bswap_u64(this.getBytesReversed(faultRes, Access.Read, address, 8));
175
+ }
176
+ getI8(faultRes, address) {
177
+ return u8SignExtend(u8(this.getU8(faultRes, address)));
178
+ }
179
+ getI16(faultRes, address) {
180
+ return u16SignExtend(u16(this.getU16(faultRes, address)));
181
+ }
182
+ getI32(faultRes, address) {
183
+ return u32SignExtend(u32(this.getU32(faultRes, address)));
184
+ }
185
+ setU8(faultRes, address, value) {
186
+ this.setBytes(faultRes, address, value, 1);
187
+ }
188
+ setU16(faultRes, address, value) {
189
+ this.setBytes(faultRes, address, value, 2);
190
+ }
191
+ setU32(faultRes, address, value) {
192
+ this.setBytes(faultRes, address, value, 4);
193
+ }
194
+ setU64(faultRes, address, value) {
195
+ this.setBytes(faultRes, address, value, 8);
196
+ }
197
+ /**
198
+ * DO NOT USE.
199
+ *
200
+ * @deprecated exposed temporarily for debugger/typeberry API.
201
+ */
202
+ getMemory(fault, address, length) {
203
+ // first traverse memory and see if we don't page fault
204
+ if (length > 0) {
205
+ let nextAddress = address;
206
+ const pagesToCheck = i32(portable.u64_add(u64(length), u64(PAGE_SIZE - 1)) >> u64(PAGE_SIZE_SHIFT));
207
+ for (let page = 0; page < pagesToCheck; page++) {
208
+ const pageData = this.pageResult;
209
+ this.getPage(fault, pageData, Access.Read, nextAddress);
210
+ if (fault.isFault) {
211
+ return null;
212
+ }
213
+ nextAddress += PAGE_SIZE;
214
+ }
215
+ }
216
+ // only after, actually allocate and read the bytes.
217
+ const destination = new Uint8Array(length);
218
+ this.bytesRead(fault, address, destination, 0);
219
+ if (fault.isFault) {
220
+ return null;
221
+ }
222
+ return destination;
223
+ }
224
+ bytesRead(faultRes, address, destination, destinationOffset) {
225
+ let nextAddress = address;
226
+ let destinationIndex = i32(destinationOffset);
227
+ while (destinationIndex < destination.length) {
228
+ const bytesLeft = destination.length - destinationIndex;
229
+ const pageData = this.pageResult;
230
+ this.getPage(faultRes, pageData, Access.Read, nextAddress);
231
+ if (faultRes.isFault) {
232
+ return;
233
+ }
234
+ const relAddress = pageData.relativeAddress;
235
+ const bytesToRead = relAddress + bytesLeft < PAGE_SIZE ? bytesLeft : PAGE_SIZE - pageData.relativeAddress;
236
+ // actually copy the bytes
237
+ const pageEnd = relAddress + bytesToRead;
238
+ const data = pageData.page.raw.data;
239
+ for (let i = relAddress; i < pageEnd; i++) {
240
+ destination[destinationIndex] = data[i];
241
+ destinationIndex++;
242
+ }
243
+ // move the pointers
244
+ nextAddress += bytesToRead;
245
+ }
246
+ return;
247
+ }
248
+ /** Write bytes from given `source` (with `sourceOffset`) at given `address`. */
249
+ bytesWrite(faultRes, address, source, sourceOffset) {
250
+ let nextAddress = address;
251
+ let sourceIndex = i32(sourceOffset);
252
+ while (sourceIndex < source.length) {
253
+ const bytesLeft = source.length - sourceIndex;
254
+ const pageData = this.pageResult;
255
+ this.getPage(faultRes, pageData, Access.Write, nextAddress);
256
+ if (faultRes.isFault) {
257
+ return;
258
+ }
259
+ const relAddress = pageData.relativeAddress;
260
+ const bytesToWrite = relAddress + bytesLeft < PAGE_SIZE ? bytesLeft : PAGE_SIZE - pageData.relativeAddress;
261
+ // actually copy the bytes
262
+ const pageEnd = relAddress + bytesToWrite;
263
+ const data = pageData.page.raw.data;
264
+ for (let i = relAddress; i < pageEnd; i++) {
265
+ data[i] = source[sourceIndex];
266
+ sourceIndex++;
267
+ }
268
+ // move the pointers
269
+ nextAddress += bytesToWrite;
270
+ }
271
+ return;
272
+ }
273
+ getPage(faultRes, pageData, access, address) {
274
+ const pageIdx = u32(address >> PAGE_SIZE_SHIFT);
275
+ const relAddress = address % PAGE_SIZE;
276
+ const pageStart = pageIdx << PAGE_SIZE_SHIFT;
277
+ if (!this.pages.has(pageIdx)) {
278
+ fault(faultRes, pageStart);
279
+ pageData.page = EMPTY_PAGE;
280
+ pageData.relativeAddress = relAddress;
281
+ return;
282
+ }
283
+ const page = this.pages.get(pageIdx);
284
+ if (!page.can(access)) {
285
+ fault(faultRes, pageStart);
286
+ faultRes.isAccess = true;
287
+ pageData.page = EMPTY_PAGE;
288
+ pageData.relativeAddress = relAddress;
289
+ return;
290
+ }
291
+ faultRes.isFault = false;
292
+ pageData.page = page;
293
+ pageData.relativeAddress = relAddress;
294
+ return;
295
+ }
296
+ getChunks(faultRes, chunks, access, address, bytes) {
297
+ /**
298
+ * Accessing empty set of bytes is always valid.
299
+ * https://graypaper.fluffylabs.dev/#/68eaa1f/24a80024a800?v=0.6.4
300
+ */
301
+ if (bytes === 0) {
302
+ faultRes.isFault = false;
303
+ chunks.firstPageData = EMPTY_UINT8ARRAY;
304
+ chunks.firstPageOffset = 0;
305
+ chunks.secondPageData = EMPTY_UINT8ARRAY;
306
+ chunks.secondPageEnd = 0;
307
+ return;
308
+ }
309
+ const pageData = this.pageResult;
310
+ this.getPage(faultRes, pageData, access, address);
311
+ if (faultRes.isFault) {
312
+ return;
313
+ }
314
+ const page = pageData.page;
315
+ const relativeAddress = pageData.relativeAddress;
316
+ const endAddress = relativeAddress + u32(bytes);
317
+ const needSecondPage = endAddress > PAGE_SIZE;
318
+ // everything is on one page - easy case
319
+ if (!needSecondPage) {
320
+ chunks.firstPageData = page.raw.data;
321
+ chunks.firstPageOffset = relativeAddress;
322
+ return;
323
+ }
324
+ const secondPageIdx = u32((address + u32(bytes)) % MEMORY_SIZE) >> PAGE_SIZE_SHIFT;
325
+ const secondPageStart = secondPageIdx << PAGE_SIZE_SHIFT;
326
+ if (!this.pages.has(secondPageIdx)) {
327
+ fault(faultRes, secondPageStart);
328
+ return;
329
+ }
330
+ // fetch the second page and check access
331
+ const secondPage = this.pages.get(secondPageIdx);
332
+ if (!secondPage.can(access)) {
333
+ fault(faultRes, secondPageStart);
334
+ faultRes.isAccess = true;
335
+ return;
336
+ }
337
+ chunks.firstPageData = page.raw.data;
338
+ chunks.firstPageOffset = relativeAddress;
339
+ chunks.secondPageData = secondPage.raw.data;
340
+ chunks.secondPageEnd = relativeAddress + u32(bytes) - PAGE_SIZE;
341
+ return;
342
+ }
343
+ /** Write some bytes to at most 2 pages. */
344
+ setBytes(faultRes, address, value, bytes) {
345
+ const r = this.chunksResult;
346
+ this.getChunks(faultRes, r, Access.Write, address, bytes);
347
+ if (faultRes.isFault) {
348
+ return;
349
+ }
350
+ let bytesLeft = u64(value);
351
+ // write to first page
352
+ const firstPageEnd = minU32(PAGE_SIZE, r.firstPageOffset + bytes);
353
+ for (let i = r.firstPageOffset; i < firstPageEnd; i++) {
354
+ r.firstPageData[i] = u8(bytesLeft);
355
+ bytesLeft >>= u64(8);
356
+ }
357
+ // write rest to the second page
358
+ for (let i = 0; i < r.secondPageEnd; i++) {
359
+ r.secondPageData[i] = u8(bytesLeft);
360
+ bytesLeft >>= u64(8);
361
+ }
362
+ }
363
+ getBytesReversed(faultRes, access, address, bytes) {
364
+ this.getChunks(faultRes, this.chunksResult, access, address, bytes);
365
+ if (faultRes.isFault) {
366
+ return u64(0);
367
+ }
368
+ // result (bytes in reverse order)
369
+ let r = u64(0);
370
+ const firstPageEnd = minU32(PAGE_SIZE, this.chunksResult.firstPageOffset + bytes);
371
+ // read from first page
372
+ for (let i = this.chunksResult.firstPageOffset; i < firstPageEnd; i++) {
373
+ r = (r << u64(8)) | u64(this.chunksResult.firstPageData[i]);
374
+ }
375
+ // read from the second page
376
+ for (let i = 0; i < this.chunksResult.secondPageEnd; i++) {
377
+ r = (r << u64(8)) | u64(this.chunksResult.secondPageData[i]);
378
+ }
379
+ return r;
380
+ }
381
+ }
382
+ function fault(r, address) {
383
+ r.isFault = true;
384
+ r.isAccess = false;
385
+ r.fault = address;
386
+ }
@@ -0,0 +1,24 @@
1
+ export declare class portable {
2
+ static installPolyfills(): void;
3
+ static asArray<T>(v: T[]): T[];
4
+ static arrayAt<T>(v: T[], i: u32): T;
5
+ static staticArrayAt<T>(v: StaticArray<T>, i: u32): T;
6
+ static asU32(v: u32): u32;
7
+ static uint8ArrayView(data: ArrayBuffer, offset: i32, length: i32): Uint8Array;
8
+ static bswap_u16(v: u16): u16;
9
+ static bswap_u32(v: u32): u32;
10
+ static bswap_u64(v: u64): u64;
11
+ static popcnt_u32(v: u32): u32;
12
+ static popcnt_u64(v: u64): u64;
13
+ static clz_u32(v: u32): u32;
14
+ static clz_u64(v: u64): u64;
15
+ static ctz_u32(v: u32): u32;
16
+ static ctz_u64(v: u64): u64;
17
+ static rotr_u32(v: u32, shift: u32): u32;
18
+ static rotr_u64(v: u64, shift: u64): u64;
19
+ static rotl_u32(v: u32, shift: u32): u32;
20
+ static rotl_u64(v: u64, shift: u64): u64;
21
+ static u64_add(a: u64, b: u64): u64;
22
+ static u64_sub(a: u64, b: u64): u64;
23
+ static u64_mul(a: u64, b: u64): u64;
24
+ }