From fa11a6e18ba608ebd74da545e4aacf33c99a844c Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 18 Nov 2021 01:43:22 +0100 Subject: [PATCH] removed faulty and too aggressive assembly optimization of double-store --- .../target/cpu6502/codegen/AsmOptimizer.kt | 22 +++---------------- compiler/res/prog8lib/conv.p8 | 2 +- docs/source/todo.rst | 9 ++++++-- examples/test.p8 | 8 +++---- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt index 7a66e9263..cff924a73 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt @@ -1,7 +1,7 @@ package prog8.compiler.target.cpu6502.codegen -// note: see https://wiki.nesdev.com/w/index.php/6502_assembly_optimisations +// note: see https://wiki.nesdev.org/w/index.php/6502_assembly_optimisations fun optimizeAssembly(lines: MutableList): Int { @@ -252,24 +252,7 @@ private fun optimizeSameAssignments(linesByFourteen: List - sta A1 ; can be removed - */ - if(!overlappingMods && first.startsWith("st") && third.startsWith("st")) { - val reg1 = first[2] - val reg3 = third[2] - if(reg1==reg3 && (second.startsWith("ld") || second.startsWith("st"))) { - val firstvalue = first.substring(4) - val secondvalue = second.substring(4) - val thirdvalue = third.substring(4) - if(firstvalue==thirdvalue && firstvalue!=secondvalue) { - overlappingMods = true - mods.add(Modification(lines[2].index, true, null)) - } - } - } + /* sta A1 ldy A1 ; make tay @@ -295,6 +278,7 @@ private fun optimizeSameAssignments(linesByFourteen: List>>): List { // sta X + lda X, sty X + ldy X, stx X + ldx X -> the second instruction can OFTEN be eliminated // TODO this is not true if X is not a regular RAM memory address (but instead mapped I/O or ROM) but how does this code know? + // should this optimization be removed???? or teach it about the InRegularRAM ? val mods = mutableListOf() for (lines in linesByFour) { val first = lines[1].value.trimStart() diff --git a/compiler/res/prog8lib/conv.p8 b/compiler/res/prog8lib/conv.p8 index 5353f5692..f9ed355bf 100644 --- a/compiler/res/prog8lib/conv.p8 +++ b/compiler/res/prog8lib/conv.p8 @@ -516,7 +516,7 @@ asmsub uword2decimal (uword value @AY) -> ubyte @Y, ubyte @A, ubyte @X { ;Convert 16 bit Hex to Decimal (0-65535) Rev 2 ;By Omegamatrix Further optimizations by tepples -; routine from http://forums.nesdev.com/viewtopic.php?f=2&t=11341&start=15 +; routine from https://forums.nesdev.org/viewtopic.php?f=2&t=11341&start=15 ;HexToDec99 ; start in A diff --git a/docs/source/todo.rst b/docs/source/todo.rst index f70499fae..12556f4cd 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,12 +3,17 @@ TODO For next compiler release (7.4) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -BUG: Fix C-64sound issue in petaxian (regression since 7.3, sound on c64 build works fine on older versions) - BUG: fix "assignment isAugmented correctness" test optimize TODO in "Add assignment to initialize with zero" in StatementReorderer optimize TODO in after(assignment) in VariousCleanups +optimize: bitwise operations with a negative constant number -> replace the number by its positive 2 complement +optimize: add some more constant folders mentioned in test.p8 + +fix: give error when initializing an integer var with a float value + +optimize: there is an optimizations in AsmOptimizer that can only be done correctly + if it knows about regular ram vs io space ram distinction. Blocked by an official Commander-x16 v39 release diff --git a/examples/test.p8 b/examples/test.p8 index 8ccdd4c83..2ec107ce8 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -11,7 +11,8 @@ main { byte bb float fl - ; TODO: bitwise operations with a negative constant number -> replace the number by its positive 2 complement + +; TODO add these constant folders: ; (X + C1) + (Y + C2) => (X + Y) + (C1 + C2) ; (X + C1) - (Y + C2) => (X - Y) + (C1 - C2) @@ -24,16 +25,13 @@ main { xx=6 yy=8 - yy = (xx+5)+(yy+10) - ; yy = (xx+yy)+(5+10) ; TODO crashes compiler txt.print_ub(yy) ; 29 txt.nl() xx=100 yy=8 - ;yy = (xx+5)-(yy+10) - yy = (xx-yy)+(5-10) as ubyte + yy = (xx+5)-(yy+10) txt.print_ub(yy) ; 87 txt.nl()