Skip to content

Commit 40bbbcd

Browse files
committed
WIP: Update internal ABI to zero/sign-extend where necessary only
1 parent 8b5d1d7 commit 40bbbcd

Some content is hidden

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

59 files changed

+7586
-8703
lines changed

src/builtins.ts

Lines changed: 183 additions & 78 deletions
Large diffs are not rendered by default.

src/compiler.ts

Lines changed: 544 additions & 361 deletions
Large diffs are not rendered by default.

src/program.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,8 +3565,6 @@ export class Flow {
35653565
contextualTypeArguments: Map<string,Type> | null;
35663566
/** Scoped local variables. */
35673567
scopedLocals: Map<string,Local> | null = null;
3568-
/** Scoped global variables. */
3569-
// scopedGlobals: Map<Local,Global> | null = null;
35703568

35713569
/** Creates the parent flow of the specified function. */
35723570
static create(currentFunction: Function): Flow {
@@ -3699,27 +3697,6 @@ export class Flow {
36993697
return this.currentFunction.localsByName.get(name);
37003698
}
37013699

3702-
/** Adds a scoped global for an outer scoped local. */
3703-
// addScopedGlobal(scopedLocal: Local): Global {
3704-
// var scopedGlobals = this.scopedGlobals;
3705-
// var scopedGlobal: Global | null;
3706-
// if (!scopedGlobals) {
3707-
// this.scopedGlobals = scopedGlobals = new Map();
3708-
// } else {
3709-
// scopedGlobal = scopedGlobals.get(scopedLocal);
3710-
// if (scopedGlobal) return scopedGlobal;
3711-
// }
3712-
// scopedGlobal = new Global(
3713-
// scopedLocal.program,
3714-
// scopedLocal.simpleName,
3715-
// this.currentFunction.internalName + INNER_DELIMITER + scopedLocal.internalName,
3716-
// scopedLocal.type,
3717-
// assert(scopedLocal.declaration)
3718-
// );
3719-
// scopedGlobals.set(scopedLocal, scopedGlobal);
3720-
// return scopedGlobal;
3721-
// }
3722-
37233700
/** Finalizes this flow. Must be the topmost parent flow of the function. */
37243701
finalize(): void {
37253702
assert(this.parent == null); // must be the topmost parent flow

src/types.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,24 @@ export class Type {
114114
this.nonNullableType = this;
115115
}
116116

117+
/** Returns the int type of this type. Defaults to `Type.i32` if this is not an int type. */
118+
get intType(): Type {
119+
switch (this.kind) {
120+
case TypeKind.I8:
121+
case TypeKind.I16:
122+
case TypeKind.I32:
123+
case TypeKind.I64:
124+
case TypeKind.ISIZE:
125+
case TypeKind.U8:
126+
case TypeKind.U16:
127+
case TypeKind.U32:
128+
case TypeKind.U64:
129+
case TypeKind.USIZE: return this;
130+
case TypeKind.BOOL:
131+
default: return Type.i32;
132+
}
133+
}
134+
117135
/** Computes the sign-extending shift in the target type. */
118136
computeSmallIntegerShift(targetType: Type): u32 {
119137
return targetType.size - this.size;

tests/allocators/buddy/optimized.wat

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -715,22 +715,19 @@
715715
;;@ ~lib/allocator/buddy.ts:403:6
716716
(if
717717
;;@ ~lib/allocator/buddy.ts:403:10
718-
(i32.and
719-
(if (result i32)
720-
(tee_local $2
721-
(i32.ne
722-
(get_local $1)
723-
;;@ ~lib/allocator/buddy.ts:403:20
724-
(get_global $~lib/allocator/buddy/bucket_limit)
725-
)
726-
)
727-
(get_local $2)
728-
(i32.eqz
729-
;;@ ~lib/allocator/buddy.ts:403:36
718+
(if (result i32)
719+
(tee_local $2
720+
(i32.ne
730721
(get_local $1)
722+
;;@ ~lib/allocator/buddy.ts:403:20
723+
(get_global $~lib/allocator/buddy/bucket_limit)
731724
)
732725
)
733-
(i32.const 1)
726+
(get_local $2)
727+
(i32.eqz
728+
;;@ ~lib/allocator/buddy.ts:403:36
729+
(get_local $1)
730+
)
734731
)
735732
;;@ ~lib/allocator/buddy.ts:403:49
736733
(block
@@ -1002,8 +999,8 @@
1002999
)
10031000
)
10041001
(get_local $2)
1005-
;;@ ~lib/allocator/buddy.ts:517:30
10061002
(i32.eq
1003+
;;@ ~lib/allocator/buddy.ts:517:30
10071004
(get_local $1)
10081005
;;@ ~lib/allocator/buddy.ts:517:40
10091006
(get_global $~lib/allocator/buddy/bucket_limit)

tests/allocators/buddy/untouched.wat

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -923,24 +923,21 @@
923923
;;@ ~lib/allocator/buddy.ts:403:6
924924
(if
925925
;;@ ~lib/allocator/buddy.ts:403:10
926-
(i32.and
927-
(if (result i32)
928-
(tee_local $7
929-
(i32.ne
930-
(get_local $2)
931-
;;@ ~lib/allocator/buddy.ts:403:20
932-
(get_global $~lib/allocator/buddy/bucket_limit)
933-
)
934-
)
935-
(get_local $7)
936-
;;@ ~lib/allocator/buddy.ts:403:36
937-
(i32.eq
926+
(if (result i32)
927+
(tee_local $7
928+
(i32.ne
938929
(get_local $2)
939-
;;@ ~lib/allocator/buddy.ts:403:46
940-
(i32.const 0)
930+
;;@ ~lib/allocator/buddy.ts:403:20
931+
(get_global $~lib/allocator/buddy/bucket_limit)
941932
)
942933
)
943-
(i32.const 1)
934+
(get_local $7)
935+
;;@ ~lib/allocator/buddy.ts:403:36
936+
(i32.eq
937+
(get_local $2)
938+
;;@ ~lib/allocator/buddy.ts:403:46
939+
(i32.const 0)
940+
)
944941
)
945942
;;@ ~lib/allocator/buddy.ts:403:49
946943
(block
@@ -1248,10 +1245,13 @@
12481245
)
12491246
(get_local $3)
12501247
;;@ ~lib/allocator/buddy.ts:517:30
1251-
(i32.eq
1252-
(get_local $1)
1253-
;;@ ~lib/allocator/buddy.ts:517:40
1254-
(get_global $~lib/allocator/buddy/bucket_limit)
1248+
(i32.and
1249+
(i32.eq
1250+
(get_local $1)
1251+
;;@ ~lib/allocator/buddy.ts:517:40
1252+
(get_global $~lib/allocator/buddy/bucket_limit)
1253+
)
1254+
(i32.const 1)
12551255
)
12561256
)
12571257
;;@ ~lib/allocator/buddy.ts:518:6

tests/allocators/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const COMMON_MAX = 1 << 30;
44
function test(file) {
55
console.log("Testing '" + file + "' ...\n");
66

7-
const exports = new WebAssembly.Instance(WebAssembly.Module(fs.readFileSync(__dirname + "/" + file)), {
7+
const exports = new WebAssembly.Instance(new WebAssembly.Module(fs.readFileSync(__dirname + "/" + file)), {
88
env: {
99
abort: function(msg, file, line, column) {
1010
throw Error("Assertion failed: " + (msg ? "'" + getString(msg) + "' " : "") + "at " + getString(file) + ":" + line + ":" + column);

tests/allocators/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"private": true,
33
"scripts": {
44
"test": "node ./index",
5-
"test:forever": "node ./forever"
5+
"test:forever": "node ./forever",
6+
"test:all": "npm run test tlsf && npm run test buddy && npm run test arena"
67
}
78
}

tests/allocators/tlsf/optimized.wat

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@
10621062
;;@ ~lib/allocator/tlsf.ts:369:6
10631063
(i32.store
10641064
;;@ ~lib/allocator/tlsf.ts:368:6
1065-
(tee_local $2
1065+
(tee_local $0
10661066
;;@ ~lib/allocator/tlsf.ts:368:25
10671067
(call $~lib/allocator/tlsf/Block#get:right
10681068
;;@ ~lib/allocator/tlsf.ts:368:32
@@ -1072,7 +1072,7 @@
10721072
(i32.and
10731073
;;@ ~lib/allocator/tlsf.ts:369:6
10741074
(i32.load
1075-
(get_local $2)
1075+
(get_local $0)
10761076
)
10771077
(i32.const -3)
10781078
)
@@ -1109,7 +1109,7 @@
11091109
;;@ ~lib/allocator/tlsf.ts:446:11
11101110
(tee_local $2
11111111
;;@ ~lib/allocator/tlsf.ts:445:4
1112-
(tee_local $3
1112+
(tee_local $4
11131113
;;@ ~lib/allocator/tlsf.ts:445:21
11141114
(i32.and
11151115
(i32.add
@@ -1154,15 +1154,15 @@
11541154
(i32.const 0)
11551155
)
11561156
;;@ ~lib/allocator/tlsf.ts:451:11
1157-
(set_local $4
1157+
(set_local $3
11581158
;;@ ~lib/allocator/tlsf.ts:451:25
11591159
(i32.const 0)
11601160
)
11611161
(loop $continue|1
11621162
(if
11631163
;;@ ~lib/allocator/tlsf.ts:451:28
11641164
(i32.lt_u
1165-
(get_local $4)
1165+
(get_local $3)
11661166
;;@ ~lib/allocator/tlsf.ts:451:33
11671167
(i32.const 32)
11681168
)
@@ -1174,15 +1174,15 @@
11741174
;;@ ~lib/allocator/tlsf.ts:452:21
11751175
(get_local $1)
11761176
;;@ ~lib/allocator/tlsf.ts:452:25
1177-
(get_local $4)
1177+
(get_local $3)
11781178
;;@ ~lib/allocator/tlsf.ts:452:29
11791179
(i32.const 0)
11801180
)
11811181
;;@ ~lib/allocator/tlsf.ts:451:42
1182-
(set_local $4
1182+
(set_local $3
11831183
(i32.add
11841184
;;@ ~lib/allocator/tlsf.ts:451:44
1185-
(get_local $4)
1185+
(get_local $3)
11861186
(i32.const 1)
11871187
)
11881188
)
@@ -1211,7 +1211,7 @@
12111211
(i32.and
12121212
(i32.add
12131213
;;@ ~lib/allocator/tlsf.ts:455:20
1214-
(get_local $3)
1214+
(get_local $4)
12151215
(i32.const 2923)
12161216
)
12171217
(i32.const -8)
@@ -1253,7 +1253,7 @@
12531253
;;@ ~lib/allocator/tlsf.ts:466:8
12541254
(i32.eqz
12551255
;;@ ~lib/allocator/tlsf.ts:465:4
1256-
(tee_local $3
1256+
(tee_local $1
12571257
;;@ ~lib/allocator/tlsf.ts:465:21
12581258
(call $~lib/allocator/tlsf/Root#search
12591259
;;@ ~lib/allocator/tlsf.ts:465:16
@@ -1262,7 +1262,7 @@
12621262
(tee_local $0
12631263
;;@ ~lib/allocator/tlsf.ts:463:11
12641264
(select
1265-
(tee_local $3
1265+
(tee_local $1
12661266
;;@ ~lib/allocator/tlsf.ts:463:22
12671267
(i32.and
12681268
(i32.add
@@ -1274,13 +1274,13 @@
12741274
(i32.const -8)
12751275
)
12761276
)
1277-
(tee_local $1
1277+
(tee_local $3
12781278
;;@ ~lib/allocator/tlsf.ts:463:51
12791279
(i32.const 16)
12801280
)
12811281
(i32.gt_u
1282-
(get_local $3)
12831282
(get_local $1)
1283+
(get_local $3)
12841284
)
12851285
)
12861286
)
@@ -1296,16 +1296,16 @@
12961296
(grow_memory
12971297
;;@ ~lib/allocator/tlsf.ts:471:24
12981298
(select
1299-
(tee_local $3
1299+
(tee_local $1
13001300
;;@ ~lib/allocator/tlsf.ts:469:6
1301-
(tee_local $1
1301+
(tee_local $3
13021302
;;@ ~lib/allocator/tlsf.ts:469:24
13031303
(current_memory)
13041304
)
13051305
)
1306-
(tee_local $5
1306+
(tee_local $4
13071307
;;@ ~lib/allocator/tlsf.ts:470:6
1308-
(tee_local $4
1308+
(tee_local $5
13091309
;;@ ~lib/allocator/tlsf.ts:470:24
13101310
(i32.shr_u
13111311
(i32.and
@@ -1324,8 +1324,8 @@
13241324
)
13251325
)
13261326
(i32.gt_s
1327-
(get_local $3)
1328-
(get_local $5)
1327+
(get_local $1)
1328+
(get_local $4)
13291329
)
13301330
)
13311331
)
@@ -1338,7 +1338,7 @@
13381338
(i32.lt_s
13391339
(grow_memory
13401340
;;@ ~lib/allocator/tlsf.ts:473:24
1341-
(get_local $4)
1341+
(get_local $5)
13421342
)
13431343
;;@ ~lib/allocator/tlsf.ts:473:39
13441344
(i32.const 0)
@@ -1354,7 +1354,7 @@
13541354
(get_local $2)
13551355
;;@ ~lib/allocator/tlsf.ts:478:21
13561356
(i32.shl
1357-
(get_local $1)
1357+
(get_local $3)
13581358
;;@ ~lib/allocator/tlsf.ts:478:43
13591359
(i32.const 16)
13601360
)
@@ -1368,7 +1368,7 @@
13681368
)
13691369
)
13701370
;;@ ~lib/allocator/tlsf.ts:479:6
1371-
(set_local $3
1371+
(set_local $1
13721372
;;@ ~lib/allocator/tlsf.ts:479:14
13731373
(call $~lib/allocator/tlsf/Root#search
13741374
;;@ ~lib/allocator/tlsf.ts:479:21
@@ -1386,7 +1386,7 @@
13861386
;;@ ~lib/allocator/tlsf.ts:483:11
13871387
(get_local $2)
13881388
;;@ ~lib/allocator/tlsf.ts:483:20
1389-
(get_local $3)
1389+
(get_local $1)
13901390
;;@ ~lib/allocator/tlsf.ts:483:27
13911391
(get_local $0)
13921392
)

0 commit comments

Comments
 (0)