diff --git a/std/assembly/array.ts b/std/assembly/array.ts index 59abb3c930..5e99da31e2 100644 --- a/std/assembly/array.ts +++ b/std/assembly/array.ts @@ -1,10 +1,10 @@ import { MAX_BLENGTH, HEADER_SIZE, - allocateUnsafe, - reallocateUnsafe, + reallocateZeroedUnsafe, LOAD, - STORE + STORE, + allocateZeroedUnsafe } from "./internal/arraybuffer"; import { @@ -44,7 +44,7 @@ export class Array { const MAX_LENGTH = MAX_BLENGTH >>> alignof(); if (length > MAX_LENGTH) throw new RangeError("Invalid array length"); var byteLength = length << alignof(); - var buffer = allocateUnsafe(byteLength); + var buffer = allocateZeroedUnsafe(byteLength); this.buffer_ = buffer; this.length_ = length; memory.fill( @@ -65,7 +65,7 @@ export class Array { if (length > capacity) { const MAX_LENGTH = MAX_BLENGTH >>> alignof(); if (length > MAX_LENGTH) throw new RangeError("Invalid array length"); - buffer = reallocateUnsafe(buffer, length << alignof()); + buffer = reallocateZeroedUnsafe(buffer, length << alignof()); this.buffer_ = buffer; } this.length_ = length; @@ -105,7 +105,7 @@ export class Array { if (index >= capacity) { const MAX_LENGTH = MAX_BLENGTH >>> alignof(); if (index >= MAX_LENGTH) throw new Error("Invalid array length"); - buffer = reallocateUnsafe(buffer, (index + 1) << alignof()); + buffer = reallocateZeroedUnsafe(buffer, (index + 1) << alignof()); this.buffer_ = buffer; this.length_ = index + 1; } @@ -180,7 +180,7 @@ export class Array { if (length >= capacity) { const MAX_LENGTH = MAX_BLENGTH >>> alignof(); if (length >= MAX_LENGTH) throw new Error("Invalid array length"); - buffer = reallocateUnsafe(buffer, newLength << alignof()); + buffer = reallocateZeroedUnsafe(buffer, newLength << alignof()); this.buffer_ = buffer; } this.length_ = newLength; @@ -325,7 +325,7 @@ export class Array { if (length >= capacity) { const MAX_LENGTH = MAX_BLENGTH >>> alignof(); if (length >= MAX_LENGTH) throw new Error("Invalid array length"); - buffer = reallocateUnsafe(buffer, newLength << alignof()); + buffer = reallocateZeroedUnsafe(buffer, newLength << alignof()); capacity = buffer.byteLength >>> alignof(); this.buffer_ = buffer; } diff --git a/std/assembly/arraybuffer.ts b/std/assembly/arraybuffer.ts index bef14bdbed..fc4bc7848f 100644 --- a/std/assembly/arraybuffer.ts +++ b/std/assembly/arraybuffer.ts @@ -1,7 +1,7 @@ import { HEADER_SIZE, MAX_BLENGTH, - allocateUnsafe + allocateZeroedUnsafe } from "./internal/arraybuffer"; import { @@ -45,7 +45,7 @@ export class ArrayBuffer { constructor(length: i32, unsafe: bool = false) { if (length > MAX_BLENGTH) throw new RangeError("Invalid array buffer length"); - var buffer = allocateUnsafe(length); + var buffer = allocateZeroedUnsafe(length); if (!unsafe) memory.fill(changetype(buffer) + HEADER_SIZE, 0, length); return buffer; } @@ -57,7 +57,7 @@ export class ArrayBuffer { if (end < 0) end = max(len + end, 0); else end = min(end, len); var newLen = max(end - begin, 0); - var buffer = allocateUnsafe(newLen); + var buffer = allocateZeroedUnsafe(newLen); memory.copy(changetype(buffer) + HEADER_SIZE, changetype(this) + HEADER_SIZE + begin, newLen); return buffer; } diff --git a/std/assembly/internal/arraybuffer.ts b/std/assembly/internal/arraybuffer.ts index faf8facd41..658c09728f 100644 --- a/std/assembly/internal/arraybuffer.ts +++ b/std/assembly/internal/arraybuffer.ts @@ -19,49 +19,73 @@ function computeSize(byteLength: i32): usize { } // Low-level utility - function __gc(ref: usize): void {} -export function allocateUnsafe(byteLength: i32): ArrayBuffer { +@inline function _resize(buffer: ArrayBuffer, newByteLength: i32): ArrayBuffer { + store(changetype(buffer), newByteLength, offsetof("byteLength")); + return buffer; +} + +@inline function _allocateUnsafe(byteLength: i32): ArrayBuffer { assert(byteLength <= MAX_BLENGTH); - var buffer: usize; - if (isManaged()) { - buffer = __gc_allocate(computeSize(byteLength), __gc); // tslint:disable-line - } else { - buffer = memory.allocate(computeSize(byteLength)); - } - store(buffer, byteLength, offsetof("byteLength")); + var buffer: usize = isManaged() + ? __gc_allocate(computeSize(byteLength), __gc) // tslint:disable-line + : memory.allocate(computeSize(byteLength)); + return _resize(changetype(buffer), byteLength); +} + +export function allocateZeroedUnsafe(byteLength: i32): ArrayBuffer { + var buffer = _allocateUnsafe(byteLength); + + // zero out the buffer + memory.fill(buffer.data, 0, byteLength); return changetype(buffer); } +export function allocateUnsafe(byteLength: i32): ArrayBuffer { + return _allocateUnsafe(byteLength); +} + +/** + * This inline grow method allocates a new ArrayBuffer, then frees the old one. + */ +@inline function _growUnsafe(buffer: ArrayBuffer, oldByteLength: i32, newByteLength: i32): ArrayBuffer { + assert(newByteLength > buffer.byteLength && newByteLength <= MAX_BLENGTH); + var newBuffer = _allocateUnsafe(newByteLength); + memory.copy(newBuffer.data, buffer.data, oldByteLength); + if (!isManaged()) { + memory.free(changetype(buffer)); + } + return newBuffer; +} + +/** + * This function perform + */ +@inline function _realocateUnsafe(buffer: ArrayBuffer, oldByteLength: i32, newByteLength: i32): ArrayBuffer { + // non-negative values should be unreachable() + assert(newByteLength >= 0); + // fastest path: buffer should be the same length + if (newByteLength === oldByteLength) return buffer; + // fast path: byteLength is less than or equal to currently allocated size (this is safe) + if (newByteLength <= (computeSize(oldByteLength) - HEADER_SIZE)) { + return _resize(buffer, newByteLength); + } + + // slow path: buffer needs new allocation (_growUnsafe frees the old buffer) + return _growUnsafe(buffer, oldByteLength, newByteLength); +} + export function reallocateUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuffer { + return _realocateUnsafe(buffer, buffer.byteLength, newByteLength); +} + +export function reallocateZeroedUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuffer { var oldByteLength = buffer.byteLength; - if (newByteLength > oldByteLength) { - assert(newByteLength <= MAX_BLENGTH); - if (newByteLength <= (computeSize(oldByteLength) - HEADER_SIZE)) { // fast path: zero out additional space - store(changetype(buffer), newByteLength, offsetof("byteLength")); - } else { // slow path: copy to new buffer - let newBuffer = allocateUnsafe(newByteLength); - memory.copy( - changetype(newBuffer) + HEADER_SIZE, - changetype(buffer) + HEADER_SIZE, - oldByteLength - ); - if (!isManaged()) { - memory.free(changetype(buffer)); - } - buffer = newBuffer; - } - memory.fill( - changetype(buffer) + HEADER_SIZE + oldByteLength, - 0, - (newByteLength - oldByteLength) - ); - } else if (newByteLength < oldByteLength) { // fast path: override size - // TBD: worth to copy and release if size is significantly less than before? - assert(newByteLength >= 0); - store(changetype(buffer), newByteLength, offsetof("byteLength")); - } + buffer = _realocateUnsafe(buffer, oldByteLength, newByteLength); + + // zero out the allocated values that weren't copied + memory.fill(buffer.data + oldByteLength, 0, newByteLength - oldByteLength); return buffer; } diff --git a/std/assembly/internal/typedarray.ts b/std/assembly/internal/typedarray.ts index 089fa3a32c..f98fa319a9 100644 --- a/std/assembly/internal/typedarray.ts +++ b/std/assembly/internal/typedarray.ts @@ -1,9 +1,9 @@ import { HEADER_SIZE as AB_HEADER_SIZE, MAX_BLENGTH as AB_MAX_BLENGTH, - allocateUnsafe, LOAD, - STORE + STORE, + allocateZeroedUnsafe } from "./arraybuffer"; import { @@ -22,7 +22,7 @@ export abstract class TypedArray { const MAX_LENGTH = AB_MAX_BLENGTH / sizeof(); if (length > MAX_LENGTH) throw new RangeError("Invalid typed array length"); var byteLength = length << alignof(); - var buffer = allocateUnsafe(byteLength); + var buffer = allocateZeroedUnsafe(byteLength); memory.fill(changetype(buffer) + AB_HEADER_SIZE, 0, byteLength); this.buffer = buffer; this.byteOffset = 0; diff --git a/tests/compiler/std/array-literal.optimized.wat b/tests/compiler/std/array-literal.optimized.wat index fa45c3a8e0..c5c52a3b9b 100644 --- a/tests/compiler/std/array-literal.optimized.wat +++ b/tests/compiler/std/array-literal.optimized.wat @@ -91,34 +91,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 1073741816 - i32.gt_u - if - i32.const 0 - i32.const 168 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - call $~lib/allocator/arena/__memory_allocate - local.tee $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 2 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) local.get $1 i32.eqz @@ -337,11 +310,43 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 1073741816 + i32.gt_u + if + i32.const 0 + i32.const 168 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + i32.const 1 + i32.const 32 + local.get $0 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $1 + local.get $0 + i32.store + local.get $1 + i32.const 8 + i32.add + local.get $0 + call $~lib/internal/memory/memset + local.get $1 + ) (func $~lib/array/Array#constructor (; 4 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) i32.const 3 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $1 i32.const 8 call $~lib/allocator/arena/__memory_allocate @@ -368,7 +373,7 @@ (local $0 i32) (local $1 i32) i32.const 12 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $1 i32.const 8 call $~lib/allocator/arena/__memory_allocate diff --git a/tests/compiler/std/array-literal.untouched.wat b/tests/compiler/std/array-literal.untouched.wat index ea58225d14..74a085ef22 100644 --- a/tests/compiler/std/array-literal.untouched.wat +++ b/tests/compiler/std/array-literal.untouched.wat @@ -194,41 +194,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 5 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 168 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - block $~lib/memory/memory.allocate|inlined.0 (result i32) - local.get $0 - call $~lib/internal/arraybuffer/computeSize - local.set $2 - local.get $2 - call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.0 - end - local.set $1 - local.get $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/memory/memory.allocate (; 6 ;) (type $ii) (param $0 i32) (result i32) - local.get $0 - call $~lib/allocator/arena/__memory_allocate - return - ) - (func $~lib/internal/memory/memset (; 7 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 5 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i64) @@ -482,6 +448,73 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 6 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $1 + local.get $1 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 168 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.0 (result i32) + local.get $1 + call $~lib/internal/arraybuffer/computeSize + local.set $2 + local.get $2 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.0 + end + local.set $2 + block $~lib/internal/arraybuffer/_resize|inlined.0 (result i32) + local.get $2 + local.set $3 + local.get $1 + local.set $4 + local.get $3 + local.get $4 + i32.store + local.get $3 + end + end + local.set $5 + block $memory.fill|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + local.get $5 + local.set $2 + local.get $2 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $2 + i32.const 0 + local.set $1 + local.get $0 + local.set $4 + local.get $2 + local.get $1 + local.get $4 + call $~lib/internal/memory/memset + end + local.get $5 + ) + (func $~lib/memory/memory.allocate (; 7 ;) (type $ii) (param $0 i32) (result i32) + local.get $0 + call $~lib/allocator/arena/__memory_allocate + return + ) (func $~lib/array/Array#constructor (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) @@ -504,7 +537,7 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 block (result i32) local.get $0 @@ -527,7 +560,7 @@ local.get $0 local.get $1 i32.store offset=4 - block $memory.fill|inlined.0 + block $memory.fill|inlined.1 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -589,7 +622,7 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 block (result i32) local.get $0 @@ -612,7 +645,7 @@ local.get $0 local.get $1 i32.store offset=4 - block $memory.fill|inlined.1 + block $memory.fill|inlined.2 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -684,7 +717,7 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 block (result i32) local.get $0 @@ -707,7 +740,7 @@ local.get $0 local.get $1 i32.store offset=4 - block $memory.fill|inlined.2 + block $memory.fill|inlined.3 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -779,7 +812,7 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 block (result i32) local.get $0 @@ -802,7 +835,7 @@ local.get $0 local.get $1 i32.store offset=4 - block $memory.fill|inlined.3 + block $memory.fill|inlined.4 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 09100d36d7..0322bdb452 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -460,34 +460,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 1073741816 - i32.gt_u - if - i32.const 0 - i32.const 40 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - call $~lib/allocator/arena/__memory_allocate - local.tee $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 4 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 3 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i64) local.get $2 @@ -722,6 +695,39 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 1073741816 + i32.gt_u + if + i32.const 0 + i32.const 40 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + i32.const 1 + i32.const 32 + local.get $0 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $1 + local.get $0 + i32.store + local.get $1 + i32.const 8 + i32.add + i32.const 0 + local.get $0 + call $~lib/internal/memory/memset + local.get $1 + ) (func $~lib/array/Array#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) @@ -741,7 +747,7 @@ i32.const 2 i32.shl local.tee $3 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $2 i32.const 8 call $~lib/allocator/arena/__memory_allocate @@ -779,7 +785,7 @@ unreachable end local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.tee $2 i32.const 8 i32.add @@ -2258,30 +2264,36 @@ end end ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateZeroedUnsafe (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) - local.get $1 + (local $4 i32) + (local $5 i32) local.get $0 i32.load + local.tee $4 + local.set $3 + local.get $1 local.tee $2 - i32.gt_s + i32.const 0 + i32.lt_s if - local.get $1 - i32.const 1073741816 - i32.gt_s - if - i32.const 0 - i32.const 40 - i32.const 40 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $1 + i32.const 0 + i32.const 40 + i32.const 67 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + local.get $2 + local.get $3 + i32.eq + br_if $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + local.get $2 i32.const 1 i32.const 32 - local.get $2 + local.get $3 i32.const 7 i32.add i32.clz @@ -2292,54 +2304,81 @@ i32.le_s if local.get $0 - local.get $1 - i32.store - else - local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe - local.tee $3 - i32.const 8 - i32.add - local.get $0 - i32.const 8 - i32.add local.get $2 - call $~lib/internal/memory/memmove - local.get $3 - local.set $0 + i32.store + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 end local.get $0 - i32.const 8 - i32.add - local.get $2 - i32.add - i32.const 0 - local.get $1 + local.set $5 + local.get $3 + local.set $0 local.get $2 - i32.sub - call $~lib/internal/memory/memset - else - local.get $1 + local.get $5 + i32.load + i32.gt_s + local.tee $3 + if (result i32) + local.get $2 + i32.const 1073741816 + i32.le_s + else + local.get $3 + end + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 53 + i32.const 2 + call $~lib/env/abort + unreachable + end local.get $2 - i32.lt_s + local.tee $3 + i32.const 1073741816 + i32.gt_u if - local.get $1 i32.const 0 - i32.lt_s - if - i32.const 0 - i32.const 40 - i32.const 62 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $0 - local.get $1 - i32.store + i32.const 40 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable end + i32.const 1 + i32.const 32 + local.get $3 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $2 + local.get $3 + i32.store + local.get $2 + i32.const 8 + i32.add + local.get $5 + i32.const 8 + i32.add + local.get $0 + call $~lib/internal/memory/memmove + local.get $2 + local.set $0 end local.get $0 + i32.const 8 + i32.add + local.get $4 + i32.add + i32.const 0 + local.get $1 + local.get $4 + i32.sub + call $~lib/internal/memory/memset + local.get $0 ) (func $~lib/array/Array#push (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) @@ -2376,7 +2415,7 @@ local.get $3 i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.tee $4 i32.store end @@ -2705,7 +2744,7 @@ local.get $4 i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.tee $2 i32.load i32.const 2 @@ -3055,7 +3094,7 @@ local.tee $4 i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.tee $3 i32.store local.get $0 diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index 644f3bff85..8d51a3e7ec 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -532,41 +532,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 40 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - block $~lib/memory/memory.allocate|inlined.0 (result i32) - local.get $0 - call $~lib/internal/arraybuffer/computeSize - local.set $2 - local.get $2 - call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.0 - end - local.set $1 - local.get $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/memory/memory.allocate (; 5 ;) (type $ii) (param $0 i32) (result i32) - local.get $0 - call $~lib/allocator/arena/__memory_allocate - return - ) - (func $~lib/internal/memory/memset (; 6 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 4 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i64) @@ -820,6 +786,73 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 5 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $1 + local.get $1 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.0 (result i32) + local.get $1 + call $~lib/internal/arraybuffer/computeSize + local.set $2 + local.get $2 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.0 + end + local.set $2 + block $~lib/internal/arraybuffer/_resize|inlined.0 (result i32) + local.get $2 + local.set $3 + local.get $1 + local.set $4 + local.get $3 + local.get $4 + i32.store + local.get $3 + end + end + local.set $5 + block $memory.fill|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + local.get $5 + local.set $2 + local.get $2 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $2 + i32.const 0 + local.set $1 + local.get $0 + local.set $4 + local.get $2 + local.get $1 + local.get $4 + call $~lib/internal/memory/memset + end + local.get $5 + ) + (func $~lib/memory/memory.allocate (; 6 ;) (type $ii) (param $0 i32) (result i32) + local.get $0 + call $~lib/allocator/arena/__memory_allocate + return + ) (func $~lib/array/Array#constructor (; 7 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) @@ -842,7 +875,7 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 block (result i32) local.get $0 @@ -865,7 +898,7 @@ local.get $0 local.get $1 i32.store offset=4 - block $memory.fill|inlined.0 + block $memory.fill|inlined.1 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -943,9 +976,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.1 + block $memory.fill|inlined.2 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -2902,110 +2935,186 @@ (func $~lib/allocator/arena/__memory_free (; 28 ;) (type $i_) (param $0 i32) nop ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 29 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateZeroedUnsafe (; 29 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (local $10 i32) + (local $11 i32) + (local $12 i32) local.get $0 i32.load local.set $2 - local.get $1 - local.get $2 - i32.gt_s - if + block $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $3 + local.get $2 + local.set $4 local.get $1 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_s + local.set $5 + local.get $5 + i32.const 0 + i32.ge_s i32.eqz if i32.const 0 i32.const 40 - i32.const 40 - i32.const 4 + i32.const 67 + i32.const 2 call $~lib/env/abort unreachable end - local.get $1 - local.get $2 + local.get $5 + local.get $4 + i32.eq + if + local.get $3 + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + end + local.get $5 + local.get $4 call $~lib/internal/arraybuffer/computeSize global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.sub i32.le_s if - local.get $0 - local.get $1 - i32.store - else - local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe - local.set $3 - block $memory.copy|inlined.0 + block $~lib/internal/arraybuffer/_resize|inlined.1 (result i32) local.get $3 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.set $4 - local.get $0 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.set $5 - local.get $2 local.set $6 - local.get $4 local.get $5 + local.set $7 local.get $6 - call $~lib/internal/memory/memmove - end - block $~lib/memory/memory.free|inlined.0 - local.get $0 - local.set $6 + local.get $7 + i32.store local.get $6 - call $~lib/allocator/arena/__memory_free - br $~lib/memory/memory.free|inlined.0 end - local.get $3 - local.set $0 + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 end - block $memory.fill|inlined.3 - local.get $0 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.get $2 - i32.add - local.set $3 - i32.const 0 - local.set $6 - local.get $1 - local.get $2 - i32.sub - local.set $5 + block $~lib/internal/arraybuffer/_growUnsafe|inlined.0 (result i32) local.get $3 - local.get $6 + local.set $7 + local.get $4 + local.set $6 local.get $5 - call $~lib/internal/memory/memset - end - else - local.get $1 - local.get $2 - i32.lt_s - if - local.get $1 - i32.const 0 - i32.ge_s + local.set $8 + local.get $8 + local.get $7 + i32.load + i32.gt_s + local.tee $9 + if (result i32) + local.get $8 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_s + else + local.get $9 + end i32.eqz if i32.const 0 i32.const 40 - i32.const 62 - i32.const 4 + i32.const 53 + i32.const 2 call $~lib/env/abort unreachable end + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.1 (result i32) + local.get $8 + local.set $9 + local.get $9 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.1 (result i32) + local.get $9 + call $~lib/internal/arraybuffer/computeSize + local.set $10 + local.get $10 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.1 + end + local.set $10 + block $~lib/internal/arraybuffer/_resize|inlined.2 (result i32) + local.get $10 + local.set $11 + local.get $9 + local.set $12 + local.get $11 + local.get $12 + i32.store + local.get $11 + end + end + local.set $10 + block $memory.copy|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.1 (result i32) + local.get $10 + local.set $9 + local.get $9 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $9 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.2 (result i32) + local.get $7 + local.set $12 + local.get $12 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $12 + local.get $6 + local.set $11 + local.get $9 + local.get $12 + local.get $11 + call $~lib/internal/memory/memmove + end + block $~lib/memory/memory.free|inlined.0 + local.get $7 + local.set $11 + local.get $11 + call $~lib/allocator/arena/__memory_free + br $~lib/memory/memory.free|inlined.0 + end + local.get $10 + end + end + local.set $0 + block $memory.fill|inlined.4 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.3 (result i32) local.get $0 - local.get $1 - i32.store + local.set $5 + local.get $5 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add end + local.get $2 + i32.add + local.set $5 + i32.const 0 + local.set $4 + local.get $1 + local.get $2 + i32.sub + local.set $3 + local.get $5 + local.get $4 + local.get $3 + call $~lib/internal/memory/memset end local.get $0 ) @@ -3052,7 +3161,7 @@ local.get $5 i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $3 local.get $0 local.get $3 @@ -3587,7 +3696,7 @@ local.get $5 i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $2 local.get $2 i32.load @@ -4114,7 +4223,7 @@ i32.add i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $3 local.get $0 local.get $3 @@ -4692,7 +4801,7 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 block (result i32) local.get $0 @@ -4715,7 +4824,7 @@ local.get $0 local.get $1 i32.store offset=4 - block $memory.fill|inlined.4 + block $memory.fill|inlined.5 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -5716,15 +5825,15 @@ i32.const 2 i32.shl local.set $4 - block $~lib/memory/memory.allocate|inlined.1 (result i32) + block $~lib/memory/memory.allocate|inlined.2 (result i32) local.get $4 local.set $5 local.get $5 call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.1 + br $~lib/memory/memory.allocate|inlined.2 end local.set $6 - block $memory.fill|inlined.5 + block $memory.fill|inlined.6 local.get $6 local.set $5 i32.const 0 @@ -6675,15 +6784,15 @@ i32.const 2 i32.shl local.set $4 - block $~lib/memory/memory.allocate|inlined.2 (result i32) + block $~lib/memory/memory.allocate|inlined.3 (result i32) local.get $4 local.set $5 local.get $5 call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.2 + br $~lib/memory/memory.allocate|inlined.3 end local.set $6 - block $memory.fill|inlined.6 + block $memory.fill|inlined.7 local.get $6 local.set $5 i32.const 0 @@ -7667,15 +7776,15 @@ i32.const 2 i32.shl local.set $4 - block $~lib/memory/memory.allocate|inlined.3 (result i32) + block $~lib/memory/memory.allocate|inlined.4 (result i32) local.get $4 local.set $5 local.get $5 call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.3 + br $~lib/memory/memory.allocate|inlined.4 end local.set $6 - block $memory.fill|inlined.7 + block $memory.fill|inlined.8 local.get $6 local.set $5 i32.const 0 @@ -8513,15 +8622,15 @@ i32.const 2 i32.shl local.set $4 - block $~lib/memory/memory.allocate|inlined.4 (result i32) + block $~lib/memory/memory.allocate|inlined.5 (result i32) local.get $4 local.set $5 local.get $5 call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.4 + br $~lib/memory/memory.allocate|inlined.5 end local.set $6 - block $memory.fill|inlined.8 + block $memory.fill|inlined.9 local.get $6 local.set $5 i32.const 0 @@ -9473,7 +9582,7 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 block (result i32) local.get $0 @@ -9496,7 +9605,7 @@ local.get $0 local.get $1 i32.store offset=4 - block $memory.fill|inlined.9 + block $memory.fill|inlined.10 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -9548,7 +9657,7 @@ i32.add i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $3 local.get $0 local.get $3 @@ -10048,7 +10157,7 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 block (result i32) local.get $0 @@ -10071,7 +10180,7 @@ local.get $0 local.get $1 i32.store offset=4 - block $memory.fill|inlined.10 + block $memory.fill|inlined.11 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -10136,7 +10245,7 @@ i32.add i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $3 local.get $0 local.get $3 @@ -11268,7 +11377,7 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 block (result i32) local.get $0 @@ -11291,7 +11400,7 @@ local.get $0 local.get $1 i32.store offset=4 - block $memory.fill|inlined.11 + block $memory.fill|inlined.12 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -11330,7 +11439,7 @@ call $~lib/env/abort unreachable end - block $~lib/memory/memory.allocate|inlined.5 (result i32) + block $~lib/memory/memory.allocate|inlined.6 (result i32) global.get $~lib/internal/string/HEADER_SIZE local.get $0 i32.const 1 @@ -11339,7 +11448,7 @@ local.set $1 local.get $1 call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.5 + br $~lib/memory/memory.allocate|inlined.6 end local.set $2 local.get $2 @@ -11558,7 +11667,7 @@ i32.add i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $3 local.get $0 local.get $3 @@ -14831,7 +14940,7 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 block (result i32) local.get $0 @@ -14854,7 +14963,7 @@ local.get $0 local.get $1 i32.store offset=4 - block $memory.fill|inlined.12 + block $memory.fill|inlined.13 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add diff --git a/tests/compiler/std/arraybuffer.optimized.wat b/tests/compiler/std/arraybuffer.optimized.wat index c8c82b8845..0e11b55f86 100644 --- a/tests/compiler/std/arraybuffer.optimized.wat +++ b/tests/compiler/std/arraybuffer.optimized.wat @@ -91,34 +91,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 1073741816 - i32.gt_u - if - i32.const 0 - i32.const 56 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - call $~lib/allocator/arena/__memory_allocate - local.tee $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 2 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) local.get $1 i32.eqz @@ -337,6 +310,38 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 1073741816 + i32.gt_u + if + i32.const 0 + i32.const 56 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + i32.const 1 + i32.const 32 + local.get $0 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $1 + local.get $0 + i32.store + local.get $1 + i32.const 8 + i32.add + local.get $0 + call $~lib/internal/memory/memset + local.get $1 + ) (func $~lib/internal/memory/memcpy (; 4 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) @@ -1492,7 +1497,7 @@ i32.gt_s select local.tee $3 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.tee $2 i32.const 8 i32.add @@ -1541,7 +1546,7 @@ unreachable end local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.tee $2 i32.const 8 i32.add @@ -1591,7 +1596,7 @@ i32.const 2 i32.shl local.tee $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.tee $2 i32.const 8 i32.add @@ -1717,7 +1722,7 @@ global.get $~lib/allocator/arena/startOffset global.set $~lib/allocator/arena/offset i32.const 8 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.tee $0 i32.const 8 i32.add diff --git a/tests/compiler/std/arraybuffer.untouched.wat b/tests/compiler/std/arraybuffer.untouched.wat index cbefd3bdb1..af2509bab5 100644 --- a/tests/compiler/std/arraybuffer.untouched.wat +++ b/tests/compiler/std/arraybuffer.untouched.wat @@ -125,36 +125,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 56 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - block $~lib/memory/memory.allocate|inlined.0 (result i32) - local.get $0 - call $~lib/internal/arraybuffer/computeSize - local.set $2 - local.get $2 - call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.0 - end - local.set $1 - local.get $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 4 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 3 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i64) @@ -408,6 +379,68 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $1 + local.get $1 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 56 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.0 (result i32) + local.get $1 + call $~lib/internal/arraybuffer/computeSize + local.set $2 + local.get $2 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.0 + end + local.set $2 + block $~lib/internal/arraybuffer/_resize|inlined.0 (result i32) + local.get $2 + local.set $3 + local.get $1 + local.set $4 + local.get $3 + local.get $4 + i32.store + local.get $3 + end + end + local.set $5 + block $memory.fill|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + local.get $5 + local.set $2 + local.get $2 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $2 + i32.const 0 + local.set $1 + local.get $0 + local.set $4 + local.get $2 + local.get $1 + local.get $4 + call $~lib/internal/memory/memset + end + local.get $5 + ) (func $~lib/arraybuffer/ArrayBuffer#constructor (; 5 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) @@ -425,7 +458,7 @@ unreachable end local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 local.get $2 i32.const 0 @@ -1949,7 +1982,7 @@ select local.set $6 local.get $6 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $7 block $memory.copy|inlined.0 local.get $7 @@ -2072,9 +2105,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.1 + block $memory.fill|inlined.2 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -2153,9 +2186,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.2 + block $memory.fill|inlined.3 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -2353,14 +2386,14 @@ call $~lib/env/abort unreachable end - block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.1 (result i32) global.get $std/arraybuffer/sliced local.set $0 local.get $0 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add end - block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.1 (result i32) + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.2 (result i32) global.get $std/arraybuffer/buffer local.set $0 local.get $0 diff --git a/tests/compiler/std/dataview.optimized.wat b/tests/compiler/std/dataview.optimized.wat index c30f1b7920..ae962ed2ae 100644 --- a/tests/compiler/std/dataview.optimized.wat +++ b/tests/compiler/std/dataview.optimized.wat @@ -92,34 +92,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 1073741816 - i32.gt_u - if - i32.const 0 - i32.const 72 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - call $~lib/allocator/arena/__memory_allocate - local.tee $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 2 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) local.get $1 i32.eqz @@ -338,6 +311,38 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 1073741816 + i32.gt_u + if + i32.const 0 + i32.const 72 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + i32.const 1 + i32.const 32 + local.get $0 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $1 + local.get $0 + i32.store + local.get $1 + i32.const 8 + i32.add + local.get $0 + call $~lib/internal/memory/memset + local.get $1 + ) (func $~lib/internal/typedarray/TypedArray#constructor (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $1 @@ -352,7 +357,7 @@ unreachable end local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.tee $2 i32.const 8 i32.add diff --git a/tests/compiler/std/dataview.untouched.wat b/tests/compiler/std/dataview.untouched.wat index 6dc7ace494..f48d5ea990 100644 --- a/tests/compiler/std/dataview.untouched.wat +++ b/tests/compiler/std/dataview.untouched.wat @@ -127,36 +127,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 72 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - block $~lib/memory/memory.allocate|inlined.0 (result i32) - local.get $0 - call $~lib/internal/arraybuffer/computeSize - local.set $2 - local.get $2 - call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.0 - end - local.set $1 - local.get $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 4 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 3 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i64) @@ -410,6 +381,68 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $1 + local.get $1 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 72 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.0 (result i32) + local.get $1 + call $~lib/internal/arraybuffer/computeSize + local.set $2 + local.get $2 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.0 + end + local.set $2 + block $~lib/internal/arraybuffer/_resize|inlined.0 (result i32) + local.get $2 + local.set $3 + local.get $1 + local.set $4 + local.get $3 + local.get $4 + i32.store + local.get $3 + end + end + local.set $5 + block $memory.fill|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + local.get $5 + local.set $2 + local.get $2 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $2 + i32.const 0 + local.set $1 + local.get $0 + local.set $4 + local.get $2 + local.get $1 + local.get $4 + call $~lib/internal/memory/memset + end + local.get $5 + ) (func $~lib/memory/memory.allocate (; 5 ;) (type $ii) (param $0 i32) (result i32) local.get $0 call $~lib/allocator/arena/__memory_allocate @@ -437,9 +470,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.0 + block $memory.fill|inlined.1 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add diff --git a/tests/compiler/std/gc-array.optimized.wat b/tests/compiler/std/gc-array.optimized.wat index b11a1bfbca..cc19c9e2c0 100644 --- a/tests/compiler/std/gc-array.optimized.wat +++ b/tests/compiler/std/gc-array.optimized.wat @@ -410,35 +410,7 @@ i32.const 16 i32.add ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 11 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 1073741816 - i32.gt_u - if - i32.const 0 - i32.const 120 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - i32.const 6 - call $~lib/collector/itcm/__gc_allocate - local.tee $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memcpy (; 12 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memcpy (; 11 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1335,7 +1307,7 @@ i32.store8 end ) - (func $~lib/internal/memory/memmove (; 13 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memmove (; 12 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $0 @@ -1533,7 +1505,7 @@ end end ) - (func $~lib/internal/memory/memset (; 14 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 13 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) local.get $1 i32.eqz @@ -1752,30 +1724,36 @@ end end ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateZeroedUnsafe (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) - local.get $1 + (local $4 i32) + (local $5 i32) local.get $0 i32.load + local.tee $4 + local.set $3 + local.get $1 local.tee $2 - i32.gt_s + i32.const 0 + i32.lt_s if - local.get $1 - i32.const 1073741816 - i32.gt_s - if - i32.const 0 - i32.const 120 - i32.const 40 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $1 + i32.const 0 + i32.const 120 + i32.const 67 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + local.get $2 + local.get $3 + i32.eq + br_if $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + local.get $2 i32.const 1 i32.const 32 - local.get $2 + local.get $3 i32.const 7 i32.add i32.clz @@ -1786,55 +1764,83 @@ i32.le_s if local.get $0 - local.get $1 - i32.store - else - local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe - local.tee $3 - i32.const 8 - i32.add - local.get $0 - i32.const 8 - i32.add local.get $2 - call $~lib/internal/memory/memmove - local.get $3 - local.set $0 + i32.store + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 end local.get $0 - i32.const 8 - i32.add - local.get $2 - i32.add - local.get $1 + local.set $5 + local.get $3 + local.set $0 local.get $2 - i32.sub - call $~lib/internal/memory/memset - else - local.get $1 + local.get $5 + i32.load + i32.gt_s + local.tee $3 + if (result i32) + local.get $2 + i32.const 1073741816 + i32.le_s + else + local.get $3 + end + i32.eqz + if + i32.const 0 + i32.const 120 + i32.const 53 + i32.const 2 + call $~lib/env/abort + unreachable + end local.get $2 - i32.lt_s + local.tee $3 + i32.const 1073741816 + i32.gt_u if - local.get $1 i32.const 0 - i32.lt_s - if - i32.const 0 - i32.const 120 - i32.const 62 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $0 - local.get $1 - i32.store + i32.const 120 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable end + i32.const 1 + i32.const 32 + local.get $3 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + i32.const 6 + call $~lib/collector/itcm/__gc_allocate + local.tee $2 + local.get $3 + i32.store + local.get $2 + i32.const 8 + i32.add + local.get $5 + i32.const 8 + i32.add + local.get $0 + call $~lib/internal/memory/memmove + local.get $2 + local.set $0 end local.get $0 + i32.const 8 + i32.add + local.get $4 + i32.add + local.get $1 + local.get $4 + i32.sub + call $~lib/internal/memory/memset + local.get $0 ) - (func $~lib/collector/itcm/__gc_link (; 16 ;) (type $ii_) (param $0 i32) (param $1 i32) + (func $~lib/collector/itcm/__gc_link (; 15 ;) (type $ii_) (param $0 i32) (param $1 i32) (local $2 i32) global.get $~lib/collector/itcm/white i32.eqz @@ -1864,7 +1870,7 @@ call $~lib/collector/itcm/ManagedObject#makeGray end ) - (func $~lib/array/Array#__set (; 17 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#__set (; 16 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $1 @@ -1895,7 +1901,7 @@ local.tee $4 i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.tee $3 i32.store local.get $0 @@ -1913,7 +1919,7 @@ local.get $2 call $~lib/collector/itcm/__gc_link ) - (func $std/gc-array/main (; 18 ;) (type $i) (result i32) + (func $std/gc-array/main (; 17 ;) (type $i) (result i32) global.get $~started i32.eqz if @@ -1923,7 +1929,7 @@ end i32.const 0 ) - (func $start (; 19 ;) (type $_) + (func $start (; 18 ;) (type $_) i32.const 184 global.set $~lib/allocator/arena/startOffset global.get $~lib/allocator/arena/startOffset @@ -1953,7 +1959,7 @@ call $~lib/array/Array#__set call $~lib/collector/itcm/__gc_collect ) - (func $null (; 20 ;) (type $_) + (func $null (; 19 ;) (type $_) nop ) ) diff --git a/tests/compiler/std/gc-array.untouched.wat b/tests/compiler/std/gc-array.untouched.wat index c13743f836..20bbc84d03 100644 --- a/tests/compiler/std/gc-array.untouched.wat +++ b/tests/compiler/std/gc-array.untouched.wat @@ -565,31 +565,7 @@ (func $~lib/internal/arraybuffer/__gc (; 21 ;) (type $i_) (param $0 i32) nop ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 22 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 120 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - local.get $0 - call $~lib/internal/arraybuffer/computeSize - i32.const 6 - call $~lib/collector/itcm/__gc_allocate - local.set $1 - local.get $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memcpy (; 23 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memcpy (; 22 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1790,7 +1766,7 @@ i32.store8 end ) - (func $~lib/internal/memory/memmove (; 24 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memmove (; 23 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) local.get $0 local.get $1 @@ -2017,7 +1993,7 @@ end end ) - (func $~lib/internal/memory/memset (; 25 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 24 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i64) @@ -2271,107 +2247,179 @@ end end ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 26 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateZeroedUnsafe (; 25 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (local $10 i32) + (local $11 i32) + (local $12 i32) local.get $0 i32.load local.set $2 - local.get $1 - local.get $2 - i32.gt_s - if + block $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $3 + local.get $2 + local.set $4 local.get $1 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_s + local.set $5 + local.get $5 + i32.const 0 + i32.ge_s i32.eqz if i32.const 0 i32.const 120 - i32.const 40 - i32.const 4 + i32.const 67 + i32.const 2 call $~lib/env/abort unreachable end - local.get $1 - local.get $2 + local.get $5 + local.get $4 + i32.eq + if + local.get $3 + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + end + local.get $5 + local.get $4 call $~lib/internal/arraybuffer/computeSize global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.sub i32.le_s if - local.get $0 - local.get $1 - i32.store - else - local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe - local.set $3 - block $memory.copy|inlined.0 + block $~lib/internal/arraybuffer/_resize|inlined.0 (result i32) local.get $3 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.set $4 - local.get $0 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.set $5 - local.get $2 local.set $6 - local.get $4 local.get $5 + local.set $7 + local.get $6 + local.get $7 + i32.store local.get $6 - call $~lib/internal/memory/memmove end - local.get $3 - local.set $0 + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 end - block $memory.fill|inlined.0 - local.get $0 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.get $2 - i32.add - local.set $3 - i32.const 0 - local.set $6 - local.get $1 - local.get $2 - i32.sub - local.set $5 + block $~lib/internal/arraybuffer/_growUnsafe|inlined.0 (result i32) local.get $3 - local.get $6 + local.set $7 + local.get $4 + local.set $6 local.get $5 - call $~lib/internal/memory/memset - end - else - local.get $1 - local.get $2 - i32.lt_s - if - local.get $1 - i32.const 0 - i32.ge_s + local.set $8 + local.get $8 + local.get $7 + i32.load + i32.gt_s + local.tee $9 + if (result i32) + local.get $8 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_s + else + local.get $9 + end i32.eqz if i32.const 0 i32.const 120 - i32.const 62 - i32.const 4 + i32.const 53 + i32.const 2 call $~lib/env/abort unreachable end + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.0 (result i32) + local.get $8 + local.set $9 + local.get $9 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 120 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $9 + call $~lib/internal/arraybuffer/computeSize + i32.const 6 + call $~lib/collector/itcm/__gc_allocate + local.set $10 + block $~lib/internal/arraybuffer/_resize|inlined.1 (result i32) + local.get $10 + local.set $11 + local.get $9 + local.set $12 + local.get $11 + local.get $12 + i32.store + local.get $11 + end + end + local.set $10 + block $memory.copy|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + local.get $10 + local.set $9 + local.get $9 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $9 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.1 (result i32) + local.get $7 + local.set $12 + local.get $12 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $12 + local.get $6 + local.set $11 + local.get $9 + local.get $12 + local.get $11 + call $~lib/internal/memory/memmove + end + local.get $10 + end + end + local.set $0 + block $memory.fill|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.2 (result i32) local.get $0 - local.get $1 - i32.store + local.set $5 + local.get $5 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add end + local.get $2 + i32.add + local.set $5 + i32.const 0 + local.set $4 + local.get $1 + local.get $2 + i32.sub + local.set $3 + local.get $5 + local.get $4 + local.get $3 + call $~lib/internal/memory/memset end local.get $0 ) - (func $~lib/collector/itcm/__gc_link (; 27 ;) (type $ii_) (param $0 i32) (param $1 i32) + (func $~lib/collector/itcm/__gc_link (; 26 ;) (type $ii_) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) block $~lib/collector/itcm/refToObj|inlined.1 (result i32) @@ -2407,7 +2455,7 @@ call $~lib/collector/itcm/ManagedObject#makeGray end ) - (func $~lib/array/Array#__set (; 28 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#__set (; 27 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -2443,7 +2491,7 @@ i32.add i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $3 local.get $0 local.get $3 @@ -2477,7 +2525,7 @@ local.get $2 call $~lib/collector/itcm/__gc_link ) - (func $std/gc-array/main (; 29 ;) (type $i) (result i32) + (func $std/gc-array/main (; 28 ;) (type $i) (result i32) global.get $~started i32.eqz if @@ -2487,7 +2535,7 @@ end i32.const 0 ) - (func $start (; 30 ;) (type $_) + (func $start (; 29 ;) (type $_) (local $0 i32) (local $1 i32) (local $2 i32) @@ -2538,9 +2586,9 @@ call $~lib/array/Array#__set call $~lib/gc/gc.collect ) - (func $null (; 31 ;) (type $_) + (func $null (; 30 ;) (type $_) ) - (func $~iterateRoots (; 32 ;) (type $i_) (param $0 i32) + (func $~iterateRoots (; 31 ;) (type $i_) (param $0 i32) global.get $std/gc-array/arr local.get $0 call_indirect (type $i_) diff --git a/tests/compiler/std/map.optimized.wat b/tests/compiler/std/map.optimized.wat index 5b298b8748..2361307219 100644 --- a/tests/compiler/std/map.optimized.wat +++ b/tests/compiler/std/map.optimized.wat @@ -94,34 +94,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 1073741816 - i32.gt_u - if - i32.const 0 - i32.const 56 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - call $~lib/allocator/arena/__memory_allocate - local.tee $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 2 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) local.get $1 i32.eqz @@ -340,6 +313,38 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 1073741816 + i32.gt_u + if + i32.const 0 + i32.const 56 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + i32.const 1 + i32.const 32 + local.get $0 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $1 + local.get $0 + i32.store + local.get $1 + i32.const 8 + i32.add + local.get $0 + call $~lib/internal/memory/memset + local.get $1 + ) (func $~lib/arraybuffer/ArrayBuffer#constructor (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $0 @@ -354,7 +359,7 @@ unreachable end local.get $0 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $2 local.get $1 i32.eqz diff --git a/tests/compiler/std/map.untouched.wat b/tests/compiler/std/map.untouched.wat index 343bddaa3d..5c75944791 100644 --- a/tests/compiler/std/map.untouched.wat +++ b/tests/compiler/std/map.untouched.wat @@ -139,36 +139,7 @@ i32.sub i32.shl ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 56 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - block $~lib/memory/memory.allocate|inlined.0 (result i32) - local.get $0 - call $~lib/internal/arraybuffer/computeSize - local.set $2 - local.get $2 - call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.0 - end - local.set $1 - local.get $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 5 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 4 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i64) @@ -422,6 +393,68 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 5 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $1 + local.get $1 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 56 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.0 (result i32) + local.get $1 + call $~lib/internal/arraybuffer/computeSize + local.set $2 + local.get $2 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.0 + end + local.set $2 + block $~lib/internal/arraybuffer/_resize|inlined.0 (result i32) + local.get $2 + local.set $3 + local.get $1 + local.set $4 + local.get $3 + local.get $4 + i32.store + local.get $3 + end + end + local.set $5 + block $memory.fill|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + local.get $5 + local.set $2 + local.get $2 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $2 + i32.const 0 + local.set $1 + local.get $0 + local.set $4 + local.get $2 + local.get $1 + local.get $4 + call $~lib/internal/memory/memset + end + local.get $5 + ) (func $~lib/arraybuffer/ArrayBuffer#constructor (; 6 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) @@ -439,7 +472,7 @@ unreachable end local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 local.get $2 i32.const 0 diff --git a/tests/compiler/std/set.optimized.wat b/tests/compiler/std/set.optimized.wat index d69e5529f9..c7ecc64b92 100644 --- a/tests/compiler/std/set.optimized.wat +++ b/tests/compiler/std/set.optimized.wat @@ -95,34 +95,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 1073741816 - i32.gt_u - if - i32.const 0 - i32.const 56 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - call $~lib/allocator/arena/__memory_allocate - local.tee $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 2 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) local.get $1 i32.eqz @@ -341,6 +314,38 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 1073741816 + i32.gt_u + if + i32.const 0 + i32.const 56 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + i32.const 1 + i32.const 32 + local.get $0 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $1 + local.get $0 + i32.store + local.get $1 + i32.const 8 + i32.add + local.get $0 + call $~lib/internal/memory/memset + local.get $1 + ) (func $~lib/arraybuffer/ArrayBuffer#constructor (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $0 @@ -355,7 +360,7 @@ unreachable end local.get $0 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $2 local.get $1 i32.eqz diff --git a/tests/compiler/std/set.untouched.wat b/tests/compiler/std/set.untouched.wat index 99180a8515..13a2217aa5 100644 --- a/tests/compiler/std/set.untouched.wat +++ b/tests/compiler/std/set.untouched.wat @@ -141,36 +141,7 @@ i32.sub i32.shl ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 56 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - block $~lib/memory/memory.allocate|inlined.0 (result i32) - local.get $0 - call $~lib/internal/arraybuffer/computeSize - local.set $2 - local.get $2 - call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.0 - end - local.set $1 - local.get $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 5 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 4 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i64) @@ -424,6 +395,68 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 5 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $1 + local.get $1 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 56 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.0 (result i32) + local.get $1 + call $~lib/internal/arraybuffer/computeSize + local.set $2 + local.get $2 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.0 + end + local.set $2 + block $~lib/internal/arraybuffer/_resize|inlined.0 (result i32) + local.get $2 + local.set $3 + local.get $1 + local.set $4 + local.get $3 + local.get $4 + i32.store + local.get $3 + end + end + local.set $5 + block $memory.fill|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + local.get $5 + local.set $2 + local.get $2 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $2 + i32.const 0 + local.set $1 + local.get $0 + local.set $4 + local.get $2 + local.get $1 + local.get $4 + call $~lib/internal/memory/memset + end + local.get $5 + ) (func $~lib/arraybuffer/ArrayBuffer#constructor (; 6 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) @@ -441,7 +474,7 @@ unreachable end local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 local.get $2 i32.const 0 diff --git a/tests/compiler/std/static-array.optimized.wat b/tests/compiler/std/static-array.optimized.wat index 867cc68373..98c4009c53 100644 --- a/tests/compiler/std/static-array.optimized.wat +++ b/tests/compiler/std/static-array.optimized.wat @@ -90,34 +90,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 1073741816 - i32.gt_u - if - i32.const 0 - i32.const 216 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - call $~lib/allocator/arena/__memory_allocate - local.tee $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memcpy (; 3 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memcpy (; 2 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1014,7 +987,7 @@ i32.store8 end ) - (func $~lib/internal/memory/memmove (; 4 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memmove (; 3 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $0 @@ -1212,7 +1185,7 @@ end end ) - (func $~lib/internal/memory/memset (; 5 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) local.get $1 i32.eqz @@ -1431,30 +1404,36 @@ end end ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateZeroedUnsafe (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) - local.get $1 + (local $4 i32) + (local $5 i32) local.get $0 i32.load + local.tee $4 + local.set $3 + local.get $1 local.tee $2 - i32.gt_s + i32.const 0 + i32.lt_s if - local.get $1 - i32.const 1073741816 - i32.gt_s - if - i32.const 0 - i32.const 216 - i32.const 40 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $1 + i32.const 0 + i32.const 216 + i32.const 67 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + local.get $2 + local.get $3 + i32.eq + br_if $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + local.get $2 i32.const 1 i32.const 32 - local.get $2 + local.get $3 i32.const 7 i32.add i32.clz @@ -1465,55 +1444,82 @@ i32.le_s if local.get $0 - local.get $1 - i32.store - else - local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe - local.tee $3 - i32.const 8 - i32.add - local.get $0 - i32.const 8 - i32.add local.get $2 - call $~lib/internal/memory/memmove - local.get $3 - local.set $0 + i32.store + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 end local.get $0 - i32.const 8 - i32.add - local.get $2 - i32.add - local.get $1 + local.set $5 + local.get $3 + local.set $0 local.get $2 - i32.sub - call $~lib/internal/memory/memset - else - local.get $1 + local.get $5 + i32.load + i32.gt_s + local.tee $3 + if (result i32) + local.get $2 + i32.const 1073741816 + i32.le_s + else + local.get $3 + end + i32.eqz + if + i32.const 0 + i32.const 216 + i32.const 53 + i32.const 2 + call $~lib/env/abort + unreachable + end local.get $2 - i32.lt_s + local.tee $3 + i32.const 1073741816 + i32.gt_u if - local.get $1 i32.const 0 - i32.lt_s - if - i32.const 0 - i32.const 216 - i32.const 62 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $0 - local.get $1 - i32.store + i32.const 216 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable end + i32.const 1 + i32.const 32 + local.get $3 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $2 + local.get $3 + i32.store + local.get $2 + i32.const 8 + i32.add + local.get $5 + i32.const 8 + i32.add + local.get $0 + call $~lib/internal/memory/memmove + local.get $2 + local.set $0 end local.get $0 + i32.const 8 + i32.add + local.get $4 + i32.add + local.get $1 + local.get $4 + i32.sub + call $~lib/internal/memory/memset + local.get $0 ) - (func $~lib/array/Array#__set (; 7 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 6 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 0 i32.const 24 @@ -1527,7 +1533,7 @@ i32.const 24 local.get $0 i32.const 4 - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.tee $0 i32.store i32.const 28 @@ -1538,7 +1544,7 @@ i32.const 2 i32.store offset=8 ) - (func $~lib/array/Array#__set (; 8 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 7 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 0 i32.const 64 @@ -1552,7 +1558,7 @@ i32.const 64 local.get $0 i32.const 8 - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.tee $0 i32.store i32.const 68 @@ -1563,7 +1569,7 @@ i64.const 4 i64.store offset=8 ) - (func $~lib/array/Array#__set (; 9 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 8 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 0 i32.const 88 @@ -1577,7 +1583,7 @@ i32.const 88 local.get $0 i32.const 4 - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.tee $0 i32.store i32.const 92 @@ -1588,7 +1594,7 @@ f32.const 2.5 f32.store offset=8 ) - (func $~lib/array/Array#__set (; 10 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 9 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 0 i32.const 128 @@ -1602,7 +1608,7 @@ i32.const 128 local.get $0 i32.const 8 - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.tee $0 i32.store i32.const 132 @@ -1613,7 +1619,7 @@ f64.const 2.25 f64.store offset=8 ) - (func $start (; 11 ;) (type $_) + (func $start (; 10 ;) (type $_) (local $0 i32) i32.const 280 global.set $~lib/allocator/arena/startOffset @@ -1968,7 +1974,7 @@ unreachable end ) - (func $null (; 12 ;) (type $_) + (func $null (; 11 ;) (type $_) nop ) ) diff --git a/tests/compiler/std/static-array.untouched.wat b/tests/compiler/std/static-array.untouched.wat index e708488cbd..5d12988d15 100644 --- a/tests/compiler/std/static-array.untouched.wat +++ b/tests/compiler/std/static-array.untouched.wat @@ -166,36 +166,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 216 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - block $~lib/memory/memory.allocate|inlined.0 (result i32) - local.get $0 - call $~lib/internal/arraybuffer/computeSize - local.set $2 - local.get $2 - call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.0 - end - local.set $1 - local.get $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memcpy (; 5 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memcpy (; 4 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1396,7 +1367,7 @@ i32.store8 end ) - (func $~lib/internal/memory/memmove (; 6 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memmove (; 5 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) local.get $0 local.get $1 @@ -1623,10 +1594,10 @@ end end ) - (func $~lib/allocator/arena/__memory_free (; 7 ;) (type $i_) (param $0 i32) + (func $~lib/allocator/arena/__memory_free (; 6 ;) (type $i_) (param $0 i32) nop ) - (func $~lib/internal/memory/memset (; 8 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 7 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i64) @@ -1880,114 +1851,190 @@ end end ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateZeroedUnsafe (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (local $10 i32) + (local $11 i32) + (local $12 i32) local.get $0 i32.load local.set $2 - local.get $1 - local.get $2 - i32.gt_s - if + block $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $3 + local.get $2 + local.set $4 local.get $1 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_s + local.set $5 + local.get $5 + i32.const 0 + i32.ge_s i32.eqz if i32.const 0 i32.const 216 - i32.const 40 - i32.const 4 + i32.const 67 + i32.const 2 call $~lib/env/abort unreachable end - local.get $1 - local.get $2 + local.get $5 + local.get $4 + i32.eq + if + local.get $3 + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + end + local.get $5 + local.get $4 call $~lib/internal/arraybuffer/computeSize global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.sub i32.le_s if - local.get $0 - local.get $1 - i32.store - else - local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe - local.set $3 - block $memory.copy|inlined.0 + block $~lib/internal/arraybuffer/_resize|inlined.0 (result i32) local.get $3 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.set $4 - local.get $0 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.set $5 - local.get $2 local.set $6 - local.get $4 local.get $5 + local.set $7 local.get $6 - call $~lib/internal/memory/memmove - end - block $~lib/memory/memory.free|inlined.0 - local.get $0 - local.set $6 + local.get $7 + i32.store local.get $6 - call $~lib/allocator/arena/__memory_free - br $~lib/memory/memory.free|inlined.0 end - local.get $3 - local.set $0 + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 end - block $memory.fill|inlined.0 - local.get $0 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.get $2 - i32.add - local.set $3 - i32.const 0 - local.set $6 - local.get $1 - local.get $2 - i32.sub - local.set $5 + block $~lib/internal/arraybuffer/_growUnsafe|inlined.0 (result i32) local.get $3 - local.get $6 + local.set $7 + local.get $4 + local.set $6 local.get $5 - call $~lib/internal/memory/memset - end - else - local.get $1 - local.get $2 - i32.lt_s - if - local.get $1 - i32.const 0 - i32.ge_s + local.set $8 + local.get $8 + local.get $7 + i32.load + i32.gt_s + local.tee $9 + if (result i32) + local.get $8 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_s + else + local.get $9 + end i32.eqz if i32.const 0 i32.const 216 - i32.const 62 - i32.const 4 + i32.const 53 + i32.const 2 call $~lib/env/abort unreachable end + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.0 (result i32) + local.get $8 + local.set $9 + local.get $9 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 216 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.0 (result i32) + local.get $9 + call $~lib/internal/arraybuffer/computeSize + local.set $10 + local.get $10 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.0 + end + local.set $10 + block $~lib/internal/arraybuffer/_resize|inlined.1 (result i32) + local.get $10 + local.set $11 + local.get $9 + local.set $12 + local.get $11 + local.get $12 + i32.store + local.get $11 + end + end + local.set $10 + block $memory.copy|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + local.get $10 + local.set $9 + local.get $9 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $9 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.1 (result i32) + local.get $7 + local.set $12 + local.get $12 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $12 + local.get $6 + local.set $11 + local.get $9 + local.get $12 + local.get $11 + call $~lib/internal/memory/memmove + end + block $~lib/memory/memory.free|inlined.0 + local.get $7 + local.set $11 + local.get $11 + call $~lib/allocator/arena/__memory_free + br $~lib/memory/memory.free|inlined.0 + end + local.get $10 + end + end + local.set $0 + block $memory.fill|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.2 (result i32) local.get $0 - local.get $1 - i32.store + local.set $5 + local.get $5 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add end + local.get $2 + i32.add + local.set $5 + i32.const 0 + local.set $4 + local.get $1 + local.get $2 + i32.sub + local.set $3 + local.get $5 + local.get $4 + local.get $3 + call $~lib/internal/memory/memset end local.get $0 ) - (func $~lib/array/Array#__set (; 10 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#__set (; 9 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -2023,7 +2070,7 @@ i32.add i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $3 local.get $0 local.get $3 @@ -2054,7 +2101,7 @@ i32.store offset=8 end ) - (func $~lib/array/Array#__get (; 11 ;) (type $iiI) (param $0 i32) (param $1 i32) (result i64) + (func $~lib/array/Array#__get (; 10 ;) (type $iiI) (param $0 i32) (param $1 i32) (result i64) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2087,7 +2134,7 @@ unreachable end ) - (func $~lib/array/Array#__set (; 12 ;) (type $iiI_) (param $0 i32) (param $1 i32) (param $2 i64) + (func $~lib/array/Array#__set (; 11 ;) (type $iiI_) (param $0 i32) (param $1 i32) (param $2 i64) (local $3 i32) (local $4 i32) (local $5 i32) @@ -2123,7 +2170,7 @@ i32.add i32.const 3 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $3 local.get $0 local.get $3 @@ -2154,7 +2201,7 @@ i64.store offset=8 end ) - (func $~lib/array/Array#__get (; 13 ;) (type $iif) (param $0 i32) (param $1 i32) (result f32) + (func $~lib/array/Array#__get (; 12 ;) (type $iif) (param $0 i32) (param $1 i32) (result f32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2187,7 +2234,7 @@ unreachable end ) - (func $~lib/array/Array#__set (; 14 ;) (type $iif_) (param $0 i32) (param $1 i32) (param $2 f32) + (func $~lib/array/Array#__set (; 13 ;) (type $iif_) (param $0 i32) (param $1 i32) (param $2 f32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -2223,7 +2270,7 @@ i32.add i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $3 local.get $0 local.get $3 @@ -2254,7 +2301,7 @@ f32.store offset=8 end ) - (func $~lib/array/Array#__get (; 15 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) + (func $~lib/array/Array#__get (; 14 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2287,7 +2334,7 @@ unreachable end ) - (func $~lib/array/Array#__set (; 16 ;) (type $iiF_) (param $0 i32) (param $1 i32) (param $2 f64) + (func $~lib/array/Array#__set (; 15 ;) (type $iiF_) (param $0 i32) (param $1 i32) (param $2 f64) (local $3 i32) (local $4 i32) (local $5 i32) @@ -2323,7 +2370,7 @@ i32.add i32.const 3 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $3 local.get $0 local.get $3 @@ -2354,7 +2401,7 @@ f64.store offset=8 end ) - (func $start (; 17 ;) (type $_) + (func $start (; 16 ;) (type $_) (local $0 i32) global.get $HEAP_BASE global.get $~lib/internal/allocator/AL_MASK @@ -2619,6 +2666,6 @@ unreachable end ) - (func $null (; 18 ;) (type $_) + (func $null (; 17 ;) (type $_) ) ) diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index 34b0940446..1cd2d1072c 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -3120,34 +3120,7 @@ local.get $2 call $~lib/string/String#slice ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 35 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 1073741816 - i32.gt_u - if - i32.const 0 - i32.const 1128 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - call $~lib/allocator/arena/__memory_allocate - local.tee $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 36 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 35 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) local.get $1 i32.eqz @@ -3366,6 +3339,38 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 36 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 1073741816 + i32.gt_u + if + i32.const 0 + i32.const 1128 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + i32.const 1 + i32.const 32 + local.get $0 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $1 + local.get $0 + i32.store + local.get $1 + i32.const 8 + i32.add + local.get $0 + call $~lib/internal/memory/memset + local.get $1 + ) (func $~lib/array/Array#constructor (; 37 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) @@ -3385,7 +3390,7 @@ i32.const 2 i32.shl local.tee $3 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $2 i32.const 8 call $~lib/allocator/arena/__memory_allocate @@ -3408,30 +3413,36 @@ call $~lib/internal/memory/memset local.get $1 ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 38 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateZeroedUnsafe (; 38 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) - local.get $1 + (local $4 i32) + (local $5 i32) local.get $0 i32.load + local.tee $4 + local.set $3 + local.get $1 local.tee $2 - i32.gt_s + i32.const 0 + i32.lt_s if - local.get $1 - i32.const 1073741816 - i32.gt_s - if - i32.const 0 - i32.const 1128 - i32.const 40 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $1 + i32.const 0 + i32.const 1128 + i32.const 67 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + local.get $2 + local.get $3 + i32.eq + br_if $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + local.get $2 i32.const 1 i32.const 32 - local.get $2 + local.get $3 i32.const 7 i32.add i32.clz @@ -3442,53 +3453,80 @@ i32.le_s if local.get $0 - local.get $1 - i32.store - else - local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe - local.tee $3 - i32.const 8 - i32.add - local.get $0 - i32.const 8 - i32.add local.get $2 - call $~lib/internal/memory/memmove - local.get $3 - local.set $0 + i32.store + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 end local.get $0 - i32.const 8 - i32.add - local.get $2 - i32.add - local.get $1 + local.set $5 + local.get $3 + local.set $0 local.get $2 - i32.sub - call $~lib/internal/memory/memset - else - local.get $1 + local.get $5 + i32.load + i32.gt_s + local.tee $3 + if (result i32) + local.get $2 + i32.const 1073741816 + i32.le_s + else + local.get $3 + end + i32.eqz + if + i32.const 0 + i32.const 1128 + i32.const 53 + i32.const 2 + call $~lib/env/abort + unreachable + end local.get $2 - i32.lt_s + local.tee $3 + i32.const 1073741816 + i32.gt_u if - local.get $1 i32.const 0 - i32.lt_s - if - i32.const 0 - i32.const 1128 - i32.const 62 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $0 - local.get $1 - i32.store + i32.const 1128 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable end + i32.const 1 + i32.const 32 + local.get $3 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $2 + local.get $3 + i32.store + local.get $2 + i32.const 8 + i32.add + local.get $5 + i32.const 8 + i32.add + local.get $0 + call $~lib/internal/memory/memmove + local.get $2 + local.set $0 end local.get $0 + i32.const 8 + i32.add + local.get $4 + i32.add + local.get $1 + local.get $4 + i32.sub + call $~lib/internal/memory/memset + local.get $0 ) (func $~lib/array/Array#push (; 39 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) @@ -3525,7 +3563,7 @@ local.get $3 i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.tee $4 i32.store end diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index a1471e01be..94cefbcaa0 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -3916,41 +3916,7 @@ i32.sub i32.shl ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 37 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 1128 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - block $~lib/memory/memory.allocate|inlined.1 (result i32) - local.get $0 - call $~lib/internal/arraybuffer/computeSize - local.set $2 - local.get $2 - call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.1 - end - local.set $1 - local.get $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/memory/memory.allocate (; 38 ;) (type $ii) (param $0 i32) (result i32) - local.get $0 - call $~lib/allocator/arena/__memory_allocate - return - ) - (func $~lib/internal/memory/memset (; 39 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 37 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i64) @@ -4204,6 +4170,73 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 38 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $1 + local.get $1 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 1128 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.1 (result i32) + local.get $1 + call $~lib/internal/arraybuffer/computeSize + local.set $2 + local.get $2 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.1 + end + local.set $2 + block $~lib/internal/arraybuffer/_resize|inlined.0 (result i32) + local.get $2 + local.set $3 + local.get $1 + local.set $4 + local.get $3 + local.get $4 + i32.store + local.get $3 + end + end + local.set $5 + block $memory.fill|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + local.get $5 + local.set $2 + local.get $2 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $2 + i32.const 0 + local.set $1 + local.get $0 + local.set $4 + local.get $2 + local.get $1 + local.get $4 + call $~lib/internal/memory/memset + end + local.get $5 + ) + (func $~lib/memory/memory.allocate (; 39 ;) (type $ii) (param $0 i32) (result i32) + local.get $0 + call $~lib/allocator/arena/__memory_allocate + return + ) (func $~lib/array/Array#constructor (; 40 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) @@ -4226,7 +4259,7 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 block (result i32) local.get $0 @@ -4249,7 +4282,7 @@ local.get $0 local.get $1 i32.store offset=4 - block $memory.fill|inlined.0 + block $memory.fill|inlined.1 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -4312,110 +4345,186 @@ (func $~lib/allocator/arena/__memory_free (; 43 ;) (type $i_) (param $0 i32) nop ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 44 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateZeroedUnsafe (; 44 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (local $10 i32) + (local $11 i32) + (local $12 i32) local.get $0 i32.load local.set $2 - local.get $1 - local.get $2 - i32.gt_s - if + block $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $3 + local.get $2 + local.set $4 local.get $1 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_s + local.set $5 + local.get $5 + i32.const 0 + i32.ge_s i32.eqz if i32.const 0 i32.const 1128 - i32.const 40 - i32.const 4 + i32.const 67 + i32.const 2 call $~lib/env/abort unreachable end - local.get $1 - local.get $2 + local.get $5 + local.get $4 + i32.eq + if + local.get $3 + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 + end + local.get $5 + local.get $4 call $~lib/internal/arraybuffer/computeSize global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.sub i32.le_s if - local.get $0 - local.get $1 - i32.store - else - local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe - local.set $3 - block $memory.copy|inlined.2 + block $~lib/internal/arraybuffer/_resize|inlined.1 (result i32) local.get $3 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.set $4 - local.get $0 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.set $5 - local.get $2 local.set $6 - local.get $4 local.get $5 + local.set $7 local.get $6 - call $~lib/internal/memory/memmove - end - block $~lib/memory/memory.free|inlined.0 - local.get $0 - local.set $6 + local.get $7 + i32.store local.get $6 - call $~lib/allocator/arena/__memory_free - br $~lib/memory/memory.free|inlined.0 end - local.get $3 - local.set $0 + br $~lib/internal/arraybuffer/_realocateUnsafe|inlined.0 end - block $memory.fill|inlined.1 - local.get $0 - global.get $~lib/internal/arraybuffer/HEADER_SIZE - i32.add - local.get $2 - i32.add - local.set $3 - i32.const 0 - local.set $6 - local.get $1 - local.get $2 - i32.sub - local.set $5 + block $~lib/internal/arraybuffer/_growUnsafe|inlined.0 (result i32) local.get $3 - local.get $6 + local.set $7 + local.get $4 + local.set $6 local.get $5 - call $~lib/internal/memory/memset - end - else - local.get $1 - local.get $2 - i32.lt_s - if - local.get $1 - i32.const 0 - i32.ge_s + local.set $8 + local.get $8 + local.get $7 + i32.load + i32.gt_s + local.tee $9 + if (result i32) + local.get $8 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_s + else + local.get $9 + end i32.eqz if i32.const 0 i32.const 1128 - i32.const 62 - i32.const 4 + i32.const 53 + i32.const 2 call $~lib/env/abort unreachable end + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.1 (result i32) + local.get $8 + local.set $9 + local.get $9 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 1128 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.2 (result i32) + local.get $9 + call $~lib/internal/arraybuffer/computeSize + local.set $10 + local.get $10 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.2 + end + local.set $10 + block $~lib/internal/arraybuffer/_resize|inlined.2 (result i32) + local.get $10 + local.set $11 + local.get $9 + local.set $12 + local.get $11 + local.get $12 + i32.store + local.get $11 + end + end + local.set $10 + block $memory.copy|inlined.2 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.1 (result i32) + local.get $10 + local.set $9 + local.get $9 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $9 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.2 (result i32) + local.get $7 + local.set $12 + local.get $12 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $12 + local.get $6 + local.set $11 + local.get $9 + local.get $12 + local.get $11 + call $~lib/internal/memory/memmove + end + block $~lib/memory/memory.free|inlined.0 + local.get $7 + local.set $11 + local.get $11 + call $~lib/allocator/arena/__memory_free + br $~lib/memory/memory.free|inlined.0 + end + local.get $10 + end + end + local.set $0 + block $memory.fill|inlined.2 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.3 (result i32) local.get $0 - local.get $1 - i32.store + local.set $5 + local.get $5 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add end + local.get $2 + i32.add + local.set $5 + i32.const 0 + local.set $4 + local.get $1 + local.get $2 + i32.sub + local.set $3 + local.get $5 + local.get $4 + local.get $3 + call $~lib/internal/memory/memset end local.get $0 ) @@ -4462,7 +4571,7 @@ local.get $5 i32.const 2 i32.shl - call $~lib/internal/arraybuffer/reallocateUnsafe + call $~lib/internal/arraybuffer/reallocateZeroedUnsafe local.set $3 local.get $0 local.get $3 diff --git a/tests/compiler/std/symbol.optimized.wat b/tests/compiler/std/symbol.optimized.wat index b3e163e836..3bbb9b98b0 100644 --- a/tests/compiler/std/symbol.optimized.wat +++ b/tests/compiler/std/symbol.optimized.wat @@ -120,34 +120,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 1073741816 - i32.gt_u - if - i32.const 0 - i32.const 104 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - call $~lib/allocator/arena/__memory_allocate - local.tee $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 2 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) local.get $1 i32.eqz @@ -366,6 +339,38 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 1073741816 + i32.gt_u + if + i32.const 0 + i32.const 104 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + i32.const 1 + i32.const 32 + local.get $0 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $1 + local.get $0 + i32.store + local.get $1 + i32.const 8 + i32.add + local.get $0 + call $~lib/internal/memory/memset + local.get $1 + ) (func $~lib/arraybuffer/ArrayBuffer#constructor (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $0 @@ -380,7 +385,7 @@ unreachable end local.get $0 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $2 local.get $1 i32.eqz diff --git a/tests/compiler/std/symbol.untouched.wat b/tests/compiler/std/symbol.untouched.wat index c705bc7d68..bf9cda1910 100644 --- a/tests/compiler/std/symbol.untouched.wat +++ b/tests/compiler/std/symbol.untouched.wat @@ -189,36 +189,7 @@ i32.sub i32.shl ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 5 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 104 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - block $~lib/memory/memory.allocate|inlined.0 (result i32) - local.get $0 - call $~lib/internal/arraybuffer/computeSize - local.set $2 - local.get $2 - call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.0 - end - local.set $1 - local.get $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 6 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 5 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i64) @@ -472,6 +443,68 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 6 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $1 + local.get $1 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 104 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.0 (result i32) + local.get $1 + call $~lib/internal/arraybuffer/computeSize + local.set $2 + local.get $2 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.0 + end + local.set $2 + block $~lib/internal/arraybuffer/_resize|inlined.0 (result i32) + local.get $2 + local.set $3 + local.get $1 + local.set $4 + local.get $3 + local.get $4 + i32.store + local.get $3 + end + end + local.set $5 + block $memory.fill|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + local.get $5 + local.set $2 + local.get $2 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $2 + i32.const 0 + local.set $1 + local.get $0 + local.set $4 + local.get $2 + local.get $1 + local.get $4 + call $~lib/internal/memory/memset + end + local.get $5 + ) (func $~lib/arraybuffer/ArrayBuffer#constructor (; 7 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) @@ -489,7 +522,7 @@ unreachable end local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 local.get $2 i32.const 0 diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index 53175de155..df16e9698c 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -146,34 +146,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 1073741816 - i32.gt_u - if - i32.const 0 - i32.const 112 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - call $~lib/allocator/arena/__memory_allocate - local.tee $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 3 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 2 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i64) local.get $2 @@ -408,6 +381,39 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 1073741816 + i32.gt_u + if + i32.const 0 + i32.const 112 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + i32.const 1 + i32.const 32 + local.get $0 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__memory_allocate + local.tee $1 + local.get $0 + i32.store + local.get $1 + i32.const 8 + i32.add + i32.const 0 + local.get $0 + call $~lib/internal/memory/memset + local.get $1 + ) (func $~lib/internal/typedarray/TypedArray#constructor (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $1 @@ -422,7 +428,7 @@ unreachable end local.get $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.tee $2 i32.const 8 i32.add @@ -490,7 +496,7 @@ i32.const 1 i32.shl local.tee $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.tee $2 i32.const 8 i32.add @@ -547,7 +553,7 @@ i32.const 2 i32.shl local.tee $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.tee $2 i32.const 8 i32.add @@ -604,7 +610,7 @@ i32.const 3 i32.shl local.tee $1 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.tee $2 i32.const 8 i32.add diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index 6d1d0c2685..437f40ade6 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -191,36 +191,7 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 - global.get $~lib/internal/arraybuffer/MAX_BLENGTH - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 112 - i32.const 26 - i32.const 2 - call $~lib/env/abort - unreachable - end - block $~lib/memory/memory.allocate|inlined.0 (result i32) - local.get $0 - call $~lib/internal/arraybuffer/computeSize - local.set $2 - local.get $2 - call $~lib/allocator/arena/__memory_allocate - br $~lib/memory/memory.allocate|inlined.0 - end - local.set $1 - local.get $1 - local.get $0 - i32.store - local.get $1 - ) - (func $~lib/internal/memory/memset (; 4 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 3 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i64) @@ -474,6 +445,68 @@ end end ) + (func $~lib/internal/arraybuffer/allocateZeroedUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $~lib/internal/arraybuffer/_allocateUnsafe|inlined.0 (result i32) + local.get $0 + local.set $1 + local.get $1 + global.get $~lib/internal/arraybuffer/MAX_BLENGTH + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 112 + i32.const 30 + i32.const 2 + call $~lib/env/abort + unreachable + end + block $~lib/memory/memory.allocate|inlined.0 (result i32) + local.get $1 + call $~lib/internal/arraybuffer/computeSize + local.set $2 + local.get $2 + call $~lib/allocator/arena/__memory_allocate + br $~lib/memory/memory.allocate|inlined.0 + end + local.set $2 + block $~lib/internal/arraybuffer/_resize|inlined.0 (result i32) + local.get $2 + local.set $3 + local.get $1 + local.set $4 + local.get $3 + local.get $4 + i32.store + local.get $3 + end + end + local.set $5 + block $memory.fill|inlined.0 + block $~lib/arraybuffer/ArrayBuffer#get:data|inlined.0 (result i32) + local.get $5 + local.set $2 + local.get $2 + global.get $~lib/internal/arraybuffer/HEADER_SIZE + i32.add + end + local.set $2 + i32.const 0 + local.set $1 + local.get $0 + local.set $4 + local.get $2 + local.get $1 + local.get $4 + call $~lib/internal/memory/memset + end + local.get $5 + ) (func $~lib/memory/memory.allocate (; 5 ;) (type $ii) (param $0 i32) (result i32) local.get $0 call $~lib/allocator/arena/__memory_allocate @@ -501,9 +534,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.0 + block $memory.fill|inlined.1 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -582,9 +615,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.1 + block $memory.fill|inlined.2 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -677,9 +710,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.2 + block $memory.fill|inlined.3 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -758,9 +791,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.3 + block $memory.fill|inlined.4 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -839,9 +872,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.4 + block $memory.fill|inlined.5 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -920,9 +953,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.5 + block $memory.fill|inlined.6 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -1001,9 +1034,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.6 + block $memory.fill|inlined.7 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -1082,9 +1115,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.7 + block $memory.fill|inlined.8 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -1163,9 +1196,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.8 + block $memory.fill|inlined.9 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -1244,9 +1277,9 @@ i32.shl local.set $2 local.get $2 - call $~lib/internal/arraybuffer/allocateUnsafe + call $~lib/internal/arraybuffer/allocateZeroedUnsafe local.set $3 - block $memory.fill|inlined.9 + block $memory.fill|inlined.10 local.get $3 global.get $~lib/internal/arraybuffer/HEADER_SIZE i32.add @@ -2390,7 +2423,7 @@ br $~lib/memory/memory.allocate|inlined.3 end local.set $6 - block $memory.fill|inlined.10 + block $memory.fill|inlined.11 local.get $6 local.set $5 i32.const 0