mirror of
https://github.com/irmen/prog8.git
synced 2024-11-27 03:50:27 +00:00
optimized ubyte comparison expressions
This commit is contained in:
parent
c65279b672
commit
533d825f1a
@ -690,8 +690,97 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun assignOptimizedComparisonBytes(expr: PtBinaryExpression, assign: AsmAssignment): Boolean {
|
private fun assignOptimizedComparisonBytes(expr: PtBinaryExpression, assign: AsmAssignment): Boolean {
|
||||||
// TODO("Not yet implemented")
|
val signed = expr.left.type == DataType.BYTE || expr.right.type == DataType.BYTE
|
||||||
return false
|
|
||||||
|
fun assignExpressionOperandsLeftScratchRightA() {
|
||||||
|
if(expr.right.isSimple()) {
|
||||||
|
assignExpressionToVariable(expr.left, "P8ZP_SCRATCH_B1", DataType.UBYTE)
|
||||||
|
assignExpressionToRegister(expr.right, RegisterOrPair.A, signed)
|
||||||
|
} else {
|
||||||
|
assignExpressionToRegister(expr.right, RegisterOrPair.A, signed)
|
||||||
|
asmgen.saveRegisterStack(CpuRegister.A, false)
|
||||||
|
assignExpressionToVariable(expr.left, "P8ZP_SCRATCH_B1", DataType.UBYTE)
|
||||||
|
asmgen.restoreRegisterStack(CpuRegister.A, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
when(expr.operator) {
|
||||||
|
"==" -> {
|
||||||
|
assignExpressionOperandsLeftScratchRightA()
|
||||||
|
asmgen.out("""
|
||||||
|
cmp P8ZP_SCRATCH_B1
|
||||||
|
beq +
|
||||||
|
lda #0
|
||||||
|
beq ++
|
||||||
|
+ lda #1
|
||||||
|
+""")
|
||||||
|
}
|
||||||
|
"!=" -> {
|
||||||
|
assignExpressionOperandsLeftScratchRightA()
|
||||||
|
asmgen.out("""
|
||||||
|
cmp P8ZP_SCRATCH_B1
|
||||||
|
bne +
|
||||||
|
lda #0
|
||||||
|
beq ++
|
||||||
|
+ lda #1
|
||||||
|
+""")
|
||||||
|
}
|
||||||
|
"<" -> {
|
||||||
|
assignExpressionOperandsLeftScratchRightA()
|
||||||
|
if(signed)
|
||||||
|
return false // TODO("< signed")
|
||||||
|
else
|
||||||
|
asmgen.out("""
|
||||||
|
cmp P8ZP_SCRATCH_B1
|
||||||
|
beq +
|
||||||
|
bcs ++
|
||||||
|
+ lda #0
|
||||||
|
beq ++
|
||||||
|
+ lda #1
|
||||||
|
+""")
|
||||||
|
}
|
||||||
|
"<=" -> {
|
||||||
|
assignExpressionOperandsLeftScratchRightA()
|
||||||
|
if(signed)
|
||||||
|
return false // TODO("< signed")
|
||||||
|
else
|
||||||
|
asmgen.out("""
|
||||||
|
cmp P8ZP_SCRATCH_B1
|
||||||
|
lda #0
|
||||||
|
rol a""")
|
||||||
|
}
|
||||||
|
">" -> {
|
||||||
|
assignExpressionOperandsLeftScratchRightA()
|
||||||
|
if(signed)
|
||||||
|
return false // TODO("< signed")
|
||||||
|
else
|
||||||
|
asmgen.out("""
|
||||||
|
cmp P8ZP_SCRATCH_B1
|
||||||
|
bcc +
|
||||||
|
lda #0
|
||||||
|
beq ++
|
||||||
|
+ lda #1
|
||||||
|
+""")
|
||||||
|
}
|
||||||
|
">=" -> {
|
||||||
|
assignExpressionOperandsLeftScratchRightA()
|
||||||
|
if(signed)
|
||||||
|
return false // TODO(">= signed")
|
||||||
|
else
|
||||||
|
asmgen.out("""
|
||||||
|
cmp P8ZP_SCRATCH_B1
|
||||||
|
bcc +
|
||||||
|
beq +
|
||||||
|
lda #0
|
||||||
|
beq ++
|
||||||
|
+ lda #1
|
||||||
|
+""")
|
||||||
|
}
|
||||||
|
else -> return false
|
||||||
|
}
|
||||||
|
|
||||||
|
assignRegisterByte(assign.target, CpuRegister.A, signed)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assignOptimizedComparisonWords(expr: PtBinaryExpression, assign: AsmAssignment): Boolean {
|
private fun assignOptimizedComparisonWords(expr: PtBinaryExpression, assign: AsmAssignment): Boolean {
|
||||||
|
@ -3,6 +3,9 @@ TODO
|
|||||||
|
|
||||||
For next minor release
|
For next minor release
|
||||||
^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
- assignOptimizedComparisonBytes() / assignOptimizedComparisonWords()
|
||||||
|
- find bcc/bcs branches that could be a rol?
|
||||||
|
- find adc #0 that could be a rol?
|
||||||
- try to optimize newexpr a bit more
|
- try to optimize newexpr a bit more
|
||||||
|
|
||||||
...
|
...
|
||||||
|
Loading…
Reference in New Issue
Block a user