luau/CodeGen/include
Arseny Kapoulkine 66d379d293 Add SUBRK and DIVRK bytecode instructions to bytecode v5
Right now, we can compile R*K for all arithmetic instructions, but K*R
gets compiled into two instructions (LOADN/LOADK + arithmetic opcode).

This is problematic since it leads to reduced performance for some code.
However, we'd like to avoid adding reverse variants of ADDK et al for
all opcodes to avoid the increase in I$ footprint for interpreter.

Looking at the arithmetic instructions, % and // don't have interesting
use cases for K*V; ^ is sometimes used with constant on the left hand
side but this would need to call pow() by necessity in all cases so it
would be slow regardless of the dispatch overhead. This leaves the four
basic arithmetic operations.

For + and *, we can implement a compiler-side optimization in the future
that transforms K*R to R*K automatically. This could either be done
unconditionally at -O2, or conditionally based on the type of the value
(driven by type annotations / inference) -- this technically changes
behavior in presence of metamethods, although it might be sensible to
just always do this because non-commutative +/* are evil.

However, for - and / it is impossible for the compiler to optimize this
in the future, so we need dedicated opcodes. This only increases the
interpreter size by ~300 bytes (~1.5%) on X64.

This makes spectral-norm and math-partial-sums 6% faster.

To avoid the proliferation of bytecode versions this change piggybacks
on the bytecode version bump that was just made in 604 for vector
constants; we would still be able to enable these independently but
we'll consider v5 complete when both are enabled.
2023-11-27 09:43:05 -08:00
..
Luau Add SUBRK and DIVRK bytecode instructions to bytecode v5 2023-11-27 09:43:05 -08:00
luacodegen.h Sync to upstream/release/588 (#992) 2023-07-28 08:13:53 -07:00