removed faulty and too aggressive assembly optimization of double-store

This commit is contained in:
Irmen de Jong 2021-11-18 01:43:22 +01:00
parent 52bedce8f4
commit fa11a6e18b
4 changed files with 14 additions and 27 deletions

View File

@ -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<String>): Int {
@ -252,24 +252,7 @@ private fun optimizeSameAssignments(linesByFourteen: List<List<IndexedValue<Stri
}
}
}
/*
sta A1
<other st/ld instruction not involving A1>
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<IndexedValue<Stri
private fun optimizeStoreLoadSame(linesByFour: List<List<IndexedValue<String>>>): List<Modification> {
// 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<Modification>()
for (lines in linesByFour) {
val first = lines[1].value.trimStart()

View File

@ -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

View File

@ -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

View File

@ -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()