From d3ca06b7ce9a07b6b9bbc00986ed7db3b88d3708 Mon Sep 17 00:00:00 2001 From: dcode Date: Thu, 14 Mar 2019 12:52:46 +0100 Subject: [PATCH] inline single-use implementations --- std/assembly/allocator/arena.ts | 6 +- std/assembly/allocator/emscripten.ts | 4 +- std/assembly/allocator/system.ts | 4 +- std/assembly/allocator/tlsf.ts | 4 +- std/assembly/util/memory.ts | 6 + tests/compiler/std/runtime.optimized.wat | 954 +++++++-------- tests/compiler/std/runtime.untouched.wat | 1416 +++++++++++----------- 7 files changed, 1195 insertions(+), 1199 deletions(-) diff --git a/std/assembly/allocator/arena.ts b/std/assembly/allocator/arena.ts index eb867ca1..b63e0d7f 100644 --- a/std/assembly/allocator/arena.ts +++ b/std/assembly/allocator/arena.ts @@ -10,7 +10,7 @@ var startOffset: usize = (HEAP_BASE + AL_MASK) & ~AL_MASK; var offset: usize = startOffset; // @ts-ignore: decorator -@unsafe @global +@unsafe @global @inline function __memory_allocate(size: usize): usize { if (size > MAX_SIZE_32) unreachable(); var ptr = offset; @@ -30,12 +30,12 @@ function __memory_allocate(size: usize): usize { } // @ts-ignore: decorator -@unsafe @global +@unsafe @global @inline function __memory_free(ptr: usize): void { } // @ts-ignore: decorator -@unsafe @global +@unsafe @global @inline function __memory_reset(): void { offset = startOffset; } diff --git a/std/assembly/allocator/emscripten.ts b/std/assembly/allocator/emscripten.ts index 81c3700f..e6ef0ae2 100644 --- a/std/assembly/allocator/emscripten.ts +++ b/std/assembly/allocator/emscripten.ts @@ -7,13 +7,13 @@ declare function _malloc(size: usize): usize; declare function _free(ptr: usize): void; // @ts-ignore: decorator -@unsafe @global +@unsafe @global @inline function __memory_allocate(size: usize): usize { return _malloc(size); } // @ts-ignore: decorator -@unsafe @global +@unsafe @global @inline function __memory_free(ptr: usize): void { _free(ptr); } diff --git a/std/assembly/allocator/system.ts b/std/assembly/allocator/system.ts index 9ec0dc4a..e137e43e 100644 --- a/std/assembly/allocator/system.ts +++ b/std/assembly/allocator/system.ts @@ -7,13 +7,13 @@ declare function malloc(size: usize): usize; declare function free(ptr: usize): void; // @ts-ignore: decorator -@unsafe @global +@unsafe @global @inline function __memory_allocate(size: usize): usize { return malloc(size); } // @ts-ignore: decorator -@unsafe @global +@unsafe @global @inline function __memory_free(ptr: usize): void { free(ptr); } diff --git a/std/assembly/allocator/tlsf.ts b/std/assembly/allocator/tlsf.ts index c3c59ca1..c4bf9991 100644 --- a/std/assembly/allocator/tlsf.ts +++ b/std/assembly/allocator/tlsf.ts @@ -423,7 +423,7 @@ var ROOT: Root = changetype(0); /** Allocates a chunk of memory. */ // @ts-ignore: decorator -@unsafe @global +@unsafe @global @inline function __memory_allocate(size: usize): usize { // initialize if necessary var root = ROOT; @@ -473,7 +473,7 @@ function __memory_allocate(size: usize): usize { /** Frees the chunk of memory at the specified address. */ // @ts-ignore: decorator -@unsafe @global +@unsafe @global @inline function __memory_free(data: usize): void { if (data) { let root = ROOT; diff --git a/std/assembly/util/memory.ts b/std/assembly/util/memory.ts index d48ec44f..3b4af9d1 100644 --- a/std/assembly/util/memory.ts +++ b/std/assembly/util/memory.ts @@ -141,6 +141,8 @@ export function memcpy(dest: usize, src: usize, n: usize): void { // see: musl/s } } +// @ts-ignore: decorator +@inline export function memmove(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c if (dest === src) return; if (src + n <= dest || dest + n <= src) { @@ -182,6 +184,8 @@ export function memmove(dest: usize, src: usize, n: usize): void { // see: musl/ } } +// @ts-ignore: decorator +@inline export function memset(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset // fill head and tail with minimal branching @@ -242,6 +246,8 @@ export function memset(dest: usize, c: u8, n: usize): void { // see: musl/src/st } } +// @ts-ignore: decorator +@inline export function memcmp(vl: usize, vr: usize, n: usize): i32 { // see: musl/src/string/memcmp.c if (vl == vr) return 0; while (n != 0 && load(vl) == load(vr)) { diff --git a/tests/compiler/std/runtime.optimized.wat b/tests/compiler/std/runtime.optimized.wat index 7554028b..eac3b40a 100644 --- a/tests/compiler/std/runtime.optimized.wat +++ b/tests/compiler/std/runtime.optimized.wat @@ -994,29 +994,30 @@ i32.const 8 i32.add ) - (func $~lib/allocator/tlsf/__memory_allocate (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/memory/memory.allocate (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) - (local $4 i32) + local.get $0 + local.set $2 global.get $~lib/allocator/tlsf/ROOT local.tee $3 i32.eqz if i32.const 1 current_memory - local.tee $4 - i32.gt_s local.tee $1 + i32.gt_s + local.tee $0 if (result i32) i32.const 1 - local.get $4 + local.get $1 i32.sub grow_memory i32.const 0 i32.lt_s else - local.get $1 + local.get $0 end if unreachable @@ -1032,39 +1033,39 @@ i32.const 0 i32.store i32.const 0 - local.set $1 + local.set $0 loop $repeat|0 - local.get $1 + local.get $0 i32.const 22 i32.lt_u if i32.const 216 - local.get $1 + local.get $0 i32.const 0 call $~lib/allocator/tlsf/Root#setSLMap i32.const 0 - local.set $2 + local.set $1 loop $repeat|1 - local.get $2 + local.get $1 i32.const 32 i32.lt_u if i32.const 216 + local.get $0 local.get $1 - local.get $2 i32.const 0 call $~lib/allocator/tlsf/Root#setHead - local.get $2 + local.get $1 i32.const 1 i32.add - local.set $2 + local.set $1 br $repeat|1 end end - local.get $1 + local.get $0 i32.const 1 i32.add - local.set $1 + local.set $0 br $repeat|0 end end @@ -1075,88 +1076,83 @@ i32.shl call $~lib/allocator/tlsf/Root#addMemory end - local.get $0 + local.get $2 i32.const 1073741824 i32.gt_u if unreachable end - block (result i32) - local.get $3 - local.get $0 - i32.const 7 - i32.add - i32.const -8 - i32.and - local.tee $2 - i32.const 16 - local.get $2 - i32.const 16 - i32.gt_u - select - local.tee $0 - call $~lib/allocator/tlsf/Root#search + local.get $3 + local.get $2 + i32.const 7 + i32.add + i32.const -8 + i32.and + local.tee $0 + i32.const 16 + local.get $0 + i32.const 16 + i32.gt_u + select + local.tee $2 + call $~lib/allocator/tlsf/Root#search + local.tee $0 + i32.eqz + if + current_memory local.tee $1 - i32.eqz + local.get $2 + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $0 + local.get $1 + local.get $0 + i32.gt_s + select + grow_memory + i32.const 0 + i32.lt_s if - current_memory - local.tee $2 local.get $0 - i32.const 65535 - i32.add - i32.const -65536 - i32.and - i32.const 16 - i32.shr_u - local.tee $4 - local.tee $1 - local.get $2 - local.get $1 - i32.gt_s - select grow_memory i32.const 0 i32.lt_s if - local.get $4 - grow_memory - i32.const 0 - i32.lt_s - if - unreachable - end - end - local.get $3 - local.get $2 - i32.const 16 - i32.shl - current_memory - i32.const 16 - i32.shl - call $~lib/allocator/tlsf/Root#addMemory - local.get $3 - local.get $0 - call $~lib/allocator/tlsf/Root#search - local.tee $2 - if (result i32) - local.get $2 - else - i32.const 0 - i32.const 16 - i32.const 467 - i32.const 12 - call $~lib/env/abort unreachable end - local.set $1 end + local.get $3 local.get $1 - i32.load - i32.const -4 - i32.and - local.get $0 - i32.lt_u + i32.const 16 + i32.shl + current_memory + i32.const 16 + i32.shl + call $~lib/allocator/tlsf/Root#addMemory + local.get $3 + local.get $2 + call $~lib/allocator/tlsf/Root#search + local.tee $0 + i32.eqz + if + i32.const 0 + i32.const 16 + i32.const 467 + i32.const 12 + call $~lib/env/abort + unreachable + end end + local.get $0 + i32.load + i32.const -4 + i32.and + local.get $2 + i32.lt_u if i32.const 0 i32.const 16 @@ -1166,8 +1162,8 @@ unreachable end local.get $3 - local.get $1 local.get $0 + local.get $2 call $~lib/allocator/tlsf/Root#use ) (func $~lib/runtime/runtime.alloc (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) @@ -1180,7 +1176,7 @@ i32.clz i32.sub i32.shl - call $~lib/allocator/tlsf/__memory_allocate + call $~lib/memory/memory.allocate local.tee $1 i32.const -1520547049 i32.store @@ -2094,429 +2090,415 @@ i32.store8 end ) - (func $~lib/util/memory/memmove (; 19 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/memory/memory.copy (; 19 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) - local.get $0 - local.get $1 - i32.eq - if - return - end - local.get $1 - local.get $2 - i32.add - local.get $0 - i32.le_u - local.tee $3 - i32.eqz - if - local.get $0 + block $~lib/util/memory/memmove|inlined.0 local.get $2 - i32.add - local.get $1 - i32.le_u local.set $3 - end - local.get $3 - if - local.get $0 local.get $1 - local.get $2 - call $~lib/util/memory/memcpy - return - end - local.get $0 - local.get $1 - i32.lt_u - if - local.get $1 - i32.const 7 - i32.and local.get $0 - i32.const 7 - i32.and + local.tee $2 i32.eq + br_if $~lib/util/memory/memmove|inlined.0 + local.get $1 + local.get $3 + i32.add + local.get $2 + i32.le_u + local.tee $0 + i32.eqz if - loop $continue|0 - local.get $0 - i32.const 7 - i32.and + local.get $2 + local.get $3 + i32.add + local.get $1 + i32.le_u + local.set $0 + end + local.get $0 + if + local.get $2 + local.get $1 + local.get $3 + call $~lib/util/memory/memcpy + br $~lib/util/memory/memmove|inlined.0 + end + local.get $2 + local.get $1 + i32.lt_u + if + local.get $1 + i32.const 7 + i32.and + local.get $2 + i32.const 7 + i32.and + i32.eq + if + loop $continue|0 + local.get $2 + i32.const 7 + i32.and + if + local.get $3 + i32.eqz + br_if $~lib/util/memory/memmove|inlined.0 + local.get $3 + i32.const 1 + i32.sub + local.set $3 + local.get $2 + local.tee $4 + i32.const 1 + i32.add + local.set $2 + local.get $1 + local.tee $0 + i32.const 1 + i32.add + local.set $1 + local.get $4 + local.get $0 + i32.load8_u + i32.store8 + br $continue|0 + end + end + loop $continue|1 + local.get $3 + i32.const 8 + i32.ge_u + if + local.get $2 + local.get $1 + i64.load + i64.store + local.get $3 + i32.const 8 + i32.sub + local.set $3 + local.get $2 + i32.const 8 + i32.add + local.set $2 + local.get $1 + i32.const 8 + i32.add + local.set $1 + br $continue|1 + end + end + end + loop $continue|2 + local.get $3 if local.get $2 - i32.eqz - if - return - end - local.get $2 - i32.const 1 - i32.sub - local.set $2 - local.get $0 local.tee $4 i32.const 1 i32.add - local.set $0 + local.set $2 local.get $1 - local.tee $3 + local.tee $0 i32.const 1 i32.add local.set $1 local.get $4 - local.get $3 + local.get $0 i32.load8_u i32.store8 - br $continue|0 - end - end - loop $continue|1 - local.get $2 - i32.const 8 - i32.ge_u - if - local.get $0 - local.get $1 - i64.load - i64.store - local.get $2 - i32.const 8 - i32.sub - local.set $2 - local.get $0 - i32.const 8 - i32.add - local.set $0 - local.get $1 - i32.const 8 - i32.add - local.set $1 - br $continue|1 - end - end - end - loop $continue|2 - local.get $2 - if - local.get $0 - local.tee $4 - i32.const 1 - i32.add - local.set $0 - local.get $1 - local.tee $3 - i32.const 1 - i32.add - local.set $1 - local.get $4 - local.get $3 - i32.load8_u - i32.store8 - local.get $2 - i32.const 1 - i32.sub - local.set $2 - br $continue|2 - end - end - else - local.get $1 - i32.const 7 - i32.and - local.get $0 - i32.const 7 - i32.and - i32.eq - if - loop $continue|3 - local.get $0 - local.get $2 - i32.add - i32.const 7 - i32.and - if - local.get $2 - i32.eqz - if - return - end - local.get $2 + local.get $3 i32.const 1 i32.sub - local.tee $2 - local.get $0 + local.set $3 + br $continue|2 + end + end + else + local.get $1 + i32.const 7 + i32.and + local.get $2 + i32.const 7 + i32.and + i32.eq + if + loop $continue|3 + local.get $2 + local.get $3 + i32.add + i32.const 7 + i32.and + if + local.get $3 + i32.eqz + br_if $~lib/util/memory/memmove|inlined.0 + local.get $3 + i32.const 1 + i32.sub + local.tee $3 + local.get $2 + i32.add + local.get $1 + local.get $3 + i32.add + i32.load8_u + i32.store8 + br $continue|3 + end + end + loop $continue|4 + local.get $3 + i32.const 8 + i32.ge_u + if + local.get $3 + i32.const 8 + i32.sub + local.tee $3 + local.get $2 + i32.add + local.get $1 + local.get $3 + i32.add + i64.load + i64.store + br $continue|4 + end + end + end + loop $continue|5 + local.get $3 + if + local.get $3 + i32.const 1 + i32.sub + local.tee $3 + local.get $2 i32.add local.get $1 - local.get $2 + local.get $3 i32.add i32.load8_u i32.store8 - br $continue|3 + br $continue|5 end end - loop $continue|4 - local.get $2 - i32.const 8 - i32.ge_u - if - local.get $2 - i32.const 8 - i32.sub - local.tee $2 - local.get $0 - i32.add - local.get $1 - local.get $2 - i32.add - i64.load - i64.store - br $continue|4 - end - end - end - loop $continue|5 - local.get $2 - if - local.get $2 - i32.const 1 - i32.sub - local.tee $2 - local.get $0 - i32.add - local.get $1 - local.get $2 - i32.add - i32.load8_u - i32.store8 - br $continue|5 - end end end ) - (func $~lib/util/memory/memset (; 20 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/memory/memory.fill (; 20 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) - local.get $1 - i32.eqz - if - return - end - local.get $0 - i32.const 0 - i32.store8 - local.get $0 - local.get $1 - i32.add - i32.const 1 - i32.sub - i32.const 0 - i32.store8 - local.get $1 - i32.const 2 - i32.le_u - if - return - end - local.get $0 - i32.const 1 - i32.add - i32.const 0 - i32.store8 - local.get $0 - i32.const 2 - i32.add - i32.const 0 - i32.store8 - local.get $0 - local.get $1 - i32.add - local.tee $2 - i32.const 2 - i32.sub - i32.const 0 - i32.store8 - local.get $2 - i32.const 3 - i32.sub - i32.const 0 - i32.store8 - local.get $1 - i32.const 6 - i32.le_u - if - return - end - local.get $0 - i32.const 3 - i32.add - i32.const 0 - i32.store8 - local.get $0 - local.get $1 - i32.add - i32.const 4 - i32.sub - i32.const 0 - i32.store8 - local.get $1 - i32.const 8 - i32.le_u - if - return - end - i32.const 0 - local.get $0 - i32.sub - i32.const 3 - i32.and - local.tee $2 - local.get $0 - i32.add - local.tee $0 - i32.const 0 - i32.store - local.get $1 - local.get $2 - i32.sub - i32.const -4 - i32.and - local.tee $1 - local.get $0 - i32.add - i32.const 4 - i32.sub - i32.const 0 - i32.store - local.get $1 - i32.const 8 - i32.le_u - if - return - end - local.get $0 - i32.const 4 - i32.add - i32.const 0 - i32.store - local.get $0 - i32.const 8 - i32.add - i32.const 0 - i32.store - local.get $0 - local.get $1 - i32.add - local.tee $2 - i32.const 12 - i32.sub - i32.const 0 - i32.store - local.get $2 - i32.const 8 - i32.sub - i32.const 0 - i32.store - local.get $1 - i32.const 24 - i32.le_u - if - return - end - local.get $0 - i32.const 12 - i32.add - i32.const 0 - i32.store - local.get $0 - i32.const 16 - i32.add - i32.const 0 - i32.store - local.get $0 - i32.const 20 - i32.add - i32.const 0 - i32.store - local.get $0 - i32.const 24 - i32.add - i32.const 0 - i32.store - local.get $0 - local.get $1 - i32.add - local.tee $2 - i32.const 28 - i32.sub - i32.const 0 - i32.store - local.get $2 - i32.const 24 - i32.sub - i32.const 0 - i32.store - local.get $2 - i32.const 20 - i32.sub - i32.const 0 - i32.store - local.get $2 - i32.const 16 - i32.sub - i32.const 0 - i32.store - local.get $0 - i32.const 4 - i32.and - i32.const 24 - i32.add - local.tee $2 - local.get $0 - i32.add - local.set $0 - local.get $1 - local.get $2 - i32.sub - local.set $1 - loop $continue|0 + block $~lib/util/memory/memset|inlined.0 local.get $1 - i32.const 32 - i32.ge_u - if - local.get $0 - i64.const 0 - i64.store - local.get $0 - i32.const 8 - i32.add - i64.const 0 - i64.store - local.get $0 - i32.const 16 - i32.add - i64.const 0 - i64.store - local.get $0 - i32.const 24 - i32.add - i64.const 0 - i64.store + i32.eqz + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 0 + i32.store8 + local.get $0 + local.get $1 + i32.add + i32.const 1 + i32.sub + i32.const 0 + i32.store8 + local.get $1 + i32.const 2 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 1 + i32.add + i32.const 0 + i32.store8 + local.get $0 + i32.const 2 + i32.add + i32.const 0 + i32.store8 + local.get $0 + local.get $1 + i32.add + local.tee $2 + i32.const 2 + i32.sub + i32.const 0 + i32.store8 + local.get $2 + i32.const 3 + i32.sub + i32.const 0 + i32.store8 + local.get $1 + i32.const 6 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 3 + i32.add + i32.const 0 + i32.store8 + local.get $0 + local.get $1 + i32.add + i32.const 4 + i32.sub + i32.const 0 + i32.store8 + local.get $1 + i32.const 8 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $1 + i32.const 0 + local.get $0 + i32.sub + i32.const 3 + i32.and + local.tee $2 + i32.sub + local.set $1 + local.get $0 + local.get $2 + i32.add + local.tee $0 + i32.const 0 + i32.store + local.get $1 + i32.const -4 + i32.and + local.tee $1 + local.get $0 + i32.add + i32.const 4 + i32.sub + i32.const 0 + i32.store + local.get $1 + i32.const 8 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 4 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 8 + i32.add + i32.const 0 + i32.store + local.get $0 + local.get $1 + i32.add + local.tee $2 + i32.const 12 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 8 + i32.sub + i32.const 0 + i32.store + local.get $1 + i32.const 24 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 12 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 16 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 20 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 24 + i32.add + i32.const 0 + i32.store + local.get $0 + local.get $1 + i32.add + local.tee $2 + i32.const 28 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 24 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 20 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 16 + i32.sub + i32.const 0 + i32.store + local.get $0 + i32.const 4 + i32.and + i32.const 24 + i32.add + local.tee $2 + local.get $0 + i32.add + local.set $0 + local.get $1 + local.get $2 + i32.sub + local.set $1 + loop $continue|0 local.get $1 i32.const 32 - i32.sub - local.set $1 - local.get $0 - i32.const 32 - i32.add - local.set $0 - br $continue|0 + i32.ge_u + if + local.get $0 + i64.const 0 + i64.store + local.get $0 + i32.const 8 + i32.add + i64.const 0 + i64.store + local.get $0 + i32.const 16 + i32.add + i64.const 0 + i64.store + local.get $0 + i32.const 24 + i32.add + i64.const 0 + i64.store + local.get $1 + i32.const 32 + i32.sub + local.set $1 + local.get $0 + i32.const 32 + i32.add + local.set $0 + br $continue|0 + end end end ) - (func $~lib/memory/memory.fill (; 21 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - local.get $0 - local.get $1 - call $~lib/util/memory/memset - ) - (func $~lib/allocator/tlsf/__memory_free (; 22 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/memory/memory.free (; 21 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -2554,7 +2536,7 @@ end end ) - (func $~lib/runtime/runtime.realloc (; 23 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/runtime/runtime.realloc (; 22 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2593,7 +2575,7 @@ i32.lt_u if local.get $4 - call $~lib/allocator/tlsf/__memory_allocate + call $~lib/memory/memory.allocate local.tee $5 local.get $3 i32.load @@ -2610,7 +2592,7 @@ local.tee $4 local.get $0 local.get $2 - call $~lib/util/memory/memmove + call $~lib/memory/memory.copy local.get $2 local.get $4 i32.add @@ -2635,7 +2617,7 @@ unreachable end local.get $3 - call $~lib/allocator/tlsf/__memory_free + call $~lib/memory/memory.free else local.get $0 global.set $std/runtime/register_ref @@ -2659,7 +2641,7 @@ i32.store offset=4 local.get $0 ) - (func $~lib/runtime/runtime.unrefUnregistered (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/runtime/runtime.unrefUnregistered (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.const 232 i32.lt_u @@ -2688,7 +2670,7 @@ end local.get $0 ) - (func $start:std/runtime (; 25 ;) (type $FUNCSIG$v) + (func $start:std/runtime (; 24 ;) (type $FUNCSIG$v) (local $0 i32) (local $1 i32) (local $2 i32) @@ -2705,20 +2687,20 @@ i32.clz i32.sub i32.shl - local.tee $2 + local.tee $1 i32.const 0 i32.ne - local.tee $1 - if - local.get $2 + local.tee $2 + if (result i32) + local.get $1 i32.const 1 i32.sub - local.get $2 + local.get $1 i32.and i32.eqz - local.set $1 + else + local.get $2 end - local.get $1 if local.get $0 i32.const 1 @@ -2746,7 +2728,6 @@ i32.const 1 i32.const 32 global.get $std/runtime/barrier2 - local.tee $1 i32.const 16 i32.add i32.clz @@ -2754,7 +2735,7 @@ i32.shl i32.const 1 i32.const 32 - local.get $1 + global.get $std/runtime/barrier2 i32.const 15 i32.add i32.clz @@ -2777,7 +2758,6 @@ i32.const 1 i32.const 32 global.get $std/runtime/barrier3 - local.tee $1 i32.const 16 i32.add i32.clz @@ -2785,7 +2765,7 @@ i32.shl i32.const 1 i32.const 32 - local.get $1 + global.get $std/runtime/barrier3 i32.const 15 i32.add i32.clz @@ -2917,7 +2897,7 @@ end global.get $std/runtime/ref2 call $~lib/runtime/runtime.unrefUnregistered - call $~lib/allocator/tlsf/__memory_free + call $~lib/memory/memory.free global.get $std/runtime/barrier2 call $~lib/runtime/runtime.alloc global.set $std/runtime/ref3 @@ -3015,10 +2995,10 @@ unreachable end ) - (func $start (; 26 ;) (type $FUNCSIG$v) + (func $start (; 25 ;) (type $FUNCSIG$v) call $start:std/runtime ) - (func $null (; 27 ;) (type $FUNCSIG$v) + (func $null (; 26 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/std/runtime.untouched.wat b/tests/compiler/std/runtime.untouched.wat index f0cb2208..491839db 100644 --- a/tests/compiler/std/runtime.untouched.wat +++ b/tests/compiler/std/runtime.untouched.wat @@ -1225,7 +1225,7 @@ global.get $~lib/allocator/tlsf/Block.INFO i32.add ) - (func $~lib/allocator/tlsf/__memory_allocate (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/memory/memory.allocate (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -1233,240 +1233,241 @@ (local $5 i32) (local $6 i32) (local $7 i32) - global.get $~lib/allocator/tlsf/ROOT - local.set $1 - local.get $1 - i32.eqz - if - global.get $~lib/memory/HEAP_BASE - i32.const 7 - i32.add - i32.const 7 - i32.const -1 - i32.xor - i32.and + (local $8 i32) + block $~lib/allocator/tlsf/__memory_allocate|inlined.0 (result i32) + local.get $0 + local.set $1 + global.get $~lib/allocator/tlsf/ROOT local.set $2 - current_memory - local.set $3 local.get $2 - global.get $~lib/allocator/tlsf/Root.SIZE - i32.add - i32.const 65535 - i32.add - i32.const 65535 - i32.const -1 - i32.xor - i32.and - i32.const 16 - i32.shr_u - local.set $4 - local.get $4 - local.get $3 - i32.gt_s - local.tee $5 - if (result i32) - local.get $4 - local.get $3 - i32.sub - grow_memory - i32.const 0 - i32.lt_s - else - local.get $5 - end + i32.eqz if - unreachable - end - local.get $2 - local.tee $1 - global.set $~lib/allocator/tlsf/ROOT - local.get $1 - i32.const 0 - call $~lib/allocator/tlsf/Root#set:tailRef - local.get $1 - i32.const 0 - i32.store - block $break|0 - i32.const 0 + global.get $~lib/memory/HEAP_BASE + i32.const 7 + i32.add + i32.const 7 + i32.const -1 + i32.xor + i32.and + local.set $3 + current_memory + local.set $4 + local.get $3 + global.get $~lib/allocator/tlsf/Root.SIZE + i32.add + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u local.set $5 - loop $repeat|0 + local.get $5 + local.get $4 + i32.gt_s + local.tee $6 + if (result i32) local.get $5 - global.get $~lib/allocator/tlsf/FL_BITS - i32.lt_u - i32.eqz - br_if $break|0 - block - local.get $1 - local.get $5 - i32.const 0 - call $~lib/allocator/tlsf/Root#setSLMap - block $break|1 - i32.const 0 - local.set $6 - loop $repeat|1 - local.get $6 - global.get $~lib/allocator/tlsf/SL_SIZE - i32.lt_u - i32.eqz - br_if $break|1 - local.get $1 - local.get $5 - local.get $6 - i32.const 0 - call $~lib/allocator/tlsf/Root#setHead - local.get $6 - i32.const 1 - i32.add - local.set $6 - br $repeat|1 - unreachable - end - unreachable - end - end - local.get $5 - i32.const 1 - i32.add - local.set $5 - br $repeat|0 + local.get $4 + i32.sub + grow_memory + i32.const 0 + i32.lt_s + else + local.get $6 + end + if unreachable end + local.get $3 + local.tee $2 + global.set $~lib/allocator/tlsf/ROOT + local.get $2 + i32.const 0 + call $~lib/allocator/tlsf/Root#set:tailRef + local.get $2 + i32.const 0 + i32.store + block $break|0 + i32.const 0 + local.set $6 + loop $repeat|0 + local.get $6 + global.get $~lib/allocator/tlsf/FL_BITS + i32.lt_u + i32.eqz + br_if $break|0 + block + local.get $2 + local.get $6 + i32.const 0 + call $~lib/allocator/tlsf/Root#setSLMap + block $break|1 + i32.const 0 + local.set $7 + loop $repeat|1 + local.get $7 + global.get $~lib/allocator/tlsf/SL_SIZE + i32.lt_u + i32.eqz + br_if $break|1 + local.get $2 + local.get $6 + local.get $7 + i32.const 0 + call $~lib/allocator/tlsf/Root#setHead + local.get $7 + i32.const 1 + i32.add + local.set $7 + br $repeat|1 + unreachable + end + unreachable + end + end + local.get $6 + i32.const 1 + i32.add + local.set $6 + br $repeat|0 + unreachable + end + unreachable + end + local.get $2 + local.get $3 + global.get $~lib/allocator/tlsf/Root.SIZE + i32.add + i32.const 7 + i32.add + i32.const 7 + i32.const -1 + i32.xor + i32.and + current_memory + i32.const 16 + i32.shl + call $~lib/allocator/tlsf/Root#addMemory + drop + end + local.get $1 + global.get $~lib/allocator/tlsf/Block.MAX_SIZE + i32.gt_u + if unreachable end local.get $1 - local.get $2 - global.get $~lib/allocator/tlsf/Root.SIZE - i32.add i32.const 7 i32.add i32.const 7 i32.const -1 i32.xor i32.and - current_memory - i32.const 16 - i32.shl - call $~lib/allocator/tlsf/Root#addMemory - drop - end - local.get $0 - global.get $~lib/allocator/tlsf/Block.MAX_SIZE - i32.gt_u - if - unreachable - end - local.get $0 - i32.const 7 - i32.add - i32.const 7 - i32.const -1 - i32.xor - i32.and - local.tee $4 - global.get $~lib/allocator/tlsf/Block.MIN_SIZE - local.tee $3 - local.get $4 - local.get $3 - i32.gt_u - select - local.set $0 - local.get $1 - local.get $0 - call $~lib/allocator/tlsf/Root#search - local.set $7 - local.get $7 - i32.eqz - if - current_memory - local.set $4 - local.get $0 - i32.const 65535 - i32.add - i32.const 65535 - i32.const -1 - i32.xor - i32.and - i32.const 16 - i32.shr_u - local.set $3 - local.get $4 - local.tee $2 - local.get $3 local.tee $5 - local.get $2 + global.get $~lib/allocator/tlsf/Block.MIN_SIZE + local.tee $4 local.get $5 - i32.gt_s + local.get $4 + i32.gt_u select - local.set $2 + local.set $1 local.get $2 - grow_memory - i32.const 0 - i32.lt_s + local.get $1 + call $~lib/allocator/tlsf/Root#search + local.set $5 + local.get $5 + i32.eqz if + current_memory + local.set $4 + local.get $1 + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $4 + local.tee $6 local.get $3 + local.tee $7 + local.get $6 + local.get $7 + i32.gt_s + select + local.set $6 + local.get $6 grow_memory i32.const 0 i32.lt_s if - unreachable + local.get $3 + grow_memory + i32.const 0 + i32.lt_s + if + unreachable + end end + current_memory + local.set $7 + local.get $2 + local.get $4 + i32.const 16 + i32.shl + local.get $7 + i32.const 16 + i32.shl + call $~lib/allocator/tlsf/Root#addMemory + drop + local.get $2 + local.get $1 + call $~lib/allocator/tlsf/Root#search + local.tee $8 + i32.eqz + if (result i32) + i32.const 0 + i32.const 16 + i32.const 467 + i32.const 12 + call $~lib/env/abort + unreachable + else + local.get $8 + end + local.set $5 end - current_memory - local.set $5 - local.get $1 - local.get $4 - i32.const 16 - i32.shl local.get $5 - i32.const 16 - i32.shl - call $~lib/allocator/tlsf/Root#addMemory - drop + i32.load + global.get $~lib/allocator/tlsf/TAGS + i32.const -1 + i32.xor + i32.and local.get $1 - local.get $0 - call $~lib/allocator/tlsf/Root#search - local.tee $6 + i32.ge_u i32.eqz - if (result i32) + if i32.const 0 i32.const 16 - i32.const 467 - i32.const 12 + i32.const 470 + i32.const 2 call $~lib/env/abort unreachable - else - local.get $6 end - local.set $7 + local.get $2 + local.get $5 + local.get $1 + call $~lib/allocator/tlsf/Root#use end - local.get $7 - i32.load - global.get $~lib/allocator/tlsf/TAGS - i32.const -1 - i32.xor - i32.and - local.get $0 - i32.ge_u - i32.eqz - if - i32.const 0 - i32.const 16 - i32.const 470 - i32.const 2 - call $~lib/env/abort - unreachable - end - local.get $1 - local.get $7 - local.get $0 - call $~lib/allocator/tlsf/Root#use - ) - (func $~lib/memory/memory.allocate (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - call $~lib/allocator/tlsf/__memory_allocate return ) - (func $~lib/runtime/runtime.alloc (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/runtime/runtime.alloc (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 call $~lib/runtime/runtime.adjust @@ -1488,7 +1489,7 @@ i32.const 16 i32.add ) - (func $~lib/util/memory/memcpy (; 25 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/util/memory/memcpy (; 24 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -2689,517 +2690,530 @@ i32.store8 end ) - (func $~lib/util/memory/memmove (; 26 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) - (local $3 i32) - local.get $0 - local.get $1 - i32.eq - if - return - end - local.get $1 - local.get $2 - i32.add - local.get $0 - i32.le_u - local.tee $3 - if (result i32) - local.get $3 - else - local.get $0 - local.get $2 - i32.add - local.get $1 - i32.le_u - end - if - local.get $0 - local.get $1 - local.get $2 - call $~lib/util/memory/memcpy - return - end - local.get $0 - local.get $1 - i32.lt_u - if - local.get $1 - i32.const 7 - i32.and - local.get $0 - i32.const 7 - i32.and - i32.eq - if - block $break|0 - loop $continue|0 - local.get $0 - i32.const 7 - i32.and - if - block - local.get $2 - i32.eqz - if - return - end - local.get $2 - i32.const 1 - i32.sub - local.set $2 - block (result i32) - local.get $0 - local.tee $3 - i32.const 1 - i32.add - local.set $0 - local.get $3 - end - block (result i32) - local.get $1 - local.tee $3 - i32.const 1 - i32.add - local.set $1 - local.get $3 - end - i32.load8_u - i32.store8 - end - br $continue|0 - end - end - end - block $break|1 - loop $continue|1 - local.get $2 - i32.const 8 - i32.ge_u - if - block - local.get $0 - local.get $1 - i64.load - i64.store - local.get $2 - i32.const 8 - i32.sub - local.set $2 - local.get $0 - i32.const 8 - i32.add - local.set $0 - local.get $1 - i32.const 8 - i32.add - local.set $1 - end - br $continue|1 - end - end - end - end - block $break|2 - loop $continue|2 - local.get $2 - if - block - block (result i32) - local.get $0 - local.tee $3 - i32.const 1 - i32.add - local.set $0 - local.get $3 - end - block (result i32) - local.get $1 - local.tee $3 - i32.const 1 - i32.add - local.set $1 - local.get $3 - end - i32.load8_u - i32.store8 - local.get $2 - i32.const 1 - i32.sub - local.set $2 - end - br $continue|2 - end - end - end - else - local.get $1 - i32.const 7 - i32.and - local.get $0 - i32.const 7 - i32.and - i32.eq - if - block $break|3 - loop $continue|3 - local.get $0 - local.get $2 - i32.add - i32.const 7 - i32.and - if - block - local.get $2 - i32.eqz - if - return - end - local.get $0 - local.get $2 - i32.const 1 - i32.sub - local.tee $2 - i32.add - local.get $1 - local.get $2 - i32.add - i32.load8_u - i32.store8 - end - br $continue|3 - end - end - end - block $break|4 - loop $continue|4 - local.get $2 - i32.const 8 - i32.ge_u - if - block - local.get $2 - i32.const 8 - i32.sub - local.set $2 - local.get $0 - local.get $2 - i32.add - local.get $1 - local.get $2 - i32.add - i64.load - i64.store - end - br $continue|4 - end - end - end - end - block $break|5 - loop $continue|5 - local.get $2 - if - local.get $0 - local.get $2 - i32.const 1 - i32.sub - local.tee $2 - i32.add - local.get $1 - local.get $2 - i32.add - i32.load8_u - i32.store8 - br $continue|5 - end - end - end - end - ) - (func $~lib/memory/memory.copy (; 27 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) - local.get $0 - local.get $1 - local.get $2 - call $~lib/util/memory/memmove - ) - (func $~lib/util/memory/memset (; 28 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/memory/memory.copy (; 25 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) - (local $5 i64) - local.get $2 - i32.eqz - if - return - end - local.get $0 - local.get $1 - i32.store8 - local.get $0 - local.get $2 - i32.add - i32.const 1 - i32.sub - local.get $1 - i32.store8 - local.get $2 - i32.const 2 - i32.le_u - if - return - end - local.get $0 - i32.const 1 - i32.add - local.get $1 - i32.store8 - local.get $0 - i32.const 2 - i32.add - local.get $1 - i32.store8 - local.get $0 - local.get $2 - i32.add - i32.const 2 - i32.sub - local.get $1 - i32.store8 - local.get $0 - local.get $2 - i32.add - i32.const 3 - i32.sub - local.get $1 - i32.store8 - local.get $2 - i32.const 6 - i32.le_u - if - return - end - local.get $0 - i32.const 3 - i32.add - local.get $1 - i32.store8 - local.get $0 - local.get $2 - i32.add - i32.const 4 - i32.sub - local.get $1 - i32.store8 - local.get $2 - i32.const 8 - i32.le_u - if - return - end - i32.const 0 - local.get $0 - i32.sub - i32.const 3 - i32.and - local.set $3 - local.get $0 - local.get $3 - i32.add - local.set $0 - local.get $2 - local.get $3 - i32.sub - local.set $2 - local.get $2 - i32.const -4 - i32.and - local.set $2 - i32.const -1 - i32.const 255 - i32.div_u - local.get $1 - i32.const 255 - i32.and - i32.mul - local.set $4 - local.get $0 - local.get $4 - i32.store - local.get $0 - local.get $2 - i32.add - i32.const 4 - i32.sub - local.get $4 - i32.store - local.get $2 - i32.const 8 - i32.le_u - if - return - end - local.get $0 - i32.const 4 - i32.add - local.get $4 - i32.store - local.get $0 - i32.const 8 - i32.add - local.get $4 - i32.store - local.get $0 - local.get $2 - i32.add - i32.const 12 - i32.sub - local.get $4 - i32.store - local.get $0 - local.get $2 - i32.add - i32.const 8 - i32.sub - local.get $4 - i32.store - local.get $2 - i32.const 24 - i32.le_u - if - return - end - local.get $0 - i32.const 12 - i32.add - local.get $4 - i32.store - local.get $0 - i32.const 16 - i32.add - local.get $4 - i32.store - local.get $0 - i32.const 20 - i32.add - local.get $4 - i32.store - local.get $0 - i32.const 24 - i32.add - local.get $4 - i32.store - local.get $0 - local.get $2 - i32.add - i32.const 28 - i32.sub - local.get $4 - i32.store - local.get $0 - local.get $2 - i32.add - i32.const 24 - i32.sub - local.get $4 - i32.store - local.get $0 - local.get $2 - i32.add - i32.const 20 - i32.sub - local.get $4 - i32.store - local.get $0 - local.get $2 - i32.add - i32.const 16 - i32.sub - local.get $4 - i32.store - i32.const 24 - local.get $0 - i32.const 4 - i32.and - i32.add - local.set $3 - local.get $0 - local.get $3 - i32.add - local.set $0 - local.get $2 - local.get $3 - i32.sub - local.set $2 - local.get $4 - i64.extend_i32_u - local.get $4 - i64.extend_i32_u - i64.const 32 - i64.shl - i64.or - local.set $5 - block $break|0 - loop $continue|0 - local.get $2 - i32.const 32 - i32.ge_u + (local $5 i32) + (local $6 i32) + block $~lib/util/memory/memmove|inlined.0 + local.get $0 + local.set $3 + local.get $1 + local.set $4 + local.get $2 + local.set $5 + local.get $3 + local.get $4 + i32.eq + if + br $~lib/util/memory/memmove|inlined.0 + end + local.get $4 + local.get $5 + i32.add + local.get $3 + i32.le_u + local.tee $6 + if (result i32) + local.get $6 + else + local.get $3 + local.get $5 + i32.add + local.get $4 + i32.le_u + end + if + local.get $3 + local.get $4 + local.get $5 + call $~lib/util/memory/memcpy + br $~lib/util/memory/memmove|inlined.0 + end + local.get $3 + local.get $4 + i32.lt_u + if + local.get $4 + i32.const 7 + i32.and + local.get $3 + i32.const 7 + i32.and + i32.eq if - block - local.get $0 - local.get $5 - i64.store - local.get $0 - i32.const 8 - i32.add - local.get $5 - i64.store - local.get $0 - i32.const 16 - i32.add - local.get $5 - i64.store - local.get $0 - i32.const 24 - i32.add - local.get $5 - i64.store - local.get $2 - i32.const 32 - i32.sub - local.set $2 - local.get $0 - i32.const 32 - i32.add - local.set $0 + block $break|0 + loop $continue|0 + local.get $3 + i32.const 7 + i32.and + if + block + local.get $5 + i32.eqz + if + br $~lib/util/memory/memmove|inlined.0 + end + local.get $5 + i32.const 1 + i32.sub + local.set $5 + block (result i32) + local.get $3 + local.tee $6 + i32.const 1 + i32.add + local.set $3 + local.get $6 + end + block (result i32) + local.get $4 + local.tee $6 + i32.const 1 + i32.add + local.set $4 + local.get $6 + end + i32.load8_u + i32.store8 + end + br $continue|0 + end + end + end + block $break|1 + loop $continue|1 + local.get $5 + i32.const 8 + i32.ge_u + if + block + local.get $3 + local.get $4 + i64.load + i64.store + local.get $5 + i32.const 8 + i32.sub + local.set $5 + local.get $3 + i32.const 8 + i32.add + local.set $3 + local.get $4 + i32.const 8 + i32.add + local.set $4 + end + br $continue|1 + end + end + end + end + block $break|2 + loop $continue|2 + local.get $5 + if + block + block (result i32) + local.get $3 + local.tee $6 + i32.const 1 + i32.add + local.set $3 + local.get $6 + end + block (result i32) + local.get $4 + local.tee $6 + i32.const 1 + i32.add + local.set $4 + local.get $6 + end + i32.load8_u + i32.store8 + local.get $5 + i32.const 1 + i32.sub + local.set $5 + end + br $continue|2 + end + end + end + else + local.get $4 + i32.const 7 + i32.and + local.get $3 + i32.const 7 + i32.and + i32.eq + if + block $break|3 + loop $continue|3 + local.get $3 + local.get $5 + i32.add + i32.const 7 + i32.and + if + block + local.get $5 + i32.eqz + if + br $~lib/util/memory/memmove|inlined.0 + end + local.get $3 + local.get $5 + i32.const 1 + i32.sub + local.tee $5 + i32.add + local.get $4 + local.get $5 + i32.add + i32.load8_u + i32.store8 + end + br $continue|3 + end + end + end + block $break|4 + loop $continue|4 + local.get $5 + i32.const 8 + i32.ge_u + if + block + local.get $5 + i32.const 8 + i32.sub + local.set $5 + local.get $3 + local.get $5 + i32.add + local.get $4 + local.get $5 + i32.add + i64.load + i64.store + end + br $continue|4 + end + end + end + end + block $break|5 + loop $continue|5 + local.get $5 + if + local.get $3 + local.get $5 + i32.const 1 + i32.sub + local.tee $5 + i32.add + local.get $4 + local.get $5 + i32.add + i32.load8_u + i32.store8 + br $continue|5 + end end - br $continue|0 end end end ) - (func $~lib/memory/memory.fill (; 29 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) - local.get $0 - local.get $1 - local.get $2 - call $~lib/util/memory/memset + (func $~lib/memory/memory.fill (; 26 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i64) + block $~lib/util/memory/memset|inlined.0 + local.get $0 + local.set $3 + local.get $1 + local.set $4 + local.get $2 + local.set $5 + local.get $5 + i32.eqz + if + br $~lib/util/memory/memset|inlined.0 + end + local.get $3 + local.get $4 + i32.store8 + local.get $3 + local.get $5 + i32.add + i32.const 1 + i32.sub + local.get $4 + i32.store8 + local.get $5 + i32.const 2 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 + end + local.get $3 + i32.const 1 + i32.add + local.get $4 + i32.store8 + local.get $3 + i32.const 2 + i32.add + local.get $4 + i32.store8 + local.get $3 + local.get $5 + i32.add + i32.const 2 + i32.sub + local.get $4 + i32.store8 + local.get $3 + local.get $5 + i32.add + i32.const 3 + i32.sub + local.get $4 + i32.store8 + local.get $5 + i32.const 6 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 + end + local.get $3 + i32.const 3 + i32.add + local.get $4 + i32.store8 + local.get $3 + local.get $5 + i32.add + i32.const 4 + i32.sub + local.get $4 + i32.store8 + local.get $5 + i32.const 8 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 + end + i32.const 0 + local.get $3 + i32.sub + i32.const 3 + i32.and + local.set $6 + local.get $3 + local.get $6 + i32.add + local.set $3 + local.get $5 + local.get $6 + i32.sub + local.set $5 + local.get $5 + i32.const -4 + i32.and + local.set $5 + i32.const -1 + i32.const 255 + i32.div_u + local.get $4 + i32.const 255 + i32.and + i32.mul + local.set $7 + local.get $3 + local.get $7 + i32.store + local.get $3 + local.get $5 + i32.add + i32.const 4 + i32.sub + local.get $7 + i32.store + local.get $5 + i32.const 8 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 + end + local.get $3 + i32.const 4 + i32.add + local.get $7 + i32.store + local.get $3 + i32.const 8 + i32.add + local.get $7 + i32.store + local.get $3 + local.get $5 + i32.add + i32.const 12 + i32.sub + local.get $7 + i32.store + local.get $3 + local.get $5 + i32.add + i32.const 8 + i32.sub + local.get $7 + i32.store + local.get $5 + i32.const 24 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 + end + local.get $3 + i32.const 12 + i32.add + local.get $7 + i32.store + local.get $3 + i32.const 16 + i32.add + local.get $7 + i32.store + local.get $3 + i32.const 20 + i32.add + local.get $7 + i32.store + local.get $3 + i32.const 24 + i32.add + local.get $7 + i32.store + local.get $3 + local.get $5 + i32.add + i32.const 28 + i32.sub + local.get $7 + i32.store + local.get $3 + local.get $5 + i32.add + i32.const 24 + i32.sub + local.get $7 + i32.store + local.get $3 + local.get $5 + i32.add + i32.const 20 + i32.sub + local.get $7 + i32.store + local.get $3 + local.get $5 + i32.add + i32.const 16 + i32.sub + local.get $7 + i32.store + i32.const 24 + local.get $3 + i32.const 4 + i32.and + i32.add + local.set $6 + local.get $3 + local.get $6 + i32.add + local.set $3 + local.get $5 + local.get $6 + i32.sub + local.set $5 + local.get $7 + i64.extend_i32_u + local.get $7 + i64.extend_i32_u + i64.const 32 + i64.shl + i64.or + local.set $8 + block $break|0 + loop $continue|0 + local.get $5 + i32.const 32 + i32.ge_u + if + block + local.get $3 + local.get $8 + i64.store + local.get $3 + i32.const 8 + i32.add + local.get $8 + i64.store + local.get $3 + i32.const 16 + i32.add + local.get $8 + i64.store + local.get $3 + i32.const 24 + i32.add + local.get $8 + i64.store + local.get $5 + i32.const 32 + i32.sub + local.set $5 + local.get $3 + i32.const 32 + i32.add + local.set $3 + end + br $continue|0 + end + end + end + end ) - (func $~lib/allocator/tlsf/__memory_free (; 30 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/memory/memory.free (; 27 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) (local $2 i32) (local $3 i32) + (local $4 i32) local.get $0 + local.set $1 + local.get $1 if global.get $~lib/allocator/tlsf/ROOT - local.set $1 - local.get $1 + local.set $2 + local.get $2 if - local.get $0 + local.get $1 global.get $~lib/allocator/tlsf/Block.INFO i32.sub - local.set $2 - local.get $2 - i32.load local.set $3 local.get $3 + i32.load + local.set $4 + local.get $4 global.get $~lib/allocator/tlsf/FREE i32.and i32.eqz @@ -3212,28 +3226,24 @@ call $~lib/env/abort unreachable end - local.get $2 local.get $3 + local.get $4 global.get $~lib/allocator/tlsf/FREE i32.or i32.store + local.get $2 local.get $1 - local.get $0 global.get $~lib/allocator/tlsf/Block.INFO i32.sub call $~lib/allocator/tlsf/Root#insert end end ) - (func $~lib/memory/memory.free (; 31 ;) (type $FUNCSIG$vi) (param $0 i32) - local.get $0 - call $~lib/allocator/tlsf/__memory_free - ) - (func $std/runtime/__gc_register (; 32 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $std/runtime/__gc_register (; 28 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 global.set $std/runtime/register_ref ) - (func $~lib/runtime/runtime.realloc (; 33 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/runtime/runtime.realloc (; 29 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3337,7 +3347,7 @@ i32.store offset=4 local.get $0 ) - (func $~lib/runtime/runtime.unrefUnregistered (; 34 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/runtime/runtime.unrefUnregistered (; 30 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 global.get $~lib/memory/HEAP_BASE @@ -3372,18 +3382,18 @@ end local.get $1 ) - (func $~lib/runtime/runtime.freeUnregistered (; 35 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/runtime/runtime.freeUnregistered (; 31 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 call $~lib/runtime/runtime.unrefUnregistered call $~lib/memory/memory.free ) - (func $~lib/arraybuffer/ArrayBuffer#get:byteLength (; 36 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#get:byteLength (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.const 16 i32.sub i32.load offset=4 ) - (func $~lib/string/String#get:length (; 37 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String#get:length (; 33 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.const 16 i32.sub @@ -3391,7 +3401,7 @@ i32.const 1 i32.shr_u ) - (func $start:std/runtime (; 38 ;) (type $FUNCSIG$v) + (func $start:std/runtime (; 34 ;) (type $FUNCSIG$v) (local $0 i32) call $start:~lib/allocator/tlsf i32.const 2 @@ -3720,9 +3730,9 @@ unreachable end ) - (func $start (; 39 ;) (type $FUNCSIG$v) + (func $start (; 35 ;) (type $FUNCSIG$v) call $start:std/runtime ) - (func $null (; 40 ;) (type $FUNCSIG$v) + (func $null (; 36 ;) (type $FUNCSIG$v) ) )