Unify allocator tests even more, also test arena

This commit is contained in:
dcodeIO 2018-03-04 17:25:32 +01:00
parent 4257273d42
commit 00c4f6fa52
36 changed files with 3463 additions and 2977 deletions

2
dist/asc.js vendored

File diff suppressed because one or more lines are too long

2
dist/asc.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,25 +5,28 @@
* sure that there are no more references to cleared memory afterwards. Always aligns to 8 bytes. * sure that there are no more references to cleared memory afterwards. Always aligns to 8 bytes.
*/ */
const ALIGN_LOG2: usize = 3; const AL_BITS: usize = 3;
const ALIGN_SIZE: usize = 1 << ALIGN_LOG2; const AL_SIZE: usize = 1 << AL_BITS;
const ALIGN_MASK: usize = ALIGN_SIZE - 1; const AL_MASK: usize = AL_SIZE - 1;
var HEAP_OFFSET: usize = HEAP_BASE; var OFFSET: usize = (HEAP_BASE + AL_MASK) & ~AL_MASK;
@global @global
export function allocate_memory(size: usize): usize { export function allocate_memory(size: usize): usize {
if (!size) return 0; if (!size) return 0;
var ptr = HEAP_OFFSET; var ptr = OFFSET;
var off = (ptr + size + ALIGN_MASK) & ~ALIGN_MASK; var newPtr = (ptr + size + AL_MASK) & ~AL_MASK;
var avail = <usize>current_memory() << 16; var pagesBefore = current_memory();
if (off > avail && grow_memory( if (newPtr > <usize>pagesBefore << 16) {
<i32>max( var pagesNeeded = ((newPtr - ptr + 0xffff) & ~0xffff) >>> 16;
(((off + 0xffff) & ~0xffff) - avail) >> 16, // minimum required pages var pagesWanted = max(pagesBefore, pagesNeeded); // double memory
avail >> 16 // at least double memory if (grow_memory(pagesWanted) < 0) {
) if (grow_memory(pagesNeeded) < 0) {
) < 0) unreachable(); // out of memory unreachable(); // out of memory
HEAP_OFFSET = off; }
}
}
OFFSET = newPtr;
return ptr; return ptr;
} }
@ -34,5 +37,5 @@ export function free_memory(ptr: usize): void {
@global @global
export function reset_memory(): void { export function reset_memory(): void {
HEAP_OFFSET = HEAP_BASE; OFFSET = (HEAP_BASE + AL_MASK) & ~AL_MASK;
} }

View File

@ -0,0 +1,3 @@
import "allocator/arena";
export { allocate_memory, free_memory, reset_memory };
// export { set_memory };

View File

@ -0,0 +1,6 @@
{
"extends": "../../../../std/assembly.json",
"include": [
"./**/*.ts"
]
}

View File

@ -0,0 +1,151 @@
(module
(type $ii (func (param i32) (result i32)))
(type $iv (func (param i32)))
(type $v (func))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "allocate_memory" (func "$(lib)/allocator/arena/allocate_memory"))
(export "free_memory" (func "$(lib)/allocator/arena/free_memory"))
(export "reset_memory" (func "$(lib)/allocator/arena/reset_memory"))
(export "memory" (memory $0))
(start $(lib)/allocator/arena/reset_memory)
(func "$(lib)/allocator/arena/allocate_memory" (; 0 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
;;@ (lib)/allocator/arena.ts:16:2
(if
;;@ (lib)/allocator/arena.ts:16:6
(i32.eqz
;;@ (lib)/allocator/arena.ts:16:7
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:16:20
(return
(i32.const 0)
)
)
;;@ (lib)/allocator/arena.ts:20:2
(if
;;@ (lib)/allocator/arena.ts:20:6
(i32.gt_u
;;@ (lib)/allocator/arena.ts:18:2
(tee_local $2
;;@ (lib)/allocator/arena.ts:18:15
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:18:16
(i32.add
;;@ (lib)/allocator/arena.ts:17:2
(tee_local $1
;;@ (lib)/allocator/arena.ts:17:12
(get_global "$(lib)/allocator/arena/OFFSET")
)
;;@ (lib)/allocator/arena.ts:18:22
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:18:29
(i32.const 7)
)
(i32.const -8)
)
)
;;@ (lib)/allocator/arena.ts:20:15
(i32.shl
;;@ (lib)/allocator/arena.ts:19:2
(tee_local $0
;;@ (lib)/allocator/arena.ts:19:20
(current_memory)
)
;;@ (lib)/allocator/arena.ts:20:37
(i32.const 16)
)
)
;;@ (lib)/allocator/arena.ts:23:4
(if
;;@ (lib)/allocator/arena.ts:23:8
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:22:22
(select
;;@ (lib)/allocator/arena.ts:22:26
(get_local $0)
(tee_local $4
;;@ (lib)/allocator/arena.ts:21:4
(tee_local $3
;;@ (lib)/allocator/arena.ts:21:22
(i32.shr_u
(i32.and
;;@ (lib)/allocator/arena.ts:21:23
(i32.add
;;@ (lib)/allocator/arena.ts:21:24
(i32.sub
(get_local $2)
;;@ (lib)/allocator/arena.ts:21:33
(get_local $1)
)
;;@ (lib)/allocator/arena.ts:21:39
(i32.const 65535)
)
(i32.const -65536)
)
;;@ (lib)/allocator/arena.ts:21:62
(i32.const 16)
)
)
)
(i32.gt_s
(get_local $0)
(get_local $4)
)
)
)
;;@ (lib)/allocator/arena.ts:23:35
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:24:6
(if
;;@ (lib)/allocator/arena.ts:24:10
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:24:22
(get_local $3)
)
;;@ (lib)/allocator/arena.ts:24:37
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:25:8
(unreachable)
)
)
)
;;@ (lib)/allocator/arena.ts:29:2
(set_global "$(lib)/allocator/arena/OFFSET"
;;@ (lib)/allocator/arena.ts:29:11
(get_local $2)
)
;;@ (lib)/allocator/arena.ts:30:9
(get_local $1)
)
(func "$(lib)/allocator/arena/free_memory" (; 1 ;) (type $iv) (param $0 i32)
;;@ (lib)/allocator/arena.ts:34:46
(nop)
)
(func "$(lib)/allocator/arena/reset_memory" (; 2 ;) (type $v)
;;@ (lib)/allocator/arena.ts:40:2
(set_global "$(lib)/allocator/arena/OFFSET"
;;@ (lib)/allocator/arena.ts:40:11
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:40:12
(get_global $HEAP_BASE)
;;@ (lib)/allocator/arena.ts:40:24
(i32.const 7)
)
(i32.const -8)
)
)
)
)

View File

@ -0,0 +1,8 @@
{
"private": true,
"scripts": {
"build": "npm run build:untouched && npm run build:optimized",
"build:untouched": "asc assembly/index.ts -t untouched.wat -b untouched.wasm --validate --sourceMap --measure",
"build:optimized": "asc assembly/index.ts -t optimized.wat -b optimized.wasm --validate --sourceMap --measure --noDebug --noAssert --optimize"
}
}

View File

@ -0,0 +1,207 @@
(module
(type $i (func (result i32)))
(type $ii (func (param i32) (result i32)))
(type $iv (func (param i32)))
(type $v (func))
(global "$(lib)/allocator/arena/AL_BITS" i32 (i32.const 3))
(global "$(lib)/allocator/arena/AL_SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/arena/AL_MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "allocate_memory" (func "$(lib)/allocator/arena/allocate_memory"))
(export "free_memory" (func "$(lib)/allocator/arena/free_memory"))
(export "reset_memory" (func "$(lib)/allocator/arena/reset_memory"))
(export "memory" (memory $0))
(start $start)
(func "$(lib)/allocator/arena/allocate_memory" (; 0 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(local $7 i32)
;;@ (lib)/allocator/arena.ts:16:2
(if
;;@ (lib)/allocator/arena.ts:16:6
(i32.eqz
;;@ (lib)/allocator/arena.ts:16:7
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:16:20
(return
(i32.const 0)
)
)
;;@ (lib)/allocator/arena.ts:17:2
(set_local $1
;;@ (lib)/allocator/arena.ts:17:12
(get_global "$(lib)/allocator/arena/OFFSET")
)
;;@ (lib)/allocator/arena.ts:18:2
(set_local $2
;;@ (lib)/allocator/arena.ts:18:15
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:18:16
(i32.add
(get_local $1)
;;@ (lib)/allocator/arena.ts:18:22
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:18:29
(i32.const 7)
)
;;@ (lib)/allocator/arena.ts:18:40
(i32.xor
;;@ (lib)/allocator/arena.ts:18:41
(i32.const 7)
(i32.const -1)
)
)
)
;;@ (lib)/allocator/arena.ts:19:2
(set_local $3
;;@ (lib)/allocator/arena.ts:19:20
(current_memory)
)
;;@ (lib)/allocator/arena.ts:20:2
(if
;;@ (lib)/allocator/arena.ts:20:6
(i32.gt_u
(get_local $2)
;;@ (lib)/allocator/arena.ts:20:15
(i32.shl
(get_local $3)
;;@ (lib)/allocator/arena.ts:20:37
(i32.const 16)
)
)
;;@ (lib)/allocator/arena.ts:20:41
(block
;;@ (lib)/allocator/arena.ts:21:4
(set_local $4
;;@ (lib)/allocator/arena.ts:21:22
(i32.shr_u
(i32.and
;;@ (lib)/allocator/arena.ts:21:23
(i32.add
;;@ (lib)/allocator/arena.ts:21:24
(i32.sub
(get_local $2)
;;@ (lib)/allocator/arena.ts:21:33
(get_local $1)
)
;;@ (lib)/allocator/arena.ts:21:39
(i32.const 65535)
)
;;@ (lib)/allocator/arena.ts:21:49
(i32.xor
;;@ (lib)/allocator/arena.ts:21:50
(i32.const 65535)
(i32.const -1)
)
)
;;@ (lib)/allocator/arena.ts:21:62
(i32.const 16)
)
)
;;@ (lib)/allocator/arena.ts:22:4
(set_local $7
;;@ (lib)/allocator/arena.ts:22:22
(select
(tee_local $5
;;@ (lib)/allocator/arena.ts:22:26
(get_local $3)
)
(tee_local $6
;;@ (lib)/allocator/arena.ts:22:39
(get_local $4)
)
(i32.gt_s
(get_local $5)
(get_local $6)
)
)
)
;;@ (lib)/allocator/arena.ts:23:4
(if
;;@ (lib)/allocator/arena.ts:23:8
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:23:20
(get_local $7)
)
;;@ (lib)/allocator/arena.ts:23:35
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:24:6
(if
;;@ (lib)/allocator/arena.ts:24:10
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:24:22
(get_local $4)
)
;;@ (lib)/allocator/arena.ts:24:37
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:25:8
(unreachable)
)
)
)
)
;;@ (lib)/allocator/arena.ts:29:2
(set_global "$(lib)/allocator/arena/OFFSET"
;;@ (lib)/allocator/arena.ts:29:11
(get_local $2)
)
;;@ (lib)/allocator/arena.ts:30:9
(return
(get_local $1)
)
)
(func "$(lib)/allocator/arena/free_memory" (; 1 ;) (type $iv) (param $0 i32)
)
(func "$(lib)/allocator/arena/reset_memory" (; 2 ;) (type $v)
;;@ (lib)/allocator/arena.ts:40:2
(set_global "$(lib)/allocator/arena/OFFSET"
;;@ (lib)/allocator/arena.ts:40:11
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:40:12
(get_global $HEAP_BASE)
;;@ (lib)/allocator/arena.ts:40:24
(i32.const 7)
)
;;@ (lib)/allocator/arena.ts:40:35
(i32.xor
;;@ (lib)/allocator/arena.ts:40:36
(i32.const 7)
(i32.const -1)
)
)
)
)
(func $start (; 3 ;) (type $v)
(set_global "$(lib)/allocator/arena/OFFSET"
;;@ (lib)/allocator/arena.ts:12:20
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:12:21
(get_global $HEAP_BASE)
;;@ (lib)/allocator/arena.ts:12:33
(i32.const 7)
)
;;@ (lib)/allocator/arena.ts:12:44
(i32.xor
;;@ (lib)/allocator/arena.ts:12:45
(i32.const 7)
(i32.const -1)
)
)
)
)
)

View File

@ -1,3 +1,3 @@
import "./buddy"; import "allocator/buddy";
export { allocate_memory, free_memory }; export { allocate_memory, free_memory };
// export { set_memory }; // export { set_memory };

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,7 @@
"private": true, "private": true,
"scripts": { "scripts": {
"build": "npm run build:untouched && npm run build:optimized", "build": "npm run build:untouched && npm run build:optimized",
"build:untouched": "asc assembly/index.ts -t buddy.untouched.wat -b buddy.untouched.wasm --validate --sourceMap --measure", "build:untouched": "asc assembly/index.ts -t untouched.wat -b untouched.wasm --validate --sourceMap --measure",
"build:optimized": "asc assembly/index.ts -t buddy.optimized.wat -b buddy.optimized.wasm --validate --sourceMap --measure --noDebug --noAssert --optimize", "build:optimized": "asc assembly/index.ts -t optimized.wat -b optimized.wasm --validate --sourceMap --measure --noDebug --noAssert --optimize"
"test": "node ./index",
"test:forever": "node ../forever buddy"
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -2,13 +2,15 @@ var child_process = require("child_process");
// restarts the test forever, that is, until an issue is detected // restarts the test forever, that is, until an issue is detected
if (process.argv.length < 2) {
console.error("Usage: npm run test:forever <allocator>");
process.exit(1);
}
var count = 0; var count = 0;
while (true) { while (true) {
console.log("[ #" + ++count + " ]\n"); console.log("[ #" + ++count + " ]\n");
var script = process.argv.length > 2 var res = child_process.spawnSync("node", [ "./index", process.argv[2] ], { stdio: "inherit" });
? __dirname + "/" + process.argv[2]
: __dirname;
var res = child_process.spawnSync("node", [ script ], { stdio: "inherit" });
if (res.status !== 0) if (res.status !== 0)
throw Error("exited with " + res.status); throw Error("exited with " + res.status);
if (res.error) if (res.error)

View File

@ -19,11 +19,16 @@ function test(file) {
return String.fromCharCode.apply(String, str); return String.fromCharCode.apply(String, str);
} }
require("../runner")(exports, 50, 20000); require("./runner")(exports, 50, 20000);
console.log("mem final: " + exports.memory.buffer.byteLength); console.log("mem final: " + exports.memory.buffer.byteLength);
console.log(); console.log();
} }
test("buddy.untouched.wasm"); if (process.argv.length > 2) {
test("buddy.optimized.wasm"); test(process.argv[2] + "/untouched.wasm");
test(process.argv[2] + "/optimized.wasm");
} else {
console.error("Usage: npm test <allocator>");
process.exit(1);
}

View File

@ -0,0 +1,7 @@
{
"private": true,
"scripts": {
"test": "node ./index",
"test:forever": "node ./forever"
}
}

View File

@ -1,4 +1,7 @@
function runner(allocator, runs, allocs) { function runner(allocator, runs, allocs) {
var hasReset = !!allocator.reset_memory;
var useSet = !!allocator.set_memory;
console.log("hasReset=" + hasReset + ", useSet=" + useSet);
var ptrs = []; var ptrs = [];
function randomAlloc(maxSize) { function randomAlloc(maxSize) {
@ -9,7 +12,7 @@ function runner(allocator, runs, allocs) {
if (!ptr) throw Error(); if (!ptr) throw Error();
if ((ptr & 7) != 0) throw Error("invalid alignment: " + (ptr & 7) + " on " + ptr); if ((ptr & 7) != 0) throw Error("invalid alignment: " + (ptr & 7) + " on " + ptr);
if (ptrs.indexOf(ptr) >= 0) throw Error("duplicate pointer"); if (ptrs.indexOf(ptr) >= 0) throw Error("duplicate pointer");
if (allocator.set_memory) if (useSet)
allocator.set_memory(ptr, 0xdc, size); allocator.set_memory(ptr, 0xdc, size);
ptrs.push(ptr); ptrs.push(ptr);
return ptr; return ptr;
@ -35,7 +38,11 @@ function runner(allocator, runs, allocs) {
// remember the smallest possible memory address // remember the smallest possible memory address
var base = allocator.allocate_memory(64); var base = allocator.allocate_memory(64);
console.log("base: " + base); console.log("base: " + base);
allocator.free_memory(base); if (hasReset) {
allocator.reset_memory();
} else {
allocator.free_memory(base);
}
var currentMem = allocator.memory.buffer.byteLength; var currentMem = allocator.memory.buffer.byteLength;
console.log("mem initial: " + currentMem); console.log("mem initial: " + currentMem);
@ -65,16 +72,24 @@ function runner(allocator, runs, allocs) {
// free the rest, randomly // free the rest, randomly
while (ptrs.length) randomFree(); while (ptrs.length) randomFree();
// should now be possible to reuse the entire memory if (hasReset) {
// just try a large portion of the memory here, for example because of allocator.reset_memory();
// SL+1 for allocations in TLSF var ptr = allocator.allocate_memory(64);
var size = ((allocator.memory.buffer.byteLength - base) * 9 / 10) >>> 0; if (ptr !== base)
var ptr = allocator.allocate_memory(size); throw Error("expected " + base + " but got " + ptr);
if (allocator.set_memory) allocator.reset_memory();
allocator.set_memory(ptr, 0xac, size); } else {
if (ptr !== base) // should now be possible to reuse the entire memory
throw Error("expected " + base + " but got " + ptr); // just try a large portion of the memory here, for example because of
allocator.free_memory(ptr); // SL+1 for allocations in TLSF
var size = ((allocator.memory.buffer.byteLength - base) * 9 / 10) >>> 0;
var ptr = allocator.allocate_memory(size);
if (useSet)
allocator.set_memory(ptr, 0xac, size);
if (ptr !== base)
throw Error("expected " + base + " but got " + ptr);
allocator.free_memory(ptr);
}
testMemChanged(); testMemChanged();
} }
} finally { } finally {

View File

@ -1,28 +0,0 @@
const fs = require("fs");
function test(file) {
console.log("Testing '" + file + "' ...\n");
const exports = new WebAssembly.Instance(WebAssembly.Module(fs.readFileSync(__dirname + "/" + file)), {
env: {
abort: function(msg, file, line, column) {
throw Error("Assertion failed: " + (msg ? "'" + getString(msg) + "' " : "") + "at " + getString(file) + ":" + line + ":" + column);
},
log: function(ptr) { console.log(getString(ptr)); },
logi: function(i) { console.log(i); }
}
}).exports;
function getString(ptr) {
var len = new Uint32Array(exports.memory.buffer, ptr)[0];
var str = new Uint16Array(exports.memory.buffer, ptr + 4).subarray(0, len);
return String.fromCharCode.apply(String, str);
}
require("../runner")(exports, 50, 20000); // picked so I/O isn't the bottleneck
console.log("mem final: " + exports.memory.buffer.byteLength);
console.log();
}
test("tlsf.untouched.wasm");
test("tlsf.optimized.wasm");

View File

@ -2,9 +2,7 @@
"private": true, "private": true,
"scripts": { "scripts": {
"build": "npm run build:untouched && npm run build:optimized", "build": "npm run build:untouched && npm run build:optimized",
"build:untouched": "asc assembly/index.ts -t tlsf.untouched.wat -b tlsf.untouched.wasm --validate --sourceMap --measure", "build:untouched": "asc assembly/index.ts -t untouched.wat -b untouched.wasm --validate --sourceMap --measure",
"build:optimized": "asc assembly/index.ts -t tlsf.optimized.wat -b tlsf.optimized.wasm --validate --sourceMap --measure --noDebug --noAssert --optimize", "build:optimized": "asc assembly/index.ts -t optimized.wat -b optimized.wasm --validate --sourceMap --measure --noDebug --noAssert --optimize"
"test": "node ./index",
"test:forever": "node ../forever tlsf"
} }
} }

View File

@ -1,9 +1,4 @@
(module (module
(type $v (func))
(memory $0 1) (memory $0 1)
(export "memory" (memory $0)) (export "memory" (memory $0))
(start $start)
(func $start (; 0 ;) (type $v)
(nop)
)
) )

View File

@ -1,9 +1,4 @@
(module (module
(type $v (func))
(memory $0 1) (memory $0 1)
(export "memory" (memory $0)) (export "memory" (memory $0))
(start $start)
(func $start (; 0 ;) (type $v)
(nop)
)
) )

View File

@ -6,7 +6,7 @@
(type $iv (func (param i32))) (type $iv (func (param i32)))
(type $v (func)) (type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/HEAP_OFFSET" (mut i32) (i32.const 0)) (global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global $std/allocator_arena/ptr1 (mut i32) (i32.const 0)) (global $std/allocator_arena/ptr1 (mut i32) (i32.const 0))
(global $std/allocator_arena/ptr2 (mut i32) (i32.const 0)) (global $std/allocator_arena/ptr2 (mut i32) (i32.const 0))
(global $std/allocator_arena/i (mut i32) (i32.const 0)) (global $std/allocator_arena/i (mut i32) (i32.const 0))
@ -19,6 +19,7 @@
(local $1 i32) (local $1 i32)
(local $2 i32) (local $2 i32)
(local $3 i32) (local $3 i32)
(local $4 i32)
(if (if
(i32.eqz (i32.eqz
(get_local $0) (get_local $0)
@ -28,74 +29,73 @@
) )
) )
(if (if
(i32.and (i32.gt_u
(if (result i32) (tee_local $2
(i32.and
(i32.add
(i32.add
(tee_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
)
(get_local $0)
)
(i32.const 7)
)
(i32.const -8)
)
)
(i32.shl
(tee_local $0 (tee_local $0
(i32.gt_u (current_memory)
(tee_local $2 )
(i32.and (i32.const 16)
(i32.add )
(i32.add )
(tee_local $3 (if
(get_global "$(lib)/allocator/arena/HEAP_OFFSET") (i32.lt_s
(grow_memory
(select
(get_local $0)
(tee_local $4
(tee_local $3
(i32.shr_u
(i32.and
(i32.add
(i32.sub
(get_local $2)
(get_local $1)
)
(i32.const 65535)
) )
(get_local $0) (i32.const -65536)
) )
(i32.const 7) (i32.const 16)
) )
(i32.const -8)
) )
) )
(tee_local $1 (i32.gt_s
(i32.shl (get_local $0)
(current_memory) (get_local $4)
(i32.const 16)
)
) )
) )
) )
(i32.const 0)
)
(if
(i32.lt_s (i32.lt_s
(grow_memory (grow_memory
(select (get_local $3)
(tee_local $0
(i32.shr_u
(i32.sub
(i32.and
(i32.add
(get_local $2)
(i32.const 65535)
)
(i32.const -65536)
)
(get_local $1)
)
(i32.const 16)
)
)
(tee_local $1
(i32.shr_u
(get_local $1)
(i32.const 16)
)
)
(i32.gt_u
(get_local $0)
(get_local $1)
)
)
) )
(i32.const 0) (i32.const 0)
) )
(get_local $0) (unreachable)
) )
(i32.const 1)
) )
(unreachable)
) )
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_local $2) (get_local $2)
) )
(get_local $3) (get_local $1)
) )
(func "$(lib)/memory/set_memory" (; 2 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (func "$(lib)/memory/set_memory" (; 2 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i64) (local $3 i64)
@ -2360,13 +2360,25 @@
(nop) (nop)
) )
(func "$(lib)/allocator/arena/reset_memory" (; 7 ;) (type $v) (func "$(lib)/allocator/arena/reset_memory" (; 7 ;) (type $v)
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.const -8)
)
) )
) )
(func $start (; 8 ;) (type $v) (func $start (; 8 ;) (type $v)
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.const -8)
)
) )
(set_global $std/allocator_arena/ptr1 (set_global $std/allocator_arena/ptr1
(call "$(lib)/allocator/arena/allocate_memory" (call "$(lib)/allocator/arena/allocate_memory"
@ -2514,7 +2526,13 @@
(if (if
(i32.ne (i32.ne
(get_global $std/allocator_arena/ptr1) (get_global $std/allocator_arena/ptr1)
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.const -8)
)
) )
(block (block
(call $abort (call $abort

View File

@ -24,4 +24,4 @@ free_memory(ptr2);
reset_memory(); reset_memory();
ptr1 = allocate_memory(size); ptr1 = allocate_memory(size);
assert(ptr1 == HEAP_BASE); assert(ptr1 == ((HEAP_BASE + 7) & ~7));

View File

@ -7,10 +7,10 @@
(type $iv (func (param i32))) (type $iv (func (param i32)))
(type $v (func)) (type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/ALIGN_LOG2" i32 (i32.const 3)) (global "$(lib)/allocator/arena/AL_BITS" i32 (i32.const 3))
(global "$(lib)/allocator/arena/ALIGN_SIZE" i32 (i32.const 8)) (global "$(lib)/allocator/arena/AL_SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/arena/ALIGN_MASK" i32 (i32.const 7)) (global "$(lib)/allocator/arena/AL_MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/HEAP_OFFSET" (mut i32) (i32.const 0)) (global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global $std/allocator_arena/size i32 (i32.const 42)) (global $std/allocator_arena/size i32 (i32.const 42))
(global $std/allocator_arena/ptr1 (mut i32) (i32.const 0)) (global $std/allocator_arena/ptr1 (mut i32) (i32.const 0))
(global $std/allocator_arena/ptr2 (mut i32) (i32.const 0)) (global $std/allocator_arena/ptr2 (mut i32) (i32.const 0))
@ -26,6 +26,8 @@
(local $3 i32) (local $3 i32)
(local $4 i32) (local $4 i32)
(local $5 i32) (local $5 i32)
(local $6 i32)
(local $7 i32)
(if (if
(i32.eqz (i32.eqz
(get_local $0) (get_local $0)
@ -35,7 +37,7 @@
) )
) )
(set_local $1 (set_local $1
(get_global "$(lib)/allocator/arena/HEAP_OFFSET") (get_global "$(lib)/allocator/arena/OFFSET")
) )
(set_local $2 (set_local $2
(i32.and (i32.and
@ -53,62 +55,69 @@
) )
) )
(set_local $3 (set_local $3
(i32.shl (current_memory)
(current_memory)
(i32.const 16)
)
) )
(if (if
(i32.and (i32.gt_u
(if (result i32) (get_local $2)
(tee_local $4 (i32.shl
(i32.gt_u (get_local $3)
(get_local $2) (i32.const 16)
)
)
(block
(set_local $4
(i32.shr_u
(i32.and
(i32.add
(i32.sub
(get_local $2)
(get_local $1)
)
(i32.const 65535)
)
(i32.xor
(i32.const 65535)
(i32.const -1)
)
)
(i32.const 16)
)
)
(set_local $7
(select
(tee_local $5
(get_local $3) (get_local $3)
) )
(tee_local $6
(get_local $4)
)
(i32.gt_s
(get_local $5)
(get_local $6)
)
) )
)
(if
(i32.lt_s (i32.lt_s
(grow_memory (grow_memory
(select (get_local $7)
(tee_local $4
(i32.shr_u
(i32.sub
(i32.and
(i32.add
(get_local $2)
(i32.const 65535)
)
(i32.xor
(i32.const 65535)
(i32.const -1)
)
)
(get_local $3)
)
(i32.const 16)
)
)
(tee_local $5
(i32.shr_u
(get_local $3)
(i32.const 16)
)
)
(i32.gt_u
(get_local $4)
(get_local $5)
)
)
) )
(i32.const 0) (i32.const 0)
) )
(get_local $4) (if
(i32.lt_s
(grow_memory
(get_local $4)
)
(i32.const 0)
)
(unreachable)
)
) )
(i32.const 1)
) )
(unreachable)
) )
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_local $2) (get_local $2)
) )
(return (return
@ -2653,13 +2662,31 @@
(func "$(lib)/allocator/arena/free_memory" (; 6 ;) (type $iv) (param $0 i32) (func "$(lib)/allocator/arena/free_memory" (; 6 ;) (type $iv) (param $0 i32)
) )
(func "$(lib)/allocator/arena/reset_memory" (; 7 ;) (type $v) (func "$(lib)/allocator/arena/reset_memory" (; 7 ;) (type $v)
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.xor
(i32.const 7)
(i32.const -1)
)
)
) )
) )
(func $start (; 8 ;) (type $v) (func $start (; 8 ;) (type $v)
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.xor
(i32.const 7)
(i32.const -1)
)
)
) )
(set_global $std/allocator_arena/ptr1 (set_global $std/allocator_arena/ptr1
(call "$(lib)/allocator/arena/allocate_memory" (call "$(lib)/allocator/arena/allocate_memory"
@ -2823,7 +2850,16 @@
(i32.eqz (i32.eqz
(i32.eq (i32.eq
(get_global $std/allocator_arena/ptr1) (get_global $std/allocator_arena/ptr1)
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.xor
(i32.const 7)
(i32.const -1)
)
)
) )
) )
(block (block

View File

@ -8,7 +8,7 @@
(type $iiii (func (param i32 i32 i32) (result i32))) (type $iiii (func (param i32 i32 i32) (result i32)))
(type $v (func)) (type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/HEAP_OFFSET" (mut i32) (i32.const 0)) (global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global $std/array/arr (mut i32) (i32.const 0)) (global $std/array/arr (mut i32) (i32.const 0))
(global $std/array/i (mut i32) (i32.const 0)) (global $std/array/i (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 64)) (global $HEAP_BASE i32 (i32.const 64))
@ -21,6 +21,7 @@
(local $1 i32) (local $1 i32)
(local $2 i32) (local $2 i32)
(local $3 i32) (local $3 i32)
(local $4 i32)
(if (if
(i32.eqz (i32.eqz
(get_local $0) (get_local $0)
@ -30,74 +31,73 @@
) )
) )
(if (if
(i32.and (i32.gt_u
(if (result i32) (tee_local $2
(i32.and
(i32.add
(i32.add
(tee_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
)
(get_local $0)
)
(i32.const 7)
)
(i32.const -8)
)
)
(i32.shl
(tee_local $0 (tee_local $0
(i32.gt_u (current_memory)
(tee_local $2 )
(i32.and (i32.const 16)
(i32.add )
(i32.add )
(tee_local $3 (if
(get_global "$(lib)/allocator/arena/HEAP_OFFSET") (i32.lt_s
(grow_memory
(select
(get_local $0)
(tee_local $4
(tee_local $3
(i32.shr_u
(i32.and
(i32.add
(i32.sub
(get_local $2)
(get_local $1)
)
(i32.const 65535)
) )
(get_local $0) (i32.const -65536)
) )
(i32.const 7) (i32.const 16)
) )
(i32.const -8)
) )
) )
(tee_local $1 (i32.gt_s
(i32.shl (get_local $0)
(current_memory) (get_local $4)
(i32.const 16)
)
) )
) )
) )
(i32.const 0)
)
(if
(i32.lt_s (i32.lt_s
(grow_memory (grow_memory
(select (get_local $3)
(tee_local $0
(i32.shr_u
(i32.sub
(i32.and
(i32.add
(get_local $2)
(i32.const 65535)
)
(i32.const -65536)
)
(get_local $1)
)
(i32.const 16)
)
)
(tee_local $1
(i32.shr_u
(get_local $1)
(i32.const 16)
)
)
(i32.gt_u
(get_local $0)
(get_local $1)
)
)
) )
(i32.const 0) (i32.const 0)
) )
(get_local $0) (unreachable)
) )
(i32.const 1)
) )
(unreachable)
) )
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_local $2) (get_local $2)
) )
(get_local $3) (get_local $1)
) )
(func "$(lib)/array/Array#get:length" (; 2 ;) (type $ii) (param $0 i32) (result i32) (func "$(lib)/array/Array#get:length" (; 2 ;) (type $ii) (param $0 i32) (result i32)
(i32.load offset=8 (i32.load offset=8
@ -2905,8 +2905,14 @@
) )
) )
(func $start (; 16 ;) (type $v) (func $start (; 16 ;) (type $v)
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.const -8)
)
) )
(set_global $std/array/arr (set_global $std/array/arr
(call "$(lib)/allocator/arena/allocate_memory" (call "$(lib)/allocator/arena/allocate_memory"

View File

@ -9,10 +9,10 @@
(type $iiii (func (param i32 i32 i32) (result i32))) (type $iiii (func (param i32 i32 i32) (result i32)))
(type $v (func)) (type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/ALIGN_LOG2" i32 (i32.const 3)) (global "$(lib)/allocator/arena/AL_BITS" i32 (i32.const 3))
(global "$(lib)/allocator/arena/ALIGN_SIZE" i32 (i32.const 8)) (global "$(lib)/allocator/arena/AL_SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/arena/ALIGN_MASK" i32 (i32.const 7)) (global "$(lib)/allocator/arena/AL_MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/HEAP_OFFSET" (mut i32) (i32.const 0)) (global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global $std/array/arr (mut i32) (i32.const 0)) (global $std/array/arr (mut i32) (i32.const 0))
(global $std/array/i (mut i32) (i32.const 0)) (global $std/array/i (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 64)) (global $HEAP_BASE i32 (i32.const 64))
@ -27,6 +27,8 @@
(local $3 i32) (local $3 i32)
(local $4 i32) (local $4 i32)
(local $5 i32) (local $5 i32)
(local $6 i32)
(local $7 i32)
(if (if
(i32.eqz (i32.eqz
(get_local $0) (get_local $0)
@ -36,7 +38,7 @@
) )
) )
(set_local $1 (set_local $1
(get_global "$(lib)/allocator/arena/HEAP_OFFSET") (get_global "$(lib)/allocator/arena/OFFSET")
) )
(set_local $2 (set_local $2
(i32.and (i32.and
@ -54,62 +56,69 @@
) )
) )
(set_local $3 (set_local $3
(i32.shl (current_memory)
(current_memory)
(i32.const 16)
)
) )
(if (if
(i32.and (i32.gt_u
(if (result i32) (get_local $2)
(tee_local $4 (i32.shl
(i32.gt_u (get_local $3)
(get_local $2) (i32.const 16)
)
)
(block
(set_local $4
(i32.shr_u
(i32.and
(i32.add
(i32.sub
(get_local $2)
(get_local $1)
)
(i32.const 65535)
)
(i32.xor
(i32.const 65535)
(i32.const -1)
)
)
(i32.const 16)
)
)
(set_local $7
(select
(tee_local $5
(get_local $3) (get_local $3)
) )
(tee_local $6
(get_local $4)
)
(i32.gt_s
(get_local $5)
(get_local $6)
)
) )
)
(if
(i32.lt_s (i32.lt_s
(grow_memory (grow_memory
(select (get_local $7)
(tee_local $4
(i32.shr_u
(i32.sub
(i32.and
(i32.add
(get_local $2)
(i32.const 65535)
)
(i32.xor
(i32.const 65535)
(i32.const -1)
)
)
(get_local $3)
)
(i32.const 16)
)
)
(tee_local $5
(i32.shr_u
(get_local $3)
(i32.const 16)
)
)
(i32.gt_u
(get_local $4)
(get_local $5)
)
)
) )
(i32.const 0) (i32.const 0)
) )
(get_local $4) (if
(i32.lt_s
(grow_memory
(get_local $4)
)
(i32.const 0)
)
(unreachable)
)
) )
(i32.const 1)
) )
(unreachable)
) )
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_local $2) (get_local $2)
) )
(return (return
@ -3244,8 +3253,17 @@
) )
) )
(func $start (; 16 ;) (type $v) (func $start (; 16 ;) (type $v)
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.xor
(i32.const 7)
(i32.const -1)
)
)
) )
(set_global $std/array/arr (set_global $std/array/arr
(call "$(lib)/allocator/arena/allocate_memory" (call "$(lib)/allocator/arena/allocate_memory"

View File

@ -2,7 +2,7 @@
(type $ii (func (param i32) (result i32))) (type $ii (func (param i32) (result i32)))
(type $ifv (func (param i32 f32))) (type $ifv (func (param i32 f32)))
(type $v (func)) (type $v (func))
(global "$(lib)/allocator/arena/HEAP_OFFSET" (mut i32) (i32.const 0)) (global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global $std/new/aClass (mut i32) (i32.const 0)) (global $std/new/aClass (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4)) (global $HEAP_BASE i32 (i32.const 4))
(memory $0 1) (memory $0 1)
@ -12,6 +12,7 @@
(local $1 i32) (local $1 i32)
(local $2 i32) (local $2 i32)
(local $3 i32) (local $3 i32)
(local $4 i32)
(if (if
(i32.eqz (i32.eqz
(get_local $0) (get_local $0)
@ -21,74 +22,73 @@
) )
) )
(if (if
(i32.and (i32.gt_u
(if (result i32) (tee_local $2
(i32.and
(i32.add
(i32.add
(tee_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
)
(get_local $0)
)
(i32.const 7)
)
(i32.const -8)
)
)
(i32.shl
(tee_local $0 (tee_local $0
(i32.gt_u (current_memory)
(tee_local $2 )
(i32.and (i32.const 16)
(i32.add )
(i32.add )
(tee_local $3 (if
(get_global "$(lib)/allocator/arena/HEAP_OFFSET") (i32.lt_s
(grow_memory
(select
(get_local $0)
(tee_local $4
(tee_local $3
(i32.shr_u
(i32.and
(i32.add
(i32.sub
(get_local $2)
(get_local $1)
)
(i32.const 65535)
) )
(get_local $0) (i32.const -65536)
) )
(i32.const 7) (i32.const 16)
) )
(i32.const -8)
) )
) )
(tee_local $1 (i32.gt_s
(i32.shl (get_local $0)
(current_memory) (get_local $4)
(i32.const 16)
)
) )
) )
) )
(i32.const 0)
)
(if
(i32.lt_s (i32.lt_s
(grow_memory (grow_memory
(select (get_local $3)
(tee_local $0
(i32.shr_u
(i32.sub
(i32.and
(i32.add
(get_local $2)
(i32.const 65535)
)
(i32.const -65536)
)
(get_local $1)
)
(i32.const 16)
)
)
(tee_local $1
(i32.shr_u
(get_local $1)
(i32.const 16)
)
)
(i32.gt_u
(get_local $0)
(get_local $1)
)
)
) )
(i32.const 0) (i32.const 0)
) )
(get_local $0) (unreachable)
) )
(i32.const 1)
) )
(unreachable)
) )
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_local $2) (get_local $2)
) )
(get_local $3) (get_local $1)
) )
(func $std/new/AClass#constructor (; 1 ;) (type $ifv) (param $0 i32) (param $1 f32) (func $std/new/AClass#constructor (; 1 ;) (type $ifv) (param $0 i32) (param $1 f32)
(i32.store (i32.store
@ -107,8 +107,14 @@
) )
(func $start (; 2 ;) (type $v) (func $start (; 2 ;) (type $v)
(local $0 i32) (local $0 i32)
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.const -8)
)
) )
(set_global $std/new/aClass (set_global $std/new/aClass
(block (result i32) (block (result i32)

View File

@ -3,10 +3,10 @@
(type $ii (func (param i32) (result i32))) (type $ii (func (param i32) (result i32)))
(type $ifv (func (param i32 f32))) (type $ifv (func (param i32 f32)))
(type $v (func)) (type $v (func))
(global "$(lib)/allocator/arena/ALIGN_LOG2" i32 (i32.const 3)) (global "$(lib)/allocator/arena/AL_BITS" i32 (i32.const 3))
(global "$(lib)/allocator/arena/ALIGN_SIZE" i32 (i32.const 8)) (global "$(lib)/allocator/arena/AL_SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/arena/ALIGN_MASK" i32 (i32.const 7)) (global "$(lib)/allocator/arena/AL_MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/HEAP_OFFSET" (mut i32) (i32.const 0)) (global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global $std/new/aClass (mut i32) (i32.const 0)) (global $std/new/aClass (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4)) (global $HEAP_BASE i32 (i32.const 4))
(memory $0 1) (memory $0 1)
@ -18,6 +18,8 @@
(local $3 i32) (local $3 i32)
(local $4 i32) (local $4 i32)
(local $5 i32) (local $5 i32)
(local $6 i32)
(local $7 i32)
(if (if
(i32.eqz (i32.eqz
(get_local $0) (get_local $0)
@ -27,7 +29,7 @@
) )
) )
(set_local $1 (set_local $1
(get_global "$(lib)/allocator/arena/HEAP_OFFSET") (get_global "$(lib)/allocator/arena/OFFSET")
) )
(set_local $2 (set_local $2
(i32.and (i32.and
@ -45,62 +47,69 @@
) )
) )
(set_local $3 (set_local $3
(i32.shl (current_memory)
(current_memory)
(i32.const 16)
)
) )
(if (if
(i32.and (i32.gt_u
(if (result i32) (get_local $2)
(tee_local $4 (i32.shl
(i32.gt_u (get_local $3)
(get_local $2) (i32.const 16)
)
)
(block
(set_local $4
(i32.shr_u
(i32.and
(i32.add
(i32.sub
(get_local $2)
(get_local $1)
)
(i32.const 65535)
)
(i32.xor
(i32.const 65535)
(i32.const -1)
)
)
(i32.const 16)
)
)
(set_local $7
(select
(tee_local $5
(get_local $3) (get_local $3)
) )
(tee_local $6
(get_local $4)
)
(i32.gt_s
(get_local $5)
(get_local $6)
)
) )
)
(if
(i32.lt_s (i32.lt_s
(grow_memory (grow_memory
(select (get_local $7)
(tee_local $4
(i32.shr_u
(i32.sub
(i32.and
(i32.add
(get_local $2)
(i32.const 65535)
)
(i32.xor
(i32.const 65535)
(i32.const -1)
)
)
(get_local $3)
)
(i32.const 16)
)
)
(tee_local $5
(i32.shr_u
(get_local $3)
(i32.const 16)
)
)
(i32.gt_u
(get_local $4)
(get_local $5)
)
)
) )
(i32.const 0) (i32.const 0)
) )
(get_local $4) (if
(i32.lt_s
(grow_memory
(get_local $4)
)
(i32.const 0)
)
(unreachable)
)
) )
(i32.const 1)
) )
(unreachable)
) )
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_local $2) (get_local $2)
) )
(return (return
@ -124,8 +133,17 @@
) )
(func $start (; 2 ;) (type $v) (func $start (; 2 ;) (type $v)
(local $0 i32) (local $0 i32)
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.xor
(i32.const 7)
(i32.const -1)
)
)
) )
(set_global $std/new/aClass (set_global $std/new/aClass
(block (result i32) (block (result i32)

View File

@ -6,7 +6,7 @@
(type $iii (func (param i32 i32) (result i32))) (type $iii (func (param i32 i32) (result i32)))
(type $v (func)) (type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/HEAP_OFFSET" (mut i32) (i32.const 0)) (global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global $std/set/set (mut i32) (i32.const 0)) (global $std/set/set (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 56)) (global $HEAP_BASE i32 (i32.const 56))
(memory $0 1) (memory $0 1)
@ -18,6 +18,7 @@
(local $1 i32) (local $1 i32)
(local $2 i32) (local $2 i32)
(local $3 i32) (local $3 i32)
(local $4 i32)
(if (if
(i32.eqz (i32.eqz
(get_local $0) (get_local $0)
@ -27,74 +28,73 @@
) )
) )
(if (if
(i32.and (i32.gt_u
(if (result i32) (tee_local $2
(i32.and
(i32.add
(i32.add
(tee_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
)
(get_local $0)
)
(i32.const 7)
)
(i32.const -8)
)
)
(i32.shl
(tee_local $0 (tee_local $0
(i32.gt_u (current_memory)
(tee_local $2 )
(i32.and (i32.const 16)
(i32.add )
(i32.add )
(tee_local $3 (if
(get_global "$(lib)/allocator/arena/HEAP_OFFSET") (i32.lt_s
(grow_memory
(select
(get_local $0)
(tee_local $4
(tee_local $3
(i32.shr_u
(i32.and
(i32.add
(i32.sub
(get_local $2)
(get_local $1)
)
(i32.const 65535)
) )
(get_local $0) (i32.const -65536)
) )
(i32.const 7) (i32.const 16)
) )
(i32.const -8)
) )
) )
(tee_local $1 (i32.gt_s
(i32.shl (get_local $0)
(current_memory) (get_local $4)
(i32.const 16)
)
) )
) )
) )
(i32.const 0)
)
(if
(i32.lt_s (i32.lt_s
(grow_memory (grow_memory
(select (get_local $3)
(tee_local $0
(i32.shr_u
(i32.sub
(i32.and
(i32.add
(get_local $2)
(i32.const 65535)
)
(i32.const -65536)
)
(get_local $1)
)
(i32.const 16)
)
)
(tee_local $1
(i32.shr_u
(get_local $1)
(i32.const 16)
)
)
(i32.gt_u
(get_local $0)
(get_local $1)
)
)
) )
(i32.const 0) (i32.const 0)
) )
(get_local $0) (unreachable)
) )
(i32.const 1)
) )
(unreachable)
) )
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_local $2) (get_local $2)
) )
(get_local $3) (get_local $1)
) )
(func "$(lib)/set/Set#get:size" (; 2 ;) (type $ii) (param $0 i32) (result i32) (func "$(lib)/set/Set#get:size" (; 2 ;) (type $ii) (param $0 i32) (result i32)
(i32.load offset=8 (i32.load offset=8
@ -2273,8 +2273,14 @@
) )
) )
(func $start (; 10 ;) (type $v) (func $start (; 10 ;) (type $v)
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.const -8)
)
) )
(set_global $std/set/set (set_global $std/set/set
(call "$(lib)/allocator/arena/allocate_memory" (call "$(lib)/allocator/arena/allocate_memory"

View File

@ -7,10 +7,10 @@
(type $iii (func (param i32 i32) (result i32))) (type $iii (func (param i32 i32) (result i32)))
(type $v (func)) (type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/ALIGN_LOG2" i32 (i32.const 3)) (global "$(lib)/allocator/arena/AL_BITS" i32 (i32.const 3))
(global "$(lib)/allocator/arena/ALIGN_SIZE" i32 (i32.const 8)) (global "$(lib)/allocator/arena/AL_SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/arena/ALIGN_MASK" i32 (i32.const 7)) (global "$(lib)/allocator/arena/AL_MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/HEAP_OFFSET" (mut i32) (i32.const 0)) (global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global $std/set/set (mut i32) (i32.const 0)) (global $std/set/set (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 56)) (global $HEAP_BASE i32 (i32.const 56))
(memory $0 1) (memory $0 1)
@ -24,6 +24,8 @@
(local $3 i32) (local $3 i32)
(local $4 i32) (local $4 i32)
(local $5 i32) (local $5 i32)
(local $6 i32)
(local $7 i32)
(if (if
(i32.eqz (i32.eqz
(get_local $0) (get_local $0)
@ -33,7 +35,7 @@
) )
) )
(set_local $1 (set_local $1
(get_global "$(lib)/allocator/arena/HEAP_OFFSET") (get_global "$(lib)/allocator/arena/OFFSET")
) )
(set_local $2 (set_local $2
(i32.and (i32.and
@ -51,62 +53,69 @@
) )
) )
(set_local $3 (set_local $3
(i32.shl (current_memory)
(current_memory)
(i32.const 16)
)
) )
(if (if
(i32.and (i32.gt_u
(if (result i32) (get_local $2)
(tee_local $4 (i32.shl
(i32.gt_u (get_local $3)
(get_local $2) (i32.const 16)
)
)
(block
(set_local $4
(i32.shr_u
(i32.and
(i32.add
(i32.sub
(get_local $2)
(get_local $1)
)
(i32.const 65535)
)
(i32.xor
(i32.const 65535)
(i32.const -1)
)
)
(i32.const 16)
)
)
(set_local $7
(select
(tee_local $5
(get_local $3) (get_local $3)
) )
(tee_local $6
(get_local $4)
)
(i32.gt_s
(get_local $5)
(get_local $6)
)
) )
)
(if
(i32.lt_s (i32.lt_s
(grow_memory (grow_memory
(select (get_local $7)
(tee_local $4
(i32.shr_u
(i32.sub
(i32.and
(i32.add
(get_local $2)
(i32.const 65535)
)
(i32.xor
(i32.const 65535)
(i32.const -1)
)
)
(get_local $3)
)
(i32.const 16)
)
)
(tee_local $5
(i32.shr_u
(get_local $3)
(i32.const 16)
)
)
(i32.gt_u
(get_local $4)
(get_local $5)
)
)
) )
(i32.const 0) (i32.const 0)
) )
(get_local $4) (if
(i32.lt_s
(grow_memory
(get_local $4)
)
(i32.const 0)
)
(unreachable)
)
) )
(i32.const 1)
) )
(unreachable)
) )
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_local $2) (get_local $2)
) )
(return (return
@ -2584,8 +2593,17 @@
) )
) )
(func $start (; 10 ;) (type $v) (func $start (; 10 ;) (type $v)
(set_global "$(lib)/allocator/arena/HEAP_OFFSET" (set_global "$(lib)/allocator/arena/OFFSET"
(get_global $HEAP_BASE) (i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.xor
(i32.const 7)
(i32.const -1)
)
)
) )
(set_global $std/set/set (set_global $std/set/set
(call "$(lib)/allocator/arena/allocate_memory" (call "$(lib)/allocator/arena/allocate_memory"

View File

@ -1,14 +1,9 @@
(module (module
(type $ii (func (param i32) (result i32))) (type $ii (func (param i32) (result i32)))
(type $v (func))
(memory $0 1) (memory $0 1)
(export "alias" (func $typealias/alias)) (export "alias" (func $typealias/alias))
(export "memory" (memory $0)) (export "memory" (memory $0))
(start $start)
(func $typealias/alias (; 0 ;) (type $ii) (param $0 i32) (result i32) (func $typealias/alias (; 0 ;) (type $ii) (param $0 i32) (result i32)
(get_local $0) (get_local $0)
) )
(func $start (; 1 ;) (type $v)
(nop)
)
) )