mirror of
https://github.com/irmen/prog8.git
synced 2025-11-03 19:16:13 +00:00
fix broken uword comparison and asm peephole optimization
This commit is contained in:
@@ -463,15 +463,19 @@ private fun optimizeStoreLoadSame(
|
|||||||
mods.add(Modification(lines[2].index, true, null))
|
mods.add(Modification(lines[2].index, true, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
// all 3 registers: lda VALUE + sta SOMEWHERE + lda VALUE -> last load can be eliminated
|
// all 3 registers: lda VALUE + sta SOMEWHERE + lda VALUE -> last load can be eliminated IF NOT IO ADDRESS
|
||||||
if (first.startsWith("lda ") && second.startsWith("sta ") && third.startsWith("lda ") ||
|
if (first.startsWith("lda ") && second.startsWith("sta ") && third.startsWith("lda ") ||
|
||||||
first.startsWith("ldx ") && second.startsWith("stx ") && third.startsWith("ldx ") ||
|
first.startsWith("ldx ") && second.startsWith("stx ") && third.startsWith("ldx ") ||
|
||||||
first.startsWith("ldy ") && second.startsWith("sty ") && third.startsWith("ldy ")
|
first.startsWith("ldy ") && second.startsWith("sty ") && third.startsWith("ldy ")
|
||||||
) {
|
) {
|
||||||
val firstVal = first.substring(4).trimStart()
|
val firstVal = first.substring(4).trimStart()
|
||||||
val thirdVal = third.substring(4).trimStart()
|
val thirdVal = third.substring(4).trimStart()
|
||||||
if (firstVal == thirdVal)
|
if (firstVal == thirdVal) {
|
||||||
mods.add(Modification(lines[3].index, true, null))
|
val address = getAddressArg(third, symbolTable)
|
||||||
|
if (address != null && !machine.isIOAddress(address)) {
|
||||||
|
mods.add(Modification(lines[3].index, true, null))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mods
|
return mods
|
||||||
|
|||||||
@@ -434,7 +434,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
|
|||||||
|
|
||||||
fun isFactorOf256(number: Double): Boolean {
|
fun isFactorOf256(number: Double): Boolean {
|
||||||
val intValue = number.toInt()
|
val intValue = number.toInt()
|
||||||
return intValue > 0 && (intValue and (intValue shl 8)) == 0
|
return intValue >= 256 && (intValue and 0xFF) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leftDt.isUnsignedWord && rightVal!=null) {
|
if (leftDt.isUnsignedWord && rightVal!=null) {
|
||||||
@@ -465,7 +465,6 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
|
|||||||
else if(expr.operator == "<" && rightVal.number == 256.0 || expr.operator == "<=" && rightVal.number == 255.0) {
|
else if(expr.operator == "<" && rightVal.number == 256.0 || expr.operator == "<=" && rightVal.number == 255.0) {
|
||||||
// uword < 256 --> msb(value)==0
|
// uword < 256 --> msb(value)==0
|
||||||
// uword <= 255 --> msb(value)==0
|
// uword <= 255 --> msb(value)==0
|
||||||
// OK!
|
|
||||||
expr.operator = "=="
|
expr.operator = "=="
|
||||||
expr.left = FunctionCallExpression(IdentifierReference(listOf("msb"), expr.left.position), mutableListOf(expr.left), expr.left.position)
|
expr.left = FunctionCallExpression(IdentifierReference(listOf("msb"), expr.left.position), mutableListOf(expr.left), expr.left.position)
|
||||||
expr.right = NumericLiteral(BaseDataType.UBYTE, 0.0, expr.right.position)
|
expr.right = NumericLiteral(BaseDataType.UBYTE, 0.0, expr.right.position)
|
||||||
|
|||||||
@@ -1,15 +1,6 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
REGRESSIONS:
|
|
||||||
halloween , musicdemo is broken (wrong fade colors, hangs)
|
|
||||||
benchmark program: circles with gfx_lores is broken (black screen, returns immediately)
|
|
||||||
megascroll is 20 bytes larger
|
|
||||||
chess is a dozen bytes larger
|
|
||||||
petaxian is much larger
|
|
||||||
imageviewer/shell view: team17.iff blackscreen
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
STRUCTS and TYPED POINTERS
|
STRUCTS and TYPED POINTERS
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user