Menu

#924 Missing optimization

open
nobody
Z80 (3)
5
2024-06-13
2024-06-12
No

One missing optimization is that when you have computed the address to an object in an array, you can point to another array (in the same position), just adding the difference of the addresses of the twoOne missing optimization is that when you have computed the address to an object in an array, you can point to another array (in the same position), just adding the difference of the addresses of the two arrays to the first address.

Eg

t0 = array0[j];
t1 = array1[j];

for chars can be optimised in this way

ld hl,(_j)
ld de,_array0
add hl,de
ld a,(hl)
ld (_t0),a
ld de,_array1-_array0
add hl,de
ld a,(hl)
ld (_t1),a

If the index is a complex expression the gain is bigger.
Even if the data are integers or long, the gain is bigger.
For integers you get

ld hl,(_j)
add hl,hl
ld de,_array0
add hl,de
ld de,_t0
ldi
ldi
ld de,_array1-_array0-2
add hl,de
ld de,_t1
ldi
ldi

Discussion

  • Maarten Brock

    Maarten Brock - 2024-06-13

    In the char case you could just as easily swap the use of DE and HL and load HL simply with _array1.

     
    • Ragozini Arturo

      Ragozini Arturo - 2024-06-13

      Not sure I'm understanding... Could you please write down the snippet ?

       

Log in to post a comment.