mirror of
https://github.com/irmen/prog8.git
synced 2024-09-08 10:55:08 +00:00
todo
This commit is contained in:
parent
6922333755
commit
496a3b0d2c
@ -67,11 +67,14 @@ graphics {
|
|||||||
if positive_ix {
|
if positive_ix {
|
||||||
repeat {
|
repeat {
|
||||||
internal_plot(y1)
|
internal_plot(y1)
|
||||||
if internal_plotx==x2
|
cmp(internal_plotx,x2)
|
||||||
return
|
if_eq return
|
||||||
|
; if internal_plotx==x2
|
||||||
|
; return
|
||||||
internal_plotx++
|
internal_plotx++
|
||||||
d += dy2
|
d += dy2
|
||||||
if d > dx {
|
cmp(d,dx)
|
||||||
|
if_pl {
|
||||||
y1++
|
y1++
|
||||||
d -= dx2
|
d -= dx2
|
||||||
}
|
}
|
||||||
@ -79,11 +82,14 @@ graphics {
|
|||||||
} else {
|
} else {
|
||||||
repeat {
|
repeat {
|
||||||
internal_plot(y1)
|
internal_plot(y1)
|
||||||
if internal_plotx==x2
|
cmp(internal_plotx,x2)
|
||||||
return
|
if_eq return
|
||||||
|
; if internal_plotx==x2
|
||||||
|
; return
|
||||||
internal_plotx--
|
internal_plotx--
|
||||||
d += dy2
|
d += dy2
|
||||||
if d > dx {
|
cmp(d,dx)
|
||||||
|
if_pl {
|
||||||
y1++
|
y1++
|
||||||
d -= dx2
|
d -= dx2
|
||||||
}
|
}
|
||||||
@ -94,11 +100,14 @@ graphics {
|
|||||||
if positive_ix {
|
if positive_ix {
|
||||||
repeat {
|
repeat {
|
||||||
internal_plot(y1)
|
internal_plot(y1)
|
||||||
if y1 == y2
|
cmp(y1,y2)
|
||||||
return
|
if_eq return
|
||||||
|
; if y1 == y2
|
||||||
|
; return
|
||||||
y1++
|
y1++
|
||||||
d += dx2
|
d += dx2
|
||||||
if d > dy {
|
cmp(d,dy)
|
||||||
|
if_pl {
|
||||||
internal_plotx++
|
internal_plotx++
|
||||||
d -= dy2
|
d -= dy2
|
||||||
}
|
}
|
||||||
@ -106,11 +115,14 @@ graphics {
|
|||||||
} else {
|
} else {
|
||||||
repeat {
|
repeat {
|
||||||
internal_plot(y1)
|
internal_plot(y1)
|
||||||
if y1 == y2
|
cmp(y1,y2)
|
||||||
return
|
if_eq return
|
||||||
|
; if y1 == y2
|
||||||
|
; return
|
||||||
y1++
|
y1++
|
||||||
d += dx2
|
d += dx2
|
||||||
if d > dy {
|
cmp(d,dy)
|
||||||
|
if_pl {
|
||||||
internal_plotx--
|
internal_plotx--
|
||||||
d -= dy2
|
d -= dy2
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,8 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun translateComparisonExpressionWithJumpIfFalse(expr: BinaryExpression, jumpIfFalseLabel: String) {
|
internal fun translateComparisonExpressionWithJumpIfFalse(expr: BinaryExpression, jumpIfFalseLabel: String) {
|
||||||
// first, if it is of the form: <constvalue> <comparison> X , swap the operands around,
|
// This is a helper routine called from while, do-util, and if expressions to generate optimized conditional branching code.
|
||||||
// so that the constant value is always the right operand.
|
// First, if it is of the form: <constvalue> <comparison> X , then flip the expression so the constant is always the right operand.
|
||||||
var left = expr.left
|
var left = expr.left
|
||||||
var right = expr.right
|
var right = expr.right
|
||||||
var operator = expr.operator
|
var operator = expr.operator
|
||||||
@ -396,6 +396,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
||||||
asmgen.out(" cmp P8ZP_SCRATCH_B1 | bcs $jumpIfFalseLabel")
|
asmgen.out(" cmp P8ZP_SCRATCH_B1 | bcs $jumpIfFalseLabel")
|
||||||
@ -425,6 +426,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
@ -461,6 +463,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize this so it doesn't call a comparison-subroutine
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
||||||
asmgen.out(" jsr prog8_lib.reg_less_uw | beq $jumpIfFalseLabel")
|
asmgen.out(" jsr prog8_lib.reg_less_uw | beq $jumpIfFalseLabel")
|
||||||
@ -491,6 +494,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize this so it doesn't call a comparison-subroutine
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
||||||
asmgen.out(" jsr prog8_lib.reg_less_w | beq $jumpIfFalseLabel")
|
asmgen.out(" jsr prog8_lib.reg_less_w | beq $jumpIfFalseLabel")
|
||||||
@ -526,6 +530,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
@ -560,6 +565,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
@ -602,6 +608,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize this so it doesn't call a comparison-subroutine
|
||||||
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
|
||||||
asmgen.out(" jsr prog8_lib.reg_less_uw | beq $jumpIfFalseLabel")
|
asmgen.out(" jsr prog8_lib.reg_less_uw | beq $jumpIfFalseLabel")
|
||||||
@ -638,6 +645,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize this so it doesn't call a comparison-subroutine
|
||||||
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
|
||||||
asmgen.out(" jsr prog8_lib.reg_less_w | beq $jumpIfFalseLabel")
|
asmgen.out(" jsr prog8_lib.reg_less_w | beq $jumpIfFalseLabel")
|
||||||
@ -680,6 +688,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
@ -717,6 +726,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
@ -756,6 +766,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize this so it doesn't call a comparison-subroutine
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
||||||
asmgen.out(" jsr prog8_lib.reg_lesseq_uw | beq $jumpIfFalseLabel")
|
asmgen.out(" jsr prog8_lib.reg_lesseq_uw | beq $jumpIfFalseLabel")
|
||||||
@ -792,6 +803,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize this so it doesn't call a comparison-subroutine
|
||||||
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
|
||||||
asmgen.out(" jsr prog8_lib.reg_lesseq_w | beq $jumpIfFalseLabel")
|
asmgen.out(" jsr prog8_lib.reg_lesseq_w | beq $jumpIfFalseLabel")
|
||||||
@ -822,6 +834,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
||||||
asmgen.out(" cmp P8ZP_SCRATCH_B1 | bcc $jumpIfFalseLabel")
|
asmgen.out(" cmp P8ZP_SCRATCH_B1 | bcc $jumpIfFalseLabel")
|
||||||
@ -854,6 +867,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
@ -888,6 +902,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize this so it doesn't call a comparison-subroutine
|
||||||
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
|
||||||
asmgen.out(" jsr prog8_lib.reg_lesseq_uw | beq $jumpIfFalseLabel")
|
asmgen.out(" jsr prog8_lib.reg_lesseq_uw | beq $jumpIfFalseLabel")
|
||||||
@ -919,6 +934,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize this so it doesn't call a comparison-subroutine
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
||||||
asmgen.out(" jsr prog8_lib.reg_lesseq_w | beq $jumpIfFalseLabel")
|
asmgen.out(" jsr prog8_lib.reg_lesseq_w | beq $jumpIfFalseLabel")
|
||||||
@ -950,6 +966,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
||||||
asmgen.out(" cmp P8ZP_SCRATCH_B1 | bne $jumpIfFalseLabel")
|
asmgen.out(" cmp P8ZP_SCRATCH_B1 | bne $jumpIfFalseLabel")
|
||||||
@ -981,6 +998,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
|
||||||
asmgen.out(" cmp P8ZP_SCRATCH_B1 | beq $jumpIfFalseLabel")
|
asmgen.out(" cmp P8ZP_SCRATCH_B1 | beq $jumpIfFalseLabel")
|
||||||
@ -1014,6 +1032,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
@ -1053,6 +1072,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO optimize if right is variable or mem-read to avoid use of ZP location
|
||||||
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
|
@ -3,6 +3,8 @@ TODO
|
|||||||
====
|
====
|
||||||
|
|
||||||
- optimize comparisons followed by a conditional jump ; try to not have to jsr to the comparison routines. (so if/while/do-until are faster)
|
- optimize comparisons followed by a conditional jump ; try to not have to jsr to the comparison routines. (so if/while/do-until are faster)
|
||||||
|
see: ExpressionAsmGen translateXXXXXJump() routines, all called from translateComparisonExpressionWithJumpIfFalse()
|
||||||
|
- add cx16 vload()
|
||||||
|
|
||||||
- optimize several inner loops in gfx2
|
- optimize several inner loops in gfx2
|
||||||
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
|
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
|
||||||
|
@ -3,21 +3,12 @@
|
|||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
byte xx
|
|
||||||
word yy
|
|
||||||
|
|
||||||
uword addr = $3000
|
|
||||||
cmp(xx, @($2000))
|
|
||||||
cmp(@($2000), xx)
|
|
||||||
cmp(yy, @($2000))
|
|
||||||
cmp(@($2000), yy)
|
|
||||||
}
|
|
||||||
sub start3() {
|
|
||||||
|
|
||||||
byte xx
|
byte xx
|
||||||
byte yy
|
byte yy
|
||||||
|
|
||||||
; all comparisons with constant values are already optimized
|
; all comparisons with constant values are already optimized.
|
||||||
|
; but for variables (and memreads) we can optimize further (don't use temporary ZP location)
|
||||||
|
|
||||||
byte value = 100
|
byte value = 100
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user