extra attempt to simplify add and subtract with negative numbers

This commit is contained in:
Irmen de Jong 2020-10-19 22:51:18 +02:00
parent c1ce0be451
commit 82a28bb555
2 changed files with 19 additions and 5 deletions

View File

@ -1242,7 +1242,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
if(rightDt in ByteDatatypes) {
val incdec = if(leftVal<0) "dec" else "inc"
repeat(leftVal.absoluteValue) {
asmgen.out(" $incdec P8ESTACK_LO,x")
asmgen.out(" $incdec P8ESTACK_LO+1,x")
}
} else {
// word
@ -1272,7 +1272,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
if(leftDt in ByteDatatypes) {
val incdec = if(rightVal<0) "dec" else "inc"
repeat(rightVal.absoluteValue) {
asmgen.out(" $incdec P8ESTACK_LO,x")
asmgen.out(" $incdec P8ESTACK_LO+1,x")
}
} else {
// word
@ -1307,7 +1307,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
if(leftDt in ByteDatatypes) {
val incdec = if(rightVal<0) "inc" else "dec"
repeat(rightVal.absoluteValue) {
asmgen.out(" $incdec P8ESTACK_LO,x")
asmgen.out(" $incdec P8ESTACK_LO+1,x")
}
} else {
// word
@ -1418,9 +1418,9 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
// optimize x*2 common case
translateExpression(expr.left)
if(leftDt in ByteDatatypes) {
asmgen.out(" asl P8ESTACK_LO,x")
asmgen.out(" asl P8ESTACK_LO+1,x")
} else {
asmgen.out(" asl P8ESTACK_LO,x | rol P8ESTACK_HI,x")
asmgen.out(" asl P8ESTACK_LO+1,x | rol P8ESTACK_HI+1,x")
}
return
}

View File

@ -351,6 +351,13 @@ internal class ExpressionSimplifier(private val program: Program) : AstWalker()
}
// no need to check for left val constant (because of associativity)
val rnum = rightVal?.number?.toDouble()
if(rnum!=null && rnum<0.0) {
expr.operator = "-"
expr.right = NumericLiteralValue(rightVal.type, -rnum, rightVal.position)
return expr
}
return null
}
@ -383,6 +390,13 @@ internal class ExpressionSimplifier(private val program: Program) : AstWalker()
}
}
val rnum = rightVal?.number?.toDouble()
if(rnum!=null && rnum<0.0) {
expr.operator = "+"
expr.right = NumericLiteralValue(rightVal.type, -rnum, rightVal.position)
return expr
}
return null
}