Actual code generated:
Code: Select all
; array = arrayOfArray[index];
L0085: adc _arrayOfArray
;jsr ldaxi ; i've placed the subroutine inline here
function for reference.
That looks fairly efficient for what it does, but it's not able to do the final resolution of the pointer inline, it has to put the pointer in A:X and branch to that subroutine. (Jarhmander was missing the ASL by the way. CC65 does in fact know that index is 8-bit, but the implied *2 on the index promotes it to integer anyway.)
So in terms of efficiency, we've got maybe an extra JSR/RTS, PHA,PLA, TXA, TAX, TAX? About 25 extra cycles? The subroutine call itself accounts for half of it.
I kinda wonder how much efficiency CC65 would be able to gain with a special "7-bit index" type for accessing arrays of 16-bit data, that it could double without promoting to an int.