Skip to content

Commit 7e237cc

Browse files
authored
fix: optimize instruction sequence of interrupt (#2984)
1 parent 459b239 commit 7e237cc

File tree

167 files changed

+919
-997
lines changed

Some content is hidden

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

167 files changed

+919
-997
lines changed

std/assembly/rt/itcms.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,12 @@ function interrupt(): void {
403403
budget -= step();
404404
if (state == STATE_IDLE) {
405405
if (TRACE) trace("└ GC (auto) done at cur/max", 2, total, memory.size() << 16);
406-
threshold = <usize>(<u64>total * IDLEFACTOR / 100) + GRANULARITY;
406+
if (IDLEFACTOR % 100 == 0) {
407+
// optimization for the default GC parameters which idle factor is 200%
408+
threshold = total * (IDLEFACTOR / 100) + GRANULARITY;
409+
} else {
410+
threshold = <usize>((<u64>total * IDLEFACTOR) / 100) + GRANULARITY;
411+
}
407412
if (PROFILE) onyield(total);
408413
return;
409414
}

tests/compiler/assignment-chain.debug.wat

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,14 +1629,17 @@
16291629
if
16301630
i32.const 0
16311631
drop
1632+
i32.const 200
1633+
i32.const 100
1634+
i32.rem_u
1635+
i32.const 0
1636+
i32.eq
1637+
drop
16321638
global.get $~lib/rt/itcms/total
1633-
i64.extend_i32_u
16341639
i32.const 200
1635-
i64.extend_i32_u
1636-
i64.mul
1637-
i64.const 100
1638-
i64.div_u
1639-
i32.wrap_i64
1640+
i32.const 100
1641+
i32.div_u
1642+
i32.mul
16401643
i32.const 1024
16411644
i32.add
16421645
global.set $~lib/rt/itcms/threshold

tests/compiler/assignment-chain.release.wat

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,12 +1243,8 @@
12431243
i32.eqz
12441244
if
12451245
global.get $~lib/rt/itcms/total
1246-
i64.extend_i32_u
1247-
i64.const 200
1248-
i64.mul
1249-
i64.const 100
1250-
i64.div_u
1251-
i32.wrap_i64
1246+
i32.const 1
1247+
i32.shl
12521248
i32.const 1024
12531249
i32.add
12541250
global.set $~lib/rt/itcms/threshold

tests/compiler/bindings/esm.debug.wat

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,14 +1755,17 @@
17551755
if
17561756
i32.const 0
17571757
drop
1758+
i32.const 200
1759+
i32.const 100
1760+
i32.rem_u
1761+
i32.const 0
1762+
i32.eq
1763+
drop
17581764
global.get $~lib/rt/itcms/total
1759-
i64.extend_i32_u
17601765
i32.const 200
1761-
i64.extend_i32_u
1762-
i64.mul
1763-
i64.const 100
1764-
i64.div_u
1765-
i32.wrap_i64
1766+
i32.const 100
1767+
i32.div_u
1768+
i32.mul
17661769
i32.const 1024
17671770
i32.add
17681771
global.set $~lib/rt/itcms/threshold

tests/compiler/bindings/esm.release.wat

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,12 +1363,8 @@
13631363
i32.eqz
13641364
if
13651365
global.get $~lib/rt/itcms/total
1366-
i64.extend_i32_u
1367-
i64.const 200
1368-
i64.mul
1369-
i64.const 100
1370-
i64.div_u
1371-
i32.wrap_i64
1366+
i32.const 1
1367+
i32.shl
13721368
i32.const 1024
13731369
i32.add
13741370
global.set $~lib/rt/itcms/threshold

tests/compiler/bindings/noExportRuntime.debug.wat

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,14 +1650,17 @@
16501650
if
16511651
i32.const 0
16521652
drop
1653+
i32.const 200
1654+
i32.const 100
1655+
i32.rem_u
1656+
i32.const 0
1657+
i32.eq
1658+
drop
16531659
global.get $~lib/rt/itcms/total
1654-
i64.extend_i32_u
16551660
i32.const 200
1656-
i64.extend_i32_u
1657-
i64.mul
1658-
i64.const 100
1659-
i64.div_u
1660-
i32.wrap_i64
1661+
i32.const 100
1662+
i32.div_u
1663+
i32.mul
16611664
i32.const 1024
16621665
i32.add
16631666
global.set $~lib/rt/itcms/threshold

tests/compiler/bindings/noExportRuntime.release.wat

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,12 +1296,8 @@
12961296
i32.eqz
12971297
if
12981298
global.get $~lib/rt/itcms/total
1299-
i64.extend_i32_u
1300-
i64.const 200
1301-
i64.mul
1302-
i64.const 100
1303-
i64.div_u
1304-
i32.wrap_i64
1299+
i32.const 1
1300+
i32.shl
13051301
i32.const 1024
13061302
i32.add
13071303
global.set $~lib/rt/itcms/threshold

tests/compiler/bindings/raw.debug.wat

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,14 +1758,17 @@
17581758
if
17591759
i32.const 0
17601760
drop
1761+
i32.const 200
1762+
i32.const 100
1763+
i32.rem_u
1764+
i32.const 0
1765+
i32.eq
1766+
drop
17611767
global.get $~lib/rt/itcms/total
1762-
i64.extend_i32_u
17631768
i32.const 200
1764-
i64.extend_i32_u
1765-
i64.mul
1766-
i64.const 100
1767-
i64.div_u
1768-
i32.wrap_i64
1769+
i32.const 100
1770+
i32.div_u
1771+
i32.mul
17691772
i32.const 1024
17701773
i32.add
17711774
global.set $~lib/rt/itcms/threshold

tests/compiler/bindings/raw.release.wat

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,12 +1363,8 @@
13631363
i32.eqz
13641364
if
13651365
global.get $~lib/rt/itcms/total
1366-
i64.extend_i32_u
1367-
i64.const 200
1368-
i64.mul
1369-
i64.const 100
1370-
i64.div_u
1371-
i32.wrap_i64
1366+
i32.const 1
1367+
i32.shl
13721368
i32.const 1024
13731369
i32.add
13741370
global.set $~lib/rt/itcms/threshold

tests/compiler/call-inferred.debug.wat

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,14 +1655,17 @@
16551655
if
16561656
i32.const 0
16571657
drop
1658+
i32.const 200
1659+
i32.const 100
1660+
i32.rem_u
1661+
i32.const 0
1662+
i32.eq
1663+
drop
16581664
global.get $~lib/rt/itcms/total
1659-
i64.extend_i32_u
16601665
i32.const 200
1661-
i64.extend_i32_u
1662-
i64.mul
1663-
i64.const 100
1664-
i64.div_u
1665-
i32.wrap_i64
1666+
i32.const 100
1667+
i32.div_u
1668+
i32.mul
16661669
i32.const 1024
16671670
i32.add
16681671
global.set $~lib/rt/itcms/threshold

0 commit comments

Comments
 (0)