mirror of
https://github.com/irmen/prog8.git
synced 2024-12-24 16:29:21 +00:00
optimize const word repeat setup
This commit is contained in:
parent
aa2437cfb8
commit
6e8a89e6f1
@ -819,17 +819,15 @@ class AsmGen6502Internal (
|
|||||||
loopEndLabels.pop()
|
loopEndLabels.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun repeatWordCount(count: Int, stmt: PtRepeatLoop) {
|
private fun repeatWordCount(iterations: Int, stmt: PtRepeatLoop) {
|
||||||
require(count in 257..65535) { "invalid repeat count ${stmt.position}" }
|
require(iterations in 257..65535) { "invalid repeat count ${stmt.position}" }
|
||||||
val repeatLabel = makeLabel("repeat")
|
val repeatLabel = makeLabel("repeat")
|
||||||
val counterVar = createRepeatCounterVar(DataType.UWORD, isTargetCpu(CpuType.CPU65c02), stmt)
|
val counterVar = createRepeatCounterVar(DataType.UWORD, isTargetCpu(CpuType.CPU65c02), stmt)
|
||||||
// the iny + double dec is microoptimization of the 16 bit loop
|
val loopcount = if(iterations and 0x00ff == 0) iterations else iterations + 0x0100 // so that the loop can simply use a double-dec
|
||||||
out("""
|
out("""
|
||||||
ldy #>$count
|
ldy #>$loopcount
|
||||||
lda #<$count
|
lda #<$loopcount
|
||||||
beq +
|
sta $counterVar
|
||||||
iny
|
|
||||||
+ sta $counterVar
|
|
||||||
sty $counterVar+1
|
sty $counterVar+1
|
||||||
$repeatLabel""")
|
$repeatLabel""")
|
||||||
translate(stmt.statements)
|
translate(stmt.statements)
|
||||||
|
@ -56,6 +56,7 @@ string {
|
|||||||
sub find(str st, ubyte character) -> ubyte {
|
sub find(str st, ubyte character) -> ubyte {
|
||||||
; Locates the first position of the given character in the string,
|
; Locates the first position of the given character in the string,
|
||||||
; returns Carry set if found + index in A, or Carry clear if not found (and A will be 255, an invalid index).
|
; returns Carry set if found + index in A, or Carry clear if not found (and A will be 255, an invalid index).
|
||||||
|
; NOTE: because this isn't an asmsub, there's only a SINGLE return value here. On the c64/cx16 targets etc there are 2 return values.
|
||||||
ubyte ix
|
ubyte ix
|
||||||
for ix in 0 to length(st)-1 {
|
for ix in 0 to length(st)-1 {
|
||||||
if st[ix]==character {
|
if st[ix]==character {
|
||||||
|
Loading…
Reference in New Issue
Block a user