mirror of
https://github.com/irmen/prog8.git
synced 2025-03-01 00:30:03 +00:00
extra attempt to simplify add and subtract with negative numbers
This commit is contained in:
parent
c1ce0be451
commit
82a28bb555
@ -1242,7 +1242,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
if(rightDt in ByteDatatypes) {
|
if(rightDt in ByteDatatypes) {
|
||||||
val incdec = if(leftVal<0) "dec" else "inc"
|
val incdec = if(leftVal<0) "dec" else "inc"
|
||||||
repeat(leftVal.absoluteValue) {
|
repeat(leftVal.absoluteValue) {
|
||||||
asmgen.out(" $incdec P8ESTACK_LO,x")
|
asmgen.out(" $incdec P8ESTACK_LO+1,x")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// word
|
// word
|
||||||
@ -1272,7 +1272,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
if(leftDt in ByteDatatypes) {
|
if(leftDt in ByteDatatypes) {
|
||||||
val incdec = if(rightVal<0) "dec" else "inc"
|
val incdec = if(rightVal<0) "dec" else "inc"
|
||||||
repeat(rightVal.absoluteValue) {
|
repeat(rightVal.absoluteValue) {
|
||||||
asmgen.out(" $incdec P8ESTACK_LO,x")
|
asmgen.out(" $incdec P8ESTACK_LO+1,x")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// word
|
// word
|
||||||
@ -1307,7 +1307,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
if(leftDt in ByteDatatypes) {
|
if(leftDt in ByteDatatypes) {
|
||||||
val incdec = if(rightVal<0) "inc" else "dec"
|
val incdec = if(rightVal<0) "inc" else "dec"
|
||||||
repeat(rightVal.absoluteValue) {
|
repeat(rightVal.absoluteValue) {
|
||||||
asmgen.out(" $incdec P8ESTACK_LO,x")
|
asmgen.out(" $incdec P8ESTACK_LO+1,x")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// word
|
// word
|
||||||
@ -1418,9 +1418,9 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
// optimize x*2 common case
|
// optimize x*2 common case
|
||||||
translateExpression(expr.left)
|
translateExpression(expr.left)
|
||||||
if(leftDt in ByteDatatypes) {
|
if(leftDt in ByteDatatypes) {
|
||||||
asmgen.out(" asl P8ESTACK_LO,x")
|
asmgen.out(" asl P8ESTACK_LO+1,x")
|
||||||
} else {
|
} else {
|
||||||
asmgen.out(" asl P8ESTACK_LO,x | rol P8ESTACK_HI,x")
|
asmgen.out(" asl P8ESTACK_LO+1,x | rol P8ESTACK_HI+1,x")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -351,6 +351,13 @@ internal class ExpressionSimplifier(private val program: Program) : AstWalker()
|
|||||||
}
|
}
|
||||||
// no need to check for left val constant (because of associativity)
|
// 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
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user