pub enum Fused {
None,
AddImmLoc,
AddAtomLoc,
AddLocLoc,
AddArgLoc,
PostIncLoc,
StoreImm,
LtLocArgJump,
LtLocImmJump,
}Expand description
A fused instruction, and how many records it stands for.
Only shapes that cannot throw are fused, because at — the offset a stack trace
reports — names the first instruction of the group. A fused x += 1 that raised
would blame the wrong column; a fused x += 1 on integers cannot raise.
Variants§
None
Not fused: run Insn::op.
AddImmLoc
x += k for an integer k: get_loc x; push k; add; put_loc x.
Four dispatches become one, and this is the most common four-instruction group
in JavaScript — i += 1, total += n, every accumulator in every loop.
AddAtomLoc
x += "literal": get_loc x; push_atom_value atom; add; put_loc x.
The same group with a string constant instead of an integer, and it exists for one
reason beyond dispatch: the reference’s OP_add_loc hands the variable’s own
string to JS_ConcatStringInPlace, so text += "abc" in a loop grows one buffer
instead of building a new string per iteration. Reproducing it needs the group
fused, because only then is the variable’s one handle the only handle — through
get_loc alone it has already been cloned once.
AddLocLoc
x += y: get_loc x; get_loc y; add; put_loc x.
The same, with the other operand also a local. a is (x << 16) | y, like
Fused::LtLocArgJump.
AddArgLoc
x += y where y is an argument: get_loc x; get_arg y; add; put_loc x.
Separate from Fused::AddLocLoc rather than a flag bit, because the two read
different arrays and a bit would make every reader of the operand check it.
PostIncLoc
x++ and the value is dropped: get_loc x; post_inc; put_loc x; drop.
StoreImm
x = k: push k; put_loc x.
LtLocArgJump
if (!(x < arg)) goto target — a loop’s header: get_loc x; get_arg arg; lt; if_false target.
The condition is the one instruction group that runs on every iteration of
every loop, so collapsing it is worth the packed operands: a is
(x << 16) | arg, b is the target instruction index.
LtLocImmJump
if (!(x < k)) goto target — a loop header whose bound is a literal:
get_loc x; push k; lt; if_false target.
Fused::LtLocArgJump covers for (var i = 0; i < n; i++), where the bound is a
parameter. This covers for (var i = 0; i < 1000; i++), where it is an immediate —
measured as a 40% slowdown against the reference when it did not fuse at all, since
the header is four dispatches on every iteration. a is the slot, b is the
target instruction index, imm is the bound.