skip to content
[readonly]

Fuses local.get and constants into the next instruction of lowered WebAssembly code (superinstructions), remapping every branch

sh
$ sexc add @ajax/wasm-fuse
  • total 3
  • drwxr-xr-x-../
  • drwxr-xr-x-Oct 27 04:27v/# 1 version
  • drwxr-xr-x-Oct 27 04:27files/# the files of 0.1.0
latest
0.1.0, published Oct 27 04:27 by ajax
owners
ajax
license
MIT
dependencies
@ajax/wasm-lower ^0.1.0, @ajax/wasm-opcodes ^0.1.0, @ajax/mesh-check ^0.1.0, @ajax/wasm-builder ^0.1.0, @ajax/wasm-decode ^0.1.0, @ajax/wasm-validate ^0.1.0
dependents
@ajax/wasm-interp
keywords
wasm webassembly interpreter optimizer superinstructions
repository
https://github.com/thomasdavis/alpha-c-mesh
==> README.md <==
1# @ajax/wasm-fuse
2
3Superinstructions for `@ajax/wasm-interp`. Over a function's lowered code (`@ajax/wasm-lower`), an
4operand-making instruction directly before a plain one becomes that instruction's operand:
5`local.get A` or a constant before an arithmetic, compare, conversion, load or store, and
6`local.get A; local.get B` as one instruction. In clang's -O2 wasm32 output `local.get` is about a quarter
7of all instructions and constants a fifth, and the commonest pairs are exactly these. The interpreter
8runs a fused instruction as its operand push plus a jump into the plain instruction's code, so each pair
9costs one dispatch instead of two.
10
11Nothing is fused across a branch target (a jump must land on a whole instruction), and every target —
12branches, `if`, `br_table` entries — is remapped after the code shrinks.
13
14Part of alpha-c-mesh's WebAssembly interpreter (it replaces wasmtime's JIT in the port of
15alpha-rust-mesh's `mesh-host/src/wasm.rs`; see `@ajax/wasm-interp` for the speed this buys).
16
17Tests: `tests/fuse.c` (what fuses, what doesn't, targets remapped); the interpreter's spec,
18differential and fuzz tests run fused code.