inline single-use implementations

This commit is contained in:
dcode 2019-03-14 12:52:46 +01:00
parent 3a60638f72
commit d3ca06b7ce
7 changed files with 1195 additions and 1199 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -423,7 +423,7 @@ var ROOT: Root = changetype<Root>(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;

View File

@ -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<u8>(vl) == load<u8>(vr)) {

View File

@ -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
i32.const 1
i32.add
local.set $2
br $repeat|1
end
end
local.get $1
i32.const 1
i32.add
local.set $1
br $repeat|1
end
end
local.get $0
i32.const 1
i32.add
local.set $0
br $repeat|0
end
end
@ -1075,50 +1076,48 @@
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
local.get $2
i32.const 7
i32.add
i32.const -8
i32.and
local.tee $2
local.tee $0
i32.const 16
local.get $2
local.get $0
i32.const 16
i32.gt_u
select
local.tee $0
local.tee $2
call $~lib/allocator/tlsf/Root#search
local.tee $1
local.tee $0
i32.eqz
if
current_memory
local.tee $2
local.get $0
local.tee $1
local.get $2
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.tee $0
local.get $1
local.get $0
i32.gt_s
select
grow_memory
i32.const 0
i32.lt_s
if
local.get $4
local.get $0
grow_memory
i32.const 0
i32.lt_s
@ -1127,7 +1126,7 @@
end
end
local.get $3
local.get $2
local.get $1
i32.const 16
i32.shl
current_memory
@ -1135,12 +1134,11 @@
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
call $~lib/allocator/tlsf/Root#search
local.tee $0
i32.eqz
if
i32.const 0
i32.const 16
i32.const 467
@ -1148,15 +1146,13 @@
call $~lib/env/abort
unreachable
end
local.set $1
end
local.get $1
local.get $0
i32.load
i32.const -4
i32.and
local.get $0
local.get $2
i32.lt_u
end
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,98 +2090,98 @@
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
block $~lib/util/memory/memmove|inlined.0
local.get $2
i32.add
local.set $3
local.get $1
local.get $0
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 $3
local.tee $0
i32.eqz
if
local.get $0
local.get $2
local.get $3
i32.add
local.get $1
i32.le_u
local.set $3
local.set $0
end
local.get $3
local.get $0
if
local.get $0
local.get $1
local.get $2
local.get $1
local.get $3
call $~lib/util/memory/memcpy
return
br $~lib/util/memory/memmove|inlined.0
end
local.get $0
local.get $2
local.get $1
i32.lt_u
if
local.get $1
i32.const 7
i32.and
local.get $0
local.get $2
i32.const 7
i32.and
i32.eq
if
loop $continue|0
local.get $0
local.get $2
i32.const 7
i32.and
if
local.get $2
local.get $3
i32.eqz
if
return
end
local.get $2
br_if $~lib/util/memory/memmove|inlined.0
local.get $3
i32.const 1
i32.sub
local.set $2
local.get $0
local.set $3
local.get $2
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
local.get $3
i32.const 8
i32.ge_u
if
local.get $0
local.get $2
local.get $1
i64.load
i64.store
local.get $2
local.get $3
i32.const 8
i32.sub
local.set $2
local.get $0
local.set $3
local.get $2
i32.const 8
i32.add
local.set $0
local.set $2
local.get $1
i32.const 8
i32.add
@ -2195,26 +2191,26 @@
end
end
loop $continue|2
local.get $2
local.get $3
if
local.get $0
local.get $2
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
local.get $2
local.get $3
i32.const 1
i32.sub
local.set $2
local.set $3
br $continue|2
end
end
@ -2222,31 +2218,29 @@
local.get $1
i32.const 7
i32.and
local.get $0
local.get $2
i32.const 7
i32.and
i32.eq
if
loop $continue|3
local.get $0
local.get $2
local.get $3
i32.add
i32.const 7
i32.and
if
local.get $2
local.get $3
i32.eqz
if
return
end
local.get $2
br_if $~lib/util/memory/memmove|inlined.0
local.get $3
i32.const 1
i32.sub
local.tee $2
local.get $0
local.tee $3
local.get $2
i32.add
local.get $1
local.get $2
local.get $3
i32.add
i32.load8_u
i32.store8
@ -2254,18 +2248,18 @@
end
end
loop $continue|4
local.get $2
local.get $3
i32.const 8
i32.ge_u
if
local.get $2
local.get $3
i32.const 8
i32.sub
local.tee $2
local.get $0
local.tee $3
local.get $2
i32.add
local.get $1
local.get $2
local.get $3
i32.add
i64.load
i64.store
@ -2274,16 +2268,16 @@
end
end
loop $continue|5
local.get $2
local.get $3
if
local.get $2
local.get $3
i32.const 1
i32.sub
local.tee $2
local.get $0
local.tee $3
local.get $2
i32.add
local.get $1
local.get $2
local.get $3
i32.add
i32.load8_u
i32.store8
@ -2291,14 +2285,14 @@
end
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)
block $~lib/util/memory/memset|inlined.0
local.get $1
i32.eqz
if
return
end
br_if $~lib/util/memory/memset|inlined.0
local.get $0
i32.const 0
i32.store8
@ -2312,9 +2306,7 @@
local.get $1
i32.const 2
i32.le_u
if
return
end
br_if $~lib/util/memory/memset|inlined.0
local.get $0
i32.const 1
i32.add
@ -2341,9 +2333,7 @@
local.get $1
i32.const 6
i32.le_u
if
return
end
br_if $~lib/util/memory/memset|inlined.0
local.get $0
i32.const 3
i32.add
@ -2359,23 +2349,23 @@
local.get $1
i32.const 8
i32.le_u
if
return
end
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
local.get $2
i32.sub
i32.const -4
i32.and
local.tee $1
@ -2388,9 +2378,7 @@
local.get $1
i32.const 8
i32.le_u
if
return
end
br_if $~lib/util/memory/memset|inlined.0
local.get $0
i32.const 4
i32.add
@ -2417,9 +2405,7 @@
local.get $1
i32.const 24
i32.le_u
if
return
end
br_if $~lib/util/memory/memset|inlined.0
local.get $0
i32.const 12
i32.add
@ -2510,13 +2496,9 @@
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
)
)

File diff suppressed because it is too large Load Diff