skip to content
==> include/wasm/fuse.h <==
1/* @ajax/wasm-fuse: superinstructions for @ajax/wasm-interp. Over a function's lowered code
2 * (@ajax/wasm-lower), an operand-making instruction directly before a plain one -- `local.get A`
3 * or a constant before an arithmetic, compare, conversion, load or store -- becomes that
4 * instruction's operand, and `local.get A; local.get B` one instruction:
5 *
6 *   WASM_INS_L + op   push fp[a], then op           (a: the local)
7 *   WASM_INS_I + op   push the constant, then op    (b, or a for loads and stores: their b is the offset)
8 *   WASM_INS_GET2     push fp[a], fp[b]
9 *
10 * Nothing is fused across a branch target (a jump must land on a whole instruction), and every
11 * target -- branches, br_table entries -- is remapped. The interpreter runs a fused instruction as
12 * its operand push followed by the plain instruction's code, without a second dispatch. */
13#ifndef WASM_FUSE_H
14#define WASM_FUSE_H
15
16#include "wasm/lower.h"
17
18#include <stdbool.h>
19
20enum {
21    WASM_INS_L = 0x400,      /* + a plain op (< 0x200) */
22    WASM_INS_I = 0x600,      /* + a plain op (< 0x200) */
23    WASM_INS_GET2 = 0x800,
24    WASM_INS_FUSED_END
25};
26
27/* Fuses c in place. False only when out of memory (c is then unchanged). */
28bool wasm_fuse(wasm_fn_code *c);
29
30/* Whether a lowered instruction is a plain one fusion may take an operand into: one of the
31 * opcodes with a signature (not a constant), a load or a store. */
32bool wasm_fusible(uint16_t op);
33
34#endif