mirror of
https://github.com/irmen/prog8.git
synced 2024-12-23 09:32:43 +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
|
||||
// rts + jmp -> remove jmp
|
||||
// rts + bxx -> remove bxx
|
||||
// and some other optimizations.
|
||||
|
||||
val mods = mutableListOf<Modification>()
|
||||
for (lines in linesByFour) {
|
||||
@ -470,6 +471,32 @@ private fun optimizeJsrRtsAndOtherCombinations(linesByFour: List<List<IndexedVal
|
||||
else if (" bvc" in second || "\tbvc" in second)
|
||||
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
|
||||
}
|
||||
@ -523,8 +550,8 @@ private fun optimizeUnneededTempvarInAdd(linesByFour: List<List<IndexedValue<Str
|
||||
val fourth = lines[3].value.trimStart()
|
||||
if(first.startsWith("sta P8ZP_SCRATCH_") && second.startsWith("lda") && third.startsWith("clc") && fourth.startsWith("adc P8ZP_SCRATCH_") ) {
|
||||
if(fourth.substring(4)==first.substring(4)) {
|
||||
mods.add(Modification(lines[0].index, false, " clc"))
|
||||
mods.add(Modification(lines[1].index, false, " adc ${second.substring(3).trimStart()}"))
|
||||
mods.add(Modification(lines[0].index, false, " clc"))
|
||||
mods.add(Modification(lines[1].index, false, " adc ${second.substring(3).trimStart()}"))
|
||||
mods.add(Modification(lines[2].index, true, null))
|
||||
mods.add(Modification(lines[3].index, true, null))
|
||||
}
|
||||
|
@ -1,21 +1,6 @@
|
||||
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:
|
||||
automatons
|
||||
mandelbrot (quite a bit larger)
|
||||
|
@ -3,21 +3,28 @@
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
sub rrrr() -> ubyte {
|
||||
cx16.r0L++
|
||||
return cx16.r0L
|
||||
}
|
||||
|
||||
sub start() {
|
||||
ubyte[] flakes = [1,2,3]
|
||||
cx16.r0L = rrrr() >= 128
|
||||
|
||||
ubyte @shared idx = 2
|
||||
|
||||
if flakes[idx]==239 {
|
||||
txt.print("yes")
|
||||
} else {
|
||||
txt.print("nope")
|
||||
}
|
||||
|
||||
ubyte @shared xx = 16
|
||||
ubyte @shared yy = 20
|
||||
|
||||
txt.print_ub(xx>79 or yy > 49)
|
||||
; ubyte[] flakes = [1,2,3]
|
||||
;
|
||||
; ubyte @shared idx = 2
|
||||
;
|
||||
; if flakes[idx]==239 {
|
||||
; txt.print("yes")
|
||||
; } else {
|
||||
; txt.print("nope")
|
||||
; }
|
||||
;
|
||||
; ubyte @shared xx = 16
|
||||
; ubyte @shared yy = 20
|
||||
;
|
||||
; txt.print_ub(xx>79 or yy > 49)
|
||||
|
||||
; if xx>79 or yy > 49 {
|
||||
; if xx>79 or yy > 49 {
|
||||
|
Loading…
Reference in New Issue
Block a user