realloc on mm level

This commit is contained in:
dcode
2019-04-17 17:48:26 +02:00
parent 504e207184
commit ffdda4b695
9 changed files with 1114 additions and 587 deletions

View File

@@ -3,11 +3,11 @@
(type $FUNCSIG$i (func (result i32)))
(type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32)))
(type $FUNCSIG$vii (func (param i32 i32)))
(type $FUNCSIG$viiii (func (param i32 i32 i32 i32)))
(type $FUNCSIG$iii (func (param i32 i32) (result i32)))
(type $FUNCSIG$viiii (func (param i32 i32 i32 i32)))
(type $FUNCSIG$viii (func (param i32 i32 i32)))
(type $FUNCSIG$vi (func (param i32)))
(type $FUNCSIG$v (func))
(type $FUNCSIG$viii (func (param i32 i32 i32)))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
(memory $0 1)
(data (i32.const 8) "\10\00\00\00\"")
@@ -19,6 +19,7 @@
(global $assembly/index/ROOTS (mut i32) (i32.const 0))
(export "memory" (memory $0))
(export "__mm_allocate" (func $assembly/index/__mm_allocate))
(export "__mm_reallocate" (func $assembly/index/__mm_reallocate))
(export "__mm_free" (func $assembly/index/__mm_free))
(export "__rt_visit" (func $assembly/index/__rt_visit))
(export "__gc_retain" (func $assembly/index/__gc_retain))
@@ -497,7 +498,33 @@
call $assembly/index/addMemory
local.get $0
)
(func $assembly/index/searchBlock (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(func $assembly/index/prepareSize (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(local $1 i32)
local.get $0
i32.const 1073741824
i32.ge_u
if
i32.const 0
i32.const 24
i32.const 466
i32.const 29
call $~lib/builtins/abort
unreachable
end
local.get $0
i32.const 15
i32.add
i32.const -16
i32.and
local.tee $0
i32.const 16
local.tee $1
local.get $0
local.get $1
i32.gt_u
select
)
(func $assembly/index/searchBlock (; 6 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
local.get $0
local.get $1
@@ -598,7 +625,7 @@
end
end
)
(func $assembly/index/growMemory (; 6 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
(func $assembly/index/growMemory (; 7 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
@@ -639,16 +666,12 @@
i32.shl
call $assembly/index/addMemory
)
(func $assembly/index/prepareBlock (; 7 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $assembly/index/prepareBlock (; 8 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
local.get $1
i32.load
local.set $3
local.get $0
local.get $1
call $assembly/index/removeBlock
local.get $3
local.tee $3
i32.const -4
i32.and
local.get $2
@@ -669,7 +692,7 @@
i32.add
local.get $2
i32.add
local.tee $2
local.tee $1
local.get $4
i32.const 16
i32.sub
@@ -677,7 +700,7 @@
i32.or
i32.store
local.get $0
local.get $2
local.get $1
call $assembly/index/insertBlock
else
local.get $1
@@ -706,73 +729,347 @@
i32.and
i32.store
end
local.get $1
i32.const 16
i32.add
)
(func $assembly/index/__mm_allocate (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(local $1 i32)
(func $assembly/index/allocateBlock (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
global.get $assembly/index/ROOT
(local $3 i32)
local.get $0
local.get $1
call $assembly/index/prepareSize
local.tee $3
call $assembly/index/searchBlock
local.tee $2
i32.eqz
if
call $assembly/index/initialize
local.tee $2
global.set $assembly/index/ROOT
end
local.get $0
i32.const 1073741824
i32.ge_u
if
i32.const 0
i32.const 24
i32.const 495
i32.const 29
call $~lib/builtins/abort
unreachable
local.get $0
local.get $3
call $assembly/index/growMemory
local.get $0
local.get $3
call $assembly/index/searchBlock
local.set $2
end
local.get $2
local.get $0
i32.const 15
i32.add
i32.const -16
i32.and
local.tee $0
i32.const 16
local.tee $1
local.get $0
local.get $1
i32.gt_u
select
local.tee $1
call $assembly/index/searchBlock
local.tee $0
i32.eqz
if
local.get $2
local.get $1
call $assembly/index/growMemory
local.get $2
local.get $1
call $assembly/index/searchBlock
local.set $0
end
local.get $0
i32.const 0
i32.store offset=4
local.get $0
local.get $2
i32.const 0
i32.store offset=8
local.get $0
local.get $2
local.get $1
i32.store offset=12
local.get $0
local.get $2
call $assembly/index/removeBlock
local.get $0
local.get $2
local.get $3
call $assembly/index/prepareBlock
local.get $2
)
(func $assembly/index/__mm_allocate (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(local $1 i32)
global.get $assembly/index/ROOT
local.tee $1
i32.eqz
if
call $assembly/index/initialize
local.tee $1
global.set $assembly/index/ROOT
end
local.get $1
local.get $0
call $assembly/index/allocateBlock
i32.const 16
i32.add
)
(func $~lib/memory/memory.copy (; 11 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
block $~lib/util/memory/memmove|inlined.0
local.get $0
local.get $1
i32.eq
br_if $~lib/util/memory/memmove|inlined.0
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
loop $continue|0
local.get $0
i32.const 7
i32.and
if
local.get $2
i32.eqz
br_if $~lib/util/memory/memmove|inlined.0
local.get $2
i32.const 1
i32.sub
local.set $2
local.get $0
local.tee $3
i32.const 1
i32.add
local.set $0
local.get $3
block (result i32)
local.get $1
local.tee $3
i32.const 1
i32.add
local.set $1
local.get $3
i32.load8_u
end
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 $3
i32.const 1
i32.add
local.set $0
local.get $3
block (result i32)
local.get $1
local.tee $3
i32.const 1
i32.add
local.set $1
local.get $3
i32.load8_u
end
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
br_if $~lib/util/memory/memmove|inlined.0
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|3
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 $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 $assembly/index/reallocateBlock (; 12 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
local.get $2
call $assembly/index/prepareSize
local.tee $3
local.get $1
i32.load
local.tee $4
i32.const -4
i32.and
i32.le_u
if
local.get $0
local.get $1
local.get $3
call $assembly/index/prepareBlock
local.get $1
local.get $2
i32.store offset=12
local.get $1
return
end
local.get $1
i32.const 16
i32.add
local.get $1
i32.load
i32.const -4
i32.and
i32.add
local.tee $6
i32.load
local.tee $5
i32.const 1
i32.and
if
local.get $4
i32.const -4
i32.and
i32.const 16
i32.add
local.get $5
i32.const -4
i32.and
i32.add
local.tee $5
local.get $3
i32.ge_u
if
local.get $0
local.get $6
call $assembly/index/removeBlock
local.get $1
local.get $4
i32.const 3
i32.and
local.get $5
i32.or
i32.store
local.get $1
local.get $2
i32.store offset=12
local.get $0
local.get $1
local.get $3
call $assembly/index/prepareBlock
local.get $1
return
end
end
local.get $0
local.get $2
call $assembly/index/allocateBlock
local.tee $3
local.get $1
i32.load offset=4
i32.store offset=4
local.get $3
local.get $1
i32.load offset=8
i32.store offset=8
local.get $3
i32.const 16
i32.add
local.get $1
i32.const 16
i32.add
local.get $2
call $~lib/memory/memory.copy
local.get $1
local.get $4
i32.const 1
i32.or
i32.store
local.get $0
local.get $1
call $assembly/index/prepareBlock
call $assembly/index/insertBlock
local.get $3
)
(func $assembly/index/freeBlock (; 9 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
(func $assembly/index/__mm_reallocate (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
global.get $assembly/index/ROOT
local.get $0
i32.const 16
i32.sub
local.get $1
call $assembly/index/reallocateBlock
i32.const 16
i32.add
)
(func $assembly/index/freeBlock (; 14 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
local.get $1
local.get $1
i32.load
@@ -783,22 +1080,14 @@
local.get $1
call $assembly/index/insertBlock
)
(func $assembly/index/__mm_free (; 10 ;) (type $FUNCSIG$vi) (param $0 i32)
(local $1 i32)
(func $assembly/index/__mm_free (; 15 ;) (type $FUNCSIG$vi) (param $0 i32)
global.get $assembly/index/ROOT
local.get $0
if
global.get $assembly/index/ROOT
local.tee $1
if
local.get $1
local.get $0
i32.const 16
i32.sub
call $assembly/index/freeBlock
end
end
i32.const 16
i32.sub
call $assembly/index/freeBlock
)
(func $assembly/index/decrement (; 11 ;) (type $FUNCSIG$vi) (param $0 i32)
(func $assembly/index/decrement (; 16 ;) (type $FUNCSIG$vi) (param $0 i32)
local.get $0
i32.load offset=4
i32.const 268435455
@@ -813,7 +1102,7 @@
end
unreachable
)
(func $assembly/index/markGray (; 12 ;) (type $FUNCSIG$vi) (param $0 i32)
(func $assembly/index/markGray (; 17 ;) (type $FUNCSIG$vi) (param $0 i32)
(local $1 i32)
local.get $0
i32.load offset=4
@@ -833,7 +1122,7 @@
unreachable
end
)
(func $assembly/index/scanBlack (; 13 ;) (type $FUNCSIG$vi) (param $0 i32)
(func $assembly/index/scanBlack (; 18 ;) (type $FUNCSIG$vi) (param $0 i32)
local.get $0
local.get $0
i32.load offset=4
@@ -842,7 +1131,7 @@
i32.store offset=4
unreachable
)
(func $assembly/index/scan (; 14 ;) (type $FUNCSIG$vi) (param $0 i32)
(func $assembly/index/scan (; 19 ;) (type $FUNCSIG$vi) (param $0 i32)
(local $1 i32)
local.get $0
i32.load offset=4
@@ -872,7 +1161,7 @@
end
end
)
(func $assembly/index/collectWhite (; 15 ;) (type $FUNCSIG$vi) (param $0 i32)
(func $assembly/index/collectWhite (; 20 ;) (type $FUNCSIG$vi) (param $0 i32)
(local $1 i32)
local.get $0
i32.load offset=4
@@ -894,7 +1183,7 @@
local.get $0
call $assembly/index/freeBlock
)
(func $assembly/index/__rt_visit (; 16 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
(func $assembly/index/__rt_visit (; 21 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
block $break|0
block $case4|0
block $case3|0
@@ -944,7 +1233,7 @@
call $assembly/index/collectWhite
end
)
(func $assembly/index/__gc_retain (; 17 ;) (type $FUNCSIG$vi) (param $0 i32)
(func $assembly/index/__gc_retain (; 22 ;) (type $FUNCSIG$vi) (param $0 i32)
local.get $0
if
local.get $0
@@ -958,7 +1247,7 @@
i32.store offset=4
end
)
(func $assembly/index/__gc_release (; 18 ;) (type $FUNCSIG$vi) (param $0 i32)
(func $assembly/index/__gc_release (; 23 ;) (type $FUNCSIG$vi) (param $0 i32)
local.get $0
if
local.get $0
@@ -967,7 +1256,7 @@
call $assembly/index/decrement
end
)
(func $assembly/index/collectCycles (; 19 ;) (type $FUNCSIG$v)
(func $assembly/index/collectCycles (; 24 ;) (type $FUNCSIG$v)
(local $0 i32)
(local $1 i32)
(local $2 i32)
@@ -1089,7 +1378,7 @@
local.get $5
global.set $assembly/index/CUR
)
(func $null (; 20 ;) (type $FUNCSIG$v)
(func $null (; 25 ;) (type $FUNCSIG$v)
nop
)
)