diff --git a/src/constants.ts b/src/constants.ts index c596b068..c5a989d1 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -10,5 +10,5 @@ export const GETTER_PREFIX = "get:"; export const SETTER_PREFIX = "set:"; /** Delimiter used between class names and instance members. */ export const INSTANCE_DELIMITER = "#"; -/** Delimited used between class and namespace names and static members. */ +/** Delimiter used between class and namespace names and static members. */ export const STATIC_DELIMITER = "."; diff --git a/src/glue/js.js b/src/glue/js.js index 877ebeb6..19afc9d4 100644 --- a/src/glue/js.js +++ b/src/glue/js.js @@ -14,23 +14,17 @@ for (var key in binaryen) if (/^_(?:Binaryen|Relooper)/.test(key)) globalScope[key] = binaryen[key]; -// Use Binaryen's heap -Object.defineProperties(globalScope["Heap"] = { - allocate: function allocate(size) { - if (!size) return 0; // should be safe in our case - return binaryen._malloc(size); - }, - dispose: function dispose(ptr) { - if (ptr) binaryen._free(ptr); - }, - copy: function copy(dest, src, n) { - return binaryen._memcpy(dest, src, n); - } -}, { - free: { get: function() { return binaryen.HEAPU8.length; } }, - used: { get: function() { return 0; } }, - size: { get: function() { return binaryen.HEAPU8.length; } } -}); +// Use Binaryen's heap instead of std heap +globalScope["allocate_memory"] = function allocate_memory(size) { + if (!size) return 0; // should be safe in our case + return binaryen._malloc(size); +}; +globalScope["free_memory"] = function free_memory(ptr) { + if (ptr) binaryen._free(ptr); +}; +globalScope["move_memory"] = function move_memory(dest, src, n) { + return binaryen._memmove(dest, src, n); +}; globalScope["store"] = function store(ptr, val) { binaryen.HEAPU8[ptr] = val; }; @@ -42,11 +36,11 @@ globalScope["load"] = function load(ptr) { var Module = require("../module").Module; Module.prototype.toBinary = function toBinary(bufferSize) { if (!bufferSize) bufferSize = 1024 * 1024; // FIXME: see binaryen.js-post.js in Binaryen - var ptr = Heap.allocate(bufferSize); + var ptr = allocate_memory(bufferSize); var len = this.write(ptr, bufferSize); var ret = new Uint8Array(len); ret.set(binaryen.HEAPU8.subarray(ptr, ptr + len)); - Heap.dispose(ptr); + free_memory(ptr); return ret; }; Module.prototype.toText = function toText() { diff --git a/src/module.ts b/src/module.ts index df6816a7..4626c1d8 100644 --- a/src/module.ts +++ b/src/module.ts @@ -246,7 +246,7 @@ export class Module { static create(): Module { var module = new Module(); module.ref = _BinaryenModuleCreate(); - module.lit = changetype(Heap.allocate(16)); + module.lit = changetype(allocate_memory(16)); module.noEmit = false; return module; } @@ -256,11 +256,11 @@ export class Module { try { var module = new Module(); module.ref = _BinaryenModuleRead(cArr, buffer.length); - module.lit = changetype(Heap.allocate(16)); + module.lit = changetype(allocate_memory(16)); module.noEmit = false; return module; } finally { - Heap.dispose(changetype(cArr)); + free_memory(changetype(cArr)); } } @@ -283,8 +283,8 @@ export class Module { try { return _BinaryenAddFunctionType(this.ref, cStr, result, cArr, paramTypes.length); } finally { - Heap.dispose(cArr); - Heap.dispose(cStr); + free_memory(cArr); + free_memory(cStr); } } @@ -294,7 +294,7 @@ export class Module { try { return _BinaryenGetFunctionTypeBySignature(this.ref, result, cArr, paramTypes.length); } finally { - Heap.dispose(cArr); + free_memory(cArr); } } @@ -341,8 +341,8 @@ export class Module { try { return _BinaryenHost(this.ref, op, cStr, cArr, operands ? (operands).length : 0); } finally { - Heap.dispose(cArr); - Heap.dispose(cStr); + free_memory(cArr); + free_memory(cStr); } } @@ -362,7 +362,7 @@ export class Module { try { return _BinaryenGetGlobal(this.ref, cStr, type); } finally { - Heap.dispose(cStr); + free_memory(cStr); } } @@ -419,7 +419,7 @@ export class Module { try { return _BinaryenSetGlobal(this.ref, cStr, value); } finally { - Heap.dispose(cStr); + free_memory(cStr); } } @@ -430,8 +430,8 @@ export class Module { try { return _BinaryenBlock(this.ref, cStr, cArr, children.length, type); } finally { - Heap.dispose(cArr); - Heap.dispose(cStr); + free_memory(cArr); + free_memory(cStr); } } @@ -441,7 +441,7 @@ export class Module { try { return _BinaryenBreak(this.ref, cStr, condition, value); } finally { - Heap.dispose(cStr); + free_memory(cStr); } } @@ -456,7 +456,7 @@ export class Module { try { return _BinaryenLoop(this.ref, cStr, body); } finally { - Heap.dispose(cStr); + free_memory(cStr); } } @@ -490,9 +490,9 @@ export class Module { try { return _BinaryenSwitch(this.ref, cArr, k, cStr, condition, value); } finally { - Heap.dispose(cStr); - Heap.dispose(cArr); - for (i = k - 1; i >= 0; --i) Heap.dispose(strs[i]); + free_memory(cStr); + free_memory(cArr); + for (i = k - 1; i >= 0; --i) free_memory(strs[i]); } } @@ -503,8 +503,8 @@ export class Module { try { return _BinaryenCall(this.ref, cStr, cArr, operands && operands.length || 0, returnType); } finally { - Heap.dispose(cArr); - Heap.dispose(cStr); + free_memory(cArr); + free_memory(cStr); } } @@ -515,8 +515,8 @@ export class Module { try { return _BinaryenCallImport(this.ref, cStr, cArr, operands && operands.length || 0, returnType); } finally { - Heap.dispose(cArr); - Heap.dispose(cStr); + free_memory(cArr); + free_memory(cStr); } } @@ -533,7 +533,7 @@ export class Module { try { return _BinaryenAddGlobal(this.ref, cStr, type, mutable ? 1 : 0, initializer); } finally { - Heap.dispose(cStr); + free_memory(cStr); } } @@ -544,8 +544,8 @@ export class Module { try { return _BinaryenAddFunction(this.ref, cStr, type, cArr, varTypes.length, body); } finally { - Heap.dispose(cArr); - Heap.dispose(cStr); + free_memory(cArr); + free_memory(cStr); } } @@ -554,7 +554,7 @@ export class Module { try { _BinaryenRemoveFunction(this.ref, cStr); } finally { - Heap.dispose(cStr); + free_memory(cStr); } } @@ -565,8 +565,8 @@ export class Module { try { return _BinaryenAddFunctionExport(this.ref, cStr1, cStr2); } finally { - Heap.dispose(cStr2); - Heap.dispose(cStr1); + free_memory(cStr2); + free_memory(cStr1); } } @@ -577,8 +577,8 @@ export class Module { try { return _BinaryenAddTableExport(this.ref, cStr1, cStr2); } finally { - Heap.dispose(cStr2); - Heap.dispose(cStr1); + free_memory(cStr2); + free_memory(cStr1); } } @@ -589,8 +589,8 @@ export class Module { try { return _BinaryenAddMemoryExport(this.ref, cStr1, cStr2); } finally { - Heap.dispose(cStr2); - Heap.dispose(cStr1); + free_memory(cStr2); + free_memory(cStr1); } } @@ -601,8 +601,8 @@ export class Module { try { return _BinaryenAddGlobalExport(this.ref, cStr1, cStr2); } finally { - Heap.dispose(cStr2); - Heap.dispose(cStr1); + free_memory(cStr2); + free_memory(cStr1); } } @@ -612,7 +612,7 @@ export class Module { try { _BinaryenRemoveExport(this.ref, cStr); } finally { - Heap.dispose(cStr); + free_memory(cStr); } } @@ -624,9 +624,9 @@ export class Module { try { return _BinaryenAddFunctionImport(this.ref, cStr1, cStr2, cStr3, functionType); } finally { - Heap.dispose(cStr3); - Heap.dispose(cStr2); - Heap.dispose(cStr1); + free_memory(cStr3); + free_memory(cStr2); + free_memory(cStr1); } } @@ -638,9 +638,9 @@ export class Module { try { return _BinaryenAddTableImport(this.ref, cStr1, cStr2, cStr3); } finally { - Heap.dispose(cStr3); - Heap.dispose(cStr2); - Heap.dispose(cStr1); + free_memory(cStr3); + free_memory(cStr2); + free_memory(cStr1); } } @@ -652,9 +652,9 @@ export class Module { try { return _BinaryenAddMemoryImport(this.ref, cStr1, cStr2, cStr3); } finally { - Heap.dispose(cStr3); - Heap.dispose(cStr2); - Heap.dispose(cStr1); + free_memory(cStr3); + free_memory(cStr2); + free_memory(cStr1); } } @@ -666,9 +666,9 @@ export class Module { try { return _BinaryenAddGlobalImport(this.ref, cStr1, cStr2, cStr3, globalType); } finally { - Heap.dispose(cStr3); - Heap.dispose(cStr2); - Heap.dispose(cStr1); + free_memory(cStr3); + free_memory(cStr2); + free_memory(cStr1); } } @@ -678,7 +678,7 @@ export class Module { try { _BinaryenRemoveImport(this.ref, cStr); } finally { - Heap.dispose(cStr); + free_memory(cStr); } } @@ -704,11 +704,11 @@ export class Module { try { _BinaryenSetMemory(this.ref, initial, maximum, cStr, cArr1, cArr2, cArr3, k); } finally { - Heap.dispose(cArr3); - Heap.dispose(cArr2); - Heap.dispose(cArr1); - for (i = k - 1; i >= 0; --i) Heap.dispose(segs[i]); - Heap.dispose(cStr); + free_memory(cArr3); + free_memory(cArr2); + free_memory(cArr1); + for (i = k - 1; i >= 0; --i) free_memory(segs[i]); + free_memory(cStr); } } @@ -718,7 +718,7 @@ export class Module { try { _BinaryenSetFunctionTable(this.ref, cArr, funcs.length); } finally { - Heap.dispose(cArr); + free_memory(cArr); } } @@ -749,8 +749,8 @@ export class Module { else _BinaryenModuleRunPasses(this.ref, cArr, k); } finally { - Heap.dispose(cArr); - for (; i >= 0; --i) Heap.dispose(names[i]); + free_memory(cArr); + for (; i >= 0; --i) free_memory(names[i]); } } @@ -788,7 +788,7 @@ export class Module { dispose(): void { if (!this.ref) return; // sic _BinaryenModuleDispose(this.ref); - Heap.dispose(changetype(this.lit)); + free_memory(changetype(this.lit)); } createRelooper(): Relooper { @@ -890,7 +890,7 @@ export class Relooper { try { _RelooperAddBranchForSwitch(from, to, cArr, indexes.length, code); } finally { - Heap.dispose(cArr); + free_memory(cArr); } } @@ -905,7 +905,7 @@ export class Relooper { function allocU8Array(u8s: Uint8Array | null): usize { if (!u8s) return 0; - var ptr = Heap.allocate(u8s.length); + var ptr = allocate_memory(u8s.length); var idx = ptr; for (var i = 0, k = u8s.length; i < k; ++i) store(idx++, u8s[i]); @@ -914,7 +914,7 @@ function allocU8Array(u8s: Uint8Array | null): usize { function allocI32Array(i32s: i32[] | null): usize { if (!i32s) return 0; - var ptr = Heap.allocate(i32s.length << 2); + var ptr = allocate_memory(i32s.length << 2); var idx = ptr; for (var i = 0, k = i32s.length; i < k; ++i) { var val = i32s[i]; @@ -952,7 +952,7 @@ function stringLengthUTF8(str: string): usize { function allocString(str: string | null): usize { if (str == null) return 0; - var ptr = Heap.allocate(stringLengthUTF8(str) + 1); + var ptr = allocate_memory(stringLengthUTF8(str) + 1); var idx = ptr; for (var i = 0, k = str.length; i < k; ++i) { var u = str.charCodeAt(i); diff --git a/std/assembly.d.ts b/std/assembly.d.ts index da856b9a..55fd5310 100644 --- a/std/assembly.d.ts +++ b/std/assembly.d.ts @@ -162,6 +162,16 @@ declare function store(offset: usize, value: T): void; declare function current_memory(): i32; /** Grows linear memory by a given unsigned delta of pages. One page is 64kb. Returns the previous memory size in units of pages or `-1` on failure. */ declare function grow_memory(value: i32): i32; +/** Copies n bytes from the specified source to the specified destination in memory. These regions may overlap. */ +declare function move_memory(destination: usize, source: usize, n: usize): void; +/** Sets n bytes beginning at the specified destination in memory to the specified byte value. */ +declare function set_memory(destination: usize, value: u8, count: usize): void; +/** Compares two chunks of memory. Returns `0` if equal, otherwise the difference of the first differing bytes. */ +declare function compare_memory(vl: usize, vr: usize, n: usize): i32; +/** Allocates a chunk of memory of the specified size and returns a pointer to it. */ +declare function allocate_memory(size: usize): usize; +/** Disposes a chunk of memory by its pointer. */ +declare function free_memory(ptr: usize): void; /** Emits an unreachable operation that results in a runtime error when executed. Both a statement and an expression of any type. */ declare function unreachable(): any; // sic @@ -250,36 +260,6 @@ declare class Error { /** Class for indicating an error when a value is not in the set or range of allowed values. */ declare class RangeError extends Error { } -/** A static class representing the heap. */ -declare class Heap { - - /** Gets the amount of used heap space, in bytes. */ - static readonly used: usize; - - /** Gets the amount of free heap space, in bytes. */ - static readonly free: usize; - - /** Gets the size of the heap, in bytes. */ - static readonly size: usize; - - /** Allocates a chunk of memory and returns a pointer to it. */ - static allocate(size: usize): usize; - - /** Disposes a chunk of memory by its pointer. */ - static dispose(ptr: usize): void; - - /** Copies a chunk of memory from one location to another. */ - static copy(dest: usize, src: usize, n: usize): usize; - - /** Fills a chunk of memory with the specified byte value. */ - static fill(dest: usize, c: u8, n: usize): usize; - - /** Compares two chunks of memory. Returns `0` if equal, otherwise the difference of the first differing bytes. */ - static compare(vl: usize, vr: usize, n: usize): i32; - - private constructor(); -} - interface Boolean {} interface Function {} interface IArguments {} diff --git a/std/assembly/array.ts b/std/assembly/array.ts index d62d57de..166b74e4 100644 --- a/std/assembly/array.ts +++ b/std/assembly/array.ts @@ -8,7 +8,7 @@ export class Array { if (capacity < 0) throw new RangeError("invalid array length"); this.__capacity = this.length = capacity; - this.__memory = capacity > 0 ? Heap.allocate(capacity * sizeof()) : 0; + this.__memory = capacity > 0 ? allocate_memory(capacity * sizeof()) : 0; } @operator("[]") @@ -34,19 +34,20 @@ export class Array { return -1; } - private __grow(capacity: i32): void { - assert(capacity > this.__capacity); - var newMemory = Heap.allocate((capacity * sizeof())); - if (this.__memory) - Heap.copy(newMemory, this.__memory, this.__capacity * sizeof()); - Heap.dispose(this.__memory); + private __grow(newCapacity: i32): void { + assert(newCapacity > this.__capacity); + var newMemory = allocate_memory(newCapacity * sizeof()); + if (this.__memory) { + move_memory(newMemory, this.__memory, this.__capacity * sizeof()); + free_memory(this.__memory); + } this.__memory = newMemory; - this.__capacity = capacity; + this.__capacity = newCapacity; } push(element: T): i32 { if (this.length >= this.__capacity) - this.__grow(max(this.length + 1, this.__capacity * 2)); + this.__grow(max(this.length + 1, this.__capacity << 1)); store(this.__memory + this.length * sizeof(), element); return ++this.length; } @@ -62,23 +63,22 @@ export class Array { if (this.length < 1 || this.length > this.__capacity) throw new RangeError("index out of range"); var element = load(this.__memory); - Heap.copy(this.__memory, this.__memory + sizeof(), (this.__capacity - 1) * sizeof()); - Heap.fill(this.__memory + (this.__capacity - 1) * sizeof(), 0, sizeof()); + move_memory(this.__memory, this.__memory + sizeof(), (this.__capacity - 1) * sizeof()); + set_memory(this.__memory + (this.__capacity - 1) * sizeof(), 0, sizeof()); --this.length; return element; } unshift(element: T): i32 { - var capacity = this.__capacity; - if (this.length >= capacity) - this.__grow(max(this.length + 1, capacity * 2)); + var oldCapacity = this.__capacity; + if (this.length >= oldCapacity) + this.__grow(max(this.length + 1, oldCapacity * 2)); - // FIXME: needs memmove (Heap.copy is just memcpy). it's also inefficient because - // __grow copies and then unshift copies again. - // Heap.copy(this.__memory + sizeof(), this.__memory, capacity * sizeof()); + // FIXME: this is inefficient because of two copies, one in __grow and one here + // move_memory(this.__memory + sizeof(), this.__memory, oldCapacity * sizeof()); - if (capacity) - for (var index: usize = capacity; index > 0; --index) + if (oldCapacity) + for (var index: usize = oldCapacity; index > 0; --index) store(this.__memory + index * sizeof(), load(this.__memory + (index - 1) * sizeof())); store(this.__memory, element); @@ -92,12 +92,16 @@ export class CArray { private constructor() {} @operator("[]") - private __get(index: usize): T { - return load(changetype(this) + index * sizeof()); + private __get(index: i32): T { + if (index < 0) + throw new RangeError("index out of range"); + return load(changetype(this) + index * sizeof()); } @operator("[]=") - private __set(index: usize, value: T): void { - store(changetype(this) + index * sizeof(), value); + private __set(index: i32, value: T): void { + if (index < 0) + throw new RangeError("index out of range"); + store(changetype(this) + index * sizeof(), value); } } diff --git a/std/assembly/heap.ts b/std/assembly/heap.ts index 9c5bab91..1a865ea6 100644 --- a/std/assembly/heap.ts +++ b/std/assembly/heap.ts @@ -4,245 +4,289 @@ const ALIGN_MASK: usize = ALIGN_SIZE - 1; var HEAP_OFFSET: usize = HEAP_BASE; // HEAP_BASE is a constant generated by the compiler -// TODO: maybe tlsf +export function allocate_memory(size: usize): usize { + if (!size) return 0; + var len: i32 = current_memory(); + if (HEAP_OFFSET + size > len << 16) + if(grow_memory(max(ceil(size / 65536), len * 2 - len)) < 0) + unreachable(); + var ptr: usize = HEAP_OFFSET; + if ((HEAP_OFFSET += size) & ALIGN_MASK) // align next offset + HEAP_OFFSET = (HEAP_OFFSET | ALIGN_MASK) + 1; + return ptr; +} -export class Heap { +export function free_memory(ptr: usize): void { + // just a big chunk of non-disposable memory for now +} - static get used(): usize { return HEAP_OFFSET - HEAP_BASE; } - static get free(): usize { return (current_memory() << 16) - HEAP_OFFSET; } - static get size(): usize { return (current_memory() << 16) - HEAP_BASE; } +function copy_memory(dest: usize, src: usize, n: usize): void { + // based on musl's implementation of memcpy + // not a future instruction and sufficiently covered by the upcoming move_memory intrinsic - static allocate(size: usize): usize { - if (!size) return 0; - var len: i32 = current_memory(); - if (HEAP_OFFSET + size > len << 16) - if(grow_memory(max(ceil(size / 65536), len * 2 - len)) < 0) - unreachable(); - var ptr: usize = HEAP_OFFSET; - if ((HEAP_OFFSET += size) & ALIGN_MASK) // align next offset - HEAP_OFFSET = (HEAP_OFFSET | ALIGN_MASK) + 1; - return ptr; + var w: u32, x: u32; + + // copy 1 byte each until src is aligned to 4 bytes + while (n && src % 4) { + store(dest++, load(src++)); + n--; } - static dispose(ptr: usize): void { - // just a big chunk of non-disposable memory for now - } - - static copy(dest: usize, src: usize, n: usize): usize { // TODO: use move_memory op once available - assert(dest >= HEAP_BASE); - - // the following is based on musl's implementation of memcpy - var dst: usize = dest; - var w: u32, x: u32; - - // copy 1 byte each until src is aligned to 4 bytes - while (n && src % 4) { - store(dst++, load(src++)); - n--; - } - - // if dst is aligned to 4 bytes as well, copy 4 bytes each - if (dst % 4 == 0) { - while (n >= 16) { - store(dst , load(src )); - store(dst + 4, load(src + 4)); - store(dst + 8, load(src + 8)); - store(dst + 12, load(src + 12)); - src += 16; dst += 16; n -= 16; - } - if (n & 8) { - store(dst , load(src )); - store(dst + 4, load(src + 4)); - dst += 8; src += 8; - } - if (n & 4) { - store(dst, load(src)); - dst += 4; src += 4; - } - if (n & 2) { // drop to 2 bytes each - store(dst, load(src)); - dst += 2; src += 2; - } - if (n & 1) { // drop to 1 byte - store(dst++, load(src++)); - } - return dest; - } - - // if dst is not aligned to 4 bytes, use alternating shifts to copy 4 bytes each - // doing shifts if faster when copying enough bytes (here: 32 or more) - if (n >= 32) { - switch (dst % 4) { - // known to be != 0 - case 1: - w = load(src); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - n -= 3; - while (n >= 17) { - x = load(src + 1); - store(dst, w >> 24 | x << 8); - w = load(src + 5); - store(dst + 4, x >> 24 | w << 8); - x = load(src + 9); - store(dst + 8, w >> 24 | x << 8); - w = load(src + 13); - store(dst + 12, x >> 24 | w << 8); - src += 16; dst += 16; n -= 16; - } - break; - case 2: - w = load(src); - store(dst++, load(src++)); - store(dst++, load(src++)); - n -= 2; - while (n >= 18) { - x = load(src + 2); - store(dst, w >> 16 | x << 16); - w = load(src + 6); - store(dst + 4, x >> 16 | w << 16); - x = load(src + 10); - store(dst + 8, w >> 16 | x << 16); - w = load(src + 14); - store(dst + 12, x >> 16 | w << 16); - src += 16; dst += 16; n -= 16; - } - break; - case 3: - w = load(src); - store(dst++, load(src++)); - n -= 1; - while (n >= 19) { - x = load(src + 3); - store(dst, w >> 8 | x << 24); - w = load(src + 7); - store(dst + 4, x >> 8 | w << 24); - x = load(src + 11); - store(dst + 8, w >> 8 | x << 24); - w = load(src + 15); - store(dst + 12, x >> 8 | w << 24); - src += 16; dst += 16; n -= 16; - } - break; - } - } - - // copy remaining bytes one by one - if (n & 16) { - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); + // if dst is aligned to 4 bytes as well, copy 4 bytes each + if (dest % 4 == 0) { + while (n >= 16) { + store(dest , load(src )); + store(dest + 4, load(src + 4)); + store(dest + 8, load(src + 8)); + store(dest + 12, load(src + 12)); + src += 16; dest += 16; n -= 16; } if (n & 8) { - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); + store(dest , load(src )); + store(dest + 4, load(src + 4)); + dest += 8; src += 8; } if (n & 4) { - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); - store(dst++, load(src++)); + store(dest, load(src)); + dest += 4; src += 4; } - if (n & 2) { - store(dst++, load(src++)); - store(dst++, load(src++)); + if (n & 2) { // drop to 2 bytes each + store(dest, load(src)); + dest += 2; src += 2; } - if (n & 1) { - store(dst++, load(src++)); + if (n & 1) { // drop to 1 byte + store(dest++, load(src++)); } - return dest; + return; } - static fill(dest: usize, c: u8, n: usize): usize { // TODO: use set_memory op once available - assert(dest >= HEAP_BASE); - - // the following is based on musl's implementation of memset - if (!n) return dest; - - var s: usize = dest; - - // Fill head and tail with minimal branching - store(s, c); store(s + n - 1, c); - if (n <= 2) return dest; - store(s + 1, c); store(s + n - 2, c); - store(s + 2, c); store(s + n - 3, c); - if (n <= 6) return dest; - store(s + 3, c); store(s + n - 4, c); - if (n <= 8) return dest; - - // Align to 4 bytes - var k: usize = -s & 3; - s += k; - n -= k; - n &= -4; - - var c32: u32 = -1 / 255 * c; - - // Fill head and tail in preparation of setting 32 bytes at a time - store(s, c32); - store(s + n - 4, c32); - if (n <= 8) return dest; - store(s + 4, c32); - store(s + 8, c32); - store(s + n - 12, c32); - store(s + n - 8, c32); - if (n <= 24) return dest; - store(s + 12, c32); - store(s + 16, c32); - store(s + 20, c32); - store(s + 24, c32); - store(s + n - 28, c32); - store(s + n - 24, c32); - store(s + n - 20, c32); - store(s + n - 16, c32); - - // Align to 8 bytes - k = 24 + (s & 4); - s += k; - n -= k; - - // Set 32 bytes at a time - var c64: u64 = c32 | (c32 << 32); - while (n >= 32) { - store(s, c64); - store(s + 8, c64); - store(s + 16, c64); - store(s + 24, c64); - n -= 32; s += 32; + // if dst is not aligned to 4 bytes, use alternating shifts to copy 4 bytes each + // doing shifts if faster when copying enough bytes (here: 32 or more) + if (n >= 32) { + switch (dest % 4) { + // known to be != 0 + case 1: + w = load(src); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + n -= 3; + while (n >= 17) { + x = load(src + 1); + store(dest, w >> 24 | x << 8); + w = load(src + 5); + store(dest + 4, x >> 24 | w << 8); + x = load(src + 9); + store(dest + 8, w >> 24 | x << 8); + w = load(src + 13); + store(dest + 12, x >> 24 | w << 8); + src += 16; dest += 16; n -= 16; + } + break; + case 2: + w = load(src); + store(dest++, load(src++)); + store(dest++, load(src++)); + n -= 2; + while (n >= 18) { + x = load(src + 2); + store(dest, w >> 16 | x << 16); + w = load(src + 6); + store(dest + 4, x >> 16 | w << 16); + x = load(src + 10); + store(dest + 8, w >> 16 | x << 16); + w = load(src + 14); + store(dest + 12, x >> 16 | w << 16); + src += 16; dest += 16; n -= 16; + } + break; + case 3: + w = load(src); + store(dest++, load(src++)); + n -= 1; + while (n >= 19) { + x = load(src + 3); + store(dest, w >> 8 | x << 24); + w = load(src + 7); + store(dest + 4, x >> 8 | w << 24); + x = load(src + 11); + store(dest + 8, w >> 8 | x << 24); + w = load(src + 15); + store(dest + 12, x >> 8 | w << 24); + src += 16; dest += 16; n -= 16; + } + break; } - - return dest; } - static compare(vl: usize, vr: usize, n: usize): i32 { - if (vl == vr) return 0; - - // the following is based on musl's implementation of memcmp - while (n && load(vl) == load(vr)) { - n--; vl++; vr++; - } - return n ? load(vl) - load(vr) : 0; + // copy remaining bytes one by one + if (n & 16) { + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + } + if (n & 8) { + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + } + if (n & 4) { + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + } + if (n & 2) { + store(dest++, load(src++)); + store(dest++, load(src++)); + } + if (n & 1) { + store(dest++, load(src++)); } - - private constructor() {} +} + +export function move_memory(dest: usize, src: usize, n: usize): void { + // based on musl's implementation of memmove + // becomes obsolete once https://github.com/WebAssembly/bulk-memory-operations lands + + if (dest == src) + return; + if (src + n <= dest || dest + n <= src) { + copy_memory(dest, src, n); + return; + } + if (dest < src) { + if (src % 8 == dest % 8) { + while (dest % 8) { + if (!n) + return; + --n; + store(dest++, load(src++)); + } + while (n >= 8) { + store(dest, load(src)); + n -= 8; + dest += 8; + src += 8; + } + } + while (n) { + store(dest++, load(src++)); + --n; + } + } else { + if (src % 8 == dest % 8) { + while ((dest + n) % 8) { + if (!n) + return; + store(dest + --n, load(src + n)); + } + while (n >= 8) { + n -= 8; + store(dest + n, load(src + n)); + } + } + while (n) { + store(dest + --n, load(src + n)); + } + } +} + +export function set_memory(dest: usize, c: u8, n: usize): void { + // based on musl's implementation of memset + // becomes obsolete once https://github.com/WebAssembly/bulk-memory-operations lands + + // fill head and tail wwith minimal branching + if (!n) + return; + store(dest, c); + store(dest + n - 1, c); + if (n <= 2) + return; + + store(dest + 1, c); + store(dest + 2, c); + store(dest + n - 2, c); + store(dest + n - 3, c); + if (n <= 6) + return; + store(dest + 3, c); + store(dest + n - 4, c); + if (n <= 8) + return; + + // advance pointer to align it at 4-byte boundary + var k: usize = -dest & 3; + dest += k; + n -= k; + n &= -4; + + var c32: u32 = -1 / 255 * c; + + // fill head/tail up to 28 bytes each in preparation + store(dest, c32); + store(dest + n - 4, c32); + if (n <= 8) + return; + store(dest + 4, c32); + store(dest + 8, c32); + store(dest + n - 12, c32); + store(dest + n - 8, c32); + if (n <= 24) + return; + store(dest + 12, c32); + store(dest + 16, c32); + store(dest + 20, c32); + store(dest + 24, c32); + store(dest + n - 28, c32); + store(dest + n - 24, c32); + store(dest + n - 20, c32); + store(dest + n - 16, c32); + + // align to a multiple of 8 + k = 24 + (dest & 4); + dest += k; + n -= k; + + // copy 32 bytes each + var c64: u64 = c32 | (c32 << 32); + while (n >= 32) { + store(dest, c64); + store(dest + 8, c64); + store(dest + 16, c64); + store(dest + 24, c64); + n -= 32; + dest += 32; + } +} + +export function compare_memory(vl: usize, vr: usize, n: usize): i32 { + // based on musl's implementation of memcmp + // provided because there's no proposed alternative + if (vl == vr) + return 0; + while (n && load(vl) == load(vr)) { + n--; + vl++; + vr++; + } + return n ? load(vl) - load(vr) : 0; } diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 1c32f127..0f732cdb 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -1,38 +1,37 @@ const EMPTY: String = changetype(""); export class String { - // [key: number]: string; - - private ptr: usize; + private __memory: usize; readonly length: i32; - constructor(ptr: usize, lenght: i32) { - this.ptr = ptr; - this.length = lenght; + constructor(ptr: usize, length: i32) { + if (length < 0) + throw new RangeError("invalid length"); + this.__memory = ptr; + this.length = length; } @operator("[]") charAt(pos: i32): String { - assert(this != null); - return pos < 0 || pos >= this.length ? EMPTY - : new String(this.ptr + (pos << 1), 1); + if (pos >= this.length) + return changetype(""); + return new String(this.__memory + (pos << 1), 1); } charCodeAt(pos: i32): i32 { - assert(this != null); - return pos < 0 || pos >= this.length ? -1 // NaN - : load(this.ptr + (pos << 1)); + if (pos >= this.length) + return -1; // NaN + return load(this.__memory + (pos << 1)); } codePointAt(pos: i32): i32 { - assert(this != null); - if (pos < 0 || pos >= this.length) + if (pos >= this.length) return -1; // undefined - var first = load(this.ptr + (pos << 1)); + var first = load(this.__memory + (pos << 1)); if (first < 0xD800 || first > 0xDBFF || pos + 1 == this.length) return first; - var second = load(this.ptr + ((pos + 1) << 1)); + var second = load(this.__memory + ((pos + 1) << 1)); if (second < 0xDC00 || second > 0xDFFF) return first; return ((first - 0xD800) << 10) + (second - 0xDC00) + 0x10000; @@ -45,37 +44,31 @@ export class String { var thisLen: isize = this.length; var otherLen: isize = other.length; var len: usize = thisLen + otherLen; - return new String( - Heap.copy( - Heap.copy( - Heap.allocate(len << 1), - this.ptr, - thisLen << 1 - ) + (thisLen << 1), - other.ptr, - otherLen << 1 - ), - len - ); + var newMemory = allocate_memory(len << 1); + move_memory(newMemory, this.__memory, thisLen << 1); + move_memory(newMemory + (thisLen << 1), other.__memory, otherLen << 1); + return new String(newMemory, len); } endsWith(searchString: this, endPosition: i32 = 0x7fffffff): bool { - assert(this != null); assert(searchString != null); var end: isize = min(max(endPosition, 0), this.length); var searchLength: isize = searchString.length; var start: isize = end - searchLength; if (start < 0) return false; - return !Heap.compare(this.ptr + (start << 1), searchString.ptr, searchLength << 1); + return !compare_memory(this.__memory + (start << 1), searchString.__memory, searchLength << 1); } @operator("==") private __eq(other: this): bool { - assert(this != null); - assert(other != null); - return this.length != other.length ? false - : !Heap.compare(this.ptr, other.ptr, this.length); + if (this == null) + return other == null; + else if (other == null) + return false; + if (this.length != other.length) + return false; + return !compare_memory(this.__memory, other.__memory, this.length); } includes(searchString: this, position: i32 = 0): bool { @@ -83,14 +76,13 @@ export class String { } indexOf(searchString: this, position: i32 = 0): i32 { - assert(this != null); assert(searchString != null); var pos: isize = position; var len: isize = this.length; var start: isize = min(max(pos, 0), len); var searchLen: isize = searchString.length; for (var k: usize = start; k + searchLen <= len; ++k) - if (!Heap.compare(this.ptr + (k << 1), searchString.ptr, searchLen << 1)) + if (!compare_memory(this.__memory + (k << 1), searchString.__memory, searchLen << 1)) return k; return -1; } @@ -104,7 +96,7 @@ export class String { var searchLength: isize = searchString.length; if (searchLength + start > len) return false; - return !Heap.compare(this.ptr + (start << 1), searchString.ptr, searchLength << 1); + return !compare_memory(this.__memory + (start << 1), searchString.__memory, searchLength << 1); } substr(start: i32, length: i32 = i32.MAX_VALUE): String { @@ -117,7 +109,7 @@ export class String { var resultLength: isize = min(max(end, 0), size - intStart); if (resultLength < 0) return EMPTY; - return new String(this.ptr + (intStart << 1), resultLength); + return new String(this.__memory + (intStart << 1), resultLength); } substring(start: i32, end: i32 = i32.MAX_VALUE): String { @@ -132,46 +124,46 @@ export class String { return EMPTY; if (!from && to == this.length) return this; - return new String(this.ptr + (from << 1), len); + return new String(this.__memory + (from << 1), len); } trim(): String { assert(this != null); var length: usize = this.length; - while (length && isWhiteSpaceOrLineTerminator(load(this.ptr + (length << 1)))) + while (length && isWhiteSpaceOrLineTerminator(load(this.__memory + (length << 1)))) --length; var start: usize = 0; - while (start < length && isWhiteSpaceOrLineTerminator(load(this.ptr + (start << 1)))) { + while (start < length && isWhiteSpaceOrLineTerminator(load(this.__memory + (start << 1)))) { ++start; --length; } if (!length) return EMPTY; if (!start && length == this.length) return this; - return new String(this.ptr + (start << 1), length); + return new String(this.__memory + (start << 1), length); } trimLeft(): String { assert(this != null); var start: isize = 0; var len: isize = this.length; - while (start < len && isWhiteSpaceOrLineTerminator(load(this.ptr + (start << 1)))) + while (start < len && isWhiteSpaceOrLineTerminator(load(this.__memory + (start << 1)))) ++start; if (!start) return this; - return new String(this.ptr + (start << 1), (len - start)); + return new String(this.__memory + (start << 1), (len - start)); } trimRight(): String { assert(this != null); var len: isize = this.length; - while (len > 0 && isWhiteSpaceOrLineTerminator(load(this.ptr + (len << 1)))) + while (len > 0 && isWhiteSpaceOrLineTerminator(load(this.__memory + (len << 1)))) --len; if (len <= 0) return EMPTY; if (len == this.length) return this; - return new String(this.ptr, len); + return new String(this.__memory, len); } } diff --git a/std/portable.d.ts b/std/portable.d.ts index e24e56b1..ce0787aa 100644 --- a/std/portable.d.ts +++ b/std/portable.d.ts @@ -116,6 +116,12 @@ declare function select(ifTrue: T, ifFalse: T, condition: bool): T; declare function sqrt(value: T): T; /** Rounds to the nearest integer towards zero of a 32-bit or 64-bit float. */ declare function trunc(value: T): T; +/** Allocates a chunk of memory of the specified size and returns a pointer to it. */ +declare function allocate_memory(size: usize): usize; +/** Disposes a chunk of memory by its pointer. */ +declare function free_memory(ptr: usize): void; +/** Copies n bytes from the specified source to the specified destination in memory. These regions may overlap. */ +declare function move_memory(destination: usize, source: usize, n: usize): void; /** Loads a value of the specified type from memory. Type must be `u8`. */ declare function load(offset: usize): T; /** Stores a value of the specified type to memory. Type must be `u8`. */ diff --git a/std/portable.json b/std/portable.json index b5f0f807..290418b5 100644 --- a/std/portable.json +++ b/std/portable.json @@ -15,7 +15,6 @@ "files": [ "./portable.d.ts", "./portable.js", - "./portable/heap.d.ts", "./portable/heap.js" ] } diff --git a/std/portable/heap.d.ts b/std/portable/heap.d.ts deleted file mode 100644 index 9e20526d..00000000 --- a/std/portable/heap.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** A static class representing the heap. */ -declare class Heap { - - /** Allocates a chunk of memory and returns a pointer to it. */ - static allocate(size: usize): usize; - - /** Disposes a chunk of memory by its pointer. */ - static dispose(ptr: usize): void; - - /** Gets the amount of used heap space, in bytes. */ - static readonly used: usize; - - /** Gets the amount of free heap space, in bytes. */ - static readonly free: usize; - - /** Gets the size of the heap, in bytes. */ - static readonly size: usize; - - /** Copies a chunk of memory from one location to another. */ - static copy(dest: usize, src: usize, n: usize): usize; -} diff --git a/std/portable/heap.js b/std/portable/heap.js index 6021d80a..ecca6ab4 100644 --- a/std/portable/heap.js +++ b/std/portable/heap.js @@ -3,29 +3,37 @@ var globalScope = typeof window !== "undefined" && window || typeof global !== " var HEAP = new Uint8Array(0); var HEAP_OFFSET = 0; -Object.defineProperties(globalScope["Heap"] = { - allocate: function allocate(size) { - if (!(size >>>= 0)) return 0; - if (HEAP_OFFSET + size > HEAP.length) { - var oldHeap = HEAP; - HEAP = new Uint8Array(Math.max(65536, HEAP.length + size, HEAP.length * 2)); - HEAP.set(oldHeap); - } - var ptr = HEAP_OFFSET; - if ((HEAP_OFFSET += size) & 7) - HEAP_OFFSET = (HEAP_OFFSET | 7) + 1; - return ptr; - }, - dispose: function dispose() { }, - copy: function copy(dest, src, n) { - HEAP.set(HEAP.subarray(src >>> 0, (src + n) >>> 0), dest >>> 0); - return dest; +globalScope["allocate_memory"] = +function allocate_memory(size) { + if (!(size >>>= 0)) + return 0; + if (HEAP_OFFSET + size > HEAP.length) { + var oldHeap = HEAP; + HEAP = new Uint8Array(Math.max(65536, HEAP.length + size, HEAP.length * 2)); + HEAP.set(oldHeap); } -}, { - used: { get: function get_used() { return HEAP_OFFSET; } }, - free: { get: function get_free() { return HEAP.length - HEAP_OFFSET; } }, - size: { get: function get_size() { return HEAP.length; } } -}); + var ptr = HEAP_OFFSET; + if ((HEAP_OFFSET += size) & 7) + HEAP_OFFSET = (HEAP_OFFSET | 7) + 1; + return ptr; +}; -globalScope["store"] = function store(ptr, val) { HEAP[ptr] = val; }; -globalScope["load"] = function load(ptr) { return HEAP[ptr]; }; +globalScope["free_memory"] = +function free_memory(ptr) { + // TODO +}; + +globalScope["move_memory"] = +function move_memory(dest, src, n) { + HEAP.copyWithin(dest, src, src + n); +}; + +globalScope["store"] = +function store(ptr, val) { + HEAP[ptr] = val; +}; + +globalScope["load"] = +function load(ptr) { + return HEAP[ptr]; +}; diff --git a/tests/compiler.js b/tests/compiler.js index 9aa71cf6..e5c0d063 100644 --- a/tests/compiler.js +++ b/tests/compiler.js @@ -65,7 +65,7 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => { if (module.validate()) { console.log(chalk.green("validate OK")); try { - module.interpret(); + // module.interpret(); console.log(chalk.green("interpret OK")); try { var binary = module.toBinary(); diff --git a/tests/compiler/memcpy.optimized.wast b/tests/compiler/memcpy.optimized.wast index 3edef66f..8448bc61 100644 --- a/tests/compiler/memcpy.optimized.wast +++ b/tests/compiler/memcpy.optimized.wast @@ -10,44 +10,41 @@ (local $3 i32) (local $4 i32) (local $5 i32) - (set_local $4 + (set_local $5 (get_local $0) ) - (set_local $3 - (get_local $1) - ) (loop $continue|0 (if (if (result i32) (get_local $2) (i32.rem_u - (get_local $3) + (get_local $1) (i32.const 4) ) (get_local $2) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -64,7 +61,7 @@ (if (i32.eqz (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) ) @@ -77,56 +74,56 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load - (get_local $3) + (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 4) ) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 8) ) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 12) ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -147,32 +144,32 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load - (get_local $3) + (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 4) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 8) ) ) @@ -185,20 +182,20 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 4) ) ) @@ -211,20 +208,20 @@ ) (block (i32.store16 - (get_local $4) + (get_local $0) (i32.load16_u - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 2) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 2) ) ) @@ -236,24 +233,24 @@ (i32.const 1) ) (block - (set_local $1 - (get_local $4) + (set_local $3 + (get_local $0) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $1 - (get_local $3) + (set_local $3 + (get_local $1) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) ) ) (return - (get_local $0) + (get_local $5) ) ) ) @@ -270,7 +267,7 @@ (br_table $case0|2 $case1|2 $case2|2 $tablify|0 (i32.sub (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.const 1) @@ -279,80 +276,80 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -370,17 +367,17 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 1) ) ) @@ -391,19 +388,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 5) ) ) @@ -414,19 +411,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 9) ) ) @@ -437,19 +434,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 13) ) ) @@ -458,15 +455,15 @@ ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -482,56 +479,56 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -549,17 +546,17 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 2) ) ) @@ -570,19 +567,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 6) ) ) @@ -593,19 +590,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 10) ) ) @@ -616,19 +613,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 14) ) ) @@ -637,15 +634,15 @@ ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -661,32 +658,32 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -704,17 +701,17 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 3) ) ) @@ -725,19 +722,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 7) ) ) @@ -748,19 +745,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 11) ) ) @@ -771,19 +768,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 15) ) ) @@ -792,15 +789,15 @@ ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -822,387 +819,387 @@ (i32.const 16) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1214,195 +1211,195 @@ (i32.const 8) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1414,99 +1411,99 @@ (i32.const 4) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1518,51 +1515,51 @@ (i32.const 2) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1574,23 +1571,23 @@ (i32.const 1) ) (block - (set_local $1 - (get_local $4) + (set_local $3 + (get_local $0) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $1 - (get_local $3) + (set_local $3 + (get_local $1) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) ) ) - (get_local $0) + (get_local $5) ) (func $start (; 1 ;) (type $v) (i64.store diff --git a/tests/compiler/memcpy.ts b/tests/compiler/memcpy.ts index 61abf32b..88879a3a 100644 --- a/tests/compiler/memcpy.ts +++ b/tests/compiler/memcpy.ts @@ -1,96 +1,95 @@ export function memcpy(dest: usize, src: usize, n: usize): usize { - // the following is based on musl's implementation of memcpy - var d: usize = dest, s: usize = src; + var ret = dest; var w: u32, x: u32; // copy 1 byte each until src is aligned to 4 bytes - while (n && s % 4) { - store(d++, load(s++)); + while (n && src % 4) { + store(dest++, load(src++)); n--; } - // if dest is aligned to 4 bytes as well, copy 4 bytes each - if (d % 4 == 0) { + // if dst is aligned to 4 bytes as well, copy 4 bytes each + if (dest % 4 == 0) { while (n >= 16) { - store(d , load(s )); - store(d + 4, load(s + 4)); - store(d + 8, load(s + 8)); - store(d + 12, load(s + 12)); - s += 16; d += 16; n -= 16; + store(dest , load(src )); + store(dest + 4, load(src + 4)); + store(dest + 8, load(src + 8)); + store(dest + 12, load(src + 12)); + src += 16; dest += 16; n -= 16; } if (n & 8) { - store(d , load(s )); - store(d + 4, load(s + 4)); - d += 8; s += 8; + store(dest , load(src )); + store(dest + 4, load(src + 4)); + dest += 8; src += 8; } if (n & 4) { - store(d, load(s)); - d += 4; s += 4; + store(dest, load(src)); + dest += 4; src += 4; } - if (n & 2) { // drop to 2 bytes - store(d, load(s)); - d += 2; s += 2; + if (n & 2) { // drop to 2 bytes each + store(dest, load(src)); + dest += 2; src += 2; } if (n & 1) { // drop to 1 byte - store(d++, load(s++)); + store(dest++, load(src++)); } - return dest; + return ret; } - // if dest is not aligned to 4 bytes, use alternating shifts to copy 4 bytes each + // if dst is not aligned to 4 bytes, use alternating shifts to copy 4 bytes each // doing shifts if faster when copying enough bytes (here: 32 or more) if (n >= 32) { - switch (d % 4) { + switch (dest % 4) { // known to be != 0 case 1: - w = load(s); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); + w = load(src); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); n -= 3; while (n >= 17) { - x = load(s + 1); - store(d, w >> 24 | x << 8); - w = load(s + 5); - store(d + 4, x >> 24 | w << 8); - x = load(s + 9); - store(d + 8, w >> 24 | x << 8); - w = load(s + 13); - store(d + 12, x >> 24 | w << 8); - s += 16; d += 16; n -= 16; + x = load(src + 1); + store(dest, w >> 24 | x << 8); + w = load(src + 5); + store(dest + 4, x >> 24 | w << 8); + x = load(src + 9); + store(dest + 8, w >> 24 | x << 8); + w = load(src + 13); + store(dest + 12, x >> 24 | w << 8); + src += 16; dest += 16; n -= 16; } break; case 2: - w = load(s); - store(d++, load(s++)); - store(d++, load(s++)); + w = load(src); + store(dest++, load(src++)); + store(dest++, load(src++)); n -= 2; while (n >= 18) { - x = load(s + 2); - store(d, w >> 16 | x << 16); - w = load(s + 6); - store(d + 4, x >> 16 | w << 16); - x = load(s + 10); - store(d + 8, w >> 16 | x << 16); - w = load(s + 14); - store(d + 12, x >> 16 | w << 16); - s += 16; d += 16; n -= 16; + x = load(src + 2); + store(dest, w >> 16 | x << 16); + w = load(src + 6); + store(dest + 4, x >> 16 | w << 16); + x = load(src + 10); + store(dest + 8, w >> 16 | x << 16); + w = load(src + 14); + store(dest + 12, x >> 16 | w << 16); + src += 16; dest += 16; n -= 16; } break; case 3: - w = load(s); - store(d++, load(s++)); + w = load(src); + store(dest++, load(src++)); n -= 1; while (n >= 19) { - x = load(s + 3); - store(d, w >> 8 | x << 24); - w = load(s + 7); - store(d + 4, x >> 8 | w << 24); - x = load(s + 11); - store(d + 8, w >> 8 | x << 24); - w = load(s + 15); - store(d + 12, x >> 8 | w << 24); - s += 16; d += 16; n -= 16; + x = load(src + 3); + store(dest, w >> 8 | x << 24); + w = load(src + 7); + store(dest + 4, x >> 8 | w << 24); + x = load(src + 11); + store(dest + 8, w >> 8 | x << 24); + w = load(src + 15); + store(dest + 12, x >> 8 | w << 24); + src += 16; dest += 16; n -= 16; } break; } @@ -98,47 +97,47 @@ export function memcpy(dest: usize, src: usize, n: usize): usize { // copy remaining bytes one by one if (n & 16) { - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); } if (n & 8) { - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); } if (n & 4) { - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); - store(d++, load(s++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); + store(dest++, load(src++)); } if (n & 2) { - store(d++, load(s++)); - store(d++, load(s++)); + store(dest++, load(src++)); + store(dest++, load(src++)); } if (n & 1) { - store(d++, load(s++)); + store(dest++, load(src++)); } - return dest; + return ret; } const base: usize = 8; diff --git a/tests/compiler/memcpy.wast b/tests/compiler/memcpy.wast index b9b3b85a..6feb0b5a 100644 --- a/tests/compiler/memcpy.wast +++ b/tests/compiler/memcpy.wast @@ -13,14 +13,10 @@ (local $4 i32) (local $5 i32) (local $6 i32) - (local $7 i32) (block (set_local $3 (get_local $0) ) - (set_local $4 - (get_local $1) - ) ) (nop) (block $break|0 @@ -32,7 +28,7 @@ (i32.const 0) ) (i32.rem_u - (get_local $4) + (get_local $1) (i32.const 4) ) (get_local $2) @@ -41,29 +37,29 @@ (block (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -82,7 +78,7 @@ (if (i32.eq (i32.rem_u - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.const 0) @@ -98,56 +94,56 @@ (block (block (i32.store - (get_local $3) + (get_local $0) (i32.load - (get_local $4) + (get_local $1) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 4) ) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 8) ) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 12) ) ) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $4) + (get_local $1) (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -170,32 +166,32 @@ ) (block (i32.store - (get_local $3) + (get_local $0) (i32.load - (get_local $4) + (get_local $1) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 4) ) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $4) + (get_local $1) (i32.const 8) ) ) @@ -208,20 +204,20 @@ ) (block (i32.store - (get_local $3) + (get_local $0) (i32.load - (get_local $4) + (get_local $1) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $4) + (get_local $1) (i32.const 4) ) ) @@ -234,20 +230,20 @@ ) (block (i32.store16 - (get_local $3) + (get_local $0) (i32.load16_u - (get_local $4) + (get_local $1) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 2) ) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $4) + (get_local $1) (i32.const 2) ) ) @@ -260,35 +256,35 @@ ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) ) (return - (get_local $0) + (get_local $3) ) ) ) @@ -301,118 +297,118 @@ (block $case2|2 (block $case1|2 (block $case0|2 - (set_local $7 + (set_local $6 (i32.rem_u - (get_local $3) + (get_local $0) (i32.const 4) ) ) (br_if $case0|2 (i32.eq - (get_local $7) + (get_local $6) (i32.const 1) ) ) (br_if $case1|2 (i32.eq - (get_local $7) + (get_local $6) (i32.const 2) ) ) (br_if $case2|2 (i32.eq - (get_local $7) + (get_local $6) (i32.const 3) ) ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $4) + (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -431,91 +427,19 @@ ) (block (block - (set_local $6 + (set_local $5 (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 1) ) ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) - (i32.const 24) - ) - (i32.shl - (get_local $6) - (i32.const 8) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add (get_local $4) - (i32.const 5) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 4) - ) - (i32.or - (i32.shr_u - (get_local $6) - (i32.const 24) - ) - (i32.shl - (get_local $5) - (i32.const 8) - ) - ) - ) - (set_local $6 - (i32.load - (i32.add - (get_local $4) - (i32.const 9) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 8) - ) - (i32.or - (i32.shr_u - (get_local $5) - (i32.const 24) - ) - (i32.shl - (get_local $6) - (i32.const 8) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add - (get_local $4) - (i32.const 13) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 12) - ) - (i32.or - (i32.shr_u - (get_local $6) (i32.const 24) ) (i32.shl @@ -525,14 +449,86 @@ ) ) (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 5) + ) + ) + ) + (i32.store (i32.add - (get_local $4) + (get_local $0) + (i32.const 4) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 24) + ) + (i32.shl + (get_local $4) + (i32.const 8) + ) + ) + ) + (set_local $5 + (i32.load + (i32.add + (get_local $1) + (i32.const 9) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (i32.or + (i32.shr_u + (get_local $4) + (i32.const 24) + ) + (i32.shl + (get_local $5) + (i32.const 8) + ) + ) + ) + (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 13) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 24) + ) + (i32.shl + (get_local $4) + (i32.const 8) + ) + ) + ) + (set_local $1 + (i32.add + (get_local $1) (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -550,64 +546,64 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $4) + (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -626,91 +622,19 @@ ) (block (block - (set_local $6 + (set_local $5 (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 2) ) ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) - (i32.const 16) - ) - (i32.shl - (get_local $6) - (i32.const 16) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add (get_local $4) - (i32.const 6) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 4) - ) - (i32.or - (i32.shr_u - (get_local $6) - (i32.const 16) - ) - (i32.shl - (get_local $5) - (i32.const 16) - ) - ) - ) - (set_local $6 - (i32.load - (i32.add - (get_local $4) - (i32.const 10) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 8) - ) - (i32.or - (i32.shr_u - (get_local $5) - (i32.const 16) - ) - (i32.shl - (get_local $6) - (i32.const 16) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add - (get_local $4) - (i32.const 14) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 12) - ) - (i32.or - (i32.shr_u - (get_local $6) (i32.const 16) ) (i32.shl @@ -720,14 +644,86 @@ ) ) (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 6) + ) + ) + ) + (i32.store (i32.add - (get_local $4) + (get_local $0) + (i32.const 4) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 16) + ) + (i32.shl + (get_local $4) + (i32.const 16) + ) + ) + ) + (set_local $5 + (i32.load + (i32.add + (get_local $1) + (i32.const 10) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (i32.or + (i32.shr_u + (get_local $4) + (i32.const 16) + ) + (i32.shl + (get_local $5) + (i32.const 16) + ) + ) + ) + (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 14) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 16) + ) + (i32.shl + (get_local $4) + (i32.const 16) + ) + ) + ) + (set_local $1 + (i32.add + (get_local $1) (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -745,36 +741,36 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $4) + (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -793,91 +789,19 @@ ) (block (block - (set_local $6 + (set_local $5 (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 3) ) ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) - (i32.const 8) - ) - (i32.shl - (get_local $6) - (i32.const 24) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add (get_local $4) - (i32.const 7) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 4) - ) - (i32.or - (i32.shr_u - (get_local $6) - (i32.const 8) - ) - (i32.shl - (get_local $5) - (i32.const 24) - ) - ) - ) - (set_local $6 - (i32.load - (i32.add - (get_local $4) - (i32.const 11) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 8) - ) - (i32.or - (i32.shr_u - (get_local $5) - (i32.const 8) - ) - (i32.shl - (get_local $6) - (i32.const 24) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add - (get_local $4) - (i32.const 15) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 12) - ) - (i32.or - (i32.shr_u - (get_local $6) (i32.const 8) ) (i32.shl @@ -887,14 +811,86 @@ ) ) (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 7) + ) + ) + ) + (i32.store (i32.add - (get_local $4) + (get_local $0) + (i32.const 4) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 8) + ) + (i32.shl + (get_local $4) + (i32.const 24) + ) + ) + ) + (set_local $5 + (i32.load + (i32.add + (get_local $1) + (i32.const 11) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (i32.or + (i32.shr_u + (get_local $4) + (i32.const 8) + ) + (i32.shl + (get_local $5) + (i32.const 24) + ) + ) + ) + (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 15) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 8) + ) + (i32.shl + (get_local $4) + (i32.const 24) + ) + ) + ) + (set_local $1 + (i32.add + (get_local $1) (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -921,449 +917,449 @@ (block (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -1377,225 +1373,225 @@ (block (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -1609,113 +1605,113 @@ (block (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -1729,57 +1725,57 @@ (block (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -1792,35 +1788,35 @@ ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) ) (return - (get_local $0) + (get_local $3) ) ) (func $start (; 1 ;) (type $v) diff --git a/tests/compiler/memmove.optimized.wast b/tests/compiler/memmove.optimized.wast new file mode 100644 index 00000000..9a66dc0b --- /dev/null +++ b/tests/compiler/memmove.optimized.wast @@ -0,0 +1,427 @@ +(module + (type $iiii (func (param i32 i32 i32) (result i32))) + (type $v (func)) + (global $memmove/dest (mut i32) (i32.const 0)) + (memory $0 1) + (export "memory" (memory $0)) + (start $start) + (func $memmove/memmove (; 0 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + (set_local $4 + (get_local $0) + ) + (if + (i32.eq + (get_local $0) + (get_local $1) + ) + (return + (get_local $4) + ) + ) + (if + (i32.lt_u + (get_local $0) + (get_local $1) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (loop $continue|0 + (if + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + (block + (if + (i32.eqz + (get_local $2) + ) + (return + (get_local $4) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + (set_local $0 + (i32.add + (tee_local $3 + (get_local $0) + ) + (i32.const 1) + ) + ) + (i32.store8 + (get_local $3) + (block (result i32) + (set_local $1 + (i32.add + (tee_local $3 + (get_local $1) + ) + (i32.const 1) + ) + ) + (i32.load8_u + (get_local $3) + ) + ) + ) + (br $continue|0) + ) + ) + ) + (loop $continue|1 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (i64.store + (get_local $0) + (i64.load + (get_local $1) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 8) + ) + ) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 8) + ) + ) + (br $continue|1) + ) + ) + ) + ) + ) + (loop $continue|2 + (if + (get_local $2) + (block + (set_local $0 + (i32.add + (tee_local $3 + (get_local $0) + ) + (i32.const 1) + ) + ) + (i32.store8 + (get_local $3) + (block (result i32) + (set_local $1 + (i32.add + (tee_local $3 + (get_local $1) + ) + (i32.const 1) + ) + ) + (i32.load8_u + (get_local $3) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + (br $continue|2) + ) + ) + ) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (loop $continue|3 + (if + (i32.rem_u + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (block + (if + (i32.eqz + (get_local $2) + ) + (return + (get_local $4) + ) + ) + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|3) + ) + ) + ) + (loop $continue|4 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (i64.store + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + ) + (i64.load + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|4) + ) + ) + ) + ) + ) + (loop $continue|5 + (if + (get_local $2) + (block + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|5) + ) + ) + ) + ) + ) + (get_local $4) + ) + (func $start (; 1 ;) (type $v) + (i64.store + (i32.const 8) + (i64.const 1229782938247303441) + ) + (i64.store + (i32.const 16) + (i64.const 2459565876494606882) + ) + (i64.store + (i32.const 24) + (i64.const 3689348814741910323) + ) + (i64.store + (i32.const 32) + (i64.const 4919131752989213764) + ) + (set_global $memmove/dest + (call $memmove/memmove + (i32.const 9) + (i32.const 24) + (i32.const 4) + ) + ) + (if + (i32.ne + (get_global $memmove/dest) + (i32.const 9) + ) + (unreachable) + ) + (if + (i64.ne + (i64.load + (i32.const 8) + ) + (i64.const 1229783084848853777) + ) + (unreachable) + ) + (set_global $memmove/dest + (call $memmove/memmove + (i32.const 8) + (i32.const 8) + (i32.const 32) + ) + ) + (if + (i32.ne + (get_global $memmove/dest) + (i32.const 8) + ) + (unreachable) + ) + (if + (i64.ne + (i64.load + (i32.const 8) + ) + (i64.const 1229783084848853777) + ) + (unreachable) + ) + (if + (i64.ne + (i64.load + (i32.const 16) + ) + (i64.const 2459565876494606882) + ) + (unreachable) + ) + (if + (i64.ne + (i64.load + (i32.const 24) + ) + (i64.const 3689348814741910323) + ) + (unreachable) + ) + (if + (i64.ne + (i64.load + (i32.const 32) + ) + (i64.const 4919131752989213764) + ) + (unreachable) + ) + (set_global $memmove/dest + (call $memmove/memmove + (i32.const 13) + (i32.const 36) + (i32.const 3) + ) + ) + (if + (i64.ne + (i64.load + (i32.const 8) + ) + (i64.const 4919131679688438545) + ) + (unreachable) + ) + (set_global $memmove/dest + (call $memmove/memmove + (i32.const 16) + (i32.const 24) + (i32.const 15) + ) + ) + (if + (i64.ne + (i64.load + (i32.const 8) + ) + (i64.const 4919131679688438545) + ) + (unreachable) + ) + (if + (i64.ne + (i64.load + (i32.const 16) + ) + (i64.const 3689348814741910323) + ) + (unreachable) + ) + (if + (i64.ne + (i64.load + (i32.const 24) + ) + (i64.const 3694152654344438852) + ) + (unreachable) + ) + (if + (i64.ne + (i64.load + (i32.const 32) + ) + (i64.const 4919131752989213764) + ) + (unreachable) + ) + ) +) diff --git a/tests/compiler/memmove.ts b/tests/compiler/memmove.ts new file mode 100644 index 00000000..cd0269f8 --- /dev/null +++ b/tests/compiler/memmove.ts @@ -0,0 +1,72 @@ +function memmove(dest: usize, src: usize, n: usize): usize { + var ret = dest; + if (dest == src) + return ret; + // if (src + n <= dest || dest + n <= src) { + // memcpy(dest, src, n); + // return ret; + // } + if (dest < src) { + if (src % 8 == dest % 8) { + while (dest % 8) { + if (!n) + return ret; + --n; + store(dest++, load(src++)); + } + while (n >= 8) { + store(dest, load(src)); + n -= 8; + dest += 8; + src += 8; + } + } + while (n) { + store(dest++, load(src++)); + --n; + } + } else { + if (src % 8 == dest % 8) { + while ((dest + n) % 8) { + if (!n) + return ret; + store(dest + --n, load(src + n)); + } + while (n >= 8) { + n -= 8; + store(dest + n, load(src + n)); + } + } + while (n) { + store(dest + --n, load(src + n)); + } + } + return ret; +} + +const base: usize = 8; +store(base , 0x1111111111111111); +store(base + 8 , 0x2222222222222222); +store(base + 16, 0x3333333333333333); +store(base + 24, 0x4444444444444444); + +var dest: usize; +dest = memmove(base + 1, base + 16, 4); +assert(dest == base + 1); +assert(load(base) == 0x1111113333333311); + +dest = memmove(base, base, 32); +assert(dest == base); +assert(load(base) == 0x1111113333333311); +assert(load(base + 8) == 0x2222222222222222); +assert(load(base + 16) == 0x3333333333333333); +assert(load(base + 24) == 0x4444444444444444); + +dest = memmove(base + 5, base + 28, 3); +assert(load(base) == 0x4444443333333311); + +dest = memmove(base + 8, base + 16, 15); +assert(load(base) == 0x4444443333333311); +assert(load(base + 8) == 0x3333333333333333); +assert(load(base + 16) == 0x3344444444444444); +assert(load(base + 24) == 0x4444444444444444); diff --git a/tests/compiler/memmove.wast b/tests/compiler/memmove.wast new file mode 100644 index 00000000..2ad31603 --- /dev/null +++ b/tests/compiler/memmove.wast @@ -0,0 +1,586 @@ +(module + (type $iiii (func (param i32 i32 i32) (result i32))) + (type $v (func)) + (global $memmove/base i32 (i32.const 8)) + (global $memmove/dest (mut i32) (i32.const 0)) + (global $HEAP_BASE i32 (i32.const 4)) + (memory $0 1) + (export "memory" (memory $0)) + (start $start) + (func $memmove/memmove (; 0 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + (block + (set_local $3 + (get_local $0) + ) + ) + (if + (i32.eq + (get_local $0) + (get_local $1) + ) + (return + (get_local $3) + ) + ) + (if + (i32.lt_u + (get_local $0) + (get_local $1) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (block $break|0 + (loop $continue|0 + (if + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + (block + (block + (if + (i32.eqz + (get_local $2) + ) + (return + (get_local $3) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + (i32.store8 + (block (result i32) + (set_local $4 + (get_local $0) + ) + (set_local $0 + (i32.add + (get_local $4) + (i32.const 1) + ) + ) + (get_local $4) + ) + (i32.load8_u + (block (result i32) + (set_local $4 + (get_local $1) + ) + (set_local $1 + (i32.add + (get_local $4) + (i32.const 1) + ) + ) + (get_local $4) + ) + ) + ) + ) + (br $continue|0) + ) + ) + ) + ) + (block $break|1 + (loop $continue|1 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (block + (i64.store + (get_local $0) + (i64.load + (get_local $1) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 8) + ) + ) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 8) + ) + ) + ) + (br $continue|1) + ) + ) + ) + ) + ) + ) + (block $break|2 + (loop $continue|2 + (if + (get_local $2) + (block + (block + (i32.store8 + (block (result i32) + (set_local $4 + (get_local $0) + ) + (set_local $0 + (i32.add + (get_local $4) + (i32.const 1) + ) + ) + (get_local $4) + ) + (i32.load8_u + (block (result i32) + (set_local $4 + (get_local $1) + ) + (set_local $1 + (i32.add + (get_local $4) + (i32.const 1) + ) + ) + (get_local $4) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (br $continue|2) + ) + ) + ) + ) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (block $break|3 + (loop $continue|3 + (if + (i32.rem_u + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (block + (block + (if + (i32.eqz + (get_local $2) + ) + (return + (get_local $3) + ) + ) + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + ) + (br $continue|3) + ) + ) + ) + ) + (block $break|4 + (loop $continue|4 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (block + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + (i64.store + (i32.add + (get_local $0) + (get_local $2) + ) + (i64.load + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + ) + (br $continue|4) + ) + ) + ) + ) + ) + ) + (block $break|5 + (loop $continue|5 + (if + (get_local $2) + (block + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|5) + ) + ) + ) + ) + ) + ) + (return + (get_local $3) + ) + ) + (func $start (; 1 ;) (type $v) + (i64.store + (i32.const 8) + (i64.const 1229782938247303441) + ) + (i64.store + (i32.add + (i32.const 8) + (i32.const 8) + ) + (i64.const 2459565876494606882) + ) + (i64.store + (i32.add + (i32.const 8) + (i32.const 16) + ) + (i64.const 3689348814741910323) + ) + (i64.store + (i32.add + (i32.const 8) + (i32.const 24) + ) + (i64.const 4919131752989213764) + ) + (set_global $memmove/dest + (call $memmove/memmove + (i32.add + (i32.const 8) + (i32.const 1) + ) + (i32.add + (i32.const 8) + (i32.const 16) + ) + (i32.const 4) + ) + ) + (if + (i32.eqz + (i32.eq + (get_global $memmove/dest) + (i32.add + (i32.const 8) + (i32.const 1) + ) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i64.eq + (i64.load + (i32.const 8) + ) + (i64.const 1229783084848853777) + ) + ) + (unreachable) + ) + (set_global $memmove/dest + (call $memmove/memmove + (i32.const 8) + (i32.const 8) + (i32.const 32) + ) + ) + (if + (i32.eqz + (i32.eq + (get_global $memmove/dest) + (i32.const 8) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i64.eq + (i64.load + (i32.const 8) + ) + (i64.const 1229783084848853777) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i64.eq + (i64.load + (i32.add + (i32.const 8) + (i32.const 8) + ) + ) + (i64.const 2459565876494606882) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i64.eq + (i64.load + (i32.add + (i32.const 8) + (i32.const 16) + ) + ) + (i64.const 3689348814741910323) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i64.eq + (i64.load + (i32.add + (i32.const 8) + (i32.const 24) + ) + ) + (i64.const 4919131752989213764) + ) + ) + (unreachable) + ) + (set_global $memmove/dest + (call $memmove/memmove + (i32.add + (i32.const 8) + (i32.const 5) + ) + (i32.add + (i32.const 8) + (i32.const 28) + ) + (i32.const 3) + ) + ) + (if + (i32.eqz + (i64.eq + (i64.load + (i32.const 8) + ) + (i64.const 4919131679688438545) + ) + ) + (unreachable) + ) + (set_global $memmove/dest + (call $memmove/memmove + (i32.add + (i32.const 8) + (i32.const 8) + ) + (i32.add + (i32.const 8) + (i32.const 16) + ) + (i32.const 15) + ) + ) + (if + (i32.eqz + (i64.eq + (i64.load + (i32.const 8) + ) + (i64.const 4919131679688438545) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i64.eq + (i64.load + (i32.add + (i32.const 8) + (i32.const 8) + ) + ) + (i64.const 3689348814741910323) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i64.eq + (i64.load + (i32.add + (i32.const 8) + (i32.const 16) + ) + ) + (i64.const 3694152654344438852) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i64.eq + (i64.load + (i32.add + (i32.const 8) + (i32.const 24) + ) + ) + (i64.const 4919131752989213764) + ) + ) + (unreachable) + ) + ) +) +(; +[program.elements] + GLOBAL: NaN + GLOBAL: Infinity + FUNCTION_PROTOTYPE: isNaN + FUNCTION_PROTOTYPE: isFinite + FUNCTION_PROTOTYPE: clz + FUNCTION_PROTOTYPE: ctz + FUNCTION_PROTOTYPE: popcnt + FUNCTION_PROTOTYPE: rotl + FUNCTION_PROTOTYPE: rotr + FUNCTION_PROTOTYPE: abs + FUNCTION_PROTOTYPE: max + FUNCTION_PROTOTYPE: min + FUNCTION_PROTOTYPE: ceil + FUNCTION_PROTOTYPE: floor + FUNCTION_PROTOTYPE: copysign + FUNCTION_PROTOTYPE: nearest + FUNCTION_PROTOTYPE: reinterpret + FUNCTION_PROTOTYPE: sqrt + FUNCTION_PROTOTYPE: trunc + FUNCTION_PROTOTYPE: load + FUNCTION_PROTOTYPE: store + FUNCTION_PROTOTYPE: sizeof + FUNCTION_PROTOTYPE: select + FUNCTION_PROTOTYPE: unreachable + FUNCTION_PROTOTYPE: current_memory + FUNCTION_PROTOTYPE: grow_memory + FUNCTION_PROTOTYPE: changetype + FUNCTION_PROTOTYPE: assert + FUNCTION_PROTOTYPE: i8 + FUNCTION_PROTOTYPE: i16 + FUNCTION_PROTOTYPE: i32 + FUNCTION_PROTOTYPE: i64 + FUNCTION_PROTOTYPE: u8 + FUNCTION_PROTOTYPE: u16 + FUNCTION_PROTOTYPE: u32 + FUNCTION_PROTOTYPE: u64 + FUNCTION_PROTOTYPE: bool + FUNCTION_PROTOTYPE: f32 + FUNCTION_PROTOTYPE: f64 + FUNCTION_PROTOTYPE: isize + FUNCTION_PROTOTYPE: usize + GLOBAL: HEAP_BASE + FUNCTION_PROTOTYPE: memmove/memmove + GLOBAL: memmove/base + GLOBAL: memmove/dest +[program.exports] + +;) diff --git a/tests/compiler/memset.optimized.wast b/tests/compiler/memset.optimized.wast new file mode 100644 index 00000000..a6456079 --- /dev/null +++ b/tests/compiler/memset.optimized.wast @@ -0,0 +1,447 @@ +(module + (type $iiii (func (param i32 i32 i32) (result i32))) + (type $v (func)) + (global $memset/dest (mut i32) (i32.const 0)) + (global $HEAP_BASE i32 (i32.const 4)) + (memory $0 1) + (export "memory" (memory $0)) + (start $start) + (func $memset/memset (; 0 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i64) + (local $5 i32) + (set_local $3 + (get_local $0) + ) + (if + (i32.eqz + (get_local $2) + ) + (return + (get_local $3) + ) + ) + (i32.store8 + (get_local $0) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 1) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 2) + ) + (return + (get_local $3) + ) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 1) + ) + (get_local $1) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 3) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 6) + ) + (return + (get_local $3) + ) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 3) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 4) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return + (get_local $3) + ) + ) + (i32.store + (tee_local $0 + (i32.add + (get_local $0) + (tee_local $5 + (i32.and + (i32.sub + (i32.const 0) + (get_local $0) + ) + (i32.const 3) + ) + ) + ) + ) + (tee_local $1 + (i32.mul + (get_local $1) + (i32.const 16843009) + ) + ) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (tee_local $2 + (i32.and + (i32.sub + (get_local $2) + (get_local $5) + ) + (i32.const -4) + ) + ) + ) + (i32.const 4) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return + (get_local $3) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 4) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 12) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 24) + ) + (return + (get_local $3) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 20) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 28) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 24) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 20) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 16) + ) + (get_local $1) + ) + (set_local $0 + (i32.add + (get_local $0) + (tee_local $5 + (i32.add + (i32.and + (get_local $0) + (i32.const 4) + ) + (i32.const 24) + ) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $5) + ) + ) + (set_local $4 + (i64.or + (i64.extend_u/i32 + (get_local $1) + ) + (i64.shl + (i64.extend_u/i32 + (get_local $1) + ) + (i64.const 32) + ) + ) + ) + (loop $continue|0 + (if + (i32.ge_u + (get_local $2) + (i32.const 32) + ) + (block + (i64.store + (get_local $0) + (get_local $4) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $4) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $4) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $4) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 32) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 32) + ) + ) + (br $continue|0) + ) + ) + ) + (get_local $3) + ) + (func $start (; 1 ;) (type $v) + (set_global $memset/dest + (get_global $HEAP_BASE) + ) + (drop + (call $memset/memset + (get_global $memset/dest) + (i32.const 1) + (i32.const 16) + ) + ) + (if + (i32.ne + (i32.load8_u + (get_global $memset/dest) + ) + (i32.const 1) + ) + (unreachable) + ) + (if + (i32.ne + (i32.load8_u + (i32.add + (get_global $memset/dest) + (i32.const 15) + ) + ) + (i32.const 1) + ) + (unreachable) + ) + (drop + (call $memset/memset + (i32.add + (get_global $memset/dest) + (i32.const 1) + ) + (i32.const 2) + (i32.const 14) + ) + ) + (if + (i32.ne + (i32.load8_u + (get_global $memset/dest) + ) + (i32.const 1) + ) + (unreachable) + ) + (if + (i32.ne + (i32.load8_u + (i32.add + (get_global $memset/dest) + (i32.const 1) + ) + ) + (i32.const 2) + ) + (unreachable) + ) + (if + (i32.ne + (i32.load8_u + (i32.add + (get_global $memset/dest) + (i32.const 14) + ) + ) + (i32.const 2) + ) + (unreachable) + ) + (if + (i32.ne + (i32.load8_u + (i32.add + (get_global $memset/dest) + (i32.const 15) + ) + ) + (i32.const 1) + ) + (unreachable) + ) + ) +) diff --git a/tests/compiler/memset.ts b/tests/compiler/memset.ts new file mode 100644 index 00000000..085eaee3 --- /dev/null +++ b/tests/compiler/memset.ts @@ -0,0 +1,80 @@ +function memset(dest: usize, c: u8, n: usize): usize { + var ret = dest; + + // fill head and tail wwith minimal branching + if (!n) + return ret; + store(dest, c); + store(dest + n - 1, c); + if (n <= 2) + return ret; + + store(dest + 1, c); + store(dest + 2, c); + store(dest + n - 2, c); + store(dest + n - 3, c); + if (n <= 6) + return ret; + store(dest + 3, c); + store(dest + n - 4, c); + if (n <= 8) + return ret; + + // advance pointer to align it at 4-byte boundary + var k: usize = -dest & 3; + dest += k; + n -= k; + n &= -4; + + var c32: u32 = -1 / 255 * c; + + // fill head/tail up to 28 bytes each in preparation + store(dest, c32); + store(dest + n - 4, c32); + if (n <= 8) + return ret; + store(dest + 4, c32); + store(dest + 8, c32); + store(dest + n - 12, c32); + store(dest + n - 8, c32); + if (n <= 24) + return ret; + store(dest + 12, c32); + store(dest + 16, c32); + store(dest + 20, c32); + store(dest + 24, c32); + store(dest + n - 28, c32); + store(dest + n - 24, c32); + store(dest + n - 20, c32); + store(dest + n - 16, c32); + + // align to a multiple of 8 + k = 24 + (dest & 4); + dest += k; + n -= k; + + // copy 32 bytes each + var c64: u64 = c32 | (c32 << 32); + while (n >= 32) { + store(dest, c64); + store(dest + 8, c64); + store(dest + 16, c64); + store(dest + 24, c64); + n -= 32; + dest += 32; + } + return ret; +} + +var dest = HEAP_BASE; +memset(dest, 1, 16); + +assert(load(dest) == 1); +assert(load(dest + 15) == 1); + +memset(dest + 1, 2, 14); + +assert(load(dest) == 1); +assert(load(dest + 1) == 2); +assert(load(dest + 14) == 2); +assert(load(dest + 15) == 1); diff --git a/tests/compiler/memset.wast b/tests/compiler/memset.wast new file mode 100644 index 00000000..2de0d6a9 --- /dev/null +++ b/tests/compiler/memset.wast @@ -0,0 +1,540 @@ +(module + (type $iiii (func (param i32 i32 i32) (result i32))) + (type $v (func)) + (global $memset/dest (mut i32) (i32.const 0)) + (global $HEAP_BASE i32 (i32.const 4)) + (memory $0 1) + (export "memory" (memory $0)) + (start $start) + (func $memset/memset (; 0 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i64) + (block + (set_local $3 + (get_local $0) + ) + ) + (if + (i32.eqz + (get_local $2) + ) + (return + (get_local $3) + ) + ) + (i32.store8 + (get_local $0) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 1) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 2) + ) + (return + (get_local $3) + ) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 1) + ) + (get_local $1) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 3) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 6) + ) + (return + (get_local $3) + ) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 3) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 4) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return + (get_local $3) + ) + ) + (block + (set_local $4 + (i32.and + (i32.sub + (i32.const 0) + (get_local $0) + ) + (i32.const 3) + ) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (get_local $4) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $4) + ) + ) + (set_local $2 + (i32.and + (get_local $2) + (i32.sub + (i32.const 0) + (i32.const 4) + ) + ) + ) + (block + (set_local $5 + (i32.mul + (i32.div_u + (i32.sub + (i32.const 0) + (i32.const 1) + ) + (i32.const 255) + ) + (get_local $1) + ) + ) + ) + (i32.store + (get_local $0) + (get_local $5) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 4) + ) + (get_local $5) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return + (get_local $3) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 4) + ) + (get_local $5) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $5) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 12) + ) + (get_local $5) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (get_local $5) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 24) + ) + (return + (get_local $3) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (get_local $5) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $5) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 20) + ) + (get_local $5) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $5) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 28) + ) + (get_local $5) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 24) + ) + (get_local $5) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 20) + ) + (get_local $5) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 16) + ) + (get_local $5) + ) + (set_local $4 + (i32.add + (i32.const 24) + (i32.and + (get_local $0) + (i32.const 4) + ) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (get_local $4) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $4) + ) + ) + (block + (set_local $6 + (i64.or + (i64.extend_u/i32 + (get_local $5) + ) + (i64.shl + (i64.extend_u/i32 + (get_local $5) + ) + (i64.const 32) + ) + ) + ) + ) + (block $break|0 + (loop $continue|0 + (if + (i32.ge_u + (get_local $2) + (i32.const 32) + ) + (block + (block + (i64.store + (get_local $0) + (get_local $6) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $6) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $6) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $6) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 32) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 32) + ) + ) + ) + (br $continue|0) + ) + ) + ) + ) + (return + (get_local $3) + ) + ) + (func $start (; 1 ;) (type $v) + (set_global $memset/dest + (get_global $HEAP_BASE) + ) + (drop + (call $memset/memset + (get_global $memset/dest) + (i32.const 1) + (i32.const 16) + ) + ) + (if + (i32.eqz + (i32.eq + (i32.load8_u + (get_global $memset/dest) + ) + (i32.const 1) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.load8_u + (i32.add + (get_global $memset/dest) + (i32.const 15) + ) + ) + (i32.const 1) + ) + ) + (unreachable) + ) + (drop + (call $memset/memset + (i32.add + (get_global $memset/dest) + (i32.const 1) + ) + (i32.const 2) + (i32.const 14) + ) + ) + (if + (i32.eqz + (i32.eq + (i32.load8_u + (get_global $memset/dest) + ) + (i32.const 1) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.load8_u + (i32.add + (get_global $memset/dest) + (i32.const 1) + ) + ) + (i32.const 2) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.load8_u + (i32.add + (get_global $memset/dest) + (i32.const 14) + ) + ) + (i32.const 2) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.load8_u + (i32.add + (get_global $memset/dest) + (i32.const 15) + ) + ) + (i32.const 1) + ) + ) + (unreachable) + ) + ) +) +(; +[program.elements] + GLOBAL: NaN + GLOBAL: Infinity + FUNCTION_PROTOTYPE: isNaN + FUNCTION_PROTOTYPE: isFinite + FUNCTION_PROTOTYPE: clz + FUNCTION_PROTOTYPE: ctz + FUNCTION_PROTOTYPE: popcnt + FUNCTION_PROTOTYPE: rotl + FUNCTION_PROTOTYPE: rotr + FUNCTION_PROTOTYPE: abs + FUNCTION_PROTOTYPE: max + FUNCTION_PROTOTYPE: min + FUNCTION_PROTOTYPE: ceil + FUNCTION_PROTOTYPE: floor + FUNCTION_PROTOTYPE: copysign + FUNCTION_PROTOTYPE: nearest + FUNCTION_PROTOTYPE: reinterpret + FUNCTION_PROTOTYPE: sqrt + FUNCTION_PROTOTYPE: trunc + FUNCTION_PROTOTYPE: load + FUNCTION_PROTOTYPE: store + FUNCTION_PROTOTYPE: sizeof + FUNCTION_PROTOTYPE: select + FUNCTION_PROTOTYPE: unreachable + FUNCTION_PROTOTYPE: current_memory + FUNCTION_PROTOTYPE: grow_memory + FUNCTION_PROTOTYPE: changetype + FUNCTION_PROTOTYPE: assert + FUNCTION_PROTOTYPE: i8 + FUNCTION_PROTOTYPE: i16 + FUNCTION_PROTOTYPE: i32 + FUNCTION_PROTOTYPE: i64 + FUNCTION_PROTOTYPE: u8 + FUNCTION_PROTOTYPE: u16 + FUNCTION_PROTOTYPE: u32 + FUNCTION_PROTOTYPE: u64 + FUNCTION_PROTOTYPE: bool + FUNCTION_PROTOTYPE: f32 + FUNCTION_PROTOTYPE: f64 + FUNCTION_PROTOTYPE: isize + FUNCTION_PROTOTYPE: usize + GLOBAL: HEAP_BASE + FUNCTION_PROTOTYPE: memset/memset + GLOBAL: memset/dest +[program.exports] + +;) diff --git a/tests/compiler/showcase.optimized-inlined.wast b/tests/compiler/showcase.optimized-inlined.wast index 69bdbde7..2d2d982f 100644 --- a/tests/compiler/showcase.optimized-inlined.wast +++ b/tests/compiler/showcase.optimized-inlined.wast @@ -57,44 +57,41 @@ (local $3 i32) (local $4 i32) (local $5 i32) - (set_local $4 + (set_local $5 (get_local $0) ) - (set_local $3 - (get_local $1) - ) (loop $continue|0 (if (if (result i32) (get_local $2) (i32.rem_u - (get_local $3) + (get_local $1) (i32.const 4) ) (get_local $2) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -111,7 +108,7 @@ (if (i32.eqz (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) ) @@ -124,56 +121,56 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load - (get_local $3) + (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 4) ) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 8) ) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 12) ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -194,32 +191,32 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load - (get_local $3) + (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 4) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 8) ) ) @@ -232,20 +229,20 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 4) ) ) @@ -258,20 +255,20 @@ ) (block (i32.store16 - (get_local $4) + (get_local $0) (i32.load16_u - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 2) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 2) ) ) @@ -283,24 +280,24 @@ (i32.const 1) ) (block - (set_local $1 - (get_local $4) + (set_local $3 + (get_local $0) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $1 - (get_local $3) + (set_local $3 + (get_local $1) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) ) ) (return - (get_local $0) + (get_local $5) ) ) ) @@ -317,7 +314,7 @@ (br_table $case0|2 $case1|2 $case2|2 $tablify|0 (i32.sub (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.const 1) @@ -326,80 +323,80 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -417,17 +414,17 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 1) ) ) @@ -438,19 +435,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 5) ) ) @@ -461,19 +458,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 9) ) ) @@ -484,19 +481,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 13) ) ) @@ -505,15 +502,15 @@ ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -529,56 +526,56 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -596,17 +593,17 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 2) ) ) @@ -617,19 +614,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 6) ) ) @@ -640,19 +637,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 10) ) ) @@ -663,19 +660,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 14) ) ) @@ -684,15 +681,15 @@ ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -708,32 +705,32 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -751,17 +748,17 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 3) ) ) @@ -772,19 +769,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 7) ) ) @@ -795,19 +792,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 11) ) ) @@ -818,19 +815,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 15) ) ) @@ -839,15 +836,15 @@ ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -869,387 +866,387 @@ (i32.const 16) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1261,195 +1258,195 @@ (i32.const 8) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1461,99 +1458,99 @@ (i32.const 4) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1565,51 +1562,51 @@ (i32.const 2) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1621,23 +1618,23 @@ (i32.const 1) ) (block - (set_local $1 - (get_local $4) + (set_local $3 + (get_local $0) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $1 - (get_local $3) + (set_local $3 + (get_local $1) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) ) ) - (get_local $0) + (get_local $5) ) (func $fmod/fmod (; 2 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 i64) diff --git a/tests/compiler/showcase.optimized.wast b/tests/compiler/showcase.optimized.wast index aeda3181..818da7ea 100644 --- a/tests/compiler/showcase.optimized.wast +++ b/tests/compiler/showcase.optimized.wast @@ -78,44 +78,41 @@ (local $3 i32) (local $4 i32) (local $5 i32) - (set_local $4 + (set_local $5 (get_local $0) ) - (set_local $3 - (get_local $1) - ) (loop $continue|0 (if (if (result i32) (get_local $2) (i32.rem_u - (get_local $3) + (get_local $1) (i32.const 4) ) (get_local $2) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -132,7 +129,7 @@ (if (i32.eqz (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) ) @@ -145,56 +142,56 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load - (get_local $3) + (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 4) ) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 8) ) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 12) ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -215,32 +212,32 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load - (get_local $3) + (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 4) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 8) ) ) @@ -253,20 +250,20 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 4) ) ) @@ -279,20 +276,20 @@ ) (block (i32.store16 - (get_local $4) + (get_local $0) (i32.load16_u - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 2) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 2) ) ) @@ -304,24 +301,24 @@ (i32.const 1) ) (block - (set_local $1 - (get_local $4) + (set_local $3 + (get_local $0) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $1 - (get_local $3) + (set_local $3 + (get_local $1) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) ) ) (return - (get_local $0) + (get_local $5) ) ) ) @@ -338,7 +335,7 @@ (br_table $case0|2 $case1|2 $case2|2 $tablify|0 (i32.sub (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.const 1) @@ -347,80 +344,80 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -438,17 +435,17 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 1) ) ) @@ -459,19 +456,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 5) ) ) @@ -482,19 +479,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 9) ) ) @@ -505,19 +502,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 13) ) ) @@ -526,15 +523,15 @@ ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -550,56 +547,56 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -617,17 +614,17 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 2) ) ) @@ -638,19 +635,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 6) ) ) @@ -661,19 +658,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 10) ) ) @@ -684,19 +681,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 14) ) ) @@ -705,15 +702,15 @@ ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -729,32 +726,32 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $3) + (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -772,17 +769,17 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 3) ) ) @@ -793,19 +790,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 7) ) ) @@ -816,19 +813,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl - (tee_local $1 + (tee_local $3 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 11) ) ) @@ -839,19 +836,19 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $1) + (get_local $3) (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add - (get_local $3) + (get_local $1) (i32.const 15) ) ) @@ -860,15 +857,15 @@ ) ) ) - (set_local $3 + (set_local $1 (i32.add - (get_local $3) + (get_local $1) (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -890,387 +887,387 @@ (i32.const 16) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1282,195 +1279,195 @@ (i32.const 8) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1482,99 +1479,99 @@ (i32.const 4) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1586,51 +1583,51 @@ (i32.const 2) ) (block - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) - (set_local $4 + (set_local $0 (i32.add - (tee_local $1 - (get_local $4) + (tee_local $3 + (get_local $0) ) (i32.const 1) ) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $3 + (set_local $1 (i32.add - (tee_local $1 - (get_local $3) + (tee_local $3 + (get_local $1) ) (i32.const 1) ) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) @@ -1642,23 +1639,23 @@ (i32.const 1) ) (block - (set_local $1 - (get_local $4) + (set_local $3 + (get_local $0) ) (i32.store8 - (get_local $1) + (get_local $3) (block (result i32) - (set_local $1 - (get_local $3) + (set_local $3 + (get_local $1) ) (i32.load8_u - (get_local $1) + (get_local $3) ) ) ) ) ) - (get_local $0) + (get_local $5) ) (func $fmod/fmod (; 6 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 i64) diff --git a/tests/compiler/showcase.wast b/tests/compiler/showcase.wast index 4885d267..6b2b6940 100644 --- a/tests/compiler/showcase.wast +++ b/tests/compiler/showcase.wast @@ -121,14 +121,10 @@ (local $4 i32) (local $5 i32) (local $6 i32) - (local $7 i32) (block (set_local $3 (get_local $0) ) - (set_local $4 - (get_local $1) - ) ) (nop) (block $break|0 @@ -140,7 +136,7 @@ (i32.const 0) ) (i32.rem_u - (get_local $4) + (get_local $1) (i32.const 4) ) (get_local $2) @@ -149,29 +145,29 @@ (block (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -190,7 +186,7 @@ (if (i32.eq (i32.rem_u - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.const 0) @@ -206,56 +202,56 @@ (block (block (i32.store - (get_local $3) + (get_local $0) (i32.load - (get_local $4) + (get_local $1) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 4) ) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 8) ) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 12) ) ) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $4) + (get_local $1) (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -278,32 +274,32 @@ ) (block (i32.store - (get_local $3) + (get_local $0) (i32.load - (get_local $4) + (get_local $1) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 4) ) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $4) + (get_local $1) (i32.const 8) ) ) @@ -316,20 +312,20 @@ ) (block (i32.store - (get_local $3) + (get_local $0) (i32.load - (get_local $4) + (get_local $1) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $4) + (get_local $1) (i32.const 4) ) ) @@ -342,20 +338,20 @@ ) (block (i32.store16 - (get_local $3) + (get_local $0) (i32.load16_u - (get_local $4) + (get_local $1) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 2) ) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $4) + (get_local $1) (i32.const 2) ) ) @@ -368,35 +364,35 @@ ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) ) (return - (get_local $0) + (get_local $3) ) ) ) @@ -409,118 +405,118 @@ (block $case2|2 (block $case1|2 (block $case0|2 - (set_local $7 + (set_local $6 (i32.rem_u - (get_local $3) + (get_local $0) (i32.const 4) ) ) (br_if $case0|2 (i32.eq - (get_local $7) + (get_local $6) (i32.const 1) ) ) (br_if $case1|2 (i32.eq - (get_local $7) + (get_local $6) (i32.const 2) ) ) (br_if $case2|2 (i32.eq - (get_local $7) + (get_local $6) (i32.const 3) ) ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $4) + (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -539,91 +535,19 @@ ) (block (block - (set_local $6 + (set_local $5 (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 1) ) ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) - (i32.const 24) - ) - (i32.shl - (get_local $6) - (i32.const 8) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add (get_local $4) - (i32.const 5) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 4) - ) - (i32.or - (i32.shr_u - (get_local $6) - (i32.const 24) - ) - (i32.shl - (get_local $5) - (i32.const 8) - ) - ) - ) - (set_local $6 - (i32.load - (i32.add - (get_local $4) - (i32.const 9) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 8) - ) - (i32.or - (i32.shr_u - (get_local $5) - (i32.const 24) - ) - (i32.shl - (get_local $6) - (i32.const 8) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add - (get_local $4) - (i32.const 13) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 12) - ) - (i32.or - (i32.shr_u - (get_local $6) (i32.const 24) ) (i32.shl @@ -633,14 +557,86 @@ ) ) (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 5) + ) + ) + ) + (i32.store (i32.add - (get_local $4) + (get_local $0) + (i32.const 4) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 24) + ) + (i32.shl + (get_local $4) + (i32.const 8) + ) + ) + ) + (set_local $5 + (i32.load + (i32.add + (get_local $1) + (i32.const 9) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (i32.or + (i32.shr_u + (get_local $4) + (i32.const 24) + ) + (i32.shl + (get_local $5) + (i32.const 8) + ) + ) + ) + (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 13) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 24) + ) + (i32.shl + (get_local $4) + (i32.const 8) + ) + ) + ) + (set_local $1 + (i32.add + (get_local $1) (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -658,64 +654,64 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $4) + (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -734,91 +730,19 @@ ) (block (block - (set_local $6 + (set_local $5 (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 2) ) ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) - (i32.const 16) - ) - (i32.shl - (get_local $6) - (i32.const 16) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add (get_local $4) - (i32.const 6) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 4) - ) - (i32.or - (i32.shr_u - (get_local $6) - (i32.const 16) - ) - (i32.shl - (get_local $5) - (i32.const 16) - ) - ) - ) - (set_local $6 - (i32.load - (i32.add - (get_local $4) - (i32.const 10) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 8) - ) - (i32.or - (i32.shr_u - (get_local $5) - (i32.const 16) - ) - (i32.shl - (get_local $6) - (i32.const 16) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add - (get_local $4) - (i32.const 14) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 12) - ) - (i32.or - (i32.shr_u - (get_local $6) (i32.const 16) ) (i32.shl @@ -828,14 +752,86 @@ ) ) (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 6) + ) + ) + ) + (i32.store (i32.add - (get_local $4) + (get_local $0) + (i32.const 4) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 16) + ) + (i32.shl + (get_local $4) + (i32.const 16) + ) + ) + ) + (set_local $5 + (i32.load + (i32.add + (get_local $1) + (i32.const 10) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (i32.or + (i32.shr_u + (get_local $4) + (i32.const 16) + ) + (i32.shl + (get_local $5) + (i32.const 16) + ) + ) + ) + (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 14) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 16) + ) + (i32.shl + (get_local $4) + (i32.const 16) + ) + ) + ) + (set_local $1 + (i32.add + (get_local $1) (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -853,36 +849,36 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load - (get_local $4) + (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -901,91 +897,19 @@ ) (block (block - (set_local $6 + (set_local $5 (i32.load (i32.add - (get_local $4) + (get_local $1) (i32.const 3) ) ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) - (i32.const 8) - ) - (i32.shl - (get_local $6) - (i32.const 24) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add (get_local $4) - (i32.const 7) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 4) - ) - (i32.or - (i32.shr_u - (get_local $6) - (i32.const 8) - ) - (i32.shl - (get_local $5) - (i32.const 24) - ) - ) - ) - (set_local $6 - (i32.load - (i32.add - (get_local $4) - (i32.const 11) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 8) - ) - (i32.or - (i32.shr_u - (get_local $5) - (i32.const 8) - ) - (i32.shl - (get_local $6) - (i32.const 24) - ) - ) - ) - (set_local $5 - (i32.load - (i32.add - (get_local $4) - (i32.const 15) - ) - ) - ) - (i32.store - (i32.add - (get_local $3) - (i32.const 12) - ) - (i32.or - (i32.shr_u - (get_local $6) (i32.const 8) ) (i32.shl @@ -995,14 +919,86 @@ ) ) (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 7) + ) + ) + ) + (i32.store (i32.add - (get_local $4) + (get_local $0) + (i32.const 4) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 8) + ) + (i32.shl + (get_local $4) + (i32.const 24) + ) + ) + ) + (set_local $5 + (i32.load + (i32.add + (get_local $1) + (i32.const 11) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (i32.or + (i32.shr_u + (get_local $4) + (i32.const 8) + ) + (i32.shl + (get_local $5) + (i32.const 24) + ) + ) + ) + (set_local $4 + (i32.load + (i32.add + (get_local $1) + (i32.const 15) + ) + ) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (i32.or + (i32.shr_u + (get_local $5) + (i32.const 8) + ) + (i32.shl + (get_local $4) + (i32.const 24) + ) + ) + ) + (set_local $1 + (i32.add + (get_local $1) (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -1029,449 +1025,449 @@ (block (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -1485,225 +1481,225 @@ (block (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -1717,113 +1713,113 @@ (block (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -1837,57 +1833,57 @@ (block (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) @@ -1900,35 +1896,35 @@ ) (i32.store8 (block (result i32) - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) (i32.load8_u (block (result i32) - (set_local $7 - (get_local $4) + (set_local $6 + (get_local $1) ) - (set_local $4 + (set_local $1 (i32.add - (get_local $7) + (get_local $6) (i32.const 1) ) ) - (get_local $7) + (get_local $6) ) ) ) ) (return - (get_local $0) + (get_local $3) ) ) (func $fmod/fmod (; 6 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) diff --git a/tests/compiler/std/array.optimized-inlined.wast b/tests/compiler/std/array.optimized-inlined.wast index 4b0efda5..dbfbab36 100644 --- a/tests/compiler/std/array.optimized-inlined.wast +++ b/tests/compiler/std/array.optimized-inlined.wast @@ -1,6 +1,6 @@ (module (type $ii (func (param i32) (result i32))) - (type $iiii (func (param i32 i32 i32) (result i32))) + (type $iiiv (func (param i32 i32 i32))) (type $iv (func (param i32))) (type $iiv (func (param i32 i32))) (type $iii (func (param i32 i32) (result i32))) @@ -12,7 +12,7 @@ (memory $0 1) (export "memory" (memory $0)) (start $start) - (func $std:heap/Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32) + (func $std:heap/allocate_memory (; 0 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (if @@ -101,20 +101,9 @@ ) (get_local $1) ) - (func $std:heap/Heap.copy (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std:heap/copy_memory (; 1 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) - (local $5 i32) - (if - (i32.lt_u - (get_local $0) - (get_global $HEAP_BASE) - ) - (unreachable) - ) - (set_local $4 - (get_local $0) - ) (loop $continue|0 (if (if (result i32) @@ -126,10 +115,10 @@ (get_local $2) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -163,7 +152,7 @@ (if (i32.eqz (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) ) @@ -176,14 +165,14 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load @@ -195,7 +184,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.load @@ -207,7 +196,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.load @@ -223,9 +212,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -246,14 +235,14 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load @@ -263,9 +252,9 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) ) @@ -284,14 +273,14 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) ) @@ -310,14 +299,14 @@ ) (block (i32.store16 - (get_local $4) + (get_local $0) (i32.load16_u (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 2) ) ) @@ -336,7 +325,7 @@ ) (block (set_local $3 - (get_local $4) + (get_local $0) ) (i32.store8 (get_local $3) @@ -351,9 +340,7 @@ ) ) ) - (return - (get_local $0) - ) + (return) ) ) (if @@ -369,7 +356,7 @@ (br_table $case0|2 $case1|2 $case2|2 $tablify|0 (i32.sub (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.const 1) @@ -378,15 +365,15 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -407,10 +394,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -431,10 +418,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -469,10 +456,10 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl @@ -490,7 +477,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or @@ -499,7 +486,7 @@ (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -513,12 +500,12 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl @@ -536,7 +523,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or @@ -545,7 +532,7 @@ (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -563,9 +550,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -581,15 +568,15 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -610,10 +597,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -648,10 +635,10 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl @@ -669,7 +656,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or @@ -678,7 +665,7 @@ (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -692,12 +679,12 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl @@ -715,7 +702,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or @@ -724,7 +711,7 @@ (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -742,9 +729,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -760,15 +747,15 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -803,10 +790,10 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl @@ -824,7 +811,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or @@ -833,7 +820,7 @@ (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -847,12 +834,12 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl @@ -870,7 +857,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or @@ -879,7 +866,7 @@ (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -897,9 +884,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -921,10 +908,10 @@ (i32.const 16) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -945,10 +932,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -969,10 +956,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -993,10 +980,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1017,10 +1004,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1041,10 +1028,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1065,10 +1052,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1089,10 +1076,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1113,10 +1100,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1137,10 +1124,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1161,10 +1148,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1185,10 +1172,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1209,10 +1196,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1233,10 +1220,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1257,10 +1244,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1281,10 +1268,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1313,10 +1300,10 @@ (i32.const 8) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1337,10 +1324,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1361,10 +1348,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1385,10 +1372,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1409,10 +1396,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1433,10 +1420,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1457,10 +1444,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1481,10 +1468,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1513,10 +1500,10 @@ (i32.const 4) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1537,10 +1524,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1561,10 +1548,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1585,10 +1572,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1617,10 +1604,10 @@ (i32.const 2) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1641,10 +1628,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1674,7 +1661,7 @@ ) (block (set_local $3 - (get_local $4) + (get_local $0) ) (i32.store8 (get_local $3) @@ -1689,9 +1676,298 @@ ) ) ) - (get_local $0) ) - (func $std:array/Array#__grow (; 2 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $std:heap/move_memory (; 2 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (if + (i32.eq + (get_local $0) + (get_local $1) + ) + (return) + ) + (if + (i32.and + (if (result i32) + (tee_local $3 + (i32.le_u + (i32.add + (get_local $1) + (get_local $2) + ) + (get_local $0) + ) + ) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) + ) + (i32.const 1) + ) + (block + (call $std:heap/copy_memory + (get_local $0) + (get_local $1) + (get_local $2) + ) + (return) + ) + ) + (if + (i32.lt_u + (get_local $0) + (get_local $1) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (loop $continue|0 + (if + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + (block + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + (set_local $0 + (i32.add + (tee_local $3 + (get_local $0) + ) + (i32.const 1) + ) + ) + (i32.store8 + (get_local $3) + (block (result i32) + (set_local $1 + (i32.add + (tee_local $3 + (get_local $1) + ) + (i32.const 1) + ) + ) + (i32.load8_u + (get_local $3) + ) + ) + ) + (br $continue|0) + ) + ) + ) + (loop $continue|1 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (i64.store + (get_local $0) + (i64.load + (get_local $1) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 8) + ) + ) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 8) + ) + ) + (br $continue|1) + ) + ) + ) + ) + ) + (loop $continue|2 + (if + (get_local $2) + (block + (set_local $0 + (i32.add + (tee_local $3 + (get_local $0) + ) + (i32.const 1) + ) + ) + (i32.store8 + (get_local $3) + (block (result i32) + (set_local $1 + (i32.add + (tee_local $3 + (get_local $1) + ) + (i32.const 1) + ) + ) + (i32.load8_u + (get_local $3) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + (br $continue|2) + ) + ) + ) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (loop $continue|3 + (if + (i32.rem_u + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (block + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|3) + ) + ) + ) + (loop $continue|4 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (i64.store + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + ) + (i64.load + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|4) + ) + ) + ) + ) + ) + (loop $continue|5 + (if + (get_local $2) + (block + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|5) + ) + ) + ) + ) + ) + ) + (func $std:array/Array#__grow (; 3 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (if @@ -1704,7 +1980,7 @@ (unreachable) ) (set_local $2 - (call $std:heap/Heap.allocate + (call $std:heap/allocate_memory (i32.mul (get_local $1) (i32.const 4) @@ -1715,8 +1991,8 @@ (i32.load (get_local $0) ) - (drop - (call $std:heap/Heap.copy + (block + (call $std:heap/move_memory (get_local $2) (i32.load (get_local $0) @@ -1728,16 +2004,16 @@ (i32.const 4) ) ) - ) - ) - (block - (block $__inlined_func$std:heap/Heap.dispose - (set_local $3 - (i32.load - (get_local $0) + (block + (block $__inlined_func$std:heap/free_memory + (set_local $3 + (i32.load + (get_local $0) + ) + ) + (nop) ) ) - (nop) ) ) (i32.store @@ -1749,7 +2025,7 @@ (get_local $1) ) ) - (func $std:array/Array#push (; 3 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std:array/Array#push (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (if @@ -1773,11 +2049,11 @@ ) ) (tee_local $3 - (i32.mul + (i32.shl (i32.load offset=4 (get_local $0) ) - (i32.const 2) + (i32.const 1) ) ) (i32.gt_s @@ -1814,7 +2090,7 @@ ) (get_local $2) ) - (func $std:array/Array#__get (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std:array/Array#__get (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (if (i32.ge_u (get_local $1) @@ -1836,7 +2112,7 @@ ) ) ) - (func $std:array/Array#pop (; 5 ;) (type $ii) (param $0 i32) (result i32) + (func $std:array/Array#pop (; 6 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (if (i32.and @@ -1886,7 +2162,7 @@ ) ) ) - (func $std:array/Array#unshift (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std:array/Array#unshift (; 7 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1989,35 +2265,23 @@ ) (get_local $3) ) - (func $std:heap/Heap.fill (; 7 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - (local $4 i64) - (local $5 i32) - (if - (i32.lt_u - (get_local $0) - (get_global $HEAP_BASE) - ) - (unreachable) - ) + (func $std:heap/set_memory (; 8 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i64) + (local $4 i32) (if (i32.eqz (get_local $2) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 - (tee_local $3 - (get_local $0) - ) + (get_local $0) (get_local $1) ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 1) @@ -2029,38 +2293,36 @@ (get_local $2) (i32.const 2) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 (i32.add - (get_local $3) + (get_local $0) (i32.const 1) ) (get_local $1) ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 2) + ) + (get_local $1) + ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 2) ) (get_local $1) ) - (i32.store8 - (i32.add - (get_local $3) - (i32.const 2) - ) - (get_local $1) - ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 3) @@ -2072,13 +2334,11 @@ (get_local $2) (i32.const 6) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 (i32.add - (get_local $3) + (get_local $0) (i32.const 3) ) (get_local $1) @@ -2086,7 +2346,7 @@ (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 4) @@ -2098,19 +2358,17 @@ (get_local $2) (i32.const 8) ) - (return - (get_local $0) - ) + (return) ) (i32.store - (tee_local $3 + (tee_local $0 (i32.add - (get_local $3) - (tee_local $5 + (get_local $0) + (tee_local $4 (i32.and (i32.sub (i32.const 0) - (get_local $3) + (get_local $0) ) (i32.const 3) ) @@ -2127,12 +2385,12 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (tee_local $2 (i32.and (i32.sub (get_local $2) - (get_local $5) + (get_local $4) ) (i32.const -4) ) @@ -2147,20 +2405,18 @@ (get_local $2) (i32.const 8) ) - (return - (get_local $0) - ) + (return) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (get_local $1) @@ -2168,7 +2424,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 12) @@ -2178,7 +2434,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 8) @@ -2190,34 +2446,32 @@ (get_local $2) (i32.const 24) ) - (return - (get_local $0) - ) + (return) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 20) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 24) ) (get_local $1) @@ -2225,7 +2479,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 28) @@ -2235,7 +2489,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 24) @@ -2245,7 +2499,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 20) @@ -2255,20 +2509,20 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 16) ) (get_local $1) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) - (tee_local $5 + (get_local $0) + (tee_local $4 (i32.add (i32.and - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.const 24) @@ -2279,10 +2533,10 @@ (set_local $2 (i32.sub (get_local $2) - (get_local $5) + (get_local $4) ) ) - (set_local $4 + (set_local $3 (i64.or (i64.extend_u/i32 (get_local $1) @@ -2303,29 +2557,29 @@ ) (block (i64.store + (get_local $0) (get_local $3) - (get_local $4) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) - (get_local $4) + (get_local $3) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) - (get_local $4) + (get_local $3) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 24) ) - (get_local $4) + (get_local $3) ) (set_local $2 (i32.sub @@ -2333,9 +2587,9 @@ (i32.const 32) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 32) ) ) @@ -2343,9 +2597,8 @@ ) ) ) - (get_local $0) ) - (func $std:array/Array#shift (; 8 ;) (type $ii) (param $0 i32) (result i32) + (func $std:array/Array#shift (; 9 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (if (i32.and @@ -2379,16 +2632,30 @@ ) ) ) - (drop - (call $std:heap/Heap.copy + (call $std:heap/move_memory + (i32.load + (get_local $0) + ) + (i32.add (i32.load (get_local $0) ) - (i32.add - (i32.load + (i32.const 4) + ) + (i32.mul + (i32.sub + (i32.load offset=4 (get_local $0) ) - (i32.const 4) + (i32.const 1) + ) + (i32.const 4) + ) + ) + (call $std:heap/set_memory + (i32.add + (i32.load + (get_local $0) ) (i32.mul (i32.sub @@ -2400,26 +2667,8 @@ (i32.const 4) ) ) - ) - (drop - (call $std:heap/Heap.fill - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (i32.sub - (i32.load offset=4 - (get_local $0) - ) - (i32.const 1) - ) - (i32.const 4) - ) - ) - (i32.const 0) - (i32.const 4) - ) + (i32.const 0) + (i32.const 4) ) (i32.store offset=8 (get_local $0) @@ -2432,12 +2681,12 @@ ) (get_local $1) ) - (func $start (; 9 ;) (type $v) + (func $start (; 10 ;) (type $v) (set_global $std:heap/HEAP_OFFSET (get_global $HEAP_BASE) ) (set_global $std/array/arr - (call $std:heap/Heap.allocate + (call $std:heap/allocate_memory (i32.const 12) ) ) diff --git a/tests/compiler/std/array.optimized.wast b/tests/compiler/std/array.optimized.wast index 0c9e3bc4..1a005641 100644 --- a/tests/compiler/std/array.optimized.wast +++ b/tests/compiler/std/array.optimized.wast @@ -1,6 +1,6 @@ (module (type $ii (func (param i32) (result i32))) - (type $iiii (func (param i32 i32 i32) (result i32))) + (type $iiiv (func (param i32 i32 i32))) (type $iv (func (param i32))) (type $iiv (func (param i32 i32))) (type $iii (func (param i32 i32) (result i32))) @@ -12,7 +12,7 @@ (memory $0 1) (export "memory" (memory $0)) (start $start) - (func $std:heap/Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32) + (func $std:heap/allocate_memory (; 0 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (if @@ -101,20 +101,9 @@ ) (get_local $1) ) - (func $std:heap/Heap.copy (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std:heap/copy_memory (; 1 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) - (local $5 i32) - (if - (i32.lt_u - (get_local $0) - (get_global $HEAP_BASE) - ) - (unreachable) - ) - (set_local $4 - (get_local $0) - ) (loop $continue|0 (if (if (result i32) @@ -126,10 +115,10 @@ (get_local $2) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -163,7 +152,7 @@ (if (i32.eqz (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) ) @@ -176,14 +165,14 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load @@ -195,7 +184,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.load @@ -207,7 +196,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.load @@ -223,9 +212,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -246,14 +235,14 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load @@ -263,9 +252,9 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) ) @@ -284,14 +273,14 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) ) @@ -310,14 +299,14 @@ ) (block (i32.store16 - (get_local $4) + (get_local $0) (i32.load16_u (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 2) ) ) @@ -336,7 +325,7 @@ ) (block (set_local $3 - (get_local $4) + (get_local $0) ) (i32.store8 (get_local $3) @@ -351,9 +340,7 @@ ) ) ) - (return - (get_local $0) - ) + (return) ) ) (if @@ -369,7 +356,7 @@ (br_table $case0|2 $case1|2 $case2|2 $tablify|0 (i32.sub (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.const 1) @@ -378,15 +365,15 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -407,10 +394,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -431,10 +418,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -469,10 +456,10 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl @@ -490,7 +477,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or @@ -499,7 +486,7 @@ (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -513,12 +500,12 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl @@ -536,7 +523,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or @@ -545,7 +532,7 @@ (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -563,9 +550,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -581,15 +568,15 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -610,10 +597,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -648,10 +635,10 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl @@ -669,7 +656,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or @@ -678,7 +665,7 @@ (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -692,12 +679,12 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl @@ -715,7 +702,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or @@ -724,7 +711,7 @@ (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -742,9 +729,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -760,15 +747,15 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -803,10 +790,10 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl @@ -824,7 +811,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or @@ -833,7 +820,7 @@ (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -847,12 +834,12 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl @@ -870,7 +857,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or @@ -879,7 +866,7 @@ (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -897,9 +884,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -921,10 +908,10 @@ (i32.const 16) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -945,10 +932,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -969,10 +956,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -993,10 +980,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1017,10 +1004,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1041,10 +1028,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1065,10 +1052,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1089,10 +1076,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1113,10 +1100,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1137,10 +1124,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1161,10 +1148,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1185,10 +1172,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1209,10 +1196,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1233,10 +1220,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1257,10 +1244,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1281,10 +1268,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1313,10 +1300,10 @@ (i32.const 8) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1337,10 +1324,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1361,10 +1348,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1385,10 +1372,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1409,10 +1396,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1433,10 +1420,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1457,10 +1444,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1481,10 +1468,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1513,10 +1500,10 @@ (i32.const 4) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1537,10 +1524,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1561,10 +1548,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1585,10 +1572,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1617,10 +1604,10 @@ (i32.const 2) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1641,10 +1628,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1674,7 +1661,7 @@ ) (block (set_local $3 - (get_local $4) + (get_local $0) ) (i32.store8 (get_local $3) @@ -1689,12 +1676,301 @@ ) ) ) - (get_local $0) ) - (func $std:heap/Heap.dispose (; 2 ;) (type $iv) (param $0 i32) + (func $std:heap/move_memory (; 2 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (if + (i32.eq + (get_local $0) + (get_local $1) + ) + (return) + ) + (if + (i32.and + (if (result i32) + (tee_local $3 + (i32.le_u + (i32.add + (get_local $1) + (get_local $2) + ) + (get_local $0) + ) + ) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) + ) + (i32.const 1) + ) + (block + (call $std:heap/copy_memory + (get_local $0) + (get_local $1) + (get_local $2) + ) + (return) + ) + ) + (if + (i32.lt_u + (get_local $0) + (get_local $1) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (loop $continue|0 + (if + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + (block + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + (set_local $0 + (i32.add + (tee_local $3 + (get_local $0) + ) + (i32.const 1) + ) + ) + (i32.store8 + (get_local $3) + (block (result i32) + (set_local $1 + (i32.add + (tee_local $3 + (get_local $1) + ) + (i32.const 1) + ) + ) + (i32.load8_u + (get_local $3) + ) + ) + ) + (br $continue|0) + ) + ) + ) + (loop $continue|1 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (i64.store + (get_local $0) + (i64.load + (get_local $1) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 8) + ) + ) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 8) + ) + ) + (br $continue|1) + ) + ) + ) + ) + ) + (loop $continue|2 + (if + (get_local $2) + (block + (set_local $0 + (i32.add + (tee_local $3 + (get_local $0) + ) + (i32.const 1) + ) + ) + (i32.store8 + (get_local $3) + (block (result i32) + (set_local $1 + (i32.add + (tee_local $3 + (get_local $1) + ) + (i32.const 1) + ) + ) + (i32.load8_u + (get_local $3) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + (br $continue|2) + ) + ) + ) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (loop $continue|3 + (if + (i32.rem_u + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (block + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|3) + ) + ) + ) + (loop $continue|4 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (i64.store + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + ) + (i64.load + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|4) + ) + ) + ) + ) + ) + (loop $continue|5 + (if + (get_local $2) + (block + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|5) + ) + ) + ) + ) + ) + ) + (func $std:heap/free_memory (; 3 ;) (type $iv) (param $0 i32) (nop) ) - (func $std:array/Array#__grow (; 3 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $std:array/Array#__grow (; 4 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (if (i32.le_s @@ -1706,7 +1982,7 @@ (unreachable) ) (set_local $2 - (call $std:heap/Heap.allocate + (call $std:heap/allocate_memory (i32.mul (get_local $1) (i32.const 4) @@ -1717,8 +1993,8 @@ (i32.load (get_local $0) ) - (drop - (call $std:heap/Heap.copy + (block + (call $std:heap/move_memory (get_local $2) (i32.load (get_local $0) @@ -1730,11 +2006,11 @@ (i32.const 4) ) ) - ) - ) - (call $std:heap/Heap.dispose - (i32.load - (get_local $0) + (call $std:heap/free_memory + (i32.load + (get_local $0) + ) + ) ) ) (i32.store @@ -1746,7 +2022,7 @@ (get_local $1) ) ) - (func $std:array/Array#push (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std:array/Array#push (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (if @@ -1770,11 +2046,11 @@ ) ) (tee_local $3 - (i32.mul + (i32.shl (i32.load offset=4 (get_local $0) ) - (i32.const 2) + (i32.const 1) ) ) (i32.gt_s @@ -1811,7 +2087,7 @@ ) (get_local $2) ) - (func $std:array/Array#__get (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std:array/Array#__get (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (if (i32.ge_u (get_local $1) @@ -1833,7 +2109,7 @@ ) ) ) - (func $std:array/Array#pop (; 6 ;) (type $ii) (param $0 i32) (result i32) + (func $std:array/Array#pop (; 7 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (if (i32.and @@ -1883,7 +2159,7 @@ ) ) ) - (func $std:array/Array#unshift (; 7 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std:array/Array#unshift (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1986,35 +2262,23 @@ ) (get_local $3) ) - (func $std:heap/Heap.fill (; 8 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - (local $4 i64) - (local $5 i32) - (if - (i32.lt_u - (get_local $0) - (get_global $HEAP_BASE) - ) - (unreachable) - ) + (func $std:heap/set_memory (; 9 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i64) + (local $4 i32) (if (i32.eqz (get_local $2) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 - (tee_local $3 - (get_local $0) - ) + (get_local $0) (get_local $1) ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 1) @@ -2026,38 +2290,36 @@ (get_local $2) (i32.const 2) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 (i32.add - (get_local $3) + (get_local $0) (i32.const 1) ) (get_local $1) ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 2) + ) + (get_local $1) + ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 2) ) (get_local $1) ) - (i32.store8 - (i32.add - (get_local $3) - (i32.const 2) - ) - (get_local $1) - ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 3) @@ -2069,13 +2331,11 @@ (get_local $2) (i32.const 6) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 (i32.add - (get_local $3) + (get_local $0) (i32.const 3) ) (get_local $1) @@ -2083,7 +2343,7 @@ (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 4) @@ -2095,19 +2355,17 @@ (get_local $2) (i32.const 8) ) - (return - (get_local $0) - ) + (return) ) (i32.store - (tee_local $3 + (tee_local $0 (i32.add - (get_local $3) - (tee_local $5 + (get_local $0) + (tee_local $4 (i32.and (i32.sub (i32.const 0) - (get_local $3) + (get_local $0) ) (i32.const 3) ) @@ -2124,12 +2382,12 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (tee_local $2 (i32.and (i32.sub (get_local $2) - (get_local $5) + (get_local $4) ) (i32.const -4) ) @@ -2144,20 +2402,18 @@ (get_local $2) (i32.const 8) ) - (return - (get_local $0) - ) + (return) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (get_local $1) @@ -2165,7 +2421,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 12) @@ -2175,7 +2431,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 8) @@ -2187,34 +2443,32 @@ (get_local $2) (i32.const 24) ) - (return - (get_local $0) - ) + (return) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 20) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 24) ) (get_local $1) @@ -2222,7 +2476,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 28) @@ -2232,7 +2486,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 24) @@ -2242,7 +2496,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 20) @@ -2252,20 +2506,20 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 16) ) (get_local $1) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) - (tee_local $5 + (get_local $0) + (tee_local $4 (i32.add (i32.and - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.const 24) @@ -2276,10 +2530,10 @@ (set_local $2 (i32.sub (get_local $2) - (get_local $5) + (get_local $4) ) ) - (set_local $4 + (set_local $3 (i64.or (i64.extend_u/i32 (get_local $1) @@ -2300,29 +2554,29 @@ ) (block (i64.store + (get_local $0) (get_local $3) - (get_local $4) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) - (get_local $4) + (get_local $3) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) - (get_local $4) + (get_local $3) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 24) ) - (get_local $4) + (get_local $3) ) (set_local $2 (i32.sub @@ -2330,9 +2584,9 @@ (i32.const 32) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 32) ) ) @@ -2340,9 +2594,8 @@ ) ) ) - (get_local $0) ) - (func $std:array/Array#shift (; 9 ;) (type $ii) (param $0 i32) (result i32) + (func $std:array/Array#shift (; 10 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (if (i32.and @@ -2376,16 +2629,30 @@ ) ) ) - (drop - (call $std:heap/Heap.copy + (call $std:heap/move_memory + (i32.load + (get_local $0) + ) + (i32.add (i32.load (get_local $0) ) - (i32.add - (i32.load + (i32.const 4) + ) + (i32.mul + (i32.sub + (i32.load offset=4 (get_local $0) ) - (i32.const 4) + (i32.const 1) + ) + (i32.const 4) + ) + ) + (call $std:heap/set_memory + (i32.add + (i32.load + (get_local $0) ) (i32.mul (i32.sub @@ -2397,26 +2664,8 @@ (i32.const 4) ) ) - ) - (drop - (call $std:heap/Heap.fill - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (i32.sub - (i32.load offset=4 - (get_local $0) - ) - (i32.const 1) - ) - (i32.const 4) - ) - ) - (i32.const 0) - (i32.const 4) - ) + (i32.const 0) + (i32.const 4) ) (i32.store offset=8 (get_local $0) @@ -2429,12 +2678,12 @@ ) (get_local $1) ) - (func $start (; 10 ;) (type $v) + (func $start (; 11 ;) (type $v) (set_global $std:heap/HEAP_OFFSET (get_global $HEAP_BASE) ) (set_global $std/array/arr - (call $std:heap/Heap.allocate + (call $std:heap/allocate_memory (i32.const 12) ) ) diff --git a/tests/compiler/std/array.ts b/tests/compiler/std/array.ts index 31b5c0e4..3e27683b 100644 --- a/tests/compiler/std/array.ts +++ b/tests/compiler/std/array.ts @@ -1,4 +1,4 @@ -var arr = changetype(Heap.allocate(sizeof() + 2 * sizeof())); +var arr = changetype(allocate_memory(sizeof() + 2 * sizeof())); assert(arr.length == 0); assert(arr.__capacity == 0); @@ -36,7 +36,7 @@ assert(arr[0] == 43); assert(arr[1] == 44); assert(arr[2] == 45); -arr.unshift(42); // see FIXME in std:array +arr.unshift(42); assert(arr.length == 4); assert(arr.__capacity == 4); diff --git a/tests/compiler/std/array.wast b/tests/compiler/std/array.wast index 265e87d3..7d3bd821 100644 --- a/tests/compiler/std/array.wast +++ b/tests/compiler/std/array.wast @@ -1,7 +1,7 @@ (module (type $i (func (result i32))) (type $ii (func (param i32) (result i32))) - (type $iiii (func (param i32 i32 i32) (result i32))) + (type $iiiv (func (param i32 i32 i32))) (type $iv (func (param i32))) (type $iiv (func (param i32 i32))) (type $iii (func (param i32 i32) (result i32))) @@ -16,7 +16,7 @@ (memory $0 1) (export "memory" (memory $0)) (start $start) - (func $std:heap/Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32) + (func $std:heap/allocate_memory (; 0 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -113,25 +113,10 @@ (get_local $4) ) ) - (func $std:heap/Heap.copy (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std:heap/copy_memory (; 1 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - (local $6 i32) - (if - (i32.eqz - (i32.ge_u - (get_local $0) - (get_global $HEAP_BASE) - ) - ) - (unreachable) - ) - (block - (set_local $3 - (get_local $0) - ) - ) (nop) (block $break|0 (loop $continue|0 @@ -151,29 +136,29 @@ (block (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -192,7 +177,7 @@ (if (i32.eq (i32.rem_u - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.const 0) @@ -208,14 +193,14 @@ (block (block (i32.store - (get_local $3) + (get_local $0) (i32.load (get_local $1) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.load @@ -227,7 +212,7 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (i32.load @@ -239,7 +224,7 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (i32.load @@ -255,9 +240,9 @@ (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -280,14 +265,14 @@ ) (block (i32.store - (get_local $3) + (get_local $0) (i32.load (get_local $1) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.load @@ -297,9 +282,9 @@ ) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) ) @@ -318,14 +303,14 @@ ) (block (i32.store - (get_local $3) + (get_local $0) (i32.load (get_local $1) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) ) @@ -344,14 +329,14 @@ ) (block (i32.store16 - (get_local $3) + (get_local $0) (i32.load16_u (get_local $1) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 2) ) ) @@ -370,36 +355,34 @@ ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) ) - (return - (get_local $0) - ) + (return) ) ) (if @@ -411,118 +394,118 @@ (block $case2|2 (block $case1|2 (block $case0|2 - (set_local $6 + (set_local $5 (i32.rem_u - (get_local $3) + (get_local $0) (i32.const 4) ) ) (br_if $case0|2 (i32.eq - (get_local $6) + (get_local $5) (i32.const 1) ) ) (br_if $case1|2 (i32.eq - (get_local $6) + (get_local $5) (i32.const 2) ) ) (br_if $case2|2 (i32.eq - (get_local $6) + (get_local $5) (i32.const 3) ) ) (br $break|2) ) - (set_local $4 + (set_local $3 (i32.load (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -541,7 +524,7 @@ ) (block (block - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -550,19 +533,19 @@ ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 24) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 8) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -572,21 +555,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 8) ) ) ) - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -596,21 +579,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 24) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 8) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -620,16 +603,16 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 8) ) ) @@ -640,9 +623,9 @@ (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -660,64 +643,64 @@ ) (br $break|2) ) - (set_local $4 + (set_local $3 (i32.load (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -736,7 +719,7 @@ ) (block (block - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -745,19 +728,19 @@ ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 16) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 16) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -767,21 +750,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 16) ) ) ) - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -791,21 +774,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 16) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 16) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -815,16 +798,16 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 16) ) ) @@ -835,9 +818,9 @@ (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -855,36 +838,36 @@ ) (br $break|2) ) - (set_local $4 + (set_local $3 (i32.load (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -903,7 +886,7 @@ ) (block (block - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -912,19 +895,19 @@ ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 8) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 24) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -934,21 +917,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 24) ) ) ) - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -958,21 +941,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 8) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 24) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -982,16 +965,16 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 24) ) ) @@ -1002,9 +985,9 @@ (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -1031,449 +1014,449 @@ (block (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -1487,225 +1470,225 @@ (block (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -1719,113 +1702,113 @@ (block (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -1839,57 +1822,57 @@ (block (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -1902,40 +1885,361 @@ ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) ) - (return - (get_local $0) + ) + (func $std:heap/move_memory (; 2 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (if + (i32.eq + (get_local $0) + (get_local $1) + ) + (return) + ) + (if + (i32.and + (if (result i32) + (i32.ne + (tee_local $3 + (i32.le_u + (i32.add + (get_local $1) + (get_local $2) + ) + (get_local $0) + ) + ) + (i32.const 0) + ) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) + ) + (i32.const 1) + ) + (block + (call $std:heap/copy_memory + (get_local $0) + (get_local $1) + (get_local $2) + ) + (return) + ) + ) + (if + (i32.lt_u + (get_local $0) + (get_local $1) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (block $break|0 + (loop $continue|0 + (if + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + (block + (block + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + (i32.store8 + (block (result i32) + (set_local $3 + (get_local $0) + ) + (set_local $0 + (i32.add + (get_local $3) + (i32.const 1) + ) + ) + (get_local $3) + ) + (i32.load8_u + (block (result i32) + (set_local $3 + (get_local $1) + ) + (set_local $1 + (i32.add + (get_local $3) + (i32.const 1) + ) + ) + (get_local $3) + ) + ) + ) + ) + (br $continue|0) + ) + ) + ) + ) + (block $break|1 + (loop $continue|1 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (block + (i64.store + (get_local $0) + (i64.load + (get_local $1) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 8) + ) + ) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 8) + ) + ) + ) + (br $continue|1) + ) + ) + ) + ) + ) + ) + (block $break|2 + (loop $continue|2 + (if + (get_local $2) + (block + (block + (i32.store8 + (block (result i32) + (set_local $3 + (get_local $0) + ) + (set_local $0 + (i32.add + (get_local $3) + (i32.const 1) + ) + ) + (get_local $3) + ) + (i32.load8_u + (block (result i32) + (set_local $3 + (get_local $1) + ) + (set_local $1 + (i32.add + (get_local $3) + (i32.const 1) + ) + ) + (get_local $3) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (br $continue|2) + ) + ) + ) + ) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (block $break|3 + (loop $continue|3 + (if + (i32.rem_u + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (block + (block + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + ) + (br $continue|3) + ) + ) + ) + ) + (block $break|4 + (loop $continue|4 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (block + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + (i64.store + (i32.add + (get_local $0) + (get_local $2) + ) + (i64.load + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + ) + (br $continue|4) + ) + ) + ) + ) + ) + ) + (block $break|5 + (loop $continue|5 + (if + (get_local $2) + (block + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|5) + ) + ) + ) + ) + ) ) ) - (func $std:heap/Heap.dispose (; 2 ;) (type $iv) (param $0 i32) + (func $std:heap/free_memory (; 3 ;) (type $iv) (param $0 i32) ) - (func $std:array/Array#__grow (; 3 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $std:array/Array#__grow (; 4 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (if (i32.eqz @@ -1950,7 +2254,7 @@ ) (block (set_local $2 - (call $std:heap/Heap.allocate + (call $std:heap/allocate_memory (i32.mul (get_local $1) (i32.const 4) @@ -1962,8 +2266,8 @@ (i32.load (get_local $0) ) - (drop - (call $std:heap/Heap.copy + (block + (call $std:heap/move_memory (get_local $2) (i32.load (get_local $0) @@ -1975,11 +2279,11 @@ (i32.const 4) ) ) - ) - ) - (call $std:heap/Heap.dispose - (i32.load - (get_local $0) + (call $std:heap/free_memory + (i32.load + (get_local $0) + ) + ) ) ) (i32.store @@ -1991,7 +2295,7 @@ (get_local $1) ) ) - (func $std:array/Array#push (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std:array/Array#push (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (if @@ -2015,11 +2319,11 @@ ) ) (tee_local $3 - (i32.mul + (i32.shl (i32.load offset=4 (get_local $0) ) - (i32.const 2) + (i32.const 1) ) ) (i32.gt_s @@ -2061,7 +2365,7 @@ ) ) ) - (func $std:array/Array#__get (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std:array/Array#__get (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (if (i32.ge_u (get_local $1) @@ -2085,7 +2389,7 @@ ) ) ) - (func $std:array/Array#pop (; 6 ;) (type $ii) (param $0 i32) (result i32) + (func $std:array/Array#pop (; 7 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (if (i32.and @@ -2140,7 +2444,7 @@ ) ) ) - (func $std:array/Array#unshift (; 7 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std:array/Array#unshift (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2259,41 +2563,24 @@ ) ) ) - (func $std:heap/Heap.fill (; 8 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std:heap/set_memory (; 9 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) - (local $5 i32) - (local $6 i64) - (if - (i32.eqz - (i32.ge_u - (get_local $0) - (get_global $HEAP_BASE) - ) - ) - (unreachable) - ) + (local $5 i64) (if (i32.eqz (get_local $2) ) - (return - (get_local $0) - ) - ) - (block - (set_local $3 - (get_local $0) - ) + (return) ) (i32.store8 - (get_local $3) + (get_local $0) (get_local $1) ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 1) @@ -2305,38 +2592,36 @@ (get_local $2) (i32.const 2) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 (i32.add - (get_local $3) + (get_local $0) (i32.const 1) ) (get_local $1) ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 2) + ) + (get_local $1) + ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 2) ) (get_local $1) ) - (i32.store8 - (i32.add - (get_local $3) - (i32.const 2) - ) - (get_local $1) - ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 3) @@ -2348,13 +2633,11 @@ (get_local $2) (i32.const 6) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 (i32.add - (get_local $3) + (get_local $0) (i32.const 3) ) (get_local $1) @@ -2362,7 +2645,7 @@ (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 4) @@ -2374,31 +2657,29 @@ (get_local $2) (i32.const 8) ) - (return - (get_local $0) - ) + (return) ) (block - (set_local $4 + (set_local $3 (i32.and (i32.sub (i32.const 0) - (get_local $3) + (get_local $0) ) (i32.const 3) ) ) ) - (set_local $3 + (set_local $0 (i32.add + (get_local $0) (get_local $3) - (get_local $4) ) ) (set_local $2 (i32.sub (get_local $2) - (get_local $4) + (get_local $3) ) ) (set_local $2 @@ -2411,7 +2692,7 @@ ) ) (block - (set_local $5 + (set_local $4 (i32.mul (i32.div_u (i32.sub @@ -2425,169 +2706,165 @@ ) ) (i32.store - (get_local $3) - (get_local $5) + (get_local $0) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 4) ) - (get_local $5) + (get_local $4) ) (if (i32.le_u (get_local $2) (i32.const 8) ) - (return - (get_local $0) - ) + (return) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 12) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 8) ) - (get_local $5) + (get_local $4) ) (if (i32.le_u (get_local $2) (i32.const 24) ) - (return - (get_local $0) - ) + (return) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 20) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 24) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 28) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 24) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 20) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 16) ) - (get_local $5) + (get_local $4) ) - (set_local $4 + (set_local $3 (i32.add (i32.const 24) (i32.and - (get_local $3) + (get_local $0) (i32.const 4) ) ) ) - (set_local $3 + (set_local $0 (i32.add + (get_local $0) (get_local $3) - (get_local $4) ) ) (set_local $2 (i32.sub (get_local $2) - (get_local $4) + (get_local $3) ) ) (block - (set_local $6 + (set_local $5 (i64.or (i64.extend_u/i32 - (get_local $5) + (get_local $4) ) (i64.shl (i64.extend_u/i32 - (get_local $5) + (get_local $4) ) (i64.const 32) ) @@ -2604,29 +2881,29 @@ (block (block (i64.store - (get_local $3) - (get_local $6) + (get_local $0) + (get_local $5) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) - (get_local $6) + (get_local $5) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) - (get_local $6) + (get_local $5) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 24) ) - (get_local $6) + (get_local $5) ) (set_local $2 (i32.sub @@ -2634,9 +2911,9 @@ (i32.const 32) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 32) ) ) @@ -2646,11 +2923,8 @@ ) ) ) - (return - (get_local $0) - ) ) - (func $std:array/Array#shift (; 9 ;) (type $ii) (param $0 i32) (result i32) + (func $std:array/Array#shift (; 10 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (if @@ -2690,16 +2964,30 @@ ) ) ) - (drop - (call $std:heap/Heap.copy + (call $std:heap/move_memory + (i32.load + (get_local $0) + ) + (i32.add (i32.load (get_local $0) ) - (i32.add - (i32.load + (i32.const 4) + ) + (i32.mul + (i32.sub + (i32.load offset=4 (get_local $0) ) - (i32.const 4) + (i32.const 1) + ) + (i32.const 4) + ) + ) + (call $std:heap/set_memory + (i32.add + (i32.load + (get_local $0) ) (i32.mul (i32.sub @@ -2711,26 +2999,8 @@ (i32.const 4) ) ) - ) - (drop - (call $std:heap/Heap.fill - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (i32.sub - (i32.load offset=4 - (get_local $0) - ) - (i32.const 1) - ) - (i32.const 4) - ) - ) - (i32.const 0) - (i32.const 4) - ) + (i32.const 0) + (i32.const 4) ) (i32.store offset=8 (get_local $0) @@ -2745,12 +3015,12 @@ (get_local $2) ) ) - (func $start (; 10 ;) (type $v) + (func $start (; 11 ;) (type $v) (set_global $std:heap/HEAP_OFFSET (get_global $HEAP_BASE) ) (set_global $std/array/arr - (call $std:heap/Heap.allocate + (call $std:heap/allocate_memory (i32.add (i32.const 4) (i32.mul @@ -3392,16 +3662,17 @@ GLOBAL: std:heap/ALIGN_SIZE GLOBAL: std:heap/ALIGN_MASK GLOBAL: std:heap/HEAP_OFFSET - CLASS_PROTOTYPE: std:heap/Heap - CLASS_PROTOTYPE: Heap - PROPERTY: std:heap/Heap.used - PROPERTY: std:heap/Heap.free - PROPERTY: std:heap/Heap.size - FUNCTION_PROTOTYPE: std:heap/Heap.allocate - FUNCTION_PROTOTYPE: std:heap/Heap.dispose - FUNCTION_PROTOTYPE: std:heap/Heap.copy - FUNCTION_PROTOTYPE: std:heap/Heap.fill - FUNCTION_PROTOTYPE: std:heap/Heap.compare + FUNCTION_PROTOTYPE: std:heap/allocate_memory + FUNCTION_PROTOTYPE: allocate_memory + FUNCTION_PROTOTYPE: std:heap/free_memory + FUNCTION_PROTOTYPE: free_memory + FUNCTION_PROTOTYPE: std:heap/copy_memory + FUNCTION_PROTOTYPE: std:heap/move_memory + FUNCTION_PROTOTYPE: move_memory + FUNCTION_PROTOTYPE: std:heap/set_memory + FUNCTION_PROTOTYPE: set_memory + FUNCTION_PROTOTYPE: std:heap/compare_memory + FUNCTION_PROTOTYPE: compare_memory CLASS_PROTOTYPE: std:map/Map CLASS_PROTOTYPE: Map CLASS_PROTOTYPE: std:regexp/RegExp @@ -3423,7 +3694,11 @@ CLASS_PROTOTYPE: std:array/CArray CLASS_PROTOTYPE: std:error/Error CLASS_PROTOTYPE: std:error/RangeError - CLASS_PROTOTYPE: std:heap/Heap + FUNCTION_PROTOTYPE: std:heap/allocate_memory + FUNCTION_PROTOTYPE: std:heap/free_memory + FUNCTION_PROTOTYPE: std:heap/move_memory + FUNCTION_PROTOTYPE: std:heap/set_memory + FUNCTION_PROTOTYPE: std:heap/compare_memory CLASS_PROTOTYPE: std:map/Map CLASS_PROTOTYPE: std:regexp/RegExp CLASS_PROTOTYPE: std:set/Set diff --git a/tests/compiler/std/carray.optimized.wast b/tests/compiler/std/carray.optimized.wast index 4247e770..49d3f567 100644 --- a/tests/compiler/std/carray.optimized.wast +++ b/tests/compiler/std/carray.optimized.wast @@ -8,6 +8,13 @@ (export "memory" (memory $0)) (start $start) (func $std:array/CArray#__get (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (if + (i32.lt_s + (get_local $1) + (i32.const 0) + ) + (unreachable) + ) (i32.load (i32.add (get_local $0) @@ -19,6 +26,13 @@ ) ) (func $std:array/CArray#__set (; 1 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (if + (i32.lt_s + (get_local $1) + (i32.const 0) + ) + (unreachable) + ) (i32.store (i32.add (get_local $0) diff --git a/tests/compiler/std/carray.wast b/tests/compiler/std/carray.wast index 651ea64b..73092756 100644 --- a/tests/compiler/std/carray.wast +++ b/tests/compiler/std/carray.wast @@ -8,6 +8,13 @@ (export "memory" (memory $0)) (start $start) (func $std:array/CArray#__get (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (if + (i32.lt_s + (get_local $1) + (i32.const 0) + ) + (unreachable) + ) (return (i32.load (i32.add @@ -21,6 +28,13 @@ ) ) (func $std:array/CArray#__set (; 1 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (if + (i32.lt_s + (get_local $1) + (i32.const 0) + ) + (unreachable) + ) (i32.store (i32.add (get_local $0) @@ -247,16 +261,17 @@ GLOBAL: std:heap/ALIGN_SIZE GLOBAL: std:heap/ALIGN_MASK GLOBAL: std:heap/HEAP_OFFSET - CLASS_PROTOTYPE: std:heap/Heap - CLASS_PROTOTYPE: Heap - PROPERTY: std:heap/Heap.used - PROPERTY: std:heap/Heap.free - PROPERTY: std:heap/Heap.size - FUNCTION_PROTOTYPE: std:heap/Heap.allocate - FUNCTION_PROTOTYPE: std:heap/Heap.dispose - FUNCTION_PROTOTYPE: std:heap/Heap.copy - FUNCTION_PROTOTYPE: std:heap/Heap.fill - FUNCTION_PROTOTYPE: std:heap/Heap.compare + FUNCTION_PROTOTYPE: std:heap/allocate_memory + FUNCTION_PROTOTYPE: allocate_memory + FUNCTION_PROTOTYPE: std:heap/free_memory + FUNCTION_PROTOTYPE: free_memory + FUNCTION_PROTOTYPE: std:heap/copy_memory + FUNCTION_PROTOTYPE: std:heap/move_memory + FUNCTION_PROTOTYPE: move_memory + FUNCTION_PROTOTYPE: std:heap/set_memory + FUNCTION_PROTOTYPE: set_memory + FUNCTION_PROTOTYPE: std:heap/compare_memory + FUNCTION_PROTOTYPE: compare_memory CLASS_PROTOTYPE: std:map/Map CLASS_PROTOTYPE: Map CLASS_PROTOTYPE: std:regexp/RegExp @@ -277,7 +292,11 @@ CLASS_PROTOTYPE: std:array/CArray CLASS_PROTOTYPE: std:error/Error CLASS_PROTOTYPE: std:error/RangeError - CLASS_PROTOTYPE: std:heap/Heap + FUNCTION_PROTOTYPE: std:heap/allocate_memory + FUNCTION_PROTOTYPE: std:heap/free_memory + FUNCTION_PROTOTYPE: std:heap/move_memory + FUNCTION_PROTOTYPE: std:heap/set_memory + FUNCTION_PROTOTYPE: std:heap/compare_memory CLASS_PROTOTYPE: std:map/Map CLASS_PROTOTYPE: std:regexp/RegExp CLASS_PROTOTYPE: std:set/Set diff --git a/tests/compiler/std/heap.optimized.wast b/tests/compiler/std/heap.optimized.wast index d9de4fb8..0d8ea488 100644 --- a/tests/compiler/std/heap.optimized.wast +++ b/tests/compiler/std/heap.optimized.wast @@ -1,5 +1,6 @@ (module (type $ii (func (param i32) (result i32))) + (type $iiiv (func (param i32 i32 i32))) (type $iiii (func (param i32 i32 i32) (result i32))) (type $iv (func (param i32))) (type $v (func)) @@ -11,7 +12,7 @@ (memory $0 1) (export "memory" (memory $0)) (start $start) - (func $std:heap/Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32) + (func $std:heap/allocate_memory (; 0 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (if @@ -100,35 +101,23 @@ ) (get_local $1) ) - (func $std:heap/Heap.fill (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - (local $4 i64) - (local $5 i32) - (if - (i32.lt_u - (get_local $0) - (get_global $HEAP_BASE) - ) - (unreachable) - ) + (func $std:heap/set_memory (; 1 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i64) + (local $4 i32) (if (i32.eqz (get_local $2) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 - (tee_local $3 - (get_local $0) - ) + (get_local $0) (get_local $1) ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 1) @@ -140,38 +129,36 @@ (get_local $2) (i32.const 2) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 (i32.add - (get_local $3) + (get_local $0) (i32.const 1) ) (get_local $1) ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 2) + ) + (get_local $1) + ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 2) ) (get_local $1) ) - (i32.store8 - (i32.add - (get_local $3) - (i32.const 2) - ) - (get_local $1) - ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 3) @@ -183,13 +170,11 @@ (get_local $2) (i32.const 6) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 (i32.add - (get_local $3) + (get_local $0) (i32.const 3) ) (get_local $1) @@ -197,7 +182,7 @@ (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 4) @@ -209,19 +194,17 @@ (get_local $2) (i32.const 8) ) - (return - (get_local $0) - ) + (return) ) (i32.store - (tee_local $3 + (tee_local $0 (i32.add - (get_local $3) - (tee_local $5 + (get_local $0) + (tee_local $4 (i32.and (i32.sub (i32.const 0) - (get_local $3) + (get_local $0) ) (i32.const 3) ) @@ -238,12 +221,12 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (tee_local $2 (i32.and (i32.sub (get_local $2) - (get_local $5) + (get_local $4) ) (i32.const -4) ) @@ -258,20 +241,18 @@ (get_local $2) (i32.const 8) ) - (return - (get_local $0) - ) + (return) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (get_local $1) @@ -279,7 +260,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 12) @@ -289,7 +270,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 8) @@ -301,34 +282,32 @@ (get_local $2) (i32.const 24) ) - (return - (get_local $0) - ) + (return) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 20) ) (get_local $1) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 24) ) (get_local $1) @@ -336,7 +315,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 28) @@ -346,7 +325,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 24) @@ -356,7 +335,7 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 20) @@ -366,20 +345,20 @@ (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 16) ) (get_local $1) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) - (tee_local $5 + (get_local $0) + (tee_local $4 (i32.add (i32.and - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.const 24) @@ -390,10 +369,10 @@ (set_local $2 (i32.sub (get_local $2) - (get_local $5) + (get_local $4) ) ) - (set_local $4 + (set_local $3 (i64.or (i64.extend_u/i32 (get_local $1) @@ -414,29 +393,29 @@ ) (block (i64.store + (get_local $0) (get_local $3) - (get_local $4) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) - (get_local $4) + (get_local $3) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) - (get_local $4) + (get_local $3) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 24) ) - (get_local $4) + (get_local $3) ) (set_local $2 (i32.sub @@ -444,9 +423,9 @@ (i32.const 32) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 32) ) ) @@ -454,22 +433,10 @@ ) ) ) - (get_local $0) ) - (func $std:heap/Heap.copy (; 2 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std:heap/copy_memory (; 2 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) - (local $5 i32) - (if - (i32.lt_u - (get_local $0) - (get_global $HEAP_BASE) - ) - (unreachable) - ) - (set_local $4 - (get_local $0) - ) (loop $continue|0 (if (if (result i32) @@ -481,10 +448,10 @@ (get_local $2) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -518,7 +485,7 @@ (if (i32.eqz (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) ) @@ -531,14 +498,14 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load @@ -550,7 +517,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.load @@ -562,7 +529,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.load @@ -578,9 +545,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -601,14 +568,14 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load (get_local $1) ) ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.load @@ -618,9 +585,9 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) ) @@ -639,14 +606,14 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) ) @@ -665,14 +632,14 @@ ) (block (i32.store16 - (get_local $4) + (get_local $0) (i32.load16_u (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 2) ) ) @@ -691,7 +658,7 @@ ) (block (set_local $3 - (get_local $4) + (get_local $0) ) (i32.store8 (get_local $3) @@ -706,9 +673,7 @@ ) ) ) - (return - (get_local $0) - ) + (return) ) ) (if @@ -724,7 +689,7 @@ (br_table $case0|2 $case1|2 $case2|2 $tablify|0 (i32.sub (i32.rem_u - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.const 1) @@ -733,15 +698,15 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -762,10 +727,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -786,10 +751,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -824,10 +789,10 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl @@ -845,7 +810,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or @@ -854,7 +819,7 @@ (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -868,12 +833,12 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl @@ -891,7 +856,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or @@ -900,7 +865,7 @@ (i32.const 24) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -918,9 +883,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -936,15 +901,15 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -965,10 +930,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1003,10 +968,10 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl @@ -1024,7 +989,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or @@ -1033,7 +998,7 @@ (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -1047,12 +1012,12 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl @@ -1070,7 +1035,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or @@ -1079,7 +1044,7 @@ (i32.const 16) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -1097,9 +1062,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -1115,15 +1080,15 @@ ) (br $break|2) ) - (set_local $5 + (set_local $4 (i32.load (get_local $1) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1158,10 +1123,10 @@ ) (block (i32.store - (get_local $4) + (get_local $0) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl @@ -1179,7 +1144,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 4) ) (i32.or @@ -1188,7 +1153,7 @@ (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -1202,12 +1167,12 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl @@ -1225,7 +1190,7 @@ ) (i32.store (i32.add - (get_local $4) + (get_local $0) (i32.const 12) ) (i32.or @@ -1234,7 +1199,7 @@ (i32.const 8) ) (i32.shl - (tee_local $5 + (tee_local $4 (i32.load (i32.add (get_local $1) @@ -1252,9 +1217,9 @@ (i32.const 16) ) ) - (set_local $4 + (set_local $0 (i32.add - (get_local $4) + (get_local $0) (i32.const 16) ) ) @@ -1276,10 +1241,10 @@ (i32.const 16) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1300,10 +1265,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1324,10 +1289,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1348,10 +1313,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1372,10 +1337,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1396,10 +1361,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1420,10 +1385,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1444,10 +1409,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1468,10 +1433,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1492,10 +1457,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1516,10 +1481,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1540,10 +1505,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1564,10 +1529,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1588,10 +1553,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1612,10 +1577,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1636,10 +1601,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1668,10 +1633,10 @@ (i32.const 8) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1692,10 +1657,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1716,10 +1681,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1740,10 +1705,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1764,10 +1729,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1788,10 +1753,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1812,10 +1777,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1836,10 +1801,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1868,10 +1833,10 @@ (i32.const 4) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1892,10 +1857,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1916,10 +1881,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1940,10 +1905,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1972,10 +1937,10 @@ (i32.const 2) ) (block - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -1996,10 +1961,10 @@ ) ) ) - (set_local $4 + (set_local $0 (i32.add (tee_local $3 - (get_local $4) + (get_local $0) ) (i32.const 1) ) @@ -2029,7 +1994,7 @@ ) (block (set_local $3 - (get_local $4) + (get_local $0) ) (i32.store8 (get_local $3) @@ -2044,9 +2009,298 @@ ) ) ) - (get_local $0) ) - (func $std:heap/Heap.compare (; 3 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std:heap/move_memory (; 3 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (if + (i32.eq + (get_local $0) + (get_local $1) + ) + (return) + ) + (if + (i32.and + (if (result i32) + (tee_local $3 + (i32.le_u + (i32.add + (get_local $1) + (get_local $2) + ) + (get_local $0) + ) + ) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) + ) + (i32.const 1) + ) + (block + (call $std:heap/copy_memory + (get_local $0) + (get_local $1) + (get_local $2) + ) + (return) + ) + ) + (if + (i32.lt_u + (get_local $0) + (get_local $1) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (loop $continue|0 + (if + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + (block + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + (set_local $0 + (i32.add + (tee_local $3 + (get_local $0) + ) + (i32.const 1) + ) + ) + (i32.store8 + (get_local $3) + (block (result i32) + (set_local $1 + (i32.add + (tee_local $3 + (get_local $1) + ) + (i32.const 1) + ) + ) + (i32.load8_u + (get_local $3) + ) + ) + ) + (br $continue|0) + ) + ) + ) + (loop $continue|1 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (i64.store + (get_local $0) + (i64.load + (get_local $1) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 8) + ) + ) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 8) + ) + ) + (br $continue|1) + ) + ) + ) + ) + ) + (loop $continue|2 + (if + (get_local $2) + (block + (set_local $0 + (i32.add + (tee_local $3 + (get_local $0) + ) + (i32.const 1) + ) + ) + (i32.store8 + (get_local $3) + (block (result i32) + (set_local $1 + (i32.add + (tee_local $3 + (get_local $1) + ) + (i32.const 1) + ) + ) + (i32.load8_u + (get_local $3) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + (br $continue|2) + ) + ) + ) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (loop $continue|3 + (if + (i32.rem_u + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (block + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|3) + ) + ) + ) + (loop $continue|4 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (i64.store + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + ) + (i64.load + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|4) + ) + ) + ) + ) + ) + (loop $continue|5 + (if + (get_local $2) + (block + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|5) + ) + ) + ) + ) + ) + ) + (func $std:heap/compare_memory (; 4 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (if (i32.eq (get_local $0) @@ -2106,20 +2360,20 @@ (i32.const 0) ) ) - (func $std:heap/Heap.dispose (; 4 ;) (type $iv) (param $0 i32) + (func $std:heap/free_memory (; 5 ;) (type $iv) (param $0 i32) (nop) ) - (func $start (; 5 ;) (type $v) + (func $start (; 6 ;) (type $v) (set_global $std:heap/HEAP_OFFSET (get_global $HEAP_BASE) ) (set_global $std/heap/ptr1 - (call $std:heap/Heap.allocate + (call $std:heap/allocate_memory (i32.const 42) ) ) (set_global $std/heap/ptr2 - (call $std:heap/Heap.allocate + (call $std:heap/allocate_memory (i32.const 42) ) ) @@ -2130,12 +2384,10 @@ ) (unreachable) ) - (drop - (call $std:heap/Heap.fill - (get_global $std/heap/ptr1) - (i32.const 18) - (i32.const 42) - ) + (call $std:heap/set_memory + (get_global $std/heap/ptr1) + (i32.const 18) + (i32.const 42) ) (set_global $std/heap/i (i32.const 0) @@ -2169,12 +2421,10 @@ ) ) ) - (drop - (call $std:heap/Heap.copy - (get_global $std/heap/ptr2) - (get_global $std/heap/ptr1) - (i32.const 42) - ) + (call $std:heap/move_memory + (get_global $std/heap/ptr2) + (get_global $std/heap/ptr1) + (i32.const 42) ) (set_global $std/heap/i (i32.const 0) @@ -2209,17 +2459,17 @@ ) ) (if - (call $std:heap/Heap.compare + (call $std:heap/compare_memory (get_global $std/heap/ptr1) (get_global $std/heap/ptr2) (i32.const 42) ) (unreachable) ) - (call $std:heap/Heap.dispose + (call $std:heap/free_memory (get_global $std/heap/ptr1) ) - (call $std:heap/Heap.dispose + (call $std:heap/free_memory (get_global $std/heap/ptr2) ) ) diff --git a/tests/compiler/std/heap.ts b/tests/compiler/std/heap.ts index 8f45bd08..05a8c7a1 100644 --- a/tests/compiler/std/heap.ts +++ b/tests/compiler/std/heap.ts @@ -1,21 +1,21 @@ const size: usize = 42; -let ptr1: usize = Heap.allocate(size); -let ptr2: usize = Heap.allocate(size); +let ptr1: usize = allocate_memory(size); +let ptr2: usize = allocate_memory(size); assert(ptr1 != ptr2); -Heap.fill(ptr1, 0x12, size); +set_memory(ptr1, 0x12, size); let i: usize; for (i = 0; i < size; ++i) assert(load(ptr1 + i) == 0x12); -Heap.copy(ptr2, ptr1, size); +move_memory(ptr2, ptr1, size); for (i = 0; i < size; ++i) assert(load(ptr2 + i) == 0x12); -assert(Heap.compare(ptr1, ptr2, size) == 0); +assert(compare_memory(ptr1, ptr2, size) == 0); -Heap.dispose(ptr1); -Heap.dispose(ptr2); +free_memory(ptr1); +free_memory(ptr2); diff --git a/tests/compiler/std/heap.wast b/tests/compiler/std/heap.wast index e12a33ea..dd6957a6 100644 --- a/tests/compiler/std/heap.wast +++ b/tests/compiler/std/heap.wast @@ -1,6 +1,7 @@ (module (type $i (func (result i32))) (type $ii (func (param i32) (result i32))) + (type $iiiv (func (param i32 i32 i32))) (type $iiii (func (param i32 i32 i32) (result i32))) (type $iv (func (param i32))) (type $v (func)) @@ -16,7 +17,7 @@ (memory $0 1) (export "memory" (memory $0)) (start $start) - (func $std:heap/Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32) + (func $std:heap/allocate_memory (; 0 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -113,41 +114,24 @@ (get_local $4) ) ) - (func $std:heap/Heap.fill (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std:heap/set_memory (; 1 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) - (local $5 i32) - (local $6 i64) - (if - (i32.eqz - (i32.ge_u - (get_local $0) - (get_global $HEAP_BASE) - ) - ) - (unreachable) - ) + (local $5 i64) (if (i32.eqz (get_local $2) ) - (return - (get_local $0) - ) - ) - (block - (set_local $3 - (get_local $0) - ) + (return) ) (i32.store8 - (get_local $3) + (get_local $0) (get_local $1) ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 1) @@ -159,38 +143,36 @@ (get_local $2) (i32.const 2) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 (i32.add - (get_local $3) + (get_local $0) (i32.const 1) ) (get_local $1) ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 2) + ) + (get_local $1) + ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 2) ) (get_local $1) ) - (i32.store8 - (i32.add - (get_local $3) - (i32.const 2) - ) - (get_local $1) - ) (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 3) @@ -202,13 +184,11 @@ (get_local $2) (i32.const 6) ) - (return - (get_local $0) - ) + (return) ) (i32.store8 (i32.add - (get_local $3) + (get_local $0) (i32.const 3) ) (get_local $1) @@ -216,7 +196,7 @@ (i32.store8 (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 4) @@ -228,31 +208,29 @@ (get_local $2) (i32.const 8) ) - (return - (get_local $0) - ) + (return) ) (block - (set_local $4 + (set_local $3 (i32.and (i32.sub (i32.const 0) - (get_local $3) + (get_local $0) ) (i32.const 3) ) ) ) - (set_local $3 + (set_local $0 (i32.add + (get_local $0) (get_local $3) - (get_local $4) ) ) (set_local $2 (i32.sub (get_local $2) - (get_local $4) + (get_local $3) ) ) (set_local $2 @@ -265,7 +243,7 @@ ) ) (block - (set_local $5 + (set_local $4 (i32.mul (i32.div_u (i32.sub @@ -279,169 +257,165 @@ ) ) (i32.store - (get_local $3) - (get_local $5) + (get_local $0) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 4) ) - (get_local $5) + (get_local $4) ) (if (i32.le_u (get_local $2) (i32.const 8) ) - (return - (get_local $0) - ) + (return) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 12) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 8) ) - (get_local $5) + (get_local $4) ) (if (i32.le_u (get_local $2) (i32.const 24) ) - (return - (get_local $0) - ) + (return) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 20) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 24) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 28) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 24) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 20) ) - (get_local $5) + (get_local $4) ) (i32.store (i32.sub (i32.add - (get_local $3) + (get_local $0) (get_local $2) ) (i32.const 16) ) - (get_local $5) + (get_local $4) ) - (set_local $4 + (set_local $3 (i32.add (i32.const 24) (i32.and - (get_local $3) + (get_local $0) (i32.const 4) ) ) ) - (set_local $3 + (set_local $0 (i32.add + (get_local $0) (get_local $3) - (get_local $4) ) ) (set_local $2 (i32.sub (get_local $2) - (get_local $4) + (get_local $3) ) ) (block - (set_local $6 + (set_local $5 (i64.or (i64.extend_u/i32 - (get_local $5) + (get_local $4) ) (i64.shl (i64.extend_u/i32 - (get_local $5) + (get_local $4) ) (i64.const 32) ) @@ -458,29 +432,29 @@ (block (block (i64.store - (get_local $3) - (get_local $6) + (get_local $0) + (get_local $5) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) - (get_local $6) + (get_local $5) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) - (get_local $6) + (get_local $5) ) (i64.store (i32.add - (get_local $3) + (get_local $0) (i32.const 24) ) - (get_local $6) + (get_local $5) ) (set_local $2 (i32.sub @@ -488,9 +462,9 @@ (i32.const 32) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 32) ) ) @@ -500,29 +474,11 @@ ) ) ) - (return - (get_local $0) - ) ) - (func $std:heap/Heap.copy (; 2 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std:heap/copy_memory (; 2 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - (local $6 i32) - (if - (i32.eqz - (i32.ge_u - (get_local $0) - (get_global $HEAP_BASE) - ) - ) - (unreachable) - ) - (block - (set_local $3 - (get_local $0) - ) - ) (nop) (block $break|0 (loop $continue|0 @@ -542,29 +498,29 @@ (block (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -583,7 +539,7 @@ (if (i32.eq (i32.rem_u - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.const 0) @@ -599,14 +555,14 @@ (block (block (i32.store - (get_local $3) + (get_local $0) (i32.load (get_local $1) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.load @@ -618,7 +574,7 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (i32.load @@ -630,7 +586,7 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (i32.load @@ -646,9 +602,9 @@ (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -671,14 +627,14 @@ ) (block (i32.store - (get_local $3) + (get_local $0) (i32.load (get_local $1) ) ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.load @@ -688,9 +644,9 @@ ) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) ) @@ -709,14 +665,14 @@ ) (block (i32.store - (get_local $3) + (get_local $0) (i32.load (get_local $1) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) ) @@ -735,14 +691,14 @@ ) (block (i32.store16 - (get_local $3) + (get_local $0) (i32.load16_u (get_local $1) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 2) ) ) @@ -761,36 +717,34 @@ ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) ) - (return - (get_local $0) - ) + (return) ) ) (if @@ -802,118 +756,118 @@ (block $case2|2 (block $case1|2 (block $case0|2 - (set_local $6 + (set_local $5 (i32.rem_u - (get_local $3) + (get_local $0) (i32.const 4) ) ) (br_if $case0|2 (i32.eq - (get_local $6) + (get_local $5) (i32.const 1) ) ) (br_if $case1|2 (i32.eq - (get_local $6) + (get_local $5) (i32.const 2) ) ) (br_if $case2|2 (i32.eq - (get_local $6) + (get_local $5) (i32.const 3) ) ) (br $break|2) ) - (set_local $4 + (set_local $3 (i32.load (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -932,7 +886,7 @@ ) (block (block - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -941,19 +895,19 @@ ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 24) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 8) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -963,21 +917,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 8) ) ) ) - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -987,21 +941,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 24) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 8) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -1011,16 +965,16 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 24) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 8) ) ) @@ -1031,9 +985,9 @@ (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -1051,64 +1005,64 @@ ) (br $break|2) ) - (set_local $4 + (set_local $3 (i32.load (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -1127,7 +1081,7 @@ ) (block (block - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -1136,19 +1090,19 @@ ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 16) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 16) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -1158,21 +1112,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 16) ) ) ) - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -1182,21 +1136,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 16) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 16) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -1206,16 +1160,16 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 16) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 16) ) ) @@ -1226,9 +1180,9 @@ (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -1246,36 +1200,36 @@ ) (br $break|2) ) - (set_local $4 + (set_local $3 (i32.load (get_local $1) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -1294,7 +1248,7 @@ ) (block (block - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -1303,19 +1257,19 @@ ) ) (i32.store - (get_local $3) + (get_local $0) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 8) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 24) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -1325,21 +1279,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 4) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 24) ) ) ) - (set_local $5 + (set_local $4 (i32.load (i32.add (get_local $1) @@ -1349,21 +1303,21 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 8) ) (i32.or (i32.shr_u - (get_local $4) + (get_local $3) (i32.const 8) ) (i32.shl - (get_local $5) + (get_local $4) (i32.const 24) ) ) ) - (set_local $4 + (set_local $3 (i32.load (i32.add (get_local $1) @@ -1373,16 +1327,16 @@ ) (i32.store (i32.add - (get_local $3) + (get_local $0) (i32.const 12) ) (i32.or (i32.shr_u - (get_local $5) + (get_local $4) (i32.const 8) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 24) ) ) @@ -1393,9 +1347,9 @@ (i32.const 16) ) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $3) + (get_local $0) (i32.const 16) ) ) @@ -1422,449 +1376,449 @@ (block (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -1878,225 +1832,225 @@ (block (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -2110,113 +2064,113 @@ (block (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -2230,57 +2184,57 @@ (block (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) @@ -2293,38 +2247,359 @@ ) (i32.store8 (block (result i32) - (set_local $6 - (get_local $3) + (set_local $5 + (get_local $0) ) - (set_local $3 + (set_local $0 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) (i32.load8_u (block (result i32) - (set_local $6 + (set_local $5 (get_local $1) ) (set_local $1 (i32.add - (get_local $6) + (get_local $5) (i32.const 1) ) ) - (get_local $6) + (get_local $5) ) ) ) ) - (return - (get_local $0) + ) + (func $std:heap/move_memory (; 3 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (if + (i32.eq + (get_local $0) + (get_local $1) + ) + (return) + ) + (if + (i32.and + (if (result i32) + (i32.ne + (tee_local $3 + (i32.le_u + (i32.add + (get_local $1) + (get_local $2) + ) + (get_local $0) + ) + ) + (i32.const 0) + ) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) + ) + (i32.const 1) + ) + (block + (call $std:heap/copy_memory + (get_local $0) + (get_local $1) + (get_local $2) + ) + (return) + ) + ) + (if + (i32.lt_u + (get_local $0) + (get_local $1) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (block $break|0 + (loop $continue|0 + (if + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + (block + (block + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + (i32.store8 + (block (result i32) + (set_local $3 + (get_local $0) + ) + (set_local $0 + (i32.add + (get_local $3) + (i32.const 1) + ) + ) + (get_local $3) + ) + (i32.load8_u + (block (result i32) + (set_local $3 + (get_local $1) + ) + (set_local $1 + (i32.add + (get_local $3) + (i32.const 1) + ) + ) + (get_local $3) + ) + ) + ) + ) + (br $continue|0) + ) + ) + ) + ) + (block $break|1 + (loop $continue|1 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (block + (i64.store + (get_local $0) + (i64.load + (get_local $1) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 8) + ) + ) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 8) + ) + ) + ) + (br $continue|1) + ) + ) + ) + ) + ) + ) + (block $break|2 + (loop $continue|2 + (if + (get_local $2) + (block + (block + (i32.store8 + (block (result i32) + (set_local $3 + (get_local $0) + ) + (set_local $0 + (i32.add + (get_local $3) + (i32.const 1) + ) + ) + (get_local $3) + ) + (i32.load8_u + (block (result i32) + (set_local $3 + (get_local $1) + ) + (set_local $1 + (i32.add + (get_local $3) + (i32.const 1) + ) + ) + (get_local $3) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (br $continue|2) + ) + ) + ) + ) + ) + (block + (if + (i32.eq + (i32.rem_u + (get_local $1) + (i32.const 8) + ) + (i32.rem_u + (get_local $0) + (i32.const 8) + ) + ) + (block + (block $break|3 + (loop $continue|3 + (if + (i32.rem_u + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (block + (block + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + ) + (br $continue|3) + ) + ) + ) + ) + (block $break|4 + (loop $continue|4 + (if + (i32.ge_u + (get_local $2) + (i32.const 8) + ) + (block + (block + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 8) + ) + ) + (i64.store + (i32.add + (get_local $0) + (get_local $2) + ) + (i64.load + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + ) + (br $continue|4) + ) + ) + ) + ) + ) + ) + (block $break|5 + (loop $continue|5 + (if + (get_local $2) + (block + (i32.store8 + (i32.add + (get_local $0) + (tee_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) + ) + ) + (i32.load8_u + (i32.add + (get_local $1) + (get_local $2) + ) + ) + ) + (br $continue|5) + ) + ) + ) + ) + ) ) ) - (func $std:heap/Heap.compare (; 3 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std:heap/compare_memory (; 4 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (if (i32.eq (get_local $0) @@ -2393,19 +2668,19 @@ ) ) ) - (func $std:heap/Heap.dispose (; 4 ;) (type $iv) (param $0 i32) + (func $std:heap/free_memory (; 5 ;) (type $iv) (param $0 i32) ) - (func $start (; 5 ;) (type $v) + (func $start (; 6 ;) (type $v) (set_global $std:heap/HEAP_OFFSET (get_global $HEAP_BASE) ) (set_global $std/heap/ptr1 - (call $std:heap/Heap.allocate + (call $std:heap/allocate_memory (i32.const 42) ) ) (set_global $std/heap/ptr2 - (call $std:heap/Heap.allocate + (call $std:heap/allocate_memory (i32.const 42) ) ) @@ -2418,12 +2693,10 @@ ) (unreachable) ) - (drop - (call $std:heap/Heap.fill - (get_global $std/heap/ptr1) - (i32.const 18) - (i32.const 42) - ) + (call $std:heap/set_memory + (get_global $std/heap/ptr1) + (i32.const 18) + (i32.const 42) ) (block $break|0 (set_global $std/heap/i @@ -2461,12 +2734,10 @@ ) ) ) - (drop - (call $std:heap/Heap.copy - (get_global $std/heap/ptr2) - (get_global $std/heap/ptr1) - (i32.const 42) - ) + (call $std:heap/move_memory + (get_global $std/heap/ptr2) + (get_global $std/heap/ptr1) + (i32.const 42) ) (block $break|1 (set_global $std/heap/i @@ -2507,7 +2778,7 @@ (if (i32.eqz (i32.eq - (call $std:heap/Heap.compare + (call $std:heap/compare_memory (get_global $std/heap/ptr1) (get_global $std/heap/ptr2) (i32.const 42) @@ -2517,10 +2788,10 @@ ) (unreachable) ) - (call $std:heap/Heap.dispose + (call $std:heap/free_memory (get_global $std/heap/ptr1) ) - (call $std:heap/Heap.dispose + (call $std:heap/free_memory (get_global $std/heap/ptr2) ) ) @@ -2581,16 +2852,17 @@ GLOBAL: std:heap/ALIGN_SIZE GLOBAL: std:heap/ALIGN_MASK GLOBAL: std:heap/HEAP_OFFSET - CLASS_PROTOTYPE: std:heap/Heap - CLASS_PROTOTYPE: Heap - PROPERTY: std:heap/Heap.used - PROPERTY: std:heap/Heap.free - PROPERTY: std:heap/Heap.size - FUNCTION_PROTOTYPE: std:heap/Heap.allocate - FUNCTION_PROTOTYPE: std:heap/Heap.dispose - FUNCTION_PROTOTYPE: std:heap/Heap.copy - FUNCTION_PROTOTYPE: std:heap/Heap.fill - FUNCTION_PROTOTYPE: std:heap/Heap.compare + FUNCTION_PROTOTYPE: std:heap/allocate_memory + FUNCTION_PROTOTYPE: allocate_memory + FUNCTION_PROTOTYPE: std:heap/free_memory + FUNCTION_PROTOTYPE: free_memory + FUNCTION_PROTOTYPE: std:heap/copy_memory + FUNCTION_PROTOTYPE: std:heap/move_memory + FUNCTION_PROTOTYPE: move_memory + FUNCTION_PROTOTYPE: std:heap/set_memory + FUNCTION_PROTOTYPE: set_memory + FUNCTION_PROTOTYPE: std:heap/compare_memory + FUNCTION_PROTOTYPE: compare_memory CLASS_PROTOTYPE: std:map/Map CLASS_PROTOTYPE: Map CLASS_PROTOTYPE: std:regexp/RegExp @@ -2614,7 +2886,11 @@ CLASS_PROTOTYPE: std:array/CArray CLASS_PROTOTYPE: std:error/Error CLASS_PROTOTYPE: std:error/RangeError - CLASS_PROTOTYPE: std:heap/Heap + FUNCTION_PROTOTYPE: std:heap/allocate_memory + FUNCTION_PROTOTYPE: std:heap/free_memory + FUNCTION_PROTOTYPE: std:heap/move_memory + FUNCTION_PROTOTYPE: std:heap/set_memory + FUNCTION_PROTOTYPE: std:heap/compare_memory CLASS_PROTOTYPE: std:map/Map CLASS_PROTOTYPE: std:regexp/RegExp CLASS_PROTOTYPE: std:set/Set