Skip to content

Commit e28f536

Browse files
authored
fix: Support 65536 pages of memory in TLSF (#2654)
1 parent c0d86e6 commit e28f536

File tree

158 files changed

+6746
-3363
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+6746
-3363
lines changed

Diff for: std/assembly/rt/tlsf.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,9 @@ function prepareBlock(root: Root, block: Block, size: usize): void {
373373
}
374374

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

@@ -442,7 +443,7 @@ function growMemory(root: Root, size: usize): void {
442443
if (memory.grow(pagesNeeded) < 0) unreachable();
443444
}
444445
let pagesAfter = memory.size();
445-
addMemory(root, <usize>pagesBefore << 16, <usize>pagesAfter << 16);
446+
addMemory(root, <usize>pagesBefore << 16, <u64>pagesAfter << 16);
446447
}
447448

448449
/** Computes the size (excl. header) of a block. */
@@ -477,11 +478,11 @@ function initialize(): void {
477478
}
478479
let memStart = rootOffset + ROOT_SIZE;
479480
if (ASC_LOW_MEMORY_LIMIT) {
480-
const memEnd = <usize>ASC_LOW_MEMORY_LIMIT & ~AL_MASK;
481+
const memEnd = <u64>ASC_LOW_MEMORY_LIMIT & ~AL_MASK;
481482
if (memStart <= memEnd) addMemory(root, memStart, memEnd);
482483
else unreachable(); // low memory limit already exceeded
483484
} else {
484-
addMemory(root, memStart, memory.size() << 16);
485+
addMemory(root, memStart, <u64>memory.size() << 16);
485486
}
486487
ROOT = root;
487488
}

Diff for: tests/compiler/bindings/esm.debug.wat

+32-24
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
(type $i32_i32_i32_=>_none (func (param i32 i32 i32)))
88
(type $none_=>_i32 (func (result i32)))
99
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
10-
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
1110
(type $i32_i64_=>_none (func (param i32 i64)))
1211
(type $i32_i32_f64_f64_f64_f64_f64_=>_none (func (param i32 i32 f64 f64 f64 f64 f64)))
1312
(type $f64_=>_f64 (func (param f64) (result f64)))
1413
(type $i64_i64_=>_i64 (func (param i64 i64) (result i64)))
1514
(type $none_=>_i64 (func (result i64)))
15+
(type $i32_i32_i64_=>_i32 (func (param i32 i32 i64) (result i32)))
1616
(type $i32_f32_=>_none (func (param i32 f32)))
1717
(type $i32_f64_=>_none (func (param i32 f64)))
18+
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
1819
(type $i32_i32_i64_=>_none (func (param i32 i32 i64)))
1920
(type $i32_i32_=>_f32 (func (param i32 i32) (result f32)))
2021
(import "env" "Math.E" (global $~lib/bindings/dom/Math.E f64))
@@ -1123,25 +1124,30 @@
11231124
local.get $slMap
11241125
i32.store $0 offset=4
11251126
)
1126-
(func $~lib/rt/tlsf/addMemory (param $root i32) (param $start i32) (param $end i32) (result i32)
1127-
(local $root|3 i32)
1127+
(func $~lib/rt/tlsf/addMemory (param $root i32) (param $start i32) (param $endU64 i64) (result i32)
1128+
(local $end i32)
1129+
(local $root|4 i32)
11281130
(local $tail i32)
11291131
(local $tailInfo i32)
11301132
(local $size i32)
11311133
(local $leftSize i32)
11321134
(local $left i32)
1133-
(local $root|9 i32)
1134-
(local $tail|10 i32)
1135+
(local $root|10 i32)
1136+
(local $tail|11 i32)
1137+
local.get $endU64
1138+
i32.wrap_i64
1139+
local.set $end
11351140
i32.const 1
11361141
drop
11371142
local.get $start
1138-
local.get $end
1139-
i32.le_u
1143+
i64.extend_i32_u
1144+
local.get $endU64
1145+
i64.le_u
11401146
i32.eqz
11411147
if
11421148
i32.const 0
11431149
i32.const 672
1144-
i32.const 377
1150+
i32.const 378
11451151
i32.const 14
11461152
call $~lib/builtins/abort
11471153
unreachable
@@ -1166,8 +1172,8 @@
11661172
local.set $end
11671173
block $~lib/rt/tlsf/GETTAIL|inlined.0 (result i32)
11681174
local.get $root
1169-
local.set $root|3
1170-
local.get $root|3
1175+
local.set $root|4
1176+
local.get $root|4
11711177
i32.load $0 offset=1568
11721178
br $~lib/rt/tlsf/GETTAIL|inlined.0
11731179
end
@@ -1187,7 +1193,7 @@
11871193
if
11881194
i32.const 0
11891195
i32.const 672
1190-
i32.const 384
1196+
i32.const 385
11911197
i32.const 16
11921198
call $~lib/builtins/abort
11931199
unreachable
@@ -1220,7 +1226,7 @@
12201226
if
12211227
i32.const 0
12221228
i32.const 672
1223-
i32.const 397
1229+
i32.const 398
12241230
i32.const 5
12251231
call $~lib/builtins/abort
12261232
unreachable
@@ -1276,11 +1282,11 @@
12761282
i32.or
12771283
call $~lib/rt/common/BLOCK#set:mmInfo
12781284
local.get $root
1279-
local.set $root|9
1285+
local.set $root|10
12801286
local.get $tail
1281-
local.set $tail|10
1282-
local.get $root|9
1283-
local.get $tail|10
1287+
local.set $tail|11
1288+
local.get $root|10
1289+
local.get $tail|11
12841290
i32.store $0 offset=1568
12851291
local.get $root
12861292
local.get $left
@@ -1426,8 +1432,9 @@
14261432
local.get $root
14271433
local.get $memStart
14281434
memory.size $0
1429-
i32.const 16
1430-
i32.shl
1435+
i64.extend_i32_s
1436+
i64.const 16
1437+
i64.shl
14311438
call $~lib/rt/tlsf/addMemory
14321439
drop
14331440
local.get $root
@@ -1463,7 +1470,7 @@
14631470
if
14641471
i32.const 0
14651472
i32.const 672
1466-
i32.const 559
1473+
i32.const 560
14671474
i32.const 3
14681475
call $~lib/builtins/abort
14691476
unreachable
@@ -1792,7 +1799,7 @@
17921799
if
17931800
i32.const 336
17941801
i32.const 672
1795-
i32.const 458
1802+
i32.const 459
17961803
i32.const 29
17971804
call $~lib/builtins/abort
17981805
unreachable
@@ -2094,8 +2101,9 @@
20942101
i32.const 16
20952102
i32.shl
20962103
local.get $pagesAfter
2097-
i32.const 16
2098-
i32.shl
2104+
i64.extend_i32_s
2105+
i64.const 16
2106+
i64.shl
20992107
call $~lib/rt/tlsf/addMemory
21002108
drop
21012109
)
@@ -2235,7 +2243,7 @@
22352243
if
22362244
i32.const 0
22372245
i32.const 672
2238-
i32.const 496
2246+
i32.const 497
22392247
i32.const 16
22402248
call $~lib/builtins/abort
22412249
unreachable
@@ -2255,7 +2263,7 @@
22552263
if
22562264
i32.const 0
22572265
i32.const 672
2258-
i32.const 498
2266+
i32.const 499
22592267
i32.const 14
22602268
call $~lib/builtins/abort
22612269
unreachable

Diff for: tests/compiler/bindings/esm.release.wat

+26-22
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
(module
22
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
33
(type $i32_=>_none (func (param i32)))
4-
(type $i32_i32_i32_=>_none (func (param i32 i32 i32)))
54
(type $i32_=>_i32 (func (param i32) (result i32)))
65
(type $none_=>_i32 (func (result i32)))
76
(type $none_=>_none (func))
7+
(type $i32_i32_i32_=>_none (func (param i32 i32 i32)))
88
(type $i32_i32_=>_none (func (param i32 i32)))
9+
(type $i32_i32_i64_=>_none (func (param i32 i32 i64)))
910
(type $i32_i32_f64_f64_f64_f64_f64_=>_none (func (param i32 i32 f64 f64 f64 f64 f64)))
1011
(type $f64_=>_f64 (func (param f64) (result f64)))
1112
(type $i64_i64_=>_i64 (func (param i64 i64) (result i64)))
1213
(type $none_=>_i64 (func (result i64)))
1314
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
14-
(type $i32_i32_i64_=>_none (func (param i32 i32 i64)))
1515
(import "env" "Math.E" (global $~lib/bindings/dom/Math.E f64))
1616
(import "env" "trace" (func $~lib/builtins/trace (param i32 i32 f64 f64 f64 f64 f64)))
1717
(import "env" "console.log" (func $~lib/bindings/dom/console.log (param i32)))
@@ -731,16 +731,17 @@
731731
i32.or
732732
i32.store $0 offset=4
733733
)
734-
(func $~lib/rt/tlsf/addMemory (param $0 i32) (param $1 i32) (param $2 i32)
734+
(func $~lib/rt/tlsf/addMemory (param $0 i32) (param $1 i32) (param $2 i64)
735735
(local $3 i32)
736736
(local $4 i32)
737-
local.get $1
738737
local.get $2
739-
i32.gt_u
738+
local.get $1
739+
i64.extend_i32_u
740+
i64.lt_u
740741
if
741742
i32.const 0
742743
i32.const 1696
743-
i32.const 377
744+
i32.const 378
744745
i32.const 14
745746
call $~lib/builtins/abort
746747
unreachable
@@ -765,7 +766,7 @@
765766
if
766767
i32.const 0
767768
i32.const 1696
768-
i32.const 384
769+
i32.const 385
769770
i32.const 16
770771
call $~lib/builtins/abort
771772
unreachable
@@ -793,18 +794,19 @@
793794
if
794795
i32.const 0
795796
i32.const 1696
796-
i32.const 397
797+
i32.const 398
797798
i32.const 5
798799
call $~lib/builtins/abort
799800
unreachable
800801
end
801802
end
802803
local.get $2
804+
i32.wrap_i64
803805
i32.const -16
804806
i32.and
805807
local.get $1
806808
i32.sub
807-
local.tee $2
809+
local.tee $4
808810
i32.const 20
809811
i32.lt_u
810812
if
@@ -814,10 +816,10 @@
814816
local.get $3
815817
i32.const 2
816818
i32.and
817-
local.get $2
819+
local.get $4
818820
i32.const 8
819821
i32.sub
820-
local.tee $2
822+
local.tee $3
821823
i32.const 1
822824
i32.or
823825
i32.or
@@ -831,13 +833,13 @@
831833
local.get $1
832834
i32.const 4
833835
i32.add
834-
local.get $2
836+
local.get $3
835837
i32.add
836-
local.tee $2
838+
local.tee $3
837839
i32.const 2
838840
i32.store $0
839841
local.get $0
840-
local.get $2
842+
local.get $3
841843
i32.store $0 offset=1568
842844
local.get $0
843845
local.get $1
@@ -916,8 +918,9 @@
916918
i32.const 35056
917919
i32.const 36628
918920
memory.size $0
919-
i32.const 16
920-
i32.shl
921+
i64.extend_i32_s
922+
i64.const 16
923+
i64.shl
921924
call $~lib/rt/tlsf/addMemory
922925
i32.const 35056
923926
global.set $~lib/rt/tlsf/ROOT
@@ -1158,7 +1161,7 @@
11581161
if
11591162
i32.const 0
11601163
i32.const 1696
1161-
i32.const 559
1164+
i32.const 560
11621165
i32.const 3
11631166
call $~lib/builtins/abort
11641167
unreachable
@@ -1393,7 +1396,7 @@
13931396
if
13941397
i32.const 1360
13951398
i32.const 1696
1396-
i32.const 458
1399+
i32.const 459
13971400
i32.const 29
13981401
call $~lib/builtins/abort
13991402
unreachable
@@ -1472,8 +1475,9 @@
14721475
i32.const 16
14731476
i32.shl
14741477
memory.size $0
1475-
i32.const 16
1476-
i32.shl
1478+
i64.extend_i32_s
1479+
i64.const 16
1480+
i64.shl
14771481
call $~lib/rt/tlsf/addMemory
14781482
local.get $4
14791483
local.get $5
@@ -1483,7 +1487,7 @@
14831487
if
14841488
i32.const 0
14851489
i32.const 1696
1486-
i32.const 496
1490+
i32.const 497
14871491
i32.const 16
14881492
call $~lib/builtins/abort
14891493
unreachable
@@ -1498,7 +1502,7 @@
14981502
if
14991503
i32.const 0
15001504
i32.const 1696
1501-
i32.const 498
1505+
i32.const 499
15021506
i32.const 14
15031507
call $~lib/builtins/abort
15041508
unreachable

0 commit comments

Comments
 (0)