dplassgit / d2lang

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

Improve generation of array set and get #347

Open dplassgit opened 4 months ago

dplassgit commented 4 months ago

longtemp[0] = 1 is compiled to

  ; allocated RSI for calculations
  mov RSI, 5  ; const index; full index=1+dims*4+index*base size
  add RSI, RBX  ; actual location
  mov DWORD [RSI], 1  ; store it!

but it could be

  mov DWORD [RBX+5], 1  ; store it!
dplassgit commented 4 months ago

Even better, 386 supports completely orthogonal indexing, e.g., mov DWORD [RSI+RBX*4+5], 1

SEe https://www.plantation-productions.com/Webster/www.artofasm.com/DOS/ch04/CH04-3.html#HEADING3-49