don't optimize with inlining too aggressively (code bloat)

This commit is contained in:
Irmen de Jong 2021-03-16 00:33:15 +01:00
parent eb3594b18c
commit b5523c7077
3 changed files with 73 additions and 7 deletions

View File

@ -442,6 +442,19 @@ less_b .proc
bpl equal_b._equal_b_false
.pend
reg_less_uw .proc
; AY < P8ZP_SCRATCH_W2?
cpy P8ZP_SCRATCH_W2+1
bcc _true
bne _false
cmp P8ZP_SCRATCH_W2
bcc _true
_false lda #0
rts
_true lda #1
rts
.pend
less_uw .proc
lda P8ESTACK_HI+2,x
cmp P8ESTACK_HI+1,x

View File

@ -497,7 +497,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
return code("P8ZP_SCRATCH_W2+1", "P8ZP_SCRATCH_W2")
return asmgen.out(" jsr prog8_lib.reg_less_uw | beq $jumpIfFalseLabel")
}
private fun translateWordLessJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
@ -526,7 +526,13 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
}
}
// TODO optimize this so it doesn't call a comparison-subroutine reg_less_w
if(right is IdentifierReference) {
// TODO optimize comparison against identifier
// asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
// val varname = asmgen.asmVariableName(right)
// return code("$varname+1", varname)
}
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
return asmgen.out(" jsr prog8_lib.reg_less_w | beq $jumpIfFalseLabel")
@ -656,6 +662,17 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
}
private fun translateWordGreaterJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
fun code(msbCpyOperand: String, lsbCmpOperand: String) {
asmgen.out("""
cmp $lsbCmpOperand
tya
sbc $msbCpyOperand
bvc +
eor #${'$'}80
+ bpl $jumpIfFalseLabel""")
}
if(rightConstVal!=null) {
if(leftConstVal!=null) {
if(rightConstVal<=leftConstVal)
@ -685,7 +702,13 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
}
}
// TODO optimize this so it doesn't call a comparison-subroutine reg_less_w
if(right is IdentifierReference) {
// TODO optimize comparison against identifier
// asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
// val varname = asmgen.asmVariableName(right)
// return code("$varname+1", varname)
}
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
return asmgen.out(" jsr prog8_lib.reg_less_w | beq $jumpIfFalseLabel")
@ -797,7 +820,13 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
}
}
// TODO optimize this so it doesn't call a comparison-subroutine reg_lesseq_uw
if(right is IdentifierReference) {
// TODO optimize comparison against identifier
// asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
// val varname = asmgen.asmVariableName(right)
// return code("$varname+1", varname)
}
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
return asmgen.out(" jsr prog8_lib.reg_lesseq_uw | beq $jumpIfFalseLabel")
@ -833,7 +862,13 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
}
}
// TODO optimize this so it doesn't call a comparison-subroutine reg_lesseq_w
if(right is IdentifierReference) {
// TODO optimize comparison against identifier
// asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
// val varname = asmgen.asmVariableName(right)
// return code("$varname+1", varname)
}
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
return asmgen.out(" jsr prog8_lib.reg_lesseq_w | beq $jumpIfFalseLabel")
@ -934,7 +969,13 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
}
}
// TODO optimize this so it doesn't call a comparison-subroutine reg_lesseq_uw
if(right is IdentifierReference) {
// TODO optimize comparison against identifier
// asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
// val varname = asmgen.asmVariableName(right)
// return code("$varname+1", varname)
}
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
return asmgen.out(" jsr prog8_lib.reg_lesseq_uw | beq $jumpIfFalseLabel")
@ -964,7 +1005,13 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
}
}
// TODO optimize this so it doesn't call a comparison-subroutine reg_lesseq_w
if(right is IdentifierReference) {
// TODO optimize comparison against identifier
// asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
// val varname = asmgen.asmVariableName(right)
// return code("$varname+1", varname)
}
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
return asmgen.out(" jsr prog8_lib.reg_lesseq_w | beq $jumpIfFalseLabel")

View File

@ -46,6 +46,12 @@ main {
}
sub start() {
uword uw1
uword uw2
if uw1<uw2+2 {
uw1++
}
byte xx
byte yy