mirror of
https://github.com/irmen/prog8.git
synced 2024-12-27 05:29:38 +00:00
rest of optimizations following simplification of array indexer
This commit is contained in:
parent
82a28bb555
commit
1a36302cf1
@ -208,17 +208,6 @@ pop_float_fac2 .proc
|
|||||||
jmp CONUPK
|
jmp CONUPK
|
||||||
.pend
|
.pend
|
||||||
|
|
||||||
pop_float_to_indexed_var .proc
|
|
||||||
; -- pop the float on the stack, to the memory in the array at A/Y indexed by the byte on stack
|
|
||||||
sta P8ZP_SCRATCH_W1
|
|
||||||
sty P8ZP_SCRATCH_W1+1
|
|
||||||
jsr prog8_lib.pop_index_times_5
|
|
||||||
jsr prog8_lib.add_a_to_zpword
|
|
||||||
lda P8ZP_SCRATCH_W1
|
|
||||||
ldy P8ZP_SCRATCH_W1+1
|
|
||||||
jmp pop_float
|
|
||||||
.pend
|
|
||||||
|
|
||||||
copy_float .proc
|
copy_float .proc
|
||||||
; -- copies the 5 bytes of the mflt value pointed to by SCRATCH_ZPWORD1,
|
; -- copies the 5 bytes of the mflt value pointed to by SCRATCH_ZPWORD1,
|
||||||
; into the 5 bytes pointed to by A/Y. Clobbers A,Y.
|
; into the 5 bytes pointed to by A/Y. Clobbers A,Y.
|
||||||
@ -707,13 +696,12 @@ sign_f .proc
|
|||||||
|
|
||||||
|
|
||||||
set_0_array_float .proc
|
set_0_array_float .proc
|
||||||
; -- set a float in an array to zero (index on stack, array in SCRATCH_ZPWORD1)
|
; -- set a float in an array to zero (index in A, array in P8ZP_SCRATCH_W1)
|
||||||
inx
|
sta P8ZP_SCRATCH_B1
|
||||||
lda P8ESTACK_LO,x
|
|
||||||
asl a
|
asl a
|
||||||
asl a
|
asl a
|
||||||
clc
|
clc
|
||||||
adc P8ESTACK_LO,x
|
adc P8ZP_SCRATCH_B1
|
||||||
tay
|
tay
|
||||||
lda #0
|
lda #0
|
||||||
sta (P8ZP_SCRATCH_W1),y
|
sta (P8ZP_SCRATCH_W1),y
|
||||||
@ -730,13 +718,12 @@ set_0_array_float .proc
|
|||||||
|
|
||||||
|
|
||||||
set_array_float .proc
|
set_array_float .proc
|
||||||
; -- set a float in an array to a value (index on stack, float in SCRATCH_ZPWORD1, array in SCRATCH_ZPWORD2)
|
; -- set a float in an array to a value (index in A, float in P8ZP_SCRATCH_W1, array in P8ZP_SCRATCH_W2)
|
||||||
inx
|
sta P8ZP_SCRATCH_B1
|
||||||
lda P8ESTACK_LO,x
|
|
||||||
asl a
|
asl a
|
||||||
asl a
|
asl a
|
||||||
clc
|
clc
|
||||||
adc P8ESTACK_LO,x
|
adc P8ZP_SCRATCH_B1
|
||||||
adc P8ZP_SCRATCH_W2
|
adc P8ZP_SCRATCH_W2
|
||||||
ldy P8ZP_SCRATCH_W2+1
|
ldy P8ZP_SCRATCH_W2+1
|
||||||
bcc +
|
bcc +
|
||||||
|
@ -40,16 +40,6 @@ add_a_to_zpword .proc
|
|||||||
+ rts
|
+ rts
|
||||||
.pend
|
.pend
|
||||||
|
|
||||||
pop_index_times_5 .proc
|
|
||||||
inx
|
|
||||||
lda P8ESTACK_LO,x
|
|
||||||
asl a
|
|
||||||
asl a
|
|
||||||
clc
|
|
||||||
adc P8ESTACK_LO,x
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
neg_b .proc
|
neg_b .proc
|
||||||
lda #0
|
lda #0
|
||||||
sec
|
sec
|
||||||
|
@ -529,15 +529,23 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
|||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
TargetStorageKind.ARRAY -> {
|
TargetStorageKind.ARRAY -> {
|
||||||
// TODO optimize this (array indexer is just a simple number or variable), but the situation doesn't occur very often ****************************************
|
asmgen.out("""
|
||||||
// if(target.constArrayIndexValue!=null) {
|
lda #<$sourceName
|
||||||
// TODO("const index ${target.constArrayIndexValue}")
|
ldy #>$sourceName
|
||||||
// } else if(target.array!!.arrayspec.index is IdentifierReference) {
|
sta P8ZP_SCRATCH_W1
|
||||||
// TODO("array[var] ${target.constArrayIndexValue}")
|
sty P8ZP_SCRATCH_W1+1
|
||||||
// }
|
lda #<${target.asmVarname}
|
||||||
asmgen.out(" lda #<$sourceName | ldy #>$sourceName | jsr floats.push_float")
|
ldy #>${target.asmVarname}
|
||||||
asmgen.translateExpression(target.array!!.indexer)
|
sta P8ZP_SCRATCH_W2
|
||||||
asmgen.out(" lda #<${target.asmVarname} | ldy #>${target.asmVarname} | jsr floats.pop_float_to_indexed_var")
|
sty P8ZP_SCRATCH_W2+1""")
|
||||||
|
if(target.array!!.indexer.indexNum!=null) {
|
||||||
|
val index = target.array.indexer.constIndex()!!
|
||||||
|
asmgen.out(" lda #$index")
|
||||||
|
} else {
|
||||||
|
val asmvarname = asmgen.asmVariableName(target.array.indexer.indexVar!!)
|
||||||
|
asmgen.out(" lda $asmvarname")
|
||||||
|
}
|
||||||
|
asmgen.out(" jsr floats.set_array_float")
|
||||||
}
|
}
|
||||||
TargetStorageKind.MEMORY -> throw AssemblyError("can't assign float to mem byte")
|
TargetStorageKind.MEMORY -> throw AssemblyError("can't assign float to mem byte")
|
||||||
TargetStorageKind.REGISTER -> throw AssemblyError("can't assign float to register")
|
TargetStorageKind.REGISTER -> throw AssemblyError("can't assign float to register")
|
||||||
@ -824,18 +832,8 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
|||||||
throw AssemblyError("no asm gen for assign word $word to memory ${target.memory}")
|
throw AssemblyError("no asm gen for assign word $word to memory ${target.memory}")
|
||||||
}
|
}
|
||||||
TargetStorageKind.ARRAY -> {
|
TargetStorageKind.ARRAY -> {
|
||||||
// TODO optimize this (array indexer is just a simple number or variable), but the situation doesn't occur very often ****************************************
|
asmgen.loadScaledArrayIndexIntoRegister(target.array!!, DataType.UWORD, CpuRegister.Y)
|
||||||
// if(target.constArrayIndexValue!=null) {
|
|
||||||
// TODO("const index ${target.constArrayIndexValue}")
|
|
||||||
// } else if(target.array!!.arrayspec.index is IdentifierReference) {
|
|
||||||
// TODO("array[var] ${target.constArrayIndexValue}")
|
|
||||||
// }
|
|
||||||
asmgen.translateExpression(target.array!!.indexer)
|
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
inx
|
|
||||||
lda P8ESTACK_LO,x
|
|
||||||
asl a
|
|
||||||
tay
|
|
||||||
lda #<${word.toHex()}
|
lda #<${word.toHex()}
|
||||||
sta ${target.asmVarname},y
|
sta ${target.asmVarname},y
|
||||||
lda #>${word.toHex()}
|
lda #>${word.toHex()}
|
||||||
@ -931,13 +929,13 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
|||||||
sta ${target.asmVarname}+$indexValue+4
|
sta ${target.asmVarname}+$indexValue+4
|
||||||
""")
|
""")
|
||||||
} else {
|
} else {
|
||||||
// TODO optimize this (don't use stack eval) as the indexer is only a simple variable ****************************************
|
val asmvarname = asmgen.asmVariableName(target.array.indexer.indexVar!!)
|
||||||
asmgen.translateExpression(target.array.indexer.indexVar!!)
|
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
lda #<${target.asmVarname}
|
lda #<${target.asmVarname}
|
||||||
sta P8ZP_SCRATCH_W1
|
sta P8ZP_SCRATCH_W1
|
||||||
lda #>${target.asmVarname}
|
lda #>${target.asmVarname}
|
||||||
sta P8ZP_SCRATCH_W1+1
|
sta P8ZP_SCRATCH_W1+1
|
||||||
|
lda $asmvarname
|
||||||
jsr floats.set_0_array_float
|
jsr floats.set_0_array_float
|
||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
@ -984,8 +982,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
|||||||
sta $arrayVarName+$indexValue+4
|
sta $arrayVarName+$indexValue+4
|
||||||
""")
|
""")
|
||||||
} else {
|
} else {
|
||||||
// TODO optimize this (don't use stack eval) as the indexer is only a simple variable ****************************************
|
val asmvarname = asmgen.asmVariableName(target.array.indexer.indexVar!!)
|
||||||
asmgen.translateExpression(target.array.indexer.indexVar!!)
|
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
lda #<${constFloat}
|
lda #<${constFloat}
|
||||||
sta P8ZP_SCRATCH_W1
|
sta P8ZP_SCRATCH_W1
|
||||||
@ -995,6 +992,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
|||||||
sta P8ZP_SCRATCH_W2
|
sta P8ZP_SCRATCH_W2
|
||||||
lda #>${arrayVarName}
|
lda #>${arrayVarName}
|
||||||
sta P8ZP_SCRATCH_W2+1
|
sta P8ZP_SCRATCH_W2+1
|
||||||
|
lda $asmvarname
|
||||||
jsr floats.set_array_float
|
jsr floats.set_array_float
|
||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
|
@ -7,25 +7,27 @@ main {
|
|||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
|
||||||
uword vv = $1111
|
uword[] array = [1, 2, 3]
|
||||||
uword vv2
|
uword fzero = 0.0
|
||||||
vv2 = vv2+(vv/2)
|
uword fnine = 9999
|
||||||
vv2 = vv2+(vv - 1)
|
array[0] = 0
|
||||||
vv2 = vv2+(vv + $0200)
|
ubyte ii = 1
|
||||||
vv2 = vv2+(vv - $0400)
|
array[ii] = 0
|
||||||
txt.print_uw(vv2)
|
|
||||||
txt.chrout('\n')
|
|
||||||
|
|
||||||
word ww = -$1111
|
uword ff
|
||||||
word ww2 = 0
|
for ii in 0 to len(array)-1 {
|
||||||
ww2 = ww2 + ww + $0200
|
txt.print_uw(array[ii])
|
||||||
ww2 = ww2 +ww - $0400
|
|
||||||
txt.print_w(ww2)
|
|
||||||
txt.chrout('\n')
|
txt.chrout('\n')
|
||||||
ww2= ww2 + ww + -$0200
|
}
|
||||||
ww2= ww2 + ww - -$0400
|
|
||||||
txt.print_w(ww2)
|
array[0] = 9
|
||||||
|
ii = 1
|
||||||
|
array[ii] = 9
|
||||||
|
|
||||||
|
for ii in 0 to len(array)-1 {
|
||||||
|
txt.print_uw(array[ii])
|
||||||
txt.chrout('\n')
|
txt.chrout('\n')
|
||||||
|
}
|
||||||
|
|
||||||
testX()
|
testX()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user