remove redundant asm optimizer

This commit is contained in:
Irmen de Jong 2023-07-16 11:15:28 +02:00
parent 3841cef497
commit ab8173637a
3 changed files with 9 additions and 50 deletions

View File

@ -22,13 +22,6 @@ internal fun optimizeAssembly(lines: MutableList<String>, machine: IMachineDefin
numberOfOptimizations++
}
mods = optimizeCmpSequence(linesByFour)
if(mods.isNotEmpty()) {
apply(mods, lines)
linesByFour = getLinesBy(lines, 4)
numberOfOptimizations++
}
mods = optimizeStoreLoadSame(linesByFour, machine, symbolTable)
if(mods.isNotEmpty()) {
apply(mods, lines)
@ -90,27 +83,6 @@ private fun getLinesBy(lines: MutableList<String>, windowSize: Int) =
// all lines (that aren't empty or comments) in sliding windows of certain size
lines.withIndex().filter { it.value.isNotBlank() && !it.value.trimStart().startsWith(';') }.windowed(windowSize, partialWindows = false)
private fun optimizeCmpSequence(linesByFour: List<List<IndexedValue<String>>>): List<Modification> {
// when statement (on bytes) generates a sequence of:
// lda $ce01,x
// cmp #$20
// beq check_prog8_s72choice_32
// lda $ce01,x
// cmp #$21
// beq check_prog8_s73choice_33
// the repeated lda can be removed
val mods = mutableListOf<Modification>()
// for(lines in linesByFour) {
// if(lines[0].value.trim()=="lda P8ESTACK_LO+1,x" &&
// lines[1].value.trim().startsWith("cmp ") &&
// lines[2].value.trim().startsWith("beq ") &&
// lines[3].value.trim()=="lda P8ESTACK_LO+1,x") {
// mods.add(Modification(lines[3].index, true, null)) // remove the second lda
// }
// }
return mods
}
private fun optimizeSameAssignments(
linesByFourteen: List<List<IndexedValue<String>>>,
machine: IMachineDefinition,

View File

@ -1,7 +1,6 @@
TODO
====
- (branch): fix optimizeCmpSequence in AsmOptimizer
- (branch): fix up cx16/keyboardhandler.p8 X register shenanigans
- IR: instructions that do type conversion (SZ etc, CONCAT, SGN) should put the result in a DIFFERENT register.

View File

@ -5,27 +5,15 @@ main
{
sub start()
{
word zc = -5583
txt.print_w(zc)
txt.spc()
txt.print_w(zc>>10) ; -6
txt.nl()
byte zc = -55
txt.print_w(zc)
txt.spc()
txt.print_w(zc>>4) ; -349
txt.nl()
txt.print_w(zc)
txt.spc()
txt.print_w(zc>>10) ; -6
txt.nl()
cx16.r1L = (zc>>10) as ubyte
txt.print_ub(cx16.r1L) ; 250
txt.nl()
cx16.r1L = (zc>>4) as ubyte
txt.print_ub(cx16.r1L) ; 163
txt.nl()
when zc*3 {
123 -> zc++
124 -> zc++
125 -> zc++
121 -> zc++
120 -> zc++
else -> zc++
}
}
}