You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's suppose we have a conditional expression cond ? val1 : val2. If both val1 and val2 are compile-time constants, the expression can be optimized into val1 + !cond * (val2 - val1), thus allowing to generate smaller and faster bytecode.
For example, if we have this code:
Leaving out the condition part (load.s.pri c), as well as the epilogue code (retn), this would be 4 instructions in 8 cells.
But if we rewrite the code in the following manner:
which is 3 instructions (again, without load.s.pri and retn) and only 5 cells, with no unnecessary branching, which means the code would be more JIT-friendly.
Currently such optimizations require code to be rewritten manually, but I'd like to modify the compiler so it could perform them automatically. But before doing that it would be nice to know if there's something that might make this kind of optimizations undesirable. Opinions are welcome.
Minimal complete verifiable example (MCVE):
Workspace Information:
Compiler version: 3.10.10
Command line arguments provided (or sampctl version):
Operating System:
The text was updated successfully, but these errors were encountered:
Issue description:
Let's suppose we have a conditional expression
cond ? val1 : val2
. If bothval1
andval2
are compile-time constants, the expression can be optimized intoval1 + !cond * (val2 - val1)
, thus allowing to generate smaller and faster bytecode.For example, if we have this code:
the compiler would generate the following bytecode for the
return
statement:Leaving out the condition part (
load.s.pri c
), as well as the epilogue code (retn
), this would be 4 instructions in 8 cells.But if we rewrite the code in the following manner:
the generated bytecode would be
which is 3 instructions (again, without
load.s.pri
andretn
) and only 5 cells, with no unnecessary branching, which means the code would be more JIT-friendly.Currently such optimizations require code to be rewritten manually, but I'd like to modify the compiler so it could perform them automatically. But before doing that it would be nice to know if there's something that might make this kind of optimizations undesirable. Opinions are welcome.
Minimal complete verifiable example (MCVE):
Workspace Information:
The text was updated successfully, but these errors were encountered: