Open kpp opened 11 years ago
What is the actual proposal here? Reorder the operands or patch the code inserting more efficient instruction?
Anyway, I don't think it's a very important optimization :) P.S.: What are the timings for the equivalent JIT execution?
The problem is: there is a huge difference in performance between 'x+1' and '1+x'. Take a look at the bytecode below:
METHOD Undefined
main
" initialize classes "
Char initialize.
" x+1 "
[:x| x+1].
'' printNl.
" 1+x "
[:x| 1+x].
File fileIn: '../image/disasm.st'.
Undefined methods at: #main; disassemble.
^nil.
!
0000 PushLiteral 0
0001 MarkArguments 1
0002 SendMessage initialize
0003 DoSpecial popTop
0004 PushBlock
0007 PushTemporary 2
0008 PushConstant 1
0009 SendBinary +
0010 DoSpecial stackReturn
0011 DoSpecial popTop
0012 PushLiteral 2
0013 MarkArguments 1
0014 SendMessage printNl
0015 DoSpecial popTop
0016 PushBlock
0019 PushConstant 1
0020 PushTemporary 2
0021 SendBinary +
0022 DoSpecial stackReturn
0023 DoSpecial popTop
0024 PushLiteral 4
0025 PushLiteral 5
0026 MarkArguments 2
0027 SendMessage fileIn:
0028 DoSpecial popTop
0029 PushLiteral 7
0030 MarkArguments 1
0031 SendMessage methods
0032 PushLiteral 9
0033 MarkArguments 2
0034 SendMessage at:
0035 DoSpecial duplicate
0036 MarkArguments 1
0037 SendMessage disassemble
0038 DoSpecial popTop
0039 PushConstant nil
0040 DoSpecial stackReturn
0041 DoSpecial popTop
0042 DoSpecial selfReturn
Temp int + const int is faster than const int + temp int: