Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow addMemory to support 65536 wasm pages memory #2654

Merged
merged 4 commits into from Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions std/assembly/rt/tlsf.ts
Expand Up @@ -373,8 +373,9 @@ function prepareBlock(root: Root, block: Block, size: usize): void {
}

/** Adds more memory to the pool. */
function addMemory(root: Root, start: usize, end: usize): bool {
if (DEBUG) assert(start <= end); // must be valid
function addMemory(root: Root, start: usize, endU64: u64): bool {
let end = <usize>endU64;
if (DEBUG) assert(<u64>start <= endU64); // must be valid
start = ((start + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD;
end &= ~AL_MASK;

Expand Down Expand Up @@ -442,7 +443,7 @@ function growMemory(root: Root, size: usize): void {
if (memory.grow(pagesNeeded) < 0) unreachable();
}
let pagesAfter = memory.size();
addMemory(root, <usize>pagesBefore << 16, <usize>pagesAfter << 16);
addMemory(root, <usize>pagesBefore << 16, <u64>pagesAfter << 16);
}

/** Computes the size (excl. header) of a block. */
Expand Down Expand Up @@ -477,11 +478,11 @@ function initialize(): void {
}
let memStart = rootOffset + ROOT_SIZE;
if (ASC_LOW_MEMORY_LIMIT) {
const memEnd = <usize>ASC_LOW_MEMORY_LIMIT & ~AL_MASK;
const memEnd = <u64>ASC_LOW_MEMORY_LIMIT & ~AL_MASK;
if (memStart <= memEnd) addMemory(root, memStart, memEnd);
else unreachable(); // low memory limit already exceeded
} else {
addMemory(root, memStart, memory.size() << 16);
addMemory(root, memStart, <u64>memory.size() << 16);
}
ROOT = root;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/bindings/esm.debug.js
Expand Up @@ -18,10 +18,10 @@ async function instantiate(module, imports = {}) {
// ~lib/bindings/dom/Math.E: f64
Math.E
),
"Math.log": (
"Math.log"(x) {
// ~lib/bindings/dom/Math.log(f64) => f64
Math.log
),
return Math.log(x);
},
"globalThis.globalThis": (
// bindings/esm/immutableGlobalNested: ref_extern | null}
globalThis.globalThis
Expand Down
56 changes: 32 additions & 24 deletions tests/compiler/bindings/esm.debug.wat
Expand Up @@ -7,14 +7,15 @@
(type $i32_i32_i32_=>_none (func (param i32 i32 i32)))
(type $none_=>_i32 (func (result i32)))
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
(type $i32_i64_=>_none (func (param i32 i64)))
(type $i32_i32_f64_f64_f64_f64_f64_=>_none (func (param i32 i32 f64 f64 f64 f64 f64)))
(type $f64_=>_f64 (func (param f64) (result f64)))
(type $i64_i64_=>_i64 (func (param i64 i64) (result i64)))
(type $none_=>_i64 (func (result i64)))
(type $i32_i32_i64_=>_i32 (func (param i32 i32 i64) (result i32)))
(type $i32_f32_=>_none (func (param i32 f32)))
(type $i32_f64_=>_none (func (param i32 f64)))
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
(type $i32_i32_i64_=>_none (func (param i32 i32 i64)))
(type $i32_i32_=>_f32 (func (param i32 i32) (result f32)))
(import "env" "Math.E" (global $~lib/bindings/dom/Math.E f64))
Expand Down Expand Up @@ -1123,25 +1124,30 @@
local.get $slMap
i32.store $0 offset=4
)
(func $~lib/rt/tlsf/addMemory (param $root i32) (param $start i32) (param $end i32) (result i32)
(local $root|3 i32)
(func $~lib/rt/tlsf/addMemory (param $root i32) (param $start i32) (param $endU64 i64) (result i32)
(local $end i32)
(local $root|4 i32)
(local $tail i32)
(local $tailInfo i32)
(local $size i32)
(local $leftSize i32)
(local $left i32)
(local $root|9 i32)
(local $tail|10 i32)
(local $root|10 i32)
(local $tail|11 i32)
local.get $endU64
i32.wrap_i64
local.set $end
i32.const 1
drop
local.get $start
local.get $end
i32.le_u
i64.extend_i32_u
local.get $endU64
i64.le_u
i32.eqz
if
i32.const 0
i32.const 672
i32.const 377
i32.const 378
i32.const 14
call $~lib/builtins/abort
unreachable
Expand All @@ -1166,8 +1172,8 @@
local.set $end
block $~lib/rt/tlsf/GETTAIL|inlined.0 (result i32)
local.get $root
local.set $root|3
local.get $root|3
local.set $root|4
local.get $root|4
i32.load $0 offset=1568
br $~lib/rt/tlsf/GETTAIL|inlined.0
end
Expand All @@ -1187,7 +1193,7 @@
if
i32.const 0
i32.const 672
i32.const 384
i32.const 385
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1220,7 +1226,7 @@
if
i32.const 0
i32.const 672
i32.const 397
i32.const 398
i32.const 5
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1276,11 +1282,11 @@
i32.or
call $~lib/rt/common/BLOCK#set:mmInfo
local.get $root
local.set $root|9
local.set $root|10
local.get $tail
local.set $tail|10
local.get $root|9
local.get $tail|10
local.set $tail|11
local.get $root|10
local.get $tail|11
i32.store $0 offset=1568
local.get $root
local.get $left
Expand Down Expand Up @@ -1426,8 +1432,9 @@
local.get $root
local.get $memStart
memory.size $0
i32.const 16
i32.shl
i64.extend_i32_s
i64.const 16
i64.shl
call $~lib/rt/tlsf/addMemory
drop
local.get $root
Expand Down Expand Up @@ -1463,7 +1470,7 @@
if
i32.const 0
i32.const 672
i32.const 559
i32.const 560
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1792,7 +1799,7 @@
if
i32.const 336
i32.const 672
i32.const 458
i32.const 459
i32.const 29
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -2094,8 +2101,9 @@
i32.const 16
i32.shl
local.get $pagesAfter
i32.const 16
i32.shl
i64.extend_i32_s
i64.const 16
i64.shl
call $~lib/rt/tlsf/addMemory
drop
)
Expand Down Expand Up @@ -2235,7 +2243,7 @@
if
i32.const 0
i32.const 672
i32.const 496
i32.const 497
i32.const 16
call $~lib/builtins/abort
unreachable
Expand All @@ -2255,7 +2263,7 @@
if
i32.const 0
i32.const 672
i32.const 498
i32.const 499
i32.const 14
call $~lib/builtins/abort
unreachable
Expand Down
8 changes: 4 additions & 4 deletions tests/compiler/bindings/esm.release.js
Expand Up @@ -18,12 +18,12 @@ async function instantiate(module, imports = {}) {
// ~lib/bindings/dom/Math.E: f64
Math.E
),
"Math.log": (
"Math.log"(x) {
// ~lib/bindings/dom/Math.log(f64) => f64
Math.log
),
return Math.log(x);
},
"globalThis.globalThis": (
// bindings/esm/immutableGlobalNested: externref
// bindings/esm/immutableGlobalNested: ref_extern | null}
globalThis.globalThis
),
"Date.getTimezoneOffset"() {
Expand Down
48 changes: 26 additions & 22 deletions tests/compiler/bindings/esm.release.wat
@@ -1,17 +1,17 @@
(module
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
(type $i32_=>_none (func (param i32)))
(type $i32_i32_i32_=>_none (func (param i32 i32 i32)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $none_=>_i32 (func (result i32)))
(type $none_=>_none (func))
(type $i32_i32_i32_=>_none (func (param i32 i32 i32)))
(type $i32_i32_=>_none (func (param i32 i32)))
(type $i32_i32_i64_=>_none (func (param i32 i32 i64)))
(type $i32_i32_f64_f64_f64_f64_f64_=>_none (func (param i32 i32 f64 f64 f64 f64 f64)))
(type $f64_=>_f64 (func (param f64) (result f64)))
(type $i64_i64_=>_i64 (func (param i64 i64) (result i64)))
(type $none_=>_i64 (func (result i64)))
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
(type $i32_i32_i64_=>_none (func (param i32 i32 i64)))
(import "env" "Math.E" (global $~lib/bindings/dom/Math.E f64))
(import "env" "trace" (func $~lib/builtins/trace (param i32 i32 f64 f64 f64 f64 f64)))
(import "env" "console.log" (func $~lib/bindings/dom/console.log (param i32)))
Expand Down Expand Up @@ -731,16 +731,17 @@
i32.or
i32.store $0 offset=4
)
(func $~lib/rt/tlsf/addMemory (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/rt/tlsf/addMemory (param $0 i32) (param $1 i32) (param $2 i64)
(local $3 i32)
(local $4 i32)
local.get $1
local.get $2
i32.gt_u
local.get $1
i64.extend_i32_u
i64.lt_u
if
i32.const 0
i32.const 1696
i32.const 377
i32.const 378
i32.const 14
call $~lib/builtins/abort
unreachable
Expand All @@ -765,7 +766,7 @@
if
i32.const 0
i32.const 1696
i32.const 384
i32.const 385
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -793,18 +794,19 @@
if
i32.const 0
i32.const 1696
i32.const 397
i32.const 398
i32.const 5
call $~lib/builtins/abort
unreachable
end
end
local.get $2
i32.wrap_i64
i32.const -16
i32.and
local.get $1
i32.sub
local.tee $2
local.tee $4
i32.const 20
i32.lt_u
if
Expand All @@ -814,10 +816,10 @@
local.get $3
i32.const 2
i32.and
local.get $2
local.get $4
i32.const 8
i32.sub
local.tee $2
local.tee $3
i32.const 1
i32.or
i32.or
Expand All @@ -831,13 +833,13 @@
local.get $1
i32.const 4
i32.add
local.get $2
local.get $3
i32.add
local.tee $2
local.tee $3
i32.const 2
i32.store $0
local.get $0
local.get $2
local.get $3
i32.store $0 offset=1568
local.get $0
local.get $1
Expand Down Expand Up @@ -916,8 +918,9 @@
i32.const 35056
i32.const 36628
memory.size $0
i32.const 16
i32.shl
i64.extend_i32_s
i64.const 16
i64.shl
call $~lib/rt/tlsf/addMemory
i32.const 35056
global.set $~lib/rt/tlsf/ROOT
Expand Down Expand Up @@ -1158,7 +1161,7 @@
if
i32.const 0
i32.const 1696
i32.const 559
i32.const 560
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1393,7 +1396,7 @@
if
i32.const 1360
i32.const 1696
i32.const 458
i32.const 459
i32.const 29
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1472,8 +1475,9 @@
i32.const 16
i32.shl
memory.size $0
i32.const 16
i32.shl
i64.extend_i32_s
i64.const 16
i64.shl
call $~lib/rt/tlsf/addMemory
local.get $4
local.get $5
Expand All @@ -1483,7 +1487,7 @@
if
i32.const 0
i32.const 1696
i32.const 496
i32.const 497
i32.const 16
call $~lib/builtins/abort
unreachable
Expand All @@ -1498,7 +1502,7 @@
if
i32.const 0
i32.const 1696
i32.const 498
i32.const 499
i32.const 14
call $~lib/builtins/abort
unreachable
Expand Down