mirror of
https://github.com/irmen/prog8.git
synced 2025-02-19 11:31:07 +00:00
added asm optimizer for <= byte (bcc+beq->bcs)
This commit is contained in:
parent
58d9463f16
commit
a282b17286
@ -439,6 +439,7 @@ private fun optimizeJsrRtsAndOtherCombinations(linesByFour: List<List<IndexedVal
|
|||||||
// jsr Sub + rts -> jmp Sub
|
// jsr Sub + rts -> jmp Sub
|
||||||
// rts + jmp -> remove jmp
|
// rts + jmp -> remove jmp
|
||||||
// rts + bxx -> remove bxx
|
// rts + bxx -> remove bxx
|
||||||
|
// and some other optimizations.
|
||||||
|
|
||||||
val mods = mutableListOf<Modification>()
|
val mods = mutableListOf<Modification>()
|
||||||
for (lines in linesByFour) {
|
for (lines in linesByFour) {
|
||||||
@ -470,6 +471,32 @@ private fun optimizeJsrRtsAndOtherCombinations(linesByFour: List<List<IndexedVal
|
|||||||
else if (" bvc" in second || "\tbvc" in second)
|
else if (" bvc" in second || "\tbvc" in second)
|
||||||
mods += Modification(lines[1].index, true, null)
|
mods += Modification(lines[1].index, true, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
LDA NUM1
|
||||||
|
CMP NUM2
|
||||||
|
BCC LABEL
|
||||||
|
BEQ LABEL
|
||||||
|
|
||||||
|
(or something similar) which branches to LABEL when NUM1 <= NUM2. (In this case NUM1 and NUM2 are unsigned numbers.) However, consider the following sequence:
|
||||||
|
|
||||||
|
LDA NUM2
|
||||||
|
CMP NUM1
|
||||||
|
BCS LABEL
|
||||||
|
*/
|
||||||
|
val tfirst = first.trimStart()
|
||||||
|
val tsecond = second.trimStart()
|
||||||
|
val tthird = lines[2].value.trimStart()
|
||||||
|
val tfourth = lines[3].value.trimStart()
|
||||||
|
if(tfirst.startsWith("lda") && tsecond.startsWith("cmp") && tthird.startsWith("bcc") && tfourth.startsWith("beq")) {
|
||||||
|
val label = tthird.substring(4)
|
||||||
|
if(label==tfourth.substring(4)) {
|
||||||
|
mods += Modification(lines[0].index, false, " lda ${tsecond.substring(4)}")
|
||||||
|
mods += Modification(lines[1].index, false, " cmp ${tfirst.substring(4)}")
|
||||||
|
mods += Modification(lines[2].index, false, " bcs $label")
|
||||||
|
mods += Modification(lines[3].index, true, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return mods
|
return mods
|
||||||
}
|
}
|
||||||
@ -523,8 +550,8 @@ private fun optimizeUnneededTempvarInAdd(linesByFour: List<List<IndexedValue<Str
|
|||||||
val fourth = lines[3].value.trimStart()
|
val fourth = lines[3].value.trimStart()
|
||||||
if(first.startsWith("sta P8ZP_SCRATCH_") && second.startsWith("lda") && third.startsWith("clc") && fourth.startsWith("adc P8ZP_SCRATCH_") ) {
|
if(first.startsWith("sta P8ZP_SCRATCH_") && second.startsWith("lda") && third.startsWith("clc") && fourth.startsWith("adc P8ZP_SCRATCH_") ) {
|
||||||
if(fourth.substring(4)==first.substring(4)) {
|
if(fourth.substring(4)==first.substring(4)) {
|
||||||
mods.add(Modification(lines[0].index, false, " clc"))
|
mods.add(Modification(lines[0].index, false, " clc"))
|
||||||
mods.add(Modification(lines[1].index, false, " adc ${second.substring(3).trimStart()}"))
|
mods.add(Modification(lines[1].index, false, " adc ${second.substring(3).trimStart()}"))
|
||||||
mods.add(Modification(lines[2].index, true, null))
|
mods.add(Modification(lines[2].index, true, null))
|
||||||
mods.add(Modification(lines[3].index, true, null))
|
mods.add(Modification(lines[3].index, true, null))
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,6 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
add asm optimizer:
|
|
||||||
LDA NUM1
|
|
||||||
CMP NUM2
|
|
||||||
BCC LABEL
|
|
||||||
BEQ LABEL
|
|
||||||
|
|
||||||
(or something similar) which branches to LABEL when NUM1 <= NUM2. (In this case NUM1 and NUM2 are unsigned numbers.) However, consider the following sequence:
|
|
||||||
|
|
||||||
LDA NUM2
|
|
||||||
CMP NUM1
|
|
||||||
BCS LABEL
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
larger programs:
|
larger programs:
|
||||||
automatons
|
automatons
|
||||||
mandelbrot (quite a bit larger)
|
mandelbrot (quite a bit larger)
|
||||||
|
@ -3,21 +3,28 @@
|
|||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
sub rrrr() -> ubyte {
|
||||||
|
cx16.r0L++
|
||||||
|
return cx16.r0L
|
||||||
|
}
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
ubyte[] flakes = [1,2,3]
|
cx16.r0L = rrrr() >= 128
|
||||||
|
|
||||||
ubyte @shared idx = 2
|
; ubyte[] flakes = [1,2,3]
|
||||||
|
;
|
||||||
if flakes[idx]==239 {
|
; ubyte @shared idx = 2
|
||||||
txt.print("yes")
|
;
|
||||||
} else {
|
; if flakes[idx]==239 {
|
||||||
txt.print("nope")
|
; txt.print("yes")
|
||||||
}
|
; } else {
|
||||||
|
; txt.print("nope")
|
||||||
ubyte @shared xx = 16
|
; }
|
||||||
ubyte @shared yy = 20
|
;
|
||||||
|
; ubyte @shared xx = 16
|
||||||
txt.print_ub(xx>79 or yy > 49)
|
; ubyte @shared yy = 20
|
||||||
|
;
|
||||||
|
; txt.print_ub(xx>79 or yy > 49)
|
||||||
|
|
||||||
; if xx>79 or yy > 49 {
|
; if xx>79 or yy > 49 {
|
||||||
; if xx>79 or yy > 49 {
|
; if xx>79 or yy > 49 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user