dplassgit / d2lang

D2 is a strongly-typed, statically-typed, (mostly) inferred-type compiled language.
MIT License
6 stars 0 forks source link

Optimize multiple ++s into += #227

Closed dplassgit closed 8 months ago

dplassgit commented 1 year ago
a++
a++
a++

is probably faster as

a=a+3
dplassgit commented 1 year ago

It's only faster if temps are not used, but they are.

On x64, an INC is 1 tick and an ADD is also one tick.

Assuming a is a parameter, a++ maps to inc ECX . Times 3 is 3 ticks

a=a+3 maps to

mov EBX, ECX
add EBX, 3
mov ECX, EBX

which is 3 ticks. I want to get this down to one tick: add ECX, 3 which is issue #178

dplassgit commented 8 months ago

Since issue #178 is closed, this can proceed.