Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up the addition of smallints #29

Open
kpp opened this issue Oct 1, 2013 · 2 comments
Open

Speed up the addition of smallints #29

kpp opened this issue Oct 1, 2013 · 2 comments
Labels
Milestone

Comments

@kpp
Copy link
Collaborator

kpp commented Oct 1, 2013

Temp int + const int is faster than const int + temp int:

    '1+1' printNl.
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+1] ] ;printNl .
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+1] ] ;printNl .
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+1] ] ;printNl .
    '' printNl.

    'x+x' printNl.
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+x] ] ;printNl .
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+x] ] ;printNl .
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+x] ] ;printNl .
    '' printNl.

    'x+1' printNl.
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+1] ] ;printNl .
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+1] ] ;printNl .
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+1] ] ;printNl .
    '' printNl.

    '1+x' printNl.
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+x] ] ;printNl .
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+x] ] ;printNl .
    Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+x] ] ;printNl .
    '' printNl.
1+1
677
678
679

x+x
674
673
684

x+1
650
648
653

1+x
695
696
697
@0x7CFE
Copy link
Owner

0x7CFE commented Dec 29, 2013

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?

@kpp
Copy link
Collaborator Author

kpp commented Jan 9, 2014

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

@0x7CFE 0x7CFE modified the milestones: Version 0.5, Version 0.3 May 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants