diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt index 4e0e2fabb..5e14d1945 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt @@ -22,13 +22,6 @@ internal fun optimizeAssembly(lines: MutableList, 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, 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 { - // 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() -// 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>>, machine: IMachineDefinition, diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 5d7f95b95..b1c001c71 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -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. diff --git a/examples/test.p8 b/examples/test.p8 index 725b19339..d1e61c976 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -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++ + } } }