mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 04:30:03 +00:00
tweak the redundant beq asm optimizer a bit more
This commit is contained in:
parent
f46896fd74
commit
fc0fae8caf
@ -58,7 +58,7 @@ internal fun optimizeAssembly(lines: MutableList<String>, machine: IMachineDefin
|
|||||||
numberOfOptimizations++
|
numberOfOptimizations++
|
||||||
}
|
}
|
||||||
|
|
||||||
mods = optimizeSamePointerIndexing(linesByFourteen)
|
mods = optimizeSamePointerIndexingAndUselessBeq(linesByFourteen)
|
||||||
if(mods.isNotEmpty()) {
|
if(mods.isNotEmpty()) {
|
||||||
apply(mods, lines)
|
apply(mods, lines)
|
||||||
linesByFourteen = getLinesBy(lines, 14)
|
linesByFourteen = getLinesBy(lines, 14)
|
||||||
@ -306,7 +306,7 @@ private fun optimizeSameAssignments(
|
|||||||
return mods
|
return mods
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun optimizeSamePointerIndexing(linesByFourteen: Sequence<List<IndexedValue<String>>>): List<Modification> {
|
private fun optimizeSamePointerIndexingAndUselessBeq(linesByFourteen: Sequence<List<IndexedValue<String>>>): List<Modification> {
|
||||||
|
|
||||||
// Optimize same pointer indexing where for instance we load and store to the same ptr index in Y
|
// Optimize same pointer indexing where for instance we load and store to the same ptr index in Y
|
||||||
// if Y isn't modified in between we can omit the second LDY:
|
// if Y isn't modified in between we can omit the second LDY:
|
||||||
@ -343,6 +343,35 @@ private fun optimizeSamePointerIndexing(linesByFourteen: Sequence<List<IndexedVa
|
|||||||
mods.add(Modification(lines[4].index, true, null))
|
mods.add(Modification(lines[4].index, true, null))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
beq +
|
||||||
|
lda #1
|
||||||
|
+
|
||||||
|
[ optional: label_xxxx_shortcut line here]
|
||||||
|
beq label_xxxx_shortcut / bne label_xxxx_shortcut
|
||||||
|
or *_afterif labels.
|
||||||
|
|
||||||
|
This gets generated after certain if conditions, and only the branch instruction is needed in these cases.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(first=="beq +" && second=="lda #1" && third=="+") {
|
||||||
|
if((fourth.startsWith("beq label_") || fourth.startsWith("bne label_")) &&
|
||||||
|
(fourth.endsWith("_shortcut") || fourth.endsWith("_afterif") || fourth.endsWith("_shortcut:") || fourth.endsWith("_afterif:"))) {
|
||||||
|
mods.add(Modification(lines[0].index, true, null))
|
||||||
|
mods.add(Modification(lines[1].index, true, null))
|
||||||
|
mods.add(Modification(lines[2].index, true, null))
|
||||||
|
}
|
||||||
|
else if(fourth.startsWith("label_") && (fourth.endsWith("_shortcut") || fourth.endsWith("_shortcut:"))) {
|
||||||
|
if((fifth.startsWith("beq label_") || fifth.startsWith("bne label_")) &&
|
||||||
|
(fifth.endsWith("_shortcut") || fifth.endsWith("_afterif") || fifth.endsWith("_shortcut:") || fifth.endsWith("_afterif:"))) {
|
||||||
|
mods.add(Modification(lines[0].index, true, null))
|
||||||
|
mods.add(Modification(lines[1].index, true, null))
|
||||||
|
mods.add(Modification(lines[2].index, true, null))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mods
|
return mods
|
||||||
@ -540,24 +569,6 @@ private fun optimizeJsrRtsAndOtherCombinations(linesByFour: Sequence<List<Indexe
|
|||||||
mods += Modification(lines[3].index, true, null)
|
mods += Modification(lines[3].index, true, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
beq +
|
|
||||||
lda #1
|
|
||||||
+
|
|
||||||
beq label_xxxx_shortcut / bne label_xxxx_shortcut
|
|
||||||
or *_afterif labels.
|
|
||||||
|
|
||||||
This gets generated after certain if conditions, and only the branch instruction is needed in these cases.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(tfirst=="beq +" && tsecond=="lda #1" && tthird=="+") {
|
|
||||||
if((tfourth.startsWith("beq label_") || tfourth.startsWith("bne label_")) && (tfourth.endsWith("_shortcut") || tfourth.endsWith("_afterif"))) {
|
|
||||||
mods.add(Modification(lines[0].index, true, null))
|
|
||||||
mods.add(Modification(lines[1].index, true, null))
|
|
||||||
mods.add(Modification(lines[2].index, true, null))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return mods
|
return mods
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user