optimize word array reads with indexvar

This commit is contained in:
Irmen de Jong 2023-10-14 07:18:37 +02:00
parent 68539d6cc9
commit 9ea69c07b8
3 changed files with 35 additions and 25 deletions

View File

@ -88,8 +88,8 @@ internal class AssignmentAsmGen(private val program: PtProgram,
assignRegisterpairWord(assign.target, RegisterOrPair.AY) assignRegisterpairWord(assign.target, RegisterOrPair.AY)
} else { } else {
asmgen.loadScaledArrayIndexIntoRegister(value, elementDt, CpuRegister.Y) asmgen.loadScaledArrayIndexIntoRegister(value, elementDt, CpuRegister.Y)
asmgen.out(" lda ${arrayVarName}_lsb,y | tax | lda ${arrayVarName}_msb,y | tay | txa") asmgen.out(" lda ${arrayVarName}_lsb,y | ldx ${arrayVarName}_msb,y")
assignRegisterpairWord(assign.target, RegisterOrPair.AY) assignRegisterpairWord(assign.target, RegisterOrPair.AX)
} }
return return
} }
@ -122,8 +122,8 @@ internal class AssignmentAsmGen(private val program: PtProgram,
} }
in WordDatatypes -> { in WordDatatypes -> {
asmgen.loadScaledArrayIndexIntoRegister(value, elementDt, CpuRegister.Y) asmgen.loadScaledArrayIndexIntoRegister(value, elementDt, CpuRegister.Y)
asmgen.out(" lda $arrayVarName,y | tax | lda $arrayVarName+1,y | tay | txa") asmgen.out(" lda $arrayVarName,y | ldx $arrayVarName+1,y")
assignRegisterpairWord(assign.target, RegisterOrPair.AY) assignRegisterpairWord(assign.target, RegisterOrPair.AX)
} }
DataType.FLOAT -> { DataType.FLOAT -> {
asmgen.loadScaledArrayIndexIntoRegister(value, elementDt, CpuRegister.A) asmgen.loadScaledArrayIndexIntoRegister(value, elementDt, CpuRegister.A)
@ -2209,7 +2209,8 @@ internal class AssignmentAsmGen(private val program: PtProgram,
else else
program.memsizer.memorySize(arrayDt!!, constIndex) // add arrayIndexExpr * elementsize to the address of the array variable. program.memsizer.memorySize(arrayDt!!, constIndex) // add arrayIndexExpr * elementsize to the address of the array variable.
} else { } else {
TODO("address-of array element $sourceName with non-const index at ${target.position}") val eltSize = program.memsizer.memorySize(ArrayToElementTypes.getValue(arrayDt!!))
TODO("address-of array element $sourceName size $eltSize with non-const index at ${target.position}")
} }
} else 0 } else 0

View File

@ -1,13 +1,7 @@
TODO TODO
==== ====
- optimize word array assignment to not use tax/tay etc but simply lda+ldx: (note: with and without @split!) - fix TODO "address-of array element" in assignAddressOf()
uword pstep = w_array[index] ->
ldy p8_index
lda p8_w_array,y
ldx p8_w_array+1,y
sta p8_pstep
stx p8_pstep+1
- gfx2: use vera auto in/decrement in the flood fill routine - gfx2: use vera auto in/decrement in the flood fill routine

View File

@ -1,18 +1,33 @@
%import textio
%zeropage basicsafe
main { main {
sub start() { sub start() {
cx16.r1H = %00000001 ; enable auto-indent uword[] w_array = [1111,2222,3333,4444]
cx16.r2L = 4 uword[] @split split_array = [1111,2222,3333,4444]
cx16.r2H = 80 ubyte index = 2
cx16.r3L = 8
cx16.r3H = 11<<4 | 7; background_color<<4 | text_color uword value = 9999
cx16.r4 = 0 w_array[index] = value
cx16.r1L = 0 split_array[index] = value
cx16.rombank($d)
%asm {{ uword pstep = w_array[index]
ldx #2 uword psteps = split_array[index]
ldy #64 ;; uword @zp ptr = &w_array[index]
jmp $c006
}} txt.print_uw(pstep)
txt.nl()
txt.print_uw(psteps)
txt.nl()
; txt.print_uw(peekw(ptr))
; txt.nl()
w_array[index] += 10
split_array[index] += 10
txt.print_uw(w_array[index])
txt.nl()
txt.print_uw(split_array[index])
txt.nl()
} }
} }