diff --git a/src/main/fragment/cache/fragment-cache-csg65ce02.asm b/src/main/fragment/cache/fragment-cache-csg65ce02.asm index 5dae0a7cb..5bdf9ece4 100644 --- a/src/main/fragment/cache/fragment-cache-csg65ce02.asm +++ b/src/main/fragment/cache/fragment-cache-csg65ce02.asm @@ -1,4 +1,4 @@ -//KICKC FRAGMENT CACHE 12b00eb139 12b00ecab9 +//KICKC FRAGMENT CACHE 132c9fe4d5 132c9ffe57 //FRAGMENT vbuz1=vbuc1 lda #{c1} sta {z1} diff --git a/src/main/fragment/cache/fragment-cache-mega45gs02.asm b/src/main/fragment/cache/fragment-cache-mega45gs02.asm index 97335c905..66deb076a 100644 --- a/src/main/fragment/cache/fragment-cache-mega45gs02.asm +++ b/src/main/fragment/cache/fragment-cache-mega45gs02.asm @@ -1,4 +1,4 @@ -//KICKC FRAGMENT CACHE 12b00eb139 12b00ecab9 +//KICKC FRAGMENT CACHE 132c9fe4d5 132c9ffe57 //FRAGMENT _deref_pbuc1=vbuc2 lda #{c2} sta {c1} diff --git a/src/main/fragment/cache/fragment-cache-mos6502.asm b/src/main/fragment/cache/fragment-cache-mos6502.asm index d5c765e83..16818e497 100644 --- a/src/main/fragment/cache/fragment-cache-mos6502.asm +++ b/src/main/fragment/cache/fragment-cache-mos6502.asm @@ -1,4 +1,4 @@ -//KICKC FRAGMENT CACHE 12b00eb139 12b00ecab9 +//KICKC FRAGMENT CACHE 132c9fe4d5 132c9ffe57 //FRAGMENT vbuz1=vbuc1 lda #{c1} sta {z1} diff --git a/src/main/fragment/cache/fragment-cache-mos6502x.asm b/src/main/fragment/cache/fragment-cache-mos6502x.asm index 43a6289cd..339640eed 100644 --- a/src/main/fragment/cache/fragment-cache-mos6502x.asm +++ b/src/main/fragment/cache/fragment-cache-mos6502x.asm @@ -1,10 +1,7 @@ -//KICKC FRAGMENT CACHE 12b00eb139 12b00ecab9 -//FRAGMENT _deref_pbuc1=vbuc2 -lda #{c2} -sta {c1} -//FRAGMENT _deref_pbuc1=_deref_pbuc2 -lda {c2} -sta {c1} +//KICKC FRAGMENT CACHE 132c9fe4d5 132c9ffe57 +//FRAGMENT vbsz1=vbsc1 +lda #{c1} +sta {z1} //FRAGMENT vbuz1=vbuc1 lda #{c1} sta {z1} @@ -12,205 +9,20 @@ sta {z1} lda {z1} cmp #{c1} bcc {la1} -//FRAGMENT vwuz1=vbuc1 -lda #<{c1} -sta {z1} -lda #>{c1} -sta {z1}+1 -//FRAGMENT vwuz1_lt_vwuc1_then_la1 -lda {z1}+1 -cmp #>{c1} -bcc {la1} -bne !+ -lda {z1} -cmp #<{c1} -bcc {la1} -!: -//FRAGMENT _deref_pbuc1=_deref_pbuc1_bor_vbuc2 +//FRAGMENT _deref_pbuc1_neq_vbuc2_then_la1 lda #{c2} -ora {c1} -sta {c1} -//FRAGMENT _deref_pbuc1=_deref_pbuc1_band_vbuc2 -lda #{c2} -and {c1} -sta {c1} -//FRAGMENT vwuz1=vwuc1 -lda #<{c1} -sta {z1} -lda #>{c1} -sta {z1}+1 -//FRAGMENT pssz1=pssc1 -lda #<{c1} -sta {z1} -lda #>{c1} -sta {z1}+1 -//FRAGMENT vbuz1_lt_vbuz2_then_la1 -lda {z1} -cmp {z2} -bcc {la1} -//FRAGMENT vwuz1=vwuz1_plus_1 -inc {z1} -bne !+ -inc {z1}+1 -!: -//FRAGMENT vwuz1_lt_vbuc1_then_la1 -lda {z1}+1 -cmp #>{c1} -bcc {la1} -bne !+ -lda {z1} -cmp #<{c1} -bcc {la1} -!: -//FRAGMENT vbuc1_neq_vbuz1_then_la1 -lda #{c1} -cmp {z1} +cmp {c1} bne {la1} -//FRAGMENT vwuz1_le_0_then_la1 -lda {z1} -bne !+ -lda {z1}+1 -beq {la1} -!: -//FRAGMENT vwuz1=vwuz1_minus_1 -lda {z1} -sec -sbc #1 -sta {z1} -lda {z1}+1 -sbc #0 -sta {z1}+1 -//FRAGMENT vbuz1_gt_0_then_la1 -lda {z1} -bne {la1} -//FRAGMENT vbuz1=vbuz1_minus_1 -dec {z1} -//FRAGMENT vbuz1=vbuz2 -lda {z2} -sta {z1} -//FRAGMENT vbuz1=vbuz1_plus_1 -inc {z1} -//FRAGMENT pbuc1_derefidx_vbuz1=vbuc2 +//FRAGMENT _deref_pbuc1=vbuc2 lda #{c2} -ldy {z1} -sta {c1},y -//FRAGMENT pbuc1_derefidx_vbuz1=pbuc2_derefidx_vbuz1 -ldy {z1} -lda {c2},y -sta {c1},y -//FRAGMENT pbsz1_derefidx_vbuc1=pbsz1_derefidx_vbuc1_plus_pbsz1_derefidx_vbuc2 -ldy #{c2} -lda ({z1}),y -ldy #{c1} -tax -lda ({z1}),y -sty $ff - -stx $ff -clc -adc $ff -ldy $ff -sta ({z1}),y -//FRAGMENT pbsz1_derefidx_vbuc1_lt_vbsc2_then_la1 -ldy #{c1} -lda ({z1}),y - -sec -sbc #{c2} -bvc !+ -eor #$80 -!: -bmi {la1} -//FRAGMENT pbsz1_derefidx_vbuc1=vbsc2 -lda #{c1} -tay -lda #{c2} -sta ({z1}),y -//FRAGMENT pwsz1_derefidx_vbuc1_gt_vwsc2_then_la1 -ldy #{c1} -lda #<{c2} -cmp ({z1}),y -iny -lda #>{c2} -sbc ({z1}),y -bvc !+ -eor #$80 -!: -bmi {la1} -!e: -//FRAGMENT pwsz1_derefidx_vbuc1_ge_vwsc2_then_la1 -ldy #{c1} -lda ({z1}),y -cmp #<{c2} -iny -lda ({z1}),y -sbc #>{c2} -bvc !+ -eor #$80 -!: -bpl {la1} -//FRAGMENT pwsz1_derefidx_vbuc1=pwsz1_derefidx_vbuc1_plus_pbsz1_derefidx_vbuc2 -ldy #{c2} -lda ({z1}),y -sta $fe -ora #$7f -bmi !+ -lda #0 -!: -sta $ff -ldy #{c1} -clc -lda ({z1}),y -adc $fe -sta ({z1}),y -iny -lda ({z1}),y -adc $fe -sta ({z1}),y -//FRAGMENT pbuc1_derefidx_vbuz1_ge_vbuc2_then_la1 -ldy {z1} -lda {c1},y -cmp #{c2} -bcs {la1} -//FRAGMENT pbuc1_derefidx_vbuz1=_deref_pbuz2 -ldy #0 -lda ({z2}),y -ldy {z1} -sta {c1},y -//FRAGMENT vwsz1=pwsz2_derefidx_vbuc1_ror_vbuc2 -ldx #{c2} -ldy #{c1} -lda ({z2}),y +sta {c1} +//FRAGMENT pbuz1=pbuc1 +lda #<{c1} sta {z1} -iny -lda ({z2}),y +lda #>{c1} sta {z1}+1 -cpx #0 -beq !e+ -!: -lda {z1}+1 -cmp #$80 -ror {z1}+1 -ror {z1} -dex -bne !- -!e: -//FRAGMENT pbuc1_derefidx_vbuz1=_byte_vwsz2 -ldy {z1} +//FRAGMENT vbuz1=vbuz2_rol_1 lda {z2} -sta {c1},y -//FRAGMENT pssz1=pssz1_plus_vbuc1 -lda #{c1} -clc -adc {z1} -sta {z1} -bcc !+ -inc {z1}+1 -!: -//FRAGMENT vbuz1=vbuz2_rol_3 -lda {z2} -asl -asl asl sta {z1} //FRAGMENT vbuz1=vbuz2_plus_vbuz3 @@ -218,574 +30,586 @@ lda {z2} clc adc {z3} sta {z1} -//FRAGMENT pssz1=pssc1_plus_vbuz2 -lda {z2} +//FRAGMENT pbuz1_derefidx_(pbsc1_derefidx_vbuz2)=vbuc2 +lda #{c2} +ldx {z2} +ldy {c1},x +sta ({z1}),y +//FRAGMENT pbsc1_derefidx_vbuz1=pbsc1_derefidx_vbuz1_plus_pbsc2_derefidx_vbuz1 +ldy {z1} clc -adc #<{c1} -sta {z1} -lda #>{c1} -adc #0 -sta {z1}+1 -//FRAGMENT _deref_pbuz1=vbuz2 -lda {z2} -ldy #0 -sta ({z1}),y -//FRAGMENT pwsz1_derefidx_vbuc1=vwsc2 -ldy #{c1} -lda #<{c2} -sta ({z1}),y -iny -lda #>{c2} -sta ({z1}),y -//FRAGMENT pbsz1_derefidx_vbuc1=vbsz2 -lda #{c1} -tay -lda {z2} -sta ({z1}),y -//FRAGMENT pbuz1=pbuc1_plus_vwuz2 -lda {z2} -clc -adc #<{c1} -sta {z1} -lda {z2}+1 -adc #>{c1} -sta {z1}+1 -//FRAGMENT _deref_pbuz1=_deref_pbuz2 -ldy #0 -lda ({z2}),y -ldy #0 -sta ({z1}),y -//FRAGMENT _deref_pbuz1=vbuc1 -lda #{c1} -ldy #0 -sta ({z1}),y -//FRAGMENT vbuz1_ge_vbuc1_then_la1 -lda {z1} -cmp #{c1} -bcs {la1} -//FRAGMENT _deref_pbuc1=vbuz1 -lda {z1} -sta {c1} -//FRAGMENT vbuz1=_inc_vbuz1 -inc {z1} -//FRAGMENT vbuz1=vbuz1_minus_vbuc1 -lax {z1} -axs #{c1} -stx {z1} -//FRAGMENT pbuc1_derefidx_vbuz1_lt_vbuc2_then_la1 +lda {c1},y +adc {c2},y +sta {c1},y +//FRAGMENT pbsc1_derefidx_vbuz1_lt_0_then_la1 ldy {z1} lda {c1},y -cmp #{c2} -bcc {la1} -//FRAGMENT vbuc1_eq_pbuc2_derefidx_vbuz1_then_la1 +cmp #0 +bmi {la1} +//FRAGMENT pbsc1_derefidx_vbuz1_lt_vbsc2_then_la1 ldy {z1} -lda {c2},y -cmp #{c1} -beq {la1} +lda {c1},y +sec +sbc #{c2} +bvc !+ +eor #$80 +!: +bmi {la1} +//FRAGMENT vbsz1=_neg_pbsc1_derefidx_vbuz2 +ldy {z2} +lda {c1},y +eor #$ff +clc +adc #$01 +sta {z1} +//FRAGMENT pbsc1_derefidx_vbuz1=vbsz2 +lda {z2} +ldy {z1} +sta {c1},y +//FRAGMENT pbuz1_derefidx_(pbsc1_derefidx_vbuz2)=pbuc2_derefidx_vbuz2 +ldx {z2} +lda {c2},x +ldy {c1},x +sta ({z1}),y +//FRAGMENT pbuz1=pbuz1_plus_vbuc1 +lda #{c1} +clc +adc {z1} +sta {z1} +bcc !+ +inc {z1}+1 +!: +//FRAGMENT vbuz1=_inc_vbuz1 +inc {z1} //FRAGMENT pbuc1_derefidx_vbuz1=vbuz2 lda {z2} ldy {z1} sta {c1},y +//FRAGMENT vbsz1=_neg_vbsz1 +lda {z1} +eor #$ff +clc +adc #$01 +sta {z1} //FRAGMENT vbuaa_lt_vbuc1_then_la1 cmp #{c1} bcc {la1} -//FRAGMENT vbuz1_lt_vbuaa_then_la1 -cmp {z1} -beq !+ -bcs {la1} -!: -//FRAGMENT vbuc1_neq_vbuxx_then_la1 -cpx #{c1} -bne {la1} -//FRAGMENT vbuxx_lt_vbuc1_then_la1 -cpx #{c1} -bcc {la1} -//FRAGMENT vbuxx_gt_0_then_la1 -cpx #0 -bne {la1} -//FRAGMENT vbuaa=vbuz1 -lda {z1} -//FRAGMENT vbuxx=vbuz1 -ldx {z1} -//FRAGMENT vbuz1=vbuaa -sta {z1} -//FRAGMENT pbuc1_derefidx_vbuaa=vbuc2 -tay -lda #{c2} -sta {c1},y -//FRAGMENT pbuc1_derefidx_vbuxx=vbuc2 -lda #{c2} -sta {c1},x -//FRAGMENT pbuc1_derefidx_vbuyy=vbuc2 -lda #{c2} -sta {c1},y -//FRAGMENT pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx -lda {c2},x -sta {c1},x -//FRAGMENT pbuc1_derefidx_vbuyy=pbuc2_derefidx_vbuyy -lda {c2},y -sta {c1},y -//FRAGMENT vbuaa=vbuz1_rol_3 -lda {z1} -asl -asl -asl -//FRAGMENT vbuxx=vbuz1_rol_3 -lda {z1} -asl -asl -asl -tax -//FRAGMENT vbuyy=vbuz1_rol_3 -lda {z1} -asl -asl -asl -tay -//FRAGMENT vbuz1=vbuaa_rol_3 -asl -asl +//FRAGMENT vbuz1=vbuaa_rol_1 asl sta {z1} -//FRAGMENT vbuaa=vbuaa_rol_3 -asl -asl -asl -//FRAGMENT vbuxx=vbuaa_rol_3 -asl -asl -asl -tax -//FRAGMENT vbuyy=vbuaa_rol_3 -asl -asl -asl -tay -//FRAGMENT vbuz1=vbuxx_rol_3 +//FRAGMENT vbuz1=vbuxx_rol_1 txa asl -asl -asl sta {z1} -//FRAGMENT vbuaa=vbuxx_rol_3 -txa -asl -asl -asl -//FRAGMENT vbuxx=vbuxx_rol_3 -txa -asl -asl -asl -tax -//FRAGMENT vbuyy=vbuxx_rol_3 -txa -asl -asl -asl -tay -//FRAGMENT vbuz1=vbuyy_rol_3 +//FRAGMENT vbuz1=vbuyy_rol_1 tya asl -asl -asl sta {z1} -//FRAGMENT vbuaa=vbuyy_rol_3 -tya -asl -asl -asl -//FRAGMENT vbuxx=vbuyy_rol_3 -tya -asl -asl -asl -tax -//FRAGMENT vbuyy=vbuyy_rol_3 -tya -asl -asl -asl -tay -//FRAGMENT vbuz1=vbuaa_plus_vbuz2 -clc -adc {z2} -sta {z1} -//FRAGMENT vbuz1=vbuxx_plus_vbuz2 -txa -clc -adc {z2} -sta {z1} -//FRAGMENT vbuz1=vbuyy_plus_vbuz2 -tya -clc -adc {z2} -sta {z1} -//FRAGMENT vbuaa=vbuz1_plus_vbuz2 +//FRAGMENT vbuaa=vbuz1_rol_1 lda {z1} -clc -adc {z2} -//FRAGMENT vbuaa=vbuaa_plus_vbuz1 -clc -adc {z1} -//FRAGMENT vbuaa=vbuxx_plus_vbuz1 +asl +//FRAGMENT vbuaa=vbuaa_rol_1 +asl +//FRAGMENT vbuaa=vbuxx_rol_1 txa -clc -adc {z1} -//FRAGMENT vbuaa=vbuyy_plus_vbuz1 +asl +//FRAGMENT vbuaa=vbuyy_rol_1 tya -clc -adc {z1} -//FRAGMENT vbuxx=vbuz1_plus_vbuz2 +asl +//FRAGMENT vbuxx=vbuz1_rol_1 lda {z1} -clc -adc {z2} +asl tax -//FRAGMENT vbuxx=vbuaa_plus_vbuz1 -clc -adc {z1} +//FRAGMENT vbuxx=vbuaa_rol_1 +asl tax -//FRAGMENT vbuxx=vbuxx_plus_vbuz1 +//FRAGMENT vbuxx=vbuxx_rol_1 txa -clc -adc {z1} +asl tax -//FRAGMENT vbuxx=vbuyy_plus_vbuz1 +//FRAGMENT vbuxx=vbuyy_rol_1 tya -clc -adc {z1} +asl tax -//FRAGMENT vbuyy=vbuz1_plus_vbuz2 +//FRAGMENT vbuyy=vbuz1_rol_1 lda {z1} -clc -adc {z2} +asl tay -//FRAGMENT vbuyy=vbuaa_plus_vbuz1 -clc -adc {z1} +//FRAGMENT vbuyy=vbuaa_rol_1 +asl tay -//FRAGMENT vbuyy=vbuxx_plus_vbuz1 +//FRAGMENT vbuyy=vbuxx_rol_1 txa -clc -adc {z1} +asl tay -//FRAGMENT vbuyy=vbuyy_plus_vbuz1 +//FRAGMENT vbuyy=vbuyy_rol_1 tya -clc -adc {z1} +asl tay //FRAGMENT vbuz1=vbuz2_plus_vbuxx txa clc adc {z2} sta {z1} +//FRAGMENT vbuz1=vbuz2_plus_vbuyy +tya +clc +adc {z2} +sta {z1} +//FRAGMENT vbuz1=vbuaa_plus_vbuz2 +clc +adc {z2} +sta {z1} //FRAGMENT vbuz1=vbuaa_plus_vbuxx stx $ff clc adc $ff sta {z1} -//FRAGMENT vbuz1=vbuxx_plus_vbuxx -txa -asl -sta {z1} -//FRAGMENT vbuz1=vbuyy_plus_vbuxx -txa -sty $ff -clc -adc $ff -sta {z1} -//FRAGMENT vbuaa=vbuz1_plus_vbuxx -txa -clc -adc {z1} -//FRAGMENT vbuaa=vbuaa_plus_vbuxx -stx $ff -clc -adc $ff -//FRAGMENT vbuaa=vbuxx_plus_vbuxx -txa -asl -//FRAGMENT vbuaa=vbuyy_plus_vbuxx -txa -sty $ff -clc -adc $ff -//FRAGMENT vbuxx=vbuz1_plus_vbuxx -txa -clc -adc {z1} -tax -//FRAGMENT vbuxx=vbuaa_plus_vbuxx -stx $ff -clc -adc $ff -tax -//FRAGMENT vbuxx=vbuxx_plus_vbuxx -txa -asl -tax -//FRAGMENT vbuxx=vbuyy_plus_vbuxx -txa -sty $ff -clc -adc $ff -tax -//FRAGMENT vbuyy=vbuz1_plus_vbuxx -txa -clc -adc {z1} -tay -//FRAGMENT vbuyy=vbuaa_plus_vbuxx -stx $ff -clc -adc $ff -tay -//FRAGMENT vbuyy=vbuxx_plus_vbuxx -txa -asl -tay -//FRAGMENT vbuyy=vbuyy_plus_vbuxx -txa -sty $ff -clc -adc $ff -tay -//FRAGMENT vbuz1=vbuz2_plus_vbuyy -tya -clc -adc {z2} -sta {z1} //FRAGMENT vbuz1=vbuaa_plus_vbuyy sty $ff clc adc $ff sta {z1} +//FRAGMENT vbuz1=vbuxx_plus_vbuz2 +txa +clc +adc {z2} +sta {z1} +//FRAGMENT vbuz1=vbuxx_plus_vbuxx +txa +asl +sta {z1} //FRAGMENT vbuz1=vbuxx_plus_vbuyy txa sty $ff clc adc $ff sta {z1} +//FRAGMENT vbuz1=vbuyy_plus_vbuz2 +tya +clc +adc {z2} +sta {z1} +//FRAGMENT vbuz1=vbuyy_plus_vbuxx +txa +sty $ff +clc +adc $ff +sta {z1} //FRAGMENT vbuz1=vbuyy_plus_vbuyy tya asl sta {z1} +//FRAGMENT vbuaa=vbuz1_plus_vbuz2 +lda {z1} +clc +adc {z2} +//FRAGMENT vbuaa=vbuz1_plus_vbuxx +txa +clc +adc {z1} //FRAGMENT vbuaa=vbuz1_plus_vbuyy tya clc adc {z1} +//FRAGMENT vbuaa=vbuaa_plus_vbuz1 +clc +adc {z1} +//FRAGMENT vbuaa=vbuaa_plus_vbuxx +stx $ff +clc +adc $ff //FRAGMENT vbuaa=vbuaa_plus_vbuyy sty $ff clc adc $ff +//FRAGMENT vbuaa=vbuxx_plus_vbuz1 +txa +clc +adc {z1} +//FRAGMENT vbuaa=vbuxx_plus_vbuxx +txa +asl //FRAGMENT vbuaa=vbuxx_plus_vbuyy txa sty $ff clc adc $ff +//FRAGMENT vbuaa=vbuyy_plus_vbuz1 +tya +clc +adc {z1} +//FRAGMENT vbuaa=vbuyy_plus_vbuxx +txa +sty $ff +clc +adc $ff //FRAGMENT vbuaa=vbuyy_plus_vbuyy tya asl +//FRAGMENT vbuxx=vbuz1_plus_vbuz2 +lda {z1} +clc +adc {z2} +tax +//FRAGMENT vbuxx=vbuz1_plus_vbuxx +txa +clc +adc {z1} +tax //FRAGMENT vbuxx=vbuz1_plus_vbuyy tya clc adc {z1} tax +//FRAGMENT vbuxx=vbuaa_plus_vbuz1 +clc +adc {z1} +tax +//FRAGMENT vbuxx=vbuaa_plus_vbuxx +stx $ff +clc +adc $ff +tax //FRAGMENT vbuxx=vbuaa_plus_vbuyy sty $ff clc adc $ff tax +//FRAGMENT vbuxx=vbuxx_plus_vbuz1 +txa +clc +adc {z1} +tax +//FRAGMENT vbuxx=vbuxx_plus_vbuxx +txa +asl +tax //FRAGMENT vbuxx=vbuxx_plus_vbuyy txa sty $ff clc adc $ff tax +//FRAGMENT vbuxx=vbuyy_plus_vbuz1 +tya +clc +adc {z1} +tax +//FRAGMENT vbuxx=vbuyy_plus_vbuxx +txa +sty $ff +clc +adc $ff +tax //FRAGMENT vbuxx=vbuyy_plus_vbuyy tya asl tax +//FRAGMENT vbuyy=vbuz1_plus_vbuz2 +lda {z1} +clc +adc {z2} +tay +//FRAGMENT vbuyy=vbuz1_plus_vbuxx +txa +clc +adc {z1} +tay //FRAGMENT vbuyy=vbuz1_plus_vbuyy tya clc adc {z1} tay +//FRAGMENT vbuyy=vbuaa_plus_vbuz1 +clc +adc {z1} +tay +//FRAGMENT vbuyy=vbuaa_plus_vbuxx +stx $ff +clc +adc $ff +tay //FRAGMENT vbuyy=vbuaa_plus_vbuyy sty $ff clc adc $ff tay +//FRAGMENT vbuyy=vbuxx_plus_vbuz1 +txa +clc +adc {z1} +tay +//FRAGMENT vbuyy=vbuxx_plus_vbuxx +txa +asl +tay //FRAGMENT vbuyy=vbuxx_plus_vbuyy txa sty $ff clc adc $ff tay +//FRAGMENT vbuyy=vbuyy_plus_vbuz1 +tya +clc +adc {z1} +tay +//FRAGMENT vbuyy=vbuyy_plus_vbuxx +txa +sty $ff +clc +adc $ff +tay //FRAGMENT vbuyy=vbuyy_plus_vbuyy tya asl tay -//FRAGMENT pssz1=pssc1_plus_vbuaa -clc -adc #<{c1} -sta {z1} -lda #>{c1} -adc #0 -sta {z1}+1 -//FRAGMENT pssz1=pssc1_plus_vbuxx -txa -clc -adc #<{c1} -sta {z1} -lda #>{c1} -adc #0 -sta {z1}+1 -//FRAGMENT pssz1=pssc1_plus_vbuyy -tya -clc -adc #<{c1} -sta {z1} -lda #>{c1} -adc #0 -sta {z1}+1 -//FRAGMENT _deref_pbuz1=vbuxx -txa -ldy #0 +//FRAGMENT pbuz1_derefidx_(pbsc1_derefidx_vbuaa)=vbuc2 +tax +lda #{c2} +ldy {c1},x sta ({z1}),y -//FRAGMENT _deref_pbuz1=vbuyy -tya -ldy #0 +//FRAGMENT pbuz1_derefidx_(pbsc1_derefidx_vbuxx)=vbuc2 +lda #{c2} +ldy {c1},x sta ({z1}),y -//FRAGMENT pbsz1_derefidx_vbuc1=vbsxx -lda #{c1} -tay -txa -sta ({z1}),y -//FRAGMENT vbuaa_ge_vbuc1_then_la1 -cmp #{c1} -bcs {la1} -//FRAGMENT _deref_pbuc1=vbuaa -sta {c1} -//FRAGMENT vbuaa=vbuaa_minus_vbuc1 -sec -sbc #{c1} -//FRAGMENT vbuxx=vbuxx_minus_vbuc1 -txa -axs #{c1} -//FRAGMENT vbuyy=vbuyy_minus_vbuc1 +//FRAGMENT pbuz1_derefidx_(pbsc1_derefidx_vbuyy)=vbuc2 tya -sec -sbc #{c1} -tay -//FRAGMENT pbuc1_derefidx_vbuaa_lt_vbuc2_then_la1 -tay -lda {c1},y -cmp #{c2} -bcc {la1} -//FRAGMENT pbuc1_derefidx_vbuxx_lt_vbuc2_then_la1 +tax +lda #{c2} +ldy {c1},x +sta ({z1}),y +//FRAGMENT pbsc1_derefidx_vbuxx=pbsc1_derefidx_vbuxx_plus_pbsc2_derefidx_vbuxx +clc lda {c1},x -cmp #{c2} -bcc {la1} -//FRAGMENT pbuc1_derefidx_vbuyy_lt_vbuc2_then_la1 -lda {c1},y -cmp #{c2} -bcc {la1} -//FRAGMENT vbuc1_eq_pbuc2_derefidx_vbuaa_then_la1 +adc {c2},x +sta {c1},x +//FRAGMENT pbsc1_derefidx_vbuxx_lt_0_then_la1 +lda {c1},x +cmp #0 +bmi {la1} +//FRAGMENT pbsc1_derefidx_vbuxx_lt_vbsc2_then_la1 +lda {c1},x +sec +sbc #{c2} +bvc !+ +eor #$80 +!: +bmi {la1} +//FRAGMENT vbsz1=_neg_pbsc1_derefidx_vbuaa tay -lda {c2},y -cmp #{c1} -beq {la1} -//FRAGMENT vbuc1_eq_pbuc2_derefidx_vbuxx_then_la1 -lda {c2},x -cmp #{c1} -beq {la1} -//FRAGMENT vbuc1_eq_pbuc2_derefidx_vbuyy_then_la1 -lda {c2},y -cmp #{c1} -beq {la1} -//FRAGMENT pbuc1_derefidx_vbuxx=vbuz1 +lda {c1},y +eor #$ff +clc +adc #$01 +sta {z1} +//FRAGMENT vbsz1=_neg_pbsc1_derefidx_vbuxx +lda {c1},x +eor #$ff +clc +adc #$01 +sta {z1} +//FRAGMENT vbsz1=_neg_pbsc1_derefidx_vbuyy +lda {c1},y +eor #$ff +clc +adc #$01 +sta {z1} +//FRAGMENT vbsaa=_neg_pbsc1_derefidx_vbuz1 +ldy {z1} +lda {c1},y +eor #$ff +clc +adc #$01 +//FRAGMENT vbsaa=_neg_pbsc1_derefidx_vbuaa +tay +lda {c1},y +eor #$ff +clc +adc #$01 +//FRAGMENT vbsaa=_neg_pbsc1_derefidx_vbuxx +lda {c1},x +eor #$ff +clc +adc #$01 +//FRAGMENT vbsaa=_neg_pbsc1_derefidx_vbuyy +lda {c1},y +eor #$ff +clc +adc #$01 +//FRAGMENT vbsxx=_neg_pbsc1_derefidx_vbuz1 +ldx {z1} +lda {c1},x +eor #$ff +clc +adc #$01 +tax +//FRAGMENT vbsxx=_neg_pbsc1_derefidx_vbuaa +tax +lda {c1},x +eor #$ff +clc +adc #$01 +tax +//FRAGMENT vbsxx=_neg_pbsc1_derefidx_vbuxx +lda {c1},x +eor #$ff +clc +adc #$01 +tax +//FRAGMENT vbsxx=_neg_pbsc1_derefidx_vbuyy +lda {c1},y +eor #$ff +clc +adc #$01 +tax +//FRAGMENT vbsyy=_neg_pbsc1_derefidx_vbuz1 +ldy {z1} +lda {c1},y +eor #$ff +clc +adc #$01 +tay +//FRAGMENT vbsyy=_neg_pbsc1_derefidx_vbuaa +tay +lda {c1},y +eor #$ff +clc +adc #$01 +tay +//FRAGMENT vbsyy=_neg_pbsc1_derefidx_vbuxx +lda {c1},x +eor #$ff +clc +adc #$01 +tay +//FRAGMENT vbsyy=_neg_pbsc1_derefidx_vbuyy +lda {c1},y +eor #$ff +clc +adc #$01 +tay +//FRAGMENT pbsc1_derefidx_vbuxx=vbsz1 lda {z1} sta {c1},x -//FRAGMENT pbuc1_derefidx_vbuyy=vbuz1 +//FRAGMENT pbsc1_derefidx_vbuyy=vbsz1 lda {z1} sta {c1},y -//FRAGMENT pbuc1_derefidx_vbuz1=vbuxx +//FRAGMENT pbsc1_derefidx_vbuz1=vbsaa +ldy {z1} +sta {c1},y +//FRAGMENT pbsc1_derefidx_vbuyy=pbsc1_derefidx_vbuyy_plus_pbsc2_derefidx_vbuyy +clc +lda {c1},y +adc {c2},y +sta {c1},y +//FRAGMENT pbuz1_derefidx_(pbsc1_derefidx_vbuaa)=pbuc2_derefidx_vbuaa +tax +lda {c2},x +ldy {c1},x +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_(pbsc1_derefidx_vbuxx)=pbuc2_derefidx_vbuxx +lda {c2},x +ldy {c1},x +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_(pbsc1_derefidx_vbuyy)=pbuc2_derefidx_vbuyy +tya +tax +lda {c2},x +ldy {c1},x +sta ({z1}),y +//FRAGMENT pbsc1_derefidx_vbuz1=vbsxx ldy {z1} txa sta {c1},y -//FRAGMENT pbuc1_derefidx_vbuxx=vbuxx +//FRAGMENT pbsc1_derefidx_vbuz1=vbsyy +tya +ldy {z1} +sta {c1},y +//FRAGMENT pbsc1_derefidx_vbuaa=vbsz1 +tay +lda {z1} +sta {c1},y +//FRAGMENT pbsc1_derefidx_vbuaa=vbsxx +tay +txa +sta {c1},y +//FRAGMENT pbsc1_derefidx_vbuaa=vbsyy +tax +tya +sta {c1},x +//FRAGMENT pbsc1_derefidx_vbuxx=vbsxx txa sta {c1},x -//FRAGMENT pbuc1_derefidx_vbuyy=vbuxx +//FRAGMENT pbsc1_derefidx_vbuxx=vbsyy +tya +sta {c1},x +//FRAGMENT pbsc1_derefidx_vbuyy=vbsxx +txa +sta {c1},y +//FRAGMENT pbsc1_derefidx_vbuyy=vbsyy +tya +sta {c1},y +//FRAGMENT pbuc1_derefidx_vbuz1=vbuxx +ldy {z1} txa sta {c1},y //FRAGMENT pbuc1_derefidx_vbuz1=vbuyy tya ldy {z1} sta {c1},y +//FRAGMENT pbuc1_derefidx_vbuxx=vbuz1 +lda {z1} +sta {c1},x +//FRAGMENT pbuc1_derefidx_vbuxx=vbuxx +txa +sta {c1},x //FRAGMENT pbuc1_derefidx_vbuxx=vbuyy tya sta {c1},x +//FRAGMENT pbuc1_derefidx_vbuyy=vbuz1 +lda {z1} +sta {c1},y +//FRAGMENT pbuc1_derefidx_vbuyy=vbuxx +txa +sta {c1},y //FRAGMENT pbuc1_derefidx_vbuyy=vbuyy tya sta {c1},y -//FRAGMENT vbuz1=vbuxx -stx {z1} -//FRAGMENT _deref_pbuc1=vbuxx -stx {c1} -//FRAGMENT vbuaa=vbuaa_minus_1 -sec -sbc #1 -//FRAGMENT vbuxx_ge_vbuc1_then_la1 -cpx #{c1} -bcs {la1} -//FRAGMENT vbuxx=vbuxx_minus_1 -dex -//FRAGMENT vbuyy=vbuz1 -ldy {z1} -//FRAGMENT vbuyy_ge_vbuc1_then_la1 -cpy #{c1} -bcs {la1} -//FRAGMENT vbuyy=vbuyy_minus_1 +//FRAGMENT vbsxx=_neg_vbsxx +txa +eor #$ff +clc +adc #$01 +tax +//FRAGMENT vbsyy=_neg_vbsyy tya +eor #$ff +clc +adc #$01 tay -dey +//FRAGMENT vbuxx_lt_vbuc1_then_la1 +cpx #{c1} +bcc {la1} //FRAGMENT vbuxx=vbuc1 ldx #{c1} //FRAGMENT vbuxx=_inc_vbuxx inx +//FRAGMENT pbsc1_derefidx_vbuxx=vbsaa +sta {c1},x +//FRAGMENT pbsc1_derefidx_vbuyy=vbsaa +sta {c1},y //FRAGMENT vbuyy=vbuc1 ldy #{c1} -//FRAGMENT _deref_pbuc1=vbuyy -sty {c1} -//FRAGMENT vbuyy=_inc_vbuyy -iny -//FRAGMENT vbuaa=vbuc1 -lda #{c1} -//FRAGMENT vbuaa=_inc_vbuaa -clc -adc #1 -//FRAGMENT vbuz1=vbuyy -sty {z1} //FRAGMENT vbuyy_lt_vbuc1_then_la1 cpy #{c1} bcc {la1} -//FRAGMENT vbuaa=vbuxx -txa -//FRAGMENT vbuaa=vbuyy -tya -//FRAGMENT vbuxx=vbuyy -tya -tax -//FRAGMENT vbuyy=vbuxx -txa -tay -//FRAGMENT vbuxx=vbuxx_plus_1 -inx -//FRAGMENT vbuyy=vbuyy_plus_1 +//FRAGMENT vbuyy=_inc_vbuyy iny -//FRAGMENT pbuz1=pbuc1 +//FRAGMENT vbsyy=vbsc1 +ldy #{c1} +//FRAGMENT vwuz1=vwuc1 lda #<{c1} sta {z1} lda #>{c1} @@ -841,6 +665,10 @@ sta {z1} lda #0 sbc {z1}+1 sta {z1}+1 +//FRAGMENT _deref_pbuz1=vbuz2 +lda {z2} +ldy #0 +sta ({z1}),y //FRAGMENT pbuz1=_inc_pbuz1 inc {z1} bne !+ @@ -852,14 +680,6 @@ sta {z1} //FRAGMENT vbuz1=_lo_vwuz2 lda {z2} sta {z1} -//FRAGMENT pbuz1=pbuz1_plus_vbuc1 -lda #{c1} -clc -adc {z1} -sta {z1} -bcc !+ -inc {z1}+1 -!: //FRAGMENT pbuz1_lt_pbuz2_then_la1 lda {z1}+1 cmp {z2}+1 @@ -890,6 +710,14 @@ bne {la1} //FRAGMENT _deref_pbuz1=vbuaa ldy #0 sta ({z1}),y +//FRAGMENT _deref_pbuz1=vbuxx +txa +ldy #0 +sta ({z1}),y +//FRAGMENT _deref_pbuz1=vbuyy +tya +ldy #0 +sta ({z1}),y //FRAGMENT vbuaa=_hi_vwuz1 lda {z1}+1 //FRAGMENT vbuxx=_hi_vwuz1 @@ -1017,21 +845,46 @@ tay txa and #{c1} tay +//FRAGMENT vbuaa=vbuc1 +lda #{c1} //FRAGMENT vbuaa=pbuc1_derefidx_vbuxx lda {c1},x //FRAGMENT vbuaa=pbuc1_derefidx_vbuyy lda {c1},y +//FRAGMENT pbuc1_derefidx_vbuz1=vbuc2 +lda #{c2} +ldy {z1} +sta {c1},y //FRAGMENT vbuz1=vbuz1_plus_2 lda {z1} clc adc #2 sta {z1} +//FRAGMENT pbuc1_derefidx_vbuaa=vbuc2 +tay +lda #{c2} +sta {c1},y +//FRAGMENT pbuc1_derefidx_vbuxx=vbuc2 +lda #{c2} +sta {c1},x +//FRAGMENT pbuc1_derefidx_vbuyy=vbuc2 +lda #{c2} +sta {c1},y //FRAGMENT vbuxx=vbuxx_plus_2 inx inx //FRAGMENT vbuyy=vbuyy_plus_2 iny iny +//FRAGMENT vwuz1_lt_vwuc1_then_la1 +lda {z1}+1 +cmp #>{c1} +bcc {la1} +bne !+ +lda {z1} +cmp #<{c1} +bcc {la1} +!: //FRAGMENT vbsz1=vbsz2 lda {z2} sta {z1} @@ -1042,6 +895,9 @@ sta {z1} lax {z2} axs #-[{c1}] stx {z1} +//FRAGMENT vbuz1=vbuz2 +lda {z2} +sta {z1} //FRAGMENT vwuz1=vwuz1_plus_vwuz2 lda {z1} clc @@ -1062,6 +918,10 @@ bne {la1} lda {z1} cmp #<{c1} bne {la1} +//FRAGMENT _deref_pbuz1=vbuc1 +lda #{c1} +ldy #0 +sta ({z1}),y //FRAGMENT vbuc1_neq__deref_pbuz1_then_la1 ldy #0 lda ({z1}),y @@ -1129,12 +989,11 @@ sta {z1}+1 //FRAGMENT vbsz1_lt_0_then_la1 lda {z1} bmi {la1} -//FRAGMENT vbsz1=_neg_vbsz1 -lda {z1} -eor #$ff -clc -adc #$01 +//FRAGMENT vwuz1=vbuc1 +lda #<{c1} sta {z1} +lda #>{c1} +sta {z1}+1 //FRAGMENT vwuz1=vwuz1_rol_1 asl {z1} rol {z1}+1 @@ -1198,6 +1057,8 @@ adc #{c1} //FRAGMENT vbuxx=vbuc1_plus_vbuaa tax axs #-[{c1}] +//FRAGMENT vbuz1=vbuxx +stx {z1} //FRAGMENT vbuaa=_deref_pbuz1 ldy #0 lda ({z1}),y @@ -1254,6 +1115,12 @@ tay //FRAGMENT vbuz1=pbuc1_derefidx_vbuyy lda {c1},y sta {z1} +//FRAGMENT vbuaa=vbuz1 +lda {z1} +//FRAGMENT vbuxx=vbuz1 +ldx {z1} +//FRAGMENT vbuz1=vbuaa +sta {z1} //FRAGMENT vbuz1=vbuaa_minus_vbuz2 sec sbc {z2} @@ -1652,12 +1519,6 @@ txa eor #$ff clc adc #$01 -//FRAGMENT vbsxx=_neg_vbsxx -txa -eor #$ff -clc -adc #$01 -tax //FRAGMENT vbsyy=_neg_vbsxx txa eor #$ff @@ -1681,12 +1542,6 @@ eor #$ff clc adc #$01 tax -//FRAGMENT vbsyy=_neg_vbsyy -tya -eor #$ff -clc -adc #$01 -tay //FRAGMENT vbsxx_ge_0_then_la1 cpx #0 bpl {la1} @@ -1707,6 +1562,9 @@ sta {z1} lda {z1} sec sbc #{c1} +//FRAGMENT vbuaa=vbuaa_minus_vbuc1 +sec +sbc #{c1} //FRAGMENT vbuaa=vbuxx_minus_vbuc1 txa sec @@ -1789,6 +1647,8 @@ beq {la1} txa lsr tax +//FRAGMENT vbuyy=vbuz1 +ldy {z1} //FRAGMENT vbuyy_neq_0_then_la1 cpy #0 bne {la1} @@ -1806,6 +1666,15 @@ cpy #{c1} bne {la1} //FRAGMENT vbuxx=vbuaa tax +//FRAGMENT vbuxx=vbuyy +tya +tax +//FRAGMENT vbuaa=vbuyy +tya +//FRAGMENT vbuz1=vbuyy +sty {z1} +//FRAGMENT vbuaa=vbuxx +txa //FRAGMENT vbuaa=_dec_vbuaa sec sbc #1 @@ -1835,6 +1704,9 @@ tay tay //FRAGMENT vwuz1=vwuz1_sethi_vbuxx stx {z1}+1 +//FRAGMENT vbuxx=vbuxx_minus_vbuc1 +txa +axs #{c1} //FRAGMENT vbuxx=vbuyy_minus_vbuc1 tya tax @@ -1855,6 +1727,11 @@ txa sec sbc #{c1} tay +//FRAGMENT vbuyy=vbuyy_minus_vbuc1 +tya +sec +sbc #{c1} +tay //FRAGMENT vbsyy_ge_0_then_la1 cpy #0 bpl {la1} @@ -1913,9 +1790,22 @@ tax sty $ff cpx $ff beq {la1} +//FRAGMENT vbuz1_ge_vbuc1_then_la1 +lda {z1} +cmp #{c1} +bcs {la1} +//FRAGMENT vbuaa_ge_vbuc1_then_la1 +cmp #{c1} +bcs {la1} //FRAGMENT vbuaa_neq_0_then_la1 cmp #0 bne {la1} +//FRAGMENT vbuxx_ge_vbuc1_then_la1 +cpx #{c1} +bcs {la1} +//FRAGMENT vbuyy_ge_vbuc1_then_la1 +cpy #{c1} +bcs {la1} //FRAGMENT vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1 ldy {z2} lda ({z1}),y @@ -1953,6 +1843,9 @@ tay lda ({z1}),y //FRAGMENT vbuaa=pbuz1_derefidx_vbuyy lda ({z1}),y +//FRAGMENT _deref_pbuc1=vbuz1 +lda {z1} +sta {c1} //FRAGMENT vbuz1_neq_vbuz2_then_la1 lda {z1} cmp {z2} @@ -1966,6 +1859,8 @@ lda {z1} sec sbc {z2} sta {z1} +//FRAGMENT _deref_pbuc1=vbuaa +sta {c1} //FRAGMENT vbuz1_neq_vbuaa_then_la1 cmp {z1} bne {la1} @@ -2033,6 +1928,13 @@ bne {la1} sty $ff cpx $ff bcc {la1} +//FRAGMENT vbuyy=vbuxx +txa +tay +//FRAGMENT _deref_pbuc1=vbuxx +stx {c1} +//FRAGMENT _deref_pbuc1=vbuyy +sty {c1} //FRAGMENT pbuc1_derefidx_vbuz1=vbuz1 ldy {z1} tya @@ -2043,10 +1945,9 @@ sta {c1},x //FRAGMENT vbuaa_neq_vbuc1_then_la1 cmp #{c1} bne {la1} -//FRAGMENT vbuz1=vbuz2_rol_1 -lda {z2} -asl -sta {z1} +//FRAGMENT vbuaa=_inc_vbuaa +clc +adc #1 //FRAGMENT pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz1_plus_vbuc2 ldy {z1} clc @@ -2065,58 +1966,6 @@ sta {c1},y lda {c1}+1,y adc {c2}+1,y sta {c1}+1,y -//FRAGMENT vbuaa=vbuz1_rol_1 -lda {z1} -asl -//FRAGMENT vbuxx=vbuz1_rol_1 -lda {z1} -asl -tax -//FRAGMENT vbuyy=vbuz1_rol_1 -lda {z1} -asl -tay -//FRAGMENT vbuz1=vbuaa_rol_1 -asl -sta {z1} -//FRAGMENT vbuaa=vbuaa_rol_1 -asl -//FRAGMENT vbuxx=vbuaa_rol_1 -asl -tax -//FRAGMENT vbuyy=vbuaa_rol_1 -asl -tay -//FRAGMENT vbuz1=vbuxx_rol_1 -txa -asl -sta {z1} -//FRAGMENT vbuaa=vbuxx_rol_1 -txa -asl -//FRAGMENT vbuxx=vbuxx_rol_1 -txa -asl -tax -//FRAGMENT vbuyy=vbuxx_rol_1 -txa -asl -tay -//FRAGMENT vbuz1=vbuyy_rol_1 -tya -asl -sta {z1} -//FRAGMENT vbuaa=vbuyy_rol_1 -tya -asl -//FRAGMENT vbuxx=vbuyy_rol_1 -tya -asl -tax -//FRAGMENT vbuyy=vbuyy_rol_1 -tya -asl -tay //FRAGMENT pwuc1_derefidx_vbuaa=pwuc1_derefidx_vbuaa_plus_vbuc2 tay clc @@ -2164,6 +2013,10 @@ sta {c1},y lda {c1}+1,y adc {c2}+1,y sta {c1}+1,y +//FRAGMENT _deref_pbuc1=_deref_pbuc1_bor_vbuc2 +lda #{c2} +ora {c1} +sta {c1} //FRAGMENT _deref_qprc1=pprc2 lda #<{c2} sta {c1} @@ -2180,9 +2033,6 @@ lda #<{c1} sta {z1} lda #>{c1} sta {z1}+1 -//FRAGMENT vbsz1=vbsc1 -lda #{c1} -sta {z1} //FRAGMENT vbsz1=pbsc1_derefidx_vbuz2 ldy {z2} lda {c1},y @@ -2210,6 +2060,13 @@ stx {z1} lax {z1} axs #-[{c1}] stx {z1} +//FRAGMENT vbuc1_neq_vbuz1_then_la1 +lda #{c1} +cmp {z1} +bne {la1} +//FRAGMENT _deref_pbuc1=_deref_pbuc2 +lda {c2} +sta {c1} //FRAGMENT _deref_pbuz1=pbuc1_derefidx_vbuz2 ldy {z2} lda {c1},y @@ -2292,6 +2149,14 @@ lda {c1},y sta {z1} lda {c1}+1,y sta {z1}+1 +//FRAGMENT pbuz1=pbuc1_plus_vwuz2 +lda {z2} +clc +adc #<{c1} +sta {z1} +lda {z2}+1 +adc #>{c1} +sta {z1}+1 //FRAGMENT pbuz1=pbuz2_plus_vbuz3 lda {z3} clc @@ -2343,6 +2208,13 @@ beq {la1} lda #{c1} cmp {z1} beq {la1} +//FRAGMENT vbuz1_gt_0_then_la1 +lda {z1} +bne {la1} +//FRAGMENT pbuc1_derefidx_vbuz1=pbuc2_derefidx_vbuz1 +ldy {z1} +lda {c2},y +sta {c1},y //FRAGMENT vbuz1=pbuc1_derefidx_vbuz2_band_vbuc2 lda #{c2} ldy {z2} @@ -2357,6 +2229,10 @@ sta {z1} lda {z2} ora {z3} sta {z1} +//FRAGMENT vbuz1=vbuz1_minus_vbuc1 +lax {z1} +axs #{c1} +stx {z1} //FRAGMENT _deref_pbuz1=_deref_pbuc1 lda {c1} ldy #0 @@ -2801,6 +2677,12 @@ bne {la1} tay lda {c2},y sta {c1},y +//FRAGMENT pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx +lda {c2},x +sta {c1},x +//FRAGMENT pbuc1_derefidx_vbuyy=pbuc2_derefidx_vbuyy +lda {c2},y +sta {c1},y //FRAGMENT vbuz1=pbuc1_derefidx_vbuaa_band_vbuc2 tay lda #{c2} @@ -3091,12 +2973,18 @@ tay //FRAGMENT vbsyy=pbsc1_derefidx_vbuz1 ldx {z1} ldy {c1},x +//FRAGMENT vbuxx_gt_0_then_la1 +cpx #0 +bne {la1} //FRAGMENT vbuc1_eq_vbuxx_then_la1 cpx #{c1} beq {la1} //FRAGMENT vbuc1_eq_vbuyy_then_la1 cpy #{c1} beq {la1} +//FRAGMENT vbuc1_neq_vbuxx_then_la1 +cpx #{c1} +bne {la1} //FRAGMENT vbuc1_neq_vbuyy_then_la1 cpy #{c1} bne {la1} @@ -4363,6 +4251,11 @@ txa clc adc #{c1} tay +//FRAGMENT _deref_pbuz1=_deref_pbuz2 +ldy #0 +lda ({z2}),y +ldy #0 +sta ({z1}),y //FRAGMENT vbuz1=vbuz2_plus_vbuz2 lda {z2} asl @@ -4401,6 +4294,10 @@ lda ({z1}),y cmp #0 bne {la1} +//FRAGMENT vbuz1_lt_vbuz2_then_la1 +lda {z1} +cmp {z2} +bcc {la1} //FRAGMENT vwuz1=vbuz2_rol_3 lda {z2} sta {z1} @@ -4574,6 +4471,8 @@ sty {z1} sta $ff cpx $ff bcc {la1} +//FRAGMENT vbuz1=vbuz1_plus_1 +inc {z1} //FRAGMENT vbuz1=_lo__deref_pwuc1 lda {c1} sta {z1} @@ -5062,12 +4961,100 @@ lda {c2}-1,y sta {c1}-1,y dey bne !- +//FRAGMENT vbuz1=vbuz2_rol_3 +lda {z2} +asl +asl +asl +sta {z1} //FRAGMENT vwsz1=pwsc1_derefidx_vbuz2 ldy {z2} lda {c1},y sta {z1} lda {c1}+1,y sta {z1}+1 +//FRAGMENT vbuz1=vbuaa_rol_3 +asl +asl +asl +sta {z1} +//FRAGMENT vbuz1=vbuxx_rol_3 +txa +asl +asl +asl +sta {z1} +//FRAGMENT vbuz1=vbuyy_rol_3 +tya +asl +asl +asl +sta {z1} +//FRAGMENT vbuaa=vbuz1_rol_3 +lda {z1} +asl +asl +asl +//FRAGMENT vbuaa=vbuaa_rol_3 +asl +asl +asl +//FRAGMENT vbuaa=vbuxx_rol_3 +txa +asl +asl +asl +//FRAGMENT vbuaa=vbuyy_rol_3 +tya +asl +asl +asl +//FRAGMENT vbuxx=vbuz1_rol_3 +lda {z1} +asl +asl +asl +tax +//FRAGMENT vbuxx=vbuaa_rol_3 +asl +asl +asl +tax +//FRAGMENT vbuxx=vbuxx_rol_3 +txa +asl +asl +asl +tax +//FRAGMENT vbuxx=vbuyy_rol_3 +tya +asl +asl +asl +tax +//FRAGMENT vbuyy=vbuz1_rol_3 +lda {z1} +asl +asl +asl +tay +//FRAGMENT vbuyy=vbuaa_rol_3 +asl +asl +asl +tay +//FRAGMENT vbuyy=vbuxx_rol_3 +txa +asl +asl +asl +tay +//FRAGMENT vbuyy=vbuyy_rol_3 +tya +asl +asl +asl +tay //FRAGMENT vwsz1=pwsc1_derefidx_vbuaa tay lda {c1},y @@ -5639,6 +5626,11 @@ sta {z1} lda {z1}+1 adc {c1}+1,y sta {z1}+1 +//FRAGMENT vbuz1_lt_vbuaa_then_la1 +cmp {z1} +beq !+ +bcs {la1} +!: //FRAGMENT vbuxx=vbuxx_minus_2 dex dex @@ -5758,6 +5750,10 @@ lda {z2} sta {z1} lda #0 sta {z1}+1 +//FRAGMENT _deref_pbuc1=_deref_pbuc1_band_vbuc2 +lda #{c2} +and {c1} +sta {c1} //FRAGMENT vboz1=vbuz2_lt_vbuc1 lda {z2} cmp #{c1} @@ -6057,10 +6053,6 @@ tay //FRAGMENT vboz1=vboyy tya sta {z1} -//FRAGMENT _deref_pbuc1_neq_vbuc2_then_la1 -lda #{c2} -cmp {c1} -bne {la1} //FRAGMENT vbuz1=vbuc1_bor_vbuz2 lda #{c1} ora {z2} @@ -6536,6 +6528,8 @@ tya //FRAGMENT vbuxx=vbuaa_plus_1 tax inx +//FRAGMENT vbuxx=vbuxx_plus_1 +inx //FRAGMENT vbuxx=vbuyy_plus_1 tya tax @@ -6547,6 +6541,8 @@ iny txa tay iny +//FRAGMENT vbuyy=vbuyy_plus_1 +iny //FRAGMENT vbuxx=pbuc1_derefidx_vbuxx lda {c1},x tax @@ -6647,6 +6643,11 @@ lda STACK_BASE+{c1},x sta {z1} lda STACK_BASE+{c1}+1,x sta {z1}+1 +//FRAGMENT pbuc1_derefidx_vbuz1=_deref_pbuz2 +ldy #0 +lda ({z2}),y +ldy {z1} +sta {c1},y //FRAGMENT _stackpushptr_=pbuc1 lda #>{c1} pha @@ -6684,6 +6685,9 @@ dey sec sbc #1 sta {z1} +//FRAGMENT vbuaa=vbuaa_minus_1 +sec +sbc #1 //FRAGMENT vbuxx=vbuaa_minus_1 tax dex @@ -6894,6 +6898,12 @@ bne {la1} lda {z1} cmp {z2} bne {la1} +//FRAGMENT vwuz1_le_0_then_la1 +lda {z1} +bne !+ +lda {z1}+1 +beq {la1} +!: //FRAGMENT pbuz1=pbuz2_plus_vwuz3 lda {z2} clc @@ -6982,6 +6992,14 @@ sta {z1} lda {z2}+1 sbc #>{c1} sta {z1}+1 +//FRAGMENT pssz1=pssc1_plus_vbuz2 +lda {z2} +clc +adc #<{c1} +sta {z1} +lda #>{c1} +adc #0 +sta {z1}+1 //FRAGMENT vbuz1=vbuc1_rol_pbuz2_derefidx_vbuc2 ldy #{c2} lda ({z2}),y @@ -7231,6 +7249,29 @@ lda {z2} sta {c1},y lda {z2}+1 sta {c1}+1,y +//FRAGMENT pssz1=pssc1_plus_vbuaa +clc +adc #<{c1} +sta {z1} +lda #>{c1} +adc #0 +sta {z1}+1 +//FRAGMENT pssz1=pssc1_plus_vbuxx +txa +clc +adc #<{c1} +sta {z1} +lda #>{c1} +adc #0 +sta {z1}+1 +//FRAGMENT pssz1=pssc1_plus_vbuyy +tya +clc +adc #<{c1} +sta {z1} +lda #>{c1} +adc #0 +sta {z1}+1 //FRAGMENT vbuaa=vbuc1_rol_pbuz1_derefidx_vbuc2 ldy #{c2} lda ({z1}),y @@ -8385,6 +8426,15 @@ sta {z1} lda {z1}+1 eor {z2}+1 sta {z1}+1 +//FRAGMENT vwuz1_lt_vbuc1_then_la1 +lda {z1}+1 +cmp #>{c1} +bcc {la1} +bne !+ +lda {z1} +cmp #<{c1} +bcc {la1} +!: //FRAGMENT vwuz1=_word_vduz2 lda {z2} sta {z1} @@ -9258,8 +9308,6 @@ bvc !+ eor #$80 !: bmi {la1} -//FRAGMENT vbsyy=vbsc1 -ldy #{c1} //FRAGMENT vwsz1=vwsz2_ror_7 // ROL once instead of RORing 7 times lda {z2} // {z2} low byte to tmp $ff @@ -10847,6 +10895,11 @@ lda {z1} cmp #{c1} bcs {la1} !: +//FRAGMENT vwuz1=vwuz1_plus_1 +inc {z1} +bne !+ +inc {z1}+1 +!: //FRAGMENT vwuz1=vwuz1_rol_8 lda {z1} sta {z1}+1 @@ -12475,6 +12528,184 @@ rol {z1}+3 dex bne !- !e: +//FRAGMENT pssz1=pssc1 +lda #<{c1} +sta {z1} +lda #>{c1} +sta {z1}+1 +//FRAGMENT vwuz1=vwuz1_minus_1 +lda {z1} +sec +sbc #1 +sta {z1} +lda {z1}+1 +sbc #0 +sta {z1}+1 +//FRAGMENT vbuz1=vbuz1_minus_1 +dec {z1} +//FRAGMENT pbsz1_derefidx_vbuc1=pbsz1_derefidx_vbuc1_plus_pbsz1_derefidx_vbuc2 +ldy #{c2} +lda ({z1}),y +ldy #{c1} +tax +lda ({z1}),y +sty $ff + +stx $ff +clc +adc $ff +ldy $ff +sta ({z1}),y +//FRAGMENT pbsz1_derefidx_vbuc1_lt_vbsc2_then_la1 +ldy #{c1} +lda ({z1}),y + +sec +sbc #{c2} +bvc !+ +eor #$80 +!: +bmi {la1} +//FRAGMENT pbsz1_derefidx_vbuc1=vbsc2 +lda #{c1} +tay +lda #{c2} +sta ({z1}),y +//FRAGMENT pwsz1_derefidx_vbuc1_gt_vwsc2_then_la1 +ldy #{c1} +lda #<{c2} +cmp ({z1}),y +iny +lda #>{c2} +sbc ({z1}),y +bvc !+ +eor #$80 +!: +bmi {la1} +!e: +//FRAGMENT pwsz1_derefidx_vbuc1_ge_vwsc2_then_la1 +ldy #{c1} +lda ({z1}),y +cmp #<{c2} +iny +lda ({z1}),y +sbc #>{c2} +bvc !+ +eor #$80 +!: +bpl {la1} +//FRAGMENT pwsz1_derefidx_vbuc1=pwsz1_derefidx_vbuc1_plus_pbsz1_derefidx_vbuc2 +ldy #{c2} +lda ({z1}),y +sta $fe +ora #$7f +bmi !+ +lda #0 +!: +sta $ff +ldy #{c1} +clc +lda ({z1}),y +adc $fe +sta ({z1}),y +iny +lda ({z1}),y +adc $fe +sta ({z1}),y +//FRAGMENT pbuc1_derefidx_vbuz1_ge_vbuc2_then_la1 +ldy {z1} +lda {c1},y +cmp #{c2} +bcs {la1} +//FRAGMENT vwsz1=pwsz2_derefidx_vbuc1_ror_vbuc2 +ldx #{c2} +ldy #{c1} +lda ({z2}),y +sta {z1} +iny +lda ({z2}),y +sta {z1}+1 +cpx #0 +beq !e+ +!: +lda {z1}+1 +cmp #$80 +ror {z1}+1 +ror {z1} +dex +bne !- +!e: +//FRAGMENT pbuc1_derefidx_vbuz1=_byte_vwsz2 +ldy {z1} +lda {z2} +sta {c1},y +//FRAGMENT pssz1=pssz1_plus_vbuc1 +lda #{c1} +clc +adc {z1} +sta {z1} +bcc !+ +inc {z1}+1 +!: +//FRAGMENT pwsz1_derefidx_vbuc1=vwsc2 +ldy #{c1} +lda #<{c2} +sta ({z1}),y +iny +lda #>{c2} +sta ({z1}),y +//FRAGMENT pbsz1_derefidx_vbuc1=vbsz2 +lda #{c1} +tay +lda {z2} +sta ({z1}),y +//FRAGMENT pbuc1_derefidx_vbuz1_lt_vbuc2_then_la1 +ldy {z1} +lda {c1},y +cmp #{c2} +bcc {la1} +//FRAGMENT vbuc1_eq_pbuc2_derefidx_vbuz1_then_la1 +ldy {z1} +lda {c2},y +cmp #{c1} +beq {la1} +//FRAGMENT pbsz1_derefidx_vbuc1=vbsxx +lda #{c1} +tay +txa +sta ({z1}),y +//FRAGMENT pbuc1_derefidx_vbuaa_lt_vbuc2_then_la1 +tay +lda {c1},y +cmp #{c2} +bcc {la1} +//FRAGMENT pbuc1_derefidx_vbuxx_lt_vbuc2_then_la1 +lda {c1},x +cmp #{c2} +bcc {la1} +//FRAGMENT pbuc1_derefidx_vbuyy_lt_vbuc2_then_la1 +lda {c1},y +cmp #{c2} +bcc {la1} +//FRAGMENT vbuc1_eq_pbuc2_derefidx_vbuaa_then_la1 +tay +lda {c2},y +cmp #{c1} +beq {la1} +//FRAGMENT vbuc1_eq_pbuc2_derefidx_vbuxx_then_la1 +lda {c2},x +cmp #{c1} +beq {la1} +//FRAGMENT vbuc1_eq_pbuc2_derefidx_vbuyy_then_la1 +lda {c2},y +cmp #{c1} +beq {la1} +//FRAGMENT vbuxx=vbuxx_minus_1 +dex +//FRAGMENT vbuyy=vbuyy_minus_1 +tya +tay +dey //FRAGMENT vwsz1_neq_vwsc1_then_la1 lda {z1}+1 cmp #>{c1} @@ -14980,48 +15211,6 @@ sta {z1} lda {z1}+1 adc #>{c1} sta {z1}+1 -//FRAGMENT pbsc1_derefidx_vbuz1=vbsz2 -lda {z2} -ldy {z1} -sta {c1},y -//FRAGMENT pbsc1_derefidx_vbuaa=vbsz1 -tay -lda {z1} -sta {c1},y -//FRAGMENT pbsc1_derefidx_vbuxx=vbsz1 -lda {z1} -sta {c1},x -//FRAGMENT pbsc1_derefidx_vbuyy=vbsz1 -lda {z1} -sta {c1},y -//FRAGMENT pbsc1_derefidx_vbuz1=vbsxx -ldy {z1} -txa -sta {c1},y -//FRAGMENT pbsc1_derefidx_vbuaa=vbsxx -tay -txa -sta {c1},y -//FRAGMENT pbsc1_derefidx_vbuxx=vbsxx -txa -sta {c1},x -//FRAGMENT pbsc1_derefidx_vbuyy=vbsxx -txa -sta {c1},y -//FRAGMENT pbsc1_derefidx_vbuz1=vbsyy -tya -ldy {z1} -sta {c1},y -//FRAGMENT pbsc1_derefidx_vbuaa=vbsyy -tax -tya -sta {c1},x -//FRAGMENT pbsc1_derefidx_vbuxx=vbsyy -tya -sta {c1},x -//FRAGMENT pbsc1_derefidx_vbuyy=vbsyy -tya -sta {c1},y //FRAGMENT _deref_pbuc1=_deref_pbuc1_plus_vbuc2 lda #{c2} clc @@ -17833,9 +18022,6 @@ sta {c1},x //FRAGMENT pbsc1_derefidx_vbuyy=vbsc2 lda #{c2} sta {c1},y -//FRAGMENT pbsc1_derefidx_vbuz1=vbsaa -ldy {z1} -sta {c1},y //FRAGMENT _deref_pwuc1=_deref_pwuc1_plus_vwuc2 lda #<{c2} clc diff --git a/src/main/fragment/cache/fragment-cache-wdc65c02.asm b/src/main/fragment/cache/fragment-cache-wdc65c02.asm index e42eb81b1..4eb4c82a9 100644 --- a/src/main/fragment/cache/fragment-cache-wdc65c02.asm +++ b/src/main/fragment/cache/fragment-cache-wdc65c02.asm @@ -1,4 +1,4 @@ -//KICKC FRAGMENT CACHE 12b00eb139 12b00ecab9 +//KICKC FRAGMENT CACHE 132c9fe4d5 132c9ffe57 //FRAGMENT vbuz1=_deref_pbuc1 lda {c1} sta {z1} diff --git a/src/main/fragment/mos6502-common/pbuz1_derefidx_(pbsc1_derefidx_vbuxx)=vbuaa.asm b/src/main/fragment/mos6502-common/pbuz1_derefidx_(pbsc1_derefidx_vbuxx)=vbuaa.asm new file mode 100644 index 000000000..2bc89c135 --- /dev/null +++ b/src/main/fragment/mos6502-common/pbuz1_derefidx_(pbsc1_derefidx_vbuxx)=vbuaa.asm @@ -0,0 +1,2 @@ +ldy {c1},x +sta ({z1}),y diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 10efcbb59..ff6f14239 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -44,6 +44,11 @@ public class TestPrograms { public TestPrograms() { } + @Test + public void testIndexSizeofReuse() throws IOException, URISyntaxException { + compileAndCompare("index-sizeof-reuse.c"); + } + @Test public void testPragmaNoParenthesis() throws IOException, URISyntaxException { compileAndCompare("pragma-noparenthesis.c"); diff --git a/src/test/kc/index-sizeof-reuse.c b/src/test/kc/index-sizeof-reuse.c new file mode 100644 index 000000000..7b736a003 --- /dev/null +++ b/src/test/kc/index-sizeof-reuse.c @@ -0,0 +1,55 @@ +// Test that the multiplication of a idx*sizeof(element) is reused inside loops + +struct Entity { + signed char x_pos; + signed char x_vel; + char symbol; +}; + +#define NUM_ENTITIES 25 + +struct Entity entities[NUM_ENTITIES]; + +char * const VIC_RASTER = 0xd012; +char * const VIC_BG_COLOR = 0xd020; +char * const SCREEN = 0x0400; + +void main() { + + asm { sei } + + // Initialize velocities + signed char v = -1; + for(char i=0;i<NUM_ENTITIES;i++) { + entities[i].x_pos = (signed char)i; + entities[i].x_vel = v; + entities[i].symbol = i; + v = -v; + } + + while(1) { + // Wait for raster refresh + while(*VIC_RASTER!=0xff) ; + *VIC_BG_COLOR = 0; + // Move the entities + char * line = SCREEN; + for(char i=0;i<NUM_ENTITIES;i++) { + // Delete old symbol + line[entities[i].x_pos] = ' '; + // Move by velocity + entities[i].x_pos += entities[i].x_vel; + // Turn around if needed + if(entities[i].x_pos<0 || entities[i].x_pos>39) { + entities[i].x_vel = -entities[i].x_vel; + entities[i].x_pos += entities[i].x_vel; + } + // Draw symbol + line[entities[i].x_pos] = entities[i].symbol; + // Next line + line +=40; + } + *VIC_BG_COLOR = 15; + } + + +} \ No newline at end of file diff --git a/src/test/ref/index-sizeof-reuse.asm b/src/test/ref/index-sizeof-reuse.asm new file mode 100644 index 000000000..7e695497f --- /dev/null +++ b/src/test/ref/index-sizeof-reuse.asm @@ -0,0 +1,146 @@ +// Test that the multiplication of a idx*sizeof(element) is reused inside loops +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + .const OFFSET_STRUCT_ENTITY_X_VEL = 1 + .const OFFSET_STRUCT_ENTITY_SYMBOL = 2 + .label VIC_RASTER = $d012 + .label VIC_BG_COLOR = $d020 + .label SCREEN = $400 +main: { + // Initialize velocities + .label v = 2 + // Move the entities + .label line = 4 + .label i1 = 3 + // asm + sei + lda #-1 + sta.z v + ldx #0 + __b1: + // for(char i=0;i<NUM_ENTITIES;i++) + cpx #$19 + bcs !__b2+ + jmp __b2 + !__b2: + // Wait for raster refresh + __b3: + // while(*VIC_RASTER!=0xff) + lda #$ff + cmp VIC_RASTER + bne __b3 + // *VIC_BG_COLOR = 0 + lda #0 + sta VIC_BG_COLOR + lda #<SCREEN + sta.z line + lda #>SCREEN + sta.z line+1 + lda #0 + sta.z i1 + __b5: + // for(char i=0;i<NUM_ENTITIES;i++) + lda.z i1 + cmp #$19 + bcc __b6 + // *VIC_BG_COLOR = 15 + lda #$f + sta VIC_BG_COLOR + jmp __b3 + __b6: + // line[entities[i].x_pos] = ' ' + lda.z i1 + asl + clc + adc.z i1 + tax + // Delete old symbol + lda #' ' + ldy entities,x + sta (line),y + // entities[i].x_pos += entities[i].x_vel + // Move by velocity + clc + lda entities,x + adc entities+OFFSET_STRUCT_ENTITY_X_VEL,x + sta entities,x + // if(entities[i].x_pos<0 || entities[i].x_pos>39) + lda entities,x + cmp #0 + bmi __b9 + lda entities,x + sec + sbc #$27+1 + bvc !+ + eor #$80 + !: + bmi __b8 + __b9: + // -entities[i].x_vel + lda.z i1 + asl + clc + adc.z i1 + tax + lda entities+OFFSET_STRUCT_ENTITY_X_VEL,x + eor #$ff + clc + adc #1 + // entities[i].x_vel = -entities[i].x_vel + sta entities+OFFSET_STRUCT_ENTITY_X_VEL,x + // entities[i].x_pos += entities[i].x_vel + clc + lda entities,x + adc entities+OFFSET_STRUCT_ENTITY_X_VEL,x + sta entities,x + __b8: + // line[entities[i].x_pos] = entities[i].symbol + lda.z i1 + asl + clc + adc.z i1 + // Draw symbol + tax + lda entities+OFFSET_STRUCT_ENTITY_SYMBOL,x + ldy entities,x + sta (line),y + // line +=40 + // Next line + lda #$28 + clc + adc.z line + sta.z line + bcc !+ + inc.z line+1 + !: + // for(char i=0;i<NUM_ENTITIES;i++) + inc.z i1 + jmp __b5 + __b2: + // entities[i].x_pos = (signed char)i + txa + asl + stx.z $ff + clc + adc.z $ff + tay + txa + sta entities,y + // entities[i].x_vel = v + lda.z v + sta entities+OFFSET_STRUCT_ENTITY_X_VEL,y + // entities[i].symbol = i + txa + sta entities+OFFSET_STRUCT_ENTITY_SYMBOL,y + // v = -v + lda.z v + eor #$ff + clc + adc #1 + sta.z v + // for(char i=0;i<NUM_ENTITIES;i++) + inx + jmp __b1 +} + entities: .fill 3*$19, 0 diff --git a/src/test/ref/index-sizeof-reuse.cfg b/src/test/ref/index-sizeof-reuse.cfg new file mode 100644 index 000000000..91ae9de13 --- /dev/null +++ b/src/test/ref/index-sizeof-reuse.cfg @@ -0,0 +1,57 @@ + +(void()) main() +main: scope:[main] from + asm { sei } + to:main::@1 +main::@1: scope:[main] from main main::@2 + [1] (signed byte) main::v#2 ← phi( main/(signed byte) -1 main::@2/(signed byte) main::v#1 ) + [1] (byte) main::i#2 ← phi( main/(byte) 0 main::@2/(byte) main::i#1 ) + [2] if((byte) main::i#2<(byte) $19) goto main::@2 + to:main::@3 +main::@3: scope:[main] from main::@1 main::@3 main::@7 + [3] if(*((const nomodify byte*) VIC_RASTER)!=(byte) $ff) goto main::@3 + to:main::@4 +main::@4: scope:[main] from main::@3 + [4] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) 0 + to:main::@5 +main::@5: scope:[main] from main::@4 main::@8 + [5] (byte*) main::line#2 ← phi( main::@4/(const nomodify byte*) SCREEN main::@8/(byte*) main::line#1 ) + [5] (byte) main::i1#2 ← phi( main::@4/(byte) 0 main::@8/(byte) main::i1#1 ) + [6] if((byte) main::i1#2<(byte) $19) goto main::@6 + to:main::@7 +main::@7: scope:[main] from main::@5 + [7] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) $f + to:main::@3 +main::@6: scope:[main] from main::@5 + [8] (byte~) main::$23 ← (byte) main::i1#2 << (byte) 1 + [9] (byte~) main::$13 ← (byte~) main::$23 + (byte) main::i1#2 + [10] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$13)) ← (byte) ' ' + [11] *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$13) + [12] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) 0) goto main::@9 + to:main::@10 +main::@10: scope:[main] from main::@6 + [13] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) $27+(signed byte) 1) goto main::@8 + to:main::@9 +main::@9: scope:[main] from main::@10 main::@6 + [14] (byte~) main::$27 ← (byte) main::i1#2 << (byte) 1 + [15] (byte~) main::$18 ← (byte~) main::$27 + (byte) main::i1#2 + [16] (signed byte~) main::$8 ← - *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) + [17] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) ← (signed byte~) main::$8 + [18] *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) + to:main::@8 +main::@8: scope:[main] from main::@10 main::@9 + [19] (byte~) main::$25 ← (byte) main::i1#2 << (byte) 1 + [20] (byte~) main::$16 ← (byte~) main::$25 + (byte) main::i1#2 + [21] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$16)) ← *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$16) + [22] (byte*) main::line#1 ← (byte*) main::line#2 + (byte) $28 + [23] (byte) main::i1#1 ← ++ (byte) main::i1#2 + to:main::@5 +main::@2: scope:[main] from main::@1 + [24] (byte~) main::$21 ← (byte) main::i#2 << (byte) 1 + [25] (byte~) main::$10 ← (byte~) main::$21 + (byte) main::i#2 + [26] *((signed byte*)(const struct Entity*) entities + (byte~) main::$10) ← (signed byte)(byte) main::i#2 + [27] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$10) ← (signed byte) main::v#2 + [28] *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$10) ← (byte) main::i#2 + [29] (signed byte) main::v#1 ← - (signed byte) main::v#2 + [30] (byte) main::i#1 ← ++ (byte) main::i#2 + to:main::@1 diff --git a/src/test/ref/index-sizeof-reuse.log b/src/test/ref/index-sizeof-reuse.log new file mode 100644 index 000000000..171ae89f7 --- /dev/null +++ b/src/test/ref/index-sizeof-reuse.log @@ -0,0 +1,1251 @@ + +CONTROL FLOW GRAPH SSA + +(void()) main() +main: scope:[main] from __start + asm { sei } + (signed byte) main::v#0 ← (signed byte) -1 + (byte) main::i#0 ← (byte) 0 + to:main::@1 +main::@1: scope:[main] from main main::@2 + (signed byte) main::v#3 ← phi( main/(signed byte) main::v#0 main::@2/(signed byte) main::v#1 ) + (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@2/(byte) main::i#1 ) + (bool~) main::$0 ← (byte) main::i#2 < (number) $19 + if((bool~) main::$0) goto main::@2 + to:main::@3 +main::@2: scope:[main] from main::@1 + (signed byte) main::v#2 ← phi( main::@1/(signed byte) main::v#3 ) + (byte) main::i#3 ← phi( main::@1/(byte) main::i#2 ) + (byte~) main::$9 ← (byte) main::i#3 * (const byte) SIZEOF_STRUCT_ENTITY + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$9) ← (signed byte)(byte) main::i#3 + (byte~) main::$10 ← (byte) main::i#3 * (const byte) SIZEOF_STRUCT_ENTITY + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$10) ← (signed byte) main::v#2 + (byte~) main::$11 ← (byte) main::i#3 * (const byte) SIZEOF_STRUCT_ENTITY + *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$11) ← (byte) main::i#3 + (signed byte~) main::$1 ← - (signed byte) main::v#2 + (signed byte) main::v#1 ← (signed byte~) main::$1 + (byte) main::i#1 ← ++ (byte) main::i#3 + to:main::@1 +main::@3: scope:[main] from main::@1 main::@8 + (bool~) main::$20 ← (number) 0 != (number) 1 + if((bool~) main::$20) goto main::@4 + to:main::@return +main::@4: scope:[main] from main::@3 main::@4 + (bool~) main::$2 ← *((const nomodify byte*) VIC_RASTER) != (number) $ff + if((bool~) main::$2) goto main::@4 + to:main::@5 +main::@5: scope:[main] from main::@4 + *((const nomodify byte*) VIC_BG_COLOR) ← (number) 0 + (byte*) main::line#0 ← (const nomodify byte*) SCREEN + (byte) main::i1#0 ← (byte) 0 + to:main::@6 +main::@6: scope:[main] from main::@5 main::@9 + (byte*) main::line#4 ← phi( main::@5/(byte*) main::line#0 main::@9/(byte*) main::line#1 ) + (byte) main::i1#2 ← phi( main::@5/(byte) main::i1#0 main::@9/(byte) main::i1#1 ) + (bool~) main::$3 ← (byte) main::i1#2 < (number) $19 + if((bool~) main::$3) goto main::@7 + to:main::@8 +main::@7: scope:[main] from main::@6 + (byte*) main::line#2 ← phi( main::@6/(byte*) main::line#4 ) + (byte) main::i1#3 ← phi( main::@6/(byte) main::i1#2 ) + (byte~) main::$12 ← (byte) main::i1#3 * (const byte) SIZEOF_STRUCT_ENTITY + *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$12)) ← (byte) ' ' + (byte~) main::$13 ← (byte) main::i1#3 * (const byte) SIZEOF_STRUCT_ENTITY + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$13) ← *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$13) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$13) + (byte~) main::$14 ← (byte) main::i1#3 * (const byte) SIZEOF_STRUCT_ENTITY + (bool~) main::$4 ← *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$14) < (number) 0 + (byte~) main::$15 ← (byte) main::i1#3 * (const byte) SIZEOF_STRUCT_ENTITY + (bool~) main::$5 ← *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$15) > (number) $27 + (bool~) main::$6 ← (bool~) main::$4 || (bool~) main::$5 + (bool~) main::$7 ← ! (bool~) main::$6 + if((bool~) main::$7) goto main::@9 + to:main::@10 +main::@8: scope:[main] from main::@6 + *((const nomodify byte*) VIC_BG_COLOR) ← (number) $f + to:main::@3 +main::@9: scope:[main] from main::@10 main::@7 + (byte*) main::line#3 ← phi( main::@10/(byte*) main::line#5 main::@7/(byte*) main::line#2 ) + (byte) main::i1#4 ← phi( main::@10/(byte) main::i1#5 main::@7/(byte) main::i1#3 ) + (byte~) main::$16 ← (byte) main::i1#4 * (const byte) SIZEOF_STRUCT_ENTITY + *((byte*) main::line#3 + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$16)) ← *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$16) + (byte*) main::line#1 ← (byte*) main::line#3 + (number) $28 + (byte) main::i1#1 ← ++ (byte) main::i1#4 + to:main::@6 +main::@10: scope:[main] from main::@7 + (byte*) main::line#5 ← phi( main::@7/(byte*) main::line#2 ) + (byte) main::i1#5 ← phi( main::@7/(byte) main::i1#3 ) + (byte~) main::$17 ← (byte) main::i1#5 * (const byte) SIZEOF_STRUCT_ENTITY + (signed byte~) main::$8 ← - *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$17) + (byte~) main::$18 ← (byte) main::i1#5 * (const byte) SIZEOF_STRUCT_ENTITY + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) ← (signed byte~) main::$8 + (byte~) main::$19 ← (byte) main::i1#5 * (const byte) SIZEOF_STRUCT_ENTITY + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$19) ← *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$19) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$19) + to:main::@9 +main::@return: scope:[main] from main::@3 + return + to:@return + +(void()) __start() +__start: scope:[__start] from + call main + to:__start::@1 +__start::@1: scope:[__start] from __start + to:__start::@return +__start::@return: scope:[__start] from __start::@1 + return + to:@return + +SYMBOL TABLE SSA +(byte) Entity::symbol +(signed byte) Entity::x_pos +(signed byte) Entity::x_vel +(const byte) OFFSET_STRUCT_ENTITY_SYMBOL = (byte) 2 +(const byte) OFFSET_STRUCT_ENTITY_X_POS = (byte) 0 +(const byte) OFFSET_STRUCT_ENTITY_X_VEL = (byte) 1 +(const nomodify byte*) SCREEN = (byte*)(number) $400 +(const byte) SIZEOF_STRUCT_ENTITY = (byte) 3 +(const nomodify byte*) VIC_BG_COLOR = (byte*)(number) $d020 +(const nomodify byte*) VIC_RASTER = (byte*)(number) $d012 +(void()) __start() +(label) __start::@1 +(label) __start::@return +(const struct Entity*) entities[(number) $19] = { fill( $19, 0) } +(void()) main() +(bool~) main::$0 +(signed byte~) main::$1 +(byte~) main::$10 +(byte~) main::$11 +(byte~) main::$12 +(byte~) main::$13 +(byte~) main::$14 +(byte~) main::$15 +(byte~) main::$16 +(byte~) main::$17 +(byte~) main::$18 +(byte~) main::$19 +(bool~) main::$2 +(bool~) main::$20 +(bool~) main::$3 +(bool~) main::$4 +(bool~) main::$5 +(bool~) main::$6 +(bool~) main::$7 +(signed byte~) main::$8 +(byte~) main::$9 +(label) main::@1 +(label) main::@10 +(label) main::@2 +(label) main::@3 +(label) main::@4 +(label) main::@5 +(label) main::@6 +(label) main::@7 +(label) main::@8 +(label) main::@9 +(label) main::@return +(byte) main::i +(byte) main::i#0 +(byte) main::i#1 +(byte) main::i#2 +(byte) main::i#3 +(byte) main::i1 +(byte) main::i1#0 +(byte) main::i1#1 +(byte) main::i1#2 +(byte) main::i1#3 +(byte) main::i1#4 +(byte) main::i1#5 +(byte*) main::line +(byte*) main::line#0 +(byte*) main::line#1 +(byte*) main::line#2 +(byte*) main::line#3 +(byte*) main::line#4 +(byte*) main::line#5 +(signed byte) main::v +(signed byte) main::v#0 +(signed byte) main::v#1 +(signed byte) main::v#2 +(signed byte) main::v#3 + +Adding number conversion cast (unumber) $19 in (bool~) main::$0 ← (byte) main::i#2 < (number) $19 +Adding number conversion cast (unumber) $ff in (bool~) main::$2 ← *((const nomodify byte*) VIC_RASTER) != (number) $ff +Adding number conversion cast (unumber) 0 in *((const nomodify byte*) VIC_BG_COLOR) ← (number) 0 +Adding number conversion cast (unumber) $19 in (bool~) main::$3 ← (byte) main::i1#2 < (number) $19 +Adding number conversion cast (snumber) 0 in (bool~) main::$4 ← *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$14) < (number) 0 +Adding number conversion cast (snumber) $27 in (bool~) main::$5 ← *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$15) > (number) $27 +Adding number conversion cast (unumber) $f in *((const nomodify byte*) VIC_BG_COLOR) ← (number) $f +Adding number conversion cast (unumber) $28 in (byte*) main::line#1 ← (byte*) main::line#3 + (number) $28 +Successful SSA optimization PassNAddNumberTypeConversions +Inlining cast *((const nomodify byte*) VIC_BG_COLOR) ← (unumber)(number) 0 +Inlining cast *((const nomodify byte*) VIC_BG_COLOR) ← (unumber)(number) $f +Successful SSA optimization Pass2InlineCast +Simplifying constant pointer cast (byte*) 53266 +Simplifying constant pointer cast (byte*) 53280 +Simplifying constant pointer cast (byte*) 1024 +Simplifying constant integer cast $19 +Simplifying constant integer cast $ff +Simplifying constant integer cast 0 +Simplifying constant integer cast $19 +Simplifying constant integer cast 0 +Simplifying constant integer cast $27 +Simplifying constant integer cast $f +Simplifying constant integer cast $28 +Successful SSA optimization PassNCastSimplification +Finalized unsigned number type (byte) $19 +Finalized unsigned number type (byte) $ff +Finalized unsigned number type (byte) 0 +Finalized unsigned number type (byte) $19 +Finalized signed number type (signed byte) 0 +Finalized signed number type (signed byte) $27 +Finalized unsigned number type (byte) $f +Finalized unsigned number type (byte) $28 +Successful SSA optimization PassNFinalizeNumberTypeConversions +Alias main::i#2 = main::i#3 +Alias main::v#2 = main::v#3 +Alias main::v#1 = main::$1 +Alias main::i1#2 = main::i1#3 main::i1#5 +Alias main::line#2 = main::line#4 main::line#5 +Successful SSA optimization Pass2AliasElimination +Alias main::i1#2 = main::i1#4 +Alias main::line#2 = main::line#3 +Successful SSA optimization Pass2AliasElimination +Identified duplicate assignment right side [9] (byte~) main::$10 ← (byte) main::i#2 * (const byte) SIZEOF_STRUCT_ENTITY +Identified duplicate assignment right side [11] (byte~) main::$11 ← (byte) main::i#2 * (const byte) SIZEOF_STRUCT_ENTITY +Identified duplicate assignment right side [29] (byte~) main::$13 ← (byte) main::i1#2 * (const byte) SIZEOF_STRUCT_ENTITY +Identified duplicate assignment right side [31] (byte~) main::$14 ← (byte) main::i1#2 * (const byte) SIZEOF_STRUCT_ENTITY +Identified duplicate assignment right side [33] (byte~) main::$15 ← (byte) main::i1#2 * (const byte) SIZEOF_STRUCT_ENTITY +Identified duplicate assignment right side [47] (byte~) main::$18 ← (byte) main::i1#2 * (const byte) SIZEOF_STRUCT_ENTITY +Identified duplicate assignment right side [49] (byte~) main::$19 ← (byte) main::i1#2 * (const byte) SIZEOF_STRUCT_ENTITY +Successful SSA optimization Pass2DuplicateRValueIdentification +Simple Condition (bool~) main::$0 [5] if((byte) main::i#2<(byte) $19) goto main::@2 +Simple Condition (bool~) main::$20 [15] if((number) 0!=(number) 1) goto main::@4 +Simple Condition (bool~) main::$2 [17] if(*((const nomodify byte*) VIC_RASTER)!=(byte) $ff) goto main::@4 +Simple Condition (bool~) main::$3 [23] if((byte) main::i1#2<(byte) $19) goto main::@7 +Successful SSA optimization Pass2ConditionalJumpSimplification +Rewriting ! if()-condition to reversed if() [33] (bool~) main::$7 ← ! (bool~) main::$6 +Rewriting || if()-condition to two if()s [32] (bool~) main::$6 ← (bool~) main::$4 || (bool~) main::$5 +Successful SSA optimization Pass2ConditionalAndOrRewriting +Constant (const signed byte) main::v#0 = -1 +Constant (const byte) main::i#0 = 0 +Constant (const byte*) main::line#0 = SCREEN +Constant (const byte) main::i1#0 = 0 +Successful SSA optimization Pass2ConstantIdentification +if() condition always true - replacing block destination [15] if((number) 0!=(number) 1) goto main::@4 +Successful SSA optimization Pass2ConstantIfs +Simplifying expression containing zero (signed byte*)entities in [7] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$9) ← (signed byte)(byte) main::i#2 +Simplifying expression containing zero (signed byte*)entities in [25] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$12)) ← (byte) ' ' +Simplifying expression containing zero (signed byte*)entities in [27] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$13) ← *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$13) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$13) +Simplifying expression containing zero (signed byte*)entities in [27] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$13) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$13) +Simplifying expression containing zero (signed byte*)entities in [29] (bool~) main::$4 ← *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$14) < (signed byte) 0 +Simplifying expression containing zero (signed byte*)entities in [31] (bool~) main::$5 ← *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$15) > (signed byte) $27 +Simplifying expression containing zero (signed byte*)entities in [37] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$16)) ← *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$16) +Simplifying expression containing zero (signed byte*)entities in [45] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$19) ← *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$19) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$19) +Simplifying expression containing zero (signed byte*)entities in [45] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_POS + (byte~) main::$19) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$19) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$19) +Successful SSA optimization PassNSimplifyExpressionWithZero +Eliminating unused constant (const byte) OFFSET_STRUCT_ENTITY_X_POS +Successful SSA optimization PassNEliminateUnusedVars +Removing unused block main::@return +Successful SSA optimization Pass2EliminateUnusedBlocks +Removing unused procedure __start +Removing unused procedure block __start +Removing unused procedure block __start::@1 +Removing unused procedure block __start::@return +Successful SSA optimization PassNEliminateEmptyStart +Alias main::$10 = main::$9 main::$11 +Alias main::$13 = main::$12 main::$14 main::$15 +Alias main::$18 = main::$17 main::$19 +Successful SSA optimization Pass2AliasElimination +Simple Condition (bool~) main::$4 [18] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) 0) goto main::@10 +Simple Condition (bool~) main::$5 [28] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)>(signed byte) $27) goto main::@10 +Successful SSA optimization Pass2ConditionalJumpSimplification +Negating conditional jump and destination [28] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<=(signed byte) $27) goto main::@9 +Successful SSA optimization Pass2ConditionalJumpSequenceImprovement +Rewriting conditional comparison [28] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<=(signed byte) $27) goto main::@9 +Adding number conversion cast (snumber) $27+1 in if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) $27+(number) 1) goto main::@9 +Adding number conversion cast (snumber) 1 in if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(snumber)(signed byte) $27+(number) 1) goto main::@9 +Successful SSA optimization PassNAddNumberTypeConversions +Simplifying constant integer cast (signed byte) $27+(snumber)(number) 1 +Simplifying constant integer cast 1 +Successful SSA optimization PassNCastSimplification +Finalized signed number type (signed byte) 1 +Successful SSA optimization PassNFinalizeNumberTypeConversions +Rewriting multiplication to use shift and addition[3] (byte~) main::$10 ← (byte) main::i#2 * (const byte) SIZEOF_STRUCT_ENTITY +Rewriting multiplication to use shift and addition[13] (byte~) main::$13 ← (byte) main::i1#2 * (const byte) SIZEOF_STRUCT_ENTITY +Rewriting multiplication to use shift and addition[18] (byte~) main::$16 ← (byte) main::i1#2 * (const byte) SIZEOF_STRUCT_ENTITY +Rewriting multiplication to use shift and addition[22] (byte~) main::$18 ← (byte) main::i1#2 * (const byte) SIZEOF_STRUCT_ENTITY +Inlining constant with var siblings (const signed byte) main::v#0 +Inlining constant with var siblings (const byte) main::i#0 +Inlining constant with var siblings (const byte*) main::line#0 +Inlining constant with var siblings (const byte) main::i1#0 +Constant inlined main::i#0 = (byte) 0 +Constant inlined main::i1#0 = (byte) 0 +Constant inlined main::line#0 = (const nomodify byte*) SCREEN +Constant inlined main::v#0 = (signed byte) -1 +Successful SSA optimization Pass2ConstantInlining +Alias main::$10 = main::$22 +Alias main::$13 = main::$24 +Alias main::$16 = main::$26 +Alias main::$18 = main::$28 +Successful SSA optimization Pass2AliasElimination +Eliminating unused constant (const byte) SIZEOF_STRUCT_ENTITY +Successful SSA optimization PassNEliminateUnusedVars +Adding NOP phi() at start of main::@3 +CALL GRAPH + +Created 4 initial phi equivalence classes +Coalesced [25] main::i1#6 ← main::i1#1 +Coalesced [26] main::line#6 ← main::line#1 +Coalesced [34] main::i#4 ← main::i#1 +Coalesced [35] main::v#4 ← main::v#1 +Coalesced down to 4 phi equivalence classes +Culled Empty Block (label) main::@3 +Renumbering block main::@4 to main::@3 +Renumbering block main::@5 to main::@4 +Renumbering block main::@6 to main::@5 +Renumbering block main::@7 to main::@6 +Renumbering block main::@8 to main::@7 +Renumbering block main::@9 to main::@8 +Renumbering block main::@10 to main::@9 +Renumbering block main::@11 to main::@10 + +FINAL CONTROL FLOW GRAPH + +(void()) main() +main: scope:[main] from + asm { sei } + to:main::@1 +main::@1: scope:[main] from main main::@2 + [1] (signed byte) main::v#2 ← phi( main/(signed byte) -1 main::@2/(signed byte) main::v#1 ) + [1] (byte) main::i#2 ← phi( main/(byte) 0 main::@2/(byte) main::i#1 ) + [2] if((byte) main::i#2<(byte) $19) goto main::@2 + to:main::@3 +main::@3: scope:[main] from main::@1 main::@3 main::@7 + [3] if(*((const nomodify byte*) VIC_RASTER)!=(byte) $ff) goto main::@3 + to:main::@4 +main::@4: scope:[main] from main::@3 + [4] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) 0 + to:main::@5 +main::@5: scope:[main] from main::@4 main::@8 + [5] (byte*) main::line#2 ← phi( main::@4/(const nomodify byte*) SCREEN main::@8/(byte*) main::line#1 ) + [5] (byte) main::i1#2 ← phi( main::@4/(byte) 0 main::@8/(byte) main::i1#1 ) + [6] if((byte) main::i1#2<(byte) $19) goto main::@6 + to:main::@7 +main::@7: scope:[main] from main::@5 + [7] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) $f + to:main::@3 +main::@6: scope:[main] from main::@5 + [8] (byte~) main::$23 ← (byte) main::i1#2 << (byte) 1 + [9] (byte~) main::$13 ← (byte~) main::$23 + (byte) main::i1#2 + [10] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$13)) ← (byte) ' ' + [11] *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$13) + [12] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) 0) goto main::@9 + to:main::@10 +main::@10: scope:[main] from main::@6 + [13] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) $27+(signed byte) 1) goto main::@8 + to:main::@9 +main::@9: scope:[main] from main::@10 main::@6 + [14] (byte~) main::$27 ← (byte) main::i1#2 << (byte) 1 + [15] (byte~) main::$18 ← (byte~) main::$27 + (byte) main::i1#2 + [16] (signed byte~) main::$8 ← - *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) + [17] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) ← (signed byte~) main::$8 + [18] *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) + to:main::@8 +main::@8: scope:[main] from main::@10 main::@9 + [19] (byte~) main::$25 ← (byte) main::i1#2 << (byte) 1 + [20] (byte~) main::$16 ← (byte~) main::$25 + (byte) main::i1#2 + [21] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$16)) ← *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$16) + [22] (byte*) main::line#1 ← (byte*) main::line#2 + (byte) $28 + [23] (byte) main::i1#1 ← ++ (byte) main::i1#2 + to:main::@5 +main::@2: scope:[main] from main::@1 + [24] (byte~) main::$21 ← (byte) main::i#2 << (byte) 1 + [25] (byte~) main::$10 ← (byte~) main::$21 + (byte) main::i#2 + [26] *((signed byte*)(const struct Entity*) entities + (byte~) main::$10) ← (signed byte)(byte) main::i#2 + [27] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$10) ← (signed byte) main::v#2 + [28] *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$10) ← (byte) main::i#2 + [29] (signed byte) main::v#1 ← - (signed byte) main::v#2 + [30] (byte) main::i#1 ← ++ (byte) main::i#2 + to:main::@1 + + +VARIABLE REGISTER WEIGHTS +(byte) Entity::symbol +(signed byte) Entity::x_pos +(signed byte) Entity::x_vel +(void()) main() +(byte~) main::$10 14.666666666666666 +(byte~) main::$13 176.75 +(byte~) main::$16 303.0 +(byte~) main::$18 201.99999999999997 +(byte~) main::$21 22.0 +(byte~) main::$23 202.0 +(byte~) main::$25 202.0 +(byte~) main::$27 202.0 +(signed byte~) main::$8 202.0 +(byte) main::i +(byte) main::i#1 22.0 +(byte) main::i#2 8.25 +(byte) main::i1 +(byte) main::i1#1 202.0 +(byte) main::i1#2 53.470588235294116 +(byte*) main::line +(byte*) main::line#1 101.0 +(byte*) main::line#2 25.25 +(signed byte) main::v +(signed byte) main::v#1 11.0 +(signed byte) main::v#2 4.714285714285714 + +Initial phi equivalence classes +[ main::i#2 main::i#1 ] +[ main::v#2 main::v#1 ] +[ main::i1#2 main::i1#1 ] +[ main::line#2 main::line#1 ] +Added variable main::$23 to live range equivalence class [ main::$23 ] +Added variable main::$13 to live range equivalence class [ main::$13 ] +Added variable main::$27 to live range equivalence class [ main::$27 ] +Added variable main::$18 to live range equivalence class [ main::$18 ] +Added variable main::$8 to live range equivalence class [ main::$8 ] +Added variable main::$25 to live range equivalence class [ main::$25 ] +Added variable main::$16 to live range equivalence class [ main::$16 ] +Added variable main::$21 to live range equivalence class [ main::$21 ] +Added variable main::$10 to live range equivalence class [ main::$10 ] +Complete equivalence classes +[ main::i#2 main::i#1 ] +[ main::v#2 main::v#1 ] +[ main::i1#2 main::i1#1 ] +[ main::line#2 main::line#1 ] +[ main::$23 ] +[ main::$13 ] +[ main::$27 ] +[ main::$18 ] +[ main::$8 ] +[ main::$25 ] +[ main::$16 ] +[ main::$21 ] +[ main::$10 ] +Allocated zp[1]:2 [ main::i#2 main::i#1 ] +Allocated zp[1]:3 [ main::v#2 main::v#1 ] +Allocated zp[1]:4 [ main::i1#2 main::i1#1 ] +Allocated zp[2]:5 [ main::line#2 main::line#1 ] +Allocated zp[1]:7 [ main::$23 ] +Allocated zp[1]:8 [ main::$13 ] +Allocated zp[1]:9 [ main::$27 ] +Allocated zp[1]:10 [ main::$18 ] +Allocated zp[1]:11 [ main::$8 ] +Allocated zp[1]:12 [ main::$25 ] +Allocated zp[1]:13 [ main::$16 ] +Allocated zp[1]:14 [ main::$21 ] +Allocated zp[1]:15 [ main::$10 ] + +INITIAL ASM +Target platform is c64basic / MOS6502X + // File Comments +// Test that the multiplication of a idx*sizeof(element) is reused inside loops + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .const OFFSET_STRUCT_ENTITY_X_VEL = 1 + .const OFFSET_STRUCT_ENTITY_SYMBOL = 2 + .label VIC_RASTER = $d012 + .label VIC_BG_COLOR = $d020 + .label SCREEN = $400 + // main +main: { + .label __8 = $b + .label __10 = $f + .label __13 = 8 + .label __16 = $d + .label __18 = $a + // Initialize velocities + .label v = 3 + .label i = 2 + // Move the entities + .label line = 5 + .label i1 = 4 + .label __21 = $e + .label __23 = 7 + .label __25 = $c + .label __27 = 9 + // asm { sei } + sei + // [1] phi from main to main::@1 [phi:main->main::@1] + __b1_from_main: + // [1] phi (signed byte) main::v#2 = (signed byte) -1 [phi:main->main::@1#0] -- vbsz1=vbsc1 + lda #-1 + sta.z v + // [1] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1 + lda #0 + sta.z i + jmp __b1 + // main::@1 + __b1: + // [2] if((byte) main::i#2<(byte) $19) goto main::@2 -- vbuz1_lt_vbuc1_then_la1 + lda.z i + cmp #$19 + bcc __b2 + jmp __b3 + // Wait for raster refresh + // main::@3 + __b3: + // [3] if(*((const nomodify byte*) VIC_RASTER)!=(byte) $ff) goto main::@3 -- _deref_pbuc1_neq_vbuc2_then_la1 + lda #$ff + cmp VIC_RASTER + bne __b3 + jmp __b4 + // main::@4 + __b4: + // [4] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) 0 -- _deref_pbuc1=vbuc2 + lda #0 + sta VIC_BG_COLOR + // [5] phi from main::@4 to main::@5 [phi:main::@4->main::@5] + __b5_from___b4: + // [5] phi (byte*) main::line#2 = (const nomodify byte*) SCREEN [phi:main::@4->main::@5#0] -- pbuz1=pbuc1 + lda #<SCREEN + sta.z line + lda #>SCREEN + sta.z line+1 + // [5] phi (byte) main::i1#2 = (byte) 0 [phi:main::@4->main::@5#1] -- vbuz1=vbuc1 + lda #0 + sta.z i1 + jmp __b5 + // main::@5 + __b5: + // [6] if((byte) main::i1#2<(byte) $19) goto main::@6 -- vbuz1_lt_vbuc1_then_la1 + lda.z i1 + cmp #$19 + bcc __b6 + jmp __b7 + // main::@7 + __b7: + // [7] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) $f -- _deref_pbuc1=vbuc2 + lda #$f + sta VIC_BG_COLOR + jmp __b3 + // main::@6 + __b6: + // [8] (byte~) main::$23 ← (byte) main::i1#2 << (byte) 1 -- vbuz1=vbuz2_rol_1 + lda.z i1 + asl + sta.z __23 + // [9] (byte~) main::$13 ← (byte~) main::$23 + (byte) main::i1#2 -- vbuz1=vbuz2_plus_vbuz3 + lda.z __23 + clc + adc.z i1 + sta.z __13 + // [10] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$13)) ← (byte) ' ' -- pbuz1_derefidx_(pbsc1_derefidx_vbuz2)=vbuc2 + // Delete old symbol + lda #' ' + ldx.z __13 + ldy entities,x + sta (line),y + // [11] *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$13) -- pbsc1_derefidx_vbuz1=pbsc1_derefidx_vbuz1_plus_pbsc2_derefidx_vbuz1 + // Move by velocity + ldy.z __13 + clc + lda entities,y + adc entities+OFFSET_STRUCT_ENTITY_X_VEL,y + sta entities,y + // [12] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) 0) goto main::@9 -- pbsc1_derefidx_vbuz1_lt_0_then_la1 + ldy.z __13 + lda entities,y + cmp #0 + bmi __b9 + jmp __b10 + // main::@10 + __b10: + // [13] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) $27+(signed byte) 1) goto main::@8 -- pbsc1_derefidx_vbuz1_lt_vbsc2_then_la1 + ldy.z __13 + lda entities,y + sec + sbc #$27+1 + bvc !+ + eor #$80 + !: + bmi __b8 + jmp __b9 + // main::@9 + __b9: + // [14] (byte~) main::$27 ← (byte) main::i1#2 << (byte) 1 -- vbuz1=vbuz2_rol_1 + lda.z i1 + asl + sta.z __27 + // [15] (byte~) main::$18 ← (byte~) main::$27 + (byte) main::i1#2 -- vbuz1=vbuz2_plus_vbuz3 + lda.z __27 + clc + adc.z i1 + sta.z __18 + // [16] (signed byte~) main::$8 ← - *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) -- vbsz1=_neg_pbsc1_derefidx_vbuz2 + ldy.z __18 + lda entities+OFFSET_STRUCT_ENTITY_X_VEL,y + eor #$ff + clc + adc #1 + sta.z __8 + // [17] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) ← (signed byte~) main::$8 -- pbsc1_derefidx_vbuz1=vbsz2 + lda.z __8 + ldy.z __18 + sta entities+OFFSET_STRUCT_ENTITY_X_VEL,y + // [18] *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) -- pbsc1_derefidx_vbuz1=pbsc1_derefidx_vbuz1_plus_pbsc2_derefidx_vbuz1 + ldy.z __18 + clc + lda entities,y + adc entities+OFFSET_STRUCT_ENTITY_X_VEL,y + sta entities,y + jmp __b8 + // main::@8 + __b8: + // [19] (byte~) main::$25 ← (byte) main::i1#2 << (byte) 1 -- vbuz1=vbuz2_rol_1 + lda.z i1 + asl + sta.z __25 + // [20] (byte~) main::$16 ← (byte~) main::$25 + (byte) main::i1#2 -- vbuz1=vbuz2_plus_vbuz3 + lda.z __25 + clc + adc.z i1 + sta.z __16 + // [21] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$16)) ← *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$16) -- pbuz1_derefidx_(pbsc1_derefidx_vbuz2)=pbuc2_derefidx_vbuz2 + // Draw symbol + ldx.z __16 + lda entities+OFFSET_STRUCT_ENTITY_SYMBOL,x + ldy entities,x + sta (line),y + // [22] (byte*) main::line#1 ← (byte*) main::line#2 + (byte) $28 -- pbuz1=pbuz1_plus_vbuc1 + // Next line + lda #$28 + clc + adc.z line + sta.z line + bcc !+ + inc.z line+1 + !: + // [23] (byte) main::i1#1 ← ++ (byte) main::i1#2 -- vbuz1=_inc_vbuz1 + inc.z i1 + // [5] phi from main::@8 to main::@5 [phi:main::@8->main::@5] + __b5_from___b8: + // [5] phi (byte*) main::line#2 = (byte*) main::line#1 [phi:main::@8->main::@5#0] -- register_copy + // [5] phi (byte) main::i1#2 = (byte) main::i1#1 [phi:main::@8->main::@5#1] -- register_copy + jmp __b5 + // main::@2 + __b2: + // [24] (byte~) main::$21 ← (byte) main::i#2 << (byte) 1 -- vbuz1=vbuz2_rol_1 + lda.z i + asl + sta.z __21 + // [25] (byte~) main::$10 ← (byte~) main::$21 + (byte) main::i#2 -- vbuz1=vbuz2_plus_vbuz3 + lda.z __21 + clc + adc.z i + sta.z __10 + // [26] *((signed byte*)(const struct Entity*) entities + (byte~) main::$10) ← (signed byte)(byte) main::i#2 -- pbsc1_derefidx_vbuz1=vbsz2 + lda.z i + ldy.z __10 + sta entities,y + // [27] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$10) ← (signed byte) main::v#2 -- pbsc1_derefidx_vbuz1=vbsz2 + lda.z v + ldy.z __10 + sta entities+OFFSET_STRUCT_ENTITY_X_VEL,y + // [28] *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$10) ← (byte) main::i#2 -- pbuc1_derefidx_vbuz1=vbuz2 + lda.z i + ldy.z __10 + sta entities+OFFSET_STRUCT_ENTITY_SYMBOL,y + // [29] (signed byte) main::v#1 ← - (signed byte) main::v#2 -- vbsz1=_neg_vbsz1 + lda.z v + eor #$ff + clc + adc #1 + sta.z v + // [30] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 + inc.z i + // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1] + __b1_from___b2: + // [1] phi (signed byte) main::v#2 = (signed byte) main::v#1 [phi:main::@2->main::@1#0] -- register_copy + // [1] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#1] -- register_copy + jmp __b1 +} + // File Data + entities: .fill 3*$19, 0 + +REGISTER UPLIFT POTENTIAL REGISTERS +Statement [3] if(*((const nomodify byte*) VIC_RASTER)!=(byte) $ff) goto main::@3 [ ] ( [ ] { } ) always clobbers reg byte a +Statement [4] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) 0 [ ] ( [ ] { } ) always clobbers reg byte a +Statement [7] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) $f [ ] ( [ ] { } ) always clobbers reg byte a +Statement [8] (byte~) main::$23 ← (byte) main::i1#2 << (byte) 1 [ main::i1#2 main::line#2 main::$23 ] ( [ main::i1#2 main::line#2 main::$23 ] { } ) always clobbers reg byte a +Removing always clobbered register reg byte a as potential for zp[1]:4 [ main::i1#2 main::i1#1 ] +Statement [9] (byte~) main::$13 ← (byte~) main::$23 + (byte) main::i1#2 [ main::i1#2 main::line#2 main::$13 ] ( [ main::i1#2 main::line#2 main::$13 ] { } ) always clobbers reg byte a +Statement [10] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$13)) ← (byte) ' ' [ main::i1#2 main::line#2 main::$13 ] ( [ main::i1#2 main::line#2 main::$13 ] { } ) always clobbers reg byte a reg byte y +Removing always clobbered register reg byte y as potential for zp[1]:4 [ main::i1#2 main::i1#1 ] +Removing always clobbered register reg byte a as potential for zp[1]:8 [ main::$13 ] +Removing always clobbered register reg byte y as potential for zp[1]:8 [ main::$13 ] +Statement [11] *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$13) [ main::i1#2 main::line#2 main::$13 ] ( [ main::i1#2 main::line#2 main::$13 ] { } ) always clobbers reg byte a +Statement [12] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) 0) goto main::@9 [ main::i1#2 main::line#2 main::$13 ] ( [ main::i1#2 main::line#2 main::$13 ] { } ) always clobbers reg byte a +Statement [13] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) $27+(signed byte) 1) goto main::@8 [ main::i1#2 main::line#2 ] ( [ main::i1#2 main::line#2 ] { } ) always clobbers reg byte a +Statement [14] (byte~) main::$27 ← (byte) main::i1#2 << (byte) 1 [ main::i1#2 main::line#2 main::$27 ] ( [ main::i1#2 main::line#2 main::$27 ] { } ) always clobbers reg byte a +Statement [15] (byte~) main::$18 ← (byte~) main::$27 + (byte) main::i1#2 [ main::i1#2 main::line#2 main::$18 ] ( [ main::i1#2 main::line#2 main::$18 ] { } ) always clobbers reg byte a +Statement [16] (signed byte~) main::$8 ← - *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) [ main::i1#2 main::line#2 main::$18 main::$8 ] ( [ main::i1#2 main::line#2 main::$18 main::$8 ] { } ) always clobbers reg byte a +Removing always clobbered register reg byte a as potential for zp[1]:10 [ main::$18 ] +Statement [18] *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) [ main::i1#2 main::line#2 ] ( [ main::i1#2 main::line#2 ] { } ) always clobbers reg byte a +Statement [19] (byte~) main::$25 ← (byte) main::i1#2 << (byte) 1 [ main::i1#2 main::line#2 main::$25 ] ( [ main::i1#2 main::line#2 main::$25 ] { } ) always clobbers reg byte a +Statement [20] (byte~) main::$16 ← (byte~) main::$25 + (byte) main::i1#2 [ main::i1#2 main::line#2 main::$16 ] ( [ main::i1#2 main::line#2 main::$16 ] { } ) always clobbers reg byte a +Statement [21] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$16)) ← *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$16) [ main::i1#2 main::line#2 ] ( [ main::i1#2 main::line#2 ] { } ) always clobbers reg byte a reg byte y +Statement [22] (byte*) main::line#1 ← (byte*) main::line#2 + (byte) $28 [ main::i1#2 main::line#1 ] ( [ main::i1#2 main::line#1 ] { } ) always clobbers reg byte a +Statement [24] (byte~) main::$21 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::v#2 main::$21 ] ( [ main::i#2 main::v#2 main::$21 ] { } ) always clobbers reg byte a +Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ] +Removing always clobbered register reg byte a as potential for zp[1]:3 [ main::v#2 main::v#1 ] +Statement [25] (byte~) main::$10 ← (byte~) main::$21 + (byte) main::i#2 [ main::i#2 main::v#2 main::$10 ] ( [ main::i#2 main::v#2 main::$10 ] { } ) always clobbers reg byte a +Statement [26] *((signed byte*)(const struct Entity*) entities + (byte~) main::$10) ← (signed byte)(byte) main::i#2 [ main::i#2 main::v#2 main::$10 ] ( [ main::i#2 main::v#2 main::$10 ] { } ) always clobbers reg byte a +Removing always clobbered register reg byte a as potential for zp[1]:15 [ main::$10 ] +Statement [27] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$10) ← (signed byte) main::v#2 [ main::i#2 main::v#2 main::$10 ] ( [ main::i#2 main::v#2 main::$10 ] { } ) always clobbers reg byte a +Statement [28] *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$10) ← (byte) main::i#2 [ main::i#2 main::v#2 ] ( [ main::i#2 main::v#2 ] { } ) always clobbers reg byte a +Statement [29] (signed byte) main::v#1 ← - (signed byte) main::v#2 [ main::i#2 main::v#1 ] ( [ main::i#2 main::v#1 ] { } ) always clobbers reg byte a +Statement [3] if(*((const nomodify byte*) VIC_RASTER)!=(byte) $ff) goto main::@3 [ ] ( [ ] { } ) always clobbers reg byte a +Statement [4] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) 0 [ ] ( [ ] { } ) always clobbers reg byte a +Statement [7] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) $f [ ] ( [ ] { } ) always clobbers reg byte a +Statement [8] (byte~) main::$23 ← (byte) main::i1#2 << (byte) 1 [ main::i1#2 main::line#2 main::$23 ] ( [ main::i1#2 main::line#2 main::$23 ] { } ) always clobbers reg byte a +Statement [9] (byte~) main::$13 ← (byte~) main::$23 + (byte) main::i1#2 [ main::i1#2 main::line#2 main::$13 ] ( [ main::i1#2 main::line#2 main::$13 ] { } ) always clobbers reg byte a +Statement [10] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$13)) ← (byte) ' ' [ main::i1#2 main::line#2 main::$13 ] ( [ main::i1#2 main::line#2 main::$13 ] { } ) always clobbers reg byte a reg byte y +Statement [11] *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$13) [ main::i1#2 main::line#2 main::$13 ] ( [ main::i1#2 main::line#2 main::$13 ] { } ) always clobbers reg byte a +Statement [12] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) 0) goto main::@9 [ main::i1#2 main::line#2 main::$13 ] ( [ main::i1#2 main::line#2 main::$13 ] { } ) always clobbers reg byte a +Statement [13] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) $27+(signed byte) 1) goto main::@8 [ main::i1#2 main::line#2 ] ( [ main::i1#2 main::line#2 ] { } ) always clobbers reg byte a +Statement [14] (byte~) main::$27 ← (byte) main::i1#2 << (byte) 1 [ main::i1#2 main::line#2 main::$27 ] ( [ main::i1#2 main::line#2 main::$27 ] { } ) always clobbers reg byte a +Statement [15] (byte~) main::$18 ← (byte~) main::$27 + (byte) main::i1#2 [ main::i1#2 main::line#2 main::$18 ] ( [ main::i1#2 main::line#2 main::$18 ] { } ) always clobbers reg byte a +Statement [16] (signed byte~) main::$8 ← - *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) [ main::i1#2 main::line#2 main::$18 main::$8 ] ( [ main::i1#2 main::line#2 main::$18 main::$8 ] { } ) always clobbers reg byte a +Statement [18] *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) [ main::i1#2 main::line#2 ] ( [ main::i1#2 main::line#2 ] { } ) always clobbers reg byte a +Statement [19] (byte~) main::$25 ← (byte) main::i1#2 << (byte) 1 [ main::i1#2 main::line#2 main::$25 ] ( [ main::i1#2 main::line#2 main::$25 ] { } ) always clobbers reg byte a +Statement [20] (byte~) main::$16 ← (byte~) main::$25 + (byte) main::i1#2 [ main::i1#2 main::line#2 main::$16 ] ( [ main::i1#2 main::line#2 main::$16 ] { } ) always clobbers reg byte a +Statement [21] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$16)) ← *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$16) [ main::i1#2 main::line#2 ] ( [ main::i1#2 main::line#2 ] { } ) always clobbers reg byte a reg byte y +Statement [22] (byte*) main::line#1 ← (byte*) main::line#2 + (byte) $28 [ main::i1#2 main::line#1 ] ( [ main::i1#2 main::line#1 ] { } ) always clobbers reg byte a +Statement [24] (byte~) main::$21 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::v#2 main::$21 ] ( [ main::i#2 main::v#2 main::$21 ] { } ) always clobbers reg byte a +Statement [25] (byte~) main::$10 ← (byte~) main::$21 + (byte) main::i#2 [ main::i#2 main::v#2 main::$10 ] ( [ main::i#2 main::v#2 main::$10 ] { } ) always clobbers reg byte a +Statement [26] *((signed byte*)(const struct Entity*) entities + (byte~) main::$10) ← (signed byte)(byte) main::i#2 [ main::i#2 main::v#2 main::$10 ] ( [ main::i#2 main::v#2 main::$10 ] { } ) always clobbers reg byte a +Statement [27] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$10) ← (signed byte) main::v#2 [ main::i#2 main::v#2 main::$10 ] ( [ main::i#2 main::v#2 main::$10 ] { } ) always clobbers reg byte a +Statement [28] *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$10) ← (byte) main::i#2 [ main::i#2 main::v#2 ] ( [ main::i#2 main::v#2 ] { } ) always clobbers reg byte a +Statement [29] (signed byte) main::v#1 ← - (signed byte) main::v#2 [ main::i#2 main::v#1 ] ( [ main::i#2 main::v#1 ] { } ) always clobbers reg byte a +Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , reg byte y , +Potential registers zp[1]:3 [ main::v#2 main::v#1 ] : zp[1]:3 , reg byte x , reg byte y , +Potential registers zp[1]:4 [ main::i1#2 main::i1#1 ] : zp[1]:4 , reg byte x , +Potential registers zp[2]:5 [ main::line#2 main::line#1 ] : zp[2]:5 , +Potential registers zp[1]:7 [ main::$23 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , +Potential registers zp[1]:8 [ main::$13 ] : zp[1]:8 , reg byte x , +Potential registers zp[1]:9 [ main::$27 ] : zp[1]:9 , reg byte a , reg byte x , reg byte y , +Potential registers zp[1]:10 [ main::$18 ] : zp[1]:10 , reg byte x , reg byte y , +Potential registers zp[1]:11 [ main::$8 ] : zp[1]:11 , reg byte a , reg byte x , reg byte y , +Potential registers zp[1]:12 [ main::$25 ] : zp[1]:12 , reg byte a , reg byte x , reg byte y , +Potential registers zp[1]:13 [ main::$16 ] : zp[1]:13 , reg byte a , reg byte x , reg byte y , +Potential registers zp[1]:14 [ main::$21 ] : zp[1]:14 , reg byte a , reg byte x , reg byte y , +Potential registers zp[1]:15 [ main::$10 ] : zp[1]:15 , reg byte x , reg byte y , + +REGISTER UPLIFT SCOPES +Uplift Scope [main] 303: zp[1]:13 [ main::$16 ] 255.47: zp[1]:4 [ main::i1#2 main::i1#1 ] 202: zp[1]:7 [ main::$23 ] 202: zp[1]:9 [ main::$27 ] 202: zp[1]:11 [ main::$8 ] 202: zp[1]:12 [ main::$25 ] 202: zp[1]:10 [ main::$18 ] 176.75: zp[1]:8 [ main::$13 ] 126.25: zp[2]:5 [ main::line#2 main::line#1 ] 30.25: zp[1]:2 [ main::i#2 main::i#1 ] 22: zp[1]:14 [ main::$21 ] 15.71: zp[1]:3 [ main::v#2 main::v#1 ] 14.67: zp[1]:15 [ main::$10 ] +Uplift Scope [Entity] +Uplift Scope [] + +Uplifting [main] best 25607 combination reg byte a [ main::$16 ] zp[1]:4 [ main::i1#2 main::i1#1 ] reg byte a [ main::$23 ] reg byte a [ main::$27 ] zp[1]:11 [ main::$8 ] zp[1]:12 [ main::$25 ] zp[1]:10 [ main::$18 ] zp[1]:8 [ main::$13 ] zp[2]:5 [ main::line#2 main::line#1 ] zp[1]:2 [ main::i#2 main::i#1 ] zp[1]:14 [ main::$21 ] zp[1]:3 [ main::v#2 main::v#1 ] zp[1]:15 [ main::$10 ] +Limited combination testing to 100 combinations of 1327104 possible. +Uplifting [Entity] best 25607 combination +Uplifting [] best 25607 combination +Attempting to uplift remaining variables inzp[1]:4 [ main::i1#2 main::i1#1 ] +Uplifting [main] best 25607 combination zp[1]:4 [ main::i1#2 main::i1#1 ] +Attempting to uplift remaining variables inzp[1]:11 [ main::$8 ] +Uplifting [main] best 25007 combination reg byte a [ main::$8 ] +Attempting to uplift remaining variables inzp[1]:12 [ main::$25 ] +Uplifting [main] best 24407 combination reg byte a [ main::$25 ] +Attempting to uplift remaining variables inzp[1]:10 [ main::$18 ] +Uplifting [main] best 23407 combination reg byte x [ main::$18 ] +Attempting to uplift remaining variables inzp[1]:8 [ main::$13 ] +Uplifting [main] best 22107 combination reg byte x [ main::$13 ] +Attempting to uplift remaining variables inzp[1]:2 [ main::i#2 main::i#1 ] +Uplifting [main] best 21977 combination reg byte x [ main::i#2 main::i#1 ] +Attempting to uplift remaining variables inzp[1]:14 [ main::$21 ] +Uplifting [main] best 21957 combination reg byte a [ main::$21 ] +Attempting to uplift remaining variables inzp[1]:3 [ main::v#2 main::v#1 ] +Uplifting [main] best 21957 combination zp[1]:3 [ main::v#2 main::v#1 ] +Attempting to uplift remaining variables inzp[1]:15 [ main::$10 ] +Uplifting [main] best 21857 combination reg byte y [ main::$10 ] +Allocated (was zp[1]:3) zp[1]:2 [ main::v#2 main::v#1 ] +Allocated (was zp[1]:4) zp[1]:3 [ main::i1#2 main::i1#1 ] +Allocated (was zp[2]:5) zp[2]:4 [ main::line#2 main::line#1 ] + +ASSEMBLER BEFORE OPTIMIZATION + // File Comments +// Test that the multiplication of a idx*sizeof(element) is reused inside loops + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .const OFFSET_STRUCT_ENTITY_X_VEL = 1 + .const OFFSET_STRUCT_ENTITY_SYMBOL = 2 + .label VIC_RASTER = $d012 + .label VIC_BG_COLOR = $d020 + .label SCREEN = $400 + // main +main: { + // Initialize velocities + .label v = 2 + // Move the entities + .label line = 4 + .label i1 = 3 + // asm { sei } + sei + // [1] phi from main to main::@1 [phi:main->main::@1] + __b1_from_main: + // [1] phi (signed byte) main::v#2 = (signed byte) -1 [phi:main->main::@1#0] -- vbsz1=vbsc1 + lda #-1 + sta.z v + // [1] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 + ldx #0 + jmp __b1 + // main::@1 + __b1: + // [2] if((byte) main::i#2<(byte) $19) goto main::@2 -- vbuxx_lt_vbuc1_then_la1 + cpx #$19 + bcc __b2 + jmp __b3 + // Wait for raster refresh + // main::@3 + __b3: + // [3] if(*((const nomodify byte*) VIC_RASTER)!=(byte) $ff) goto main::@3 -- _deref_pbuc1_neq_vbuc2_then_la1 + lda #$ff + cmp VIC_RASTER + bne __b3 + jmp __b4 + // main::@4 + __b4: + // [4] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) 0 -- _deref_pbuc1=vbuc2 + lda #0 + sta VIC_BG_COLOR + // [5] phi from main::@4 to main::@5 [phi:main::@4->main::@5] + __b5_from___b4: + // [5] phi (byte*) main::line#2 = (const nomodify byte*) SCREEN [phi:main::@4->main::@5#0] -- pbuz1=pbuc1 + lda #<SCREEN + sta.z line + lda #>SCREEN + sta.z line+1 + // [5] phi (byte) main::i1#2 = (byte) 0 [phi:main::@4->main::@5#1] -- vbuz1=vbuc1 + lda #0 + sta.z i1 + jmp __b5 + // main::@5 + __b5: + // [6] if((byte) main::i1#2<(byte) $19) goto main::@6 -- vbuz1_lt_vbuc1_then_la1 + lda.z i1 + cmp #$19 + bcc __b6 + jmp __b7 + // main::@7 + __b7: + // [7] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) $f -- _deref_pbuc1=vbuc2 + lda #$f + sta VIC_BG_COLOR + jmp __b3 + // main::@6 + __b6: + // [8] (byte~) main::$23 ← (byte) main::i1#2 << (byte) 1 -- vbuaa=vbuz1_rol_1 + lda.z i1 + asl + // [9] (byte~) main::$13 ← (byte~) main::$23 + (byte) main::i1#2 -- vbuxx=vbuaa_plus_vbuz1 + clc + adc.z i1 + tax + // [10] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$13)) ← (byte) ' ' -- pbuz1_derefidx_(pbsc1_derefidx_vbuxx)=vbuc2 + // Delete old symbol + lda #' ' + ldy entities,x + sta (line),y + // [11] *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$13) -- pbsc1_derefidx_vbuxx=pbsc1_derefidx_vbuxx_plus_pbsc2_derefidx_vbuxx + // Move by velocity + clc + lda entities,x + adc entities+OFFSET_STRUCT_ENTITY_X_VEL,x + sta entities,x + // [12] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) 0) goto main::@9 -- pbsc1_derefidx_vbuxx_lt_0_then_la1 + lda entities,x + cmp #0 + bmi __b9 + jmp __b10 + // main::@10 + __b10: + // [13] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) $27+(signed byte) 1) goto main::@8 -- pbsc1_derefidx_vbuxx_lt_vbsc2_then_la1 + lda entities,x + sec + sbc #$27+1 + bvc !+ + eor #$80 + !: + bmi __b8 + jmp __b9 + // main::@9 + __b9: + // [14] (byte~) main::$27 ← (byte) main::i1#2 << (byte) 1 -- vbuaa=vbuz1_rol_1 + lda.z i1 + asl + // [15] (byte~) main::$18 ← (byte~) main::$27 + (byte) main::i1#2 -- vbuxx=vbuaa_plus_vbuz1 + clc + adc.z i1 + tax + // [16] (signed byte~) main::$8 ← - *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) -- vbsaa=_neg_pbsc1_derefidx_vbuxx + lda entities+OFFSET_STRUCT_ENTITY_X_VEL,x + eor #$ff + clc + adc #1 + // [17] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) ← (signed byte~) main::$8 -- pbsc1_derefidx_vbuxx=vbsaa + sta entities+OFFSET_STRUCT_ENTITY_X_VEL,x + // [18] *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) -- pbsc1_derefidx_vbuxx=pbsc1_derefidx_vbuxx_plus_pbsc2_derefidx_vbuxx + clc + lda entities,x + adc entities+OFFSET_STRUCT_ENTITY_X_VEL,x + sta entities,x + jmp __b8 + // main::@8 + __b8: + // [19] (byte~) main::$25 ← (byte) main::i1#2 << (byte) 1 -- vbuaa=vbuz1_rol_1 + lda.z i1 + asl + // [20] (byte~) main::$16 ← (byte~) main::$25 + (byte) main::i1#2 -- vbuaa=vbuaa_plus_vbuz1 + clc + adc.z i1 + // [21] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$16)) ← *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$16) -- pbuz1_derefidx_(pbsc1_derefidx_vbuaa)=pbuc2_derefidx_vbuaa + // Draw symbol + tax + lda entities+OFFSET_STRUCT_ENTITY_SYMBOL,x + ldy entities,x + sta (line),y + // [22] (byte*) main::line#1 ← (byte*) main::line#2 + (byte) $28 -- pbuz1=pbuz1_plus_vbuc1 + // Next line + lda #$28 + clc + adc.z line + sta.z line + bcc !+ + inc.z line+1 + !: + // [23] (byte) main::i1#1 ← ++ (byte) main::i1#2 -- vbuz1=_inc_vbuz1 + inc.z i1 + // [5] phi from main::@8 to main::@5 [phi:main::@8->main::@5] + __b5_from___b8: + // [5] phi (byte*) main::line#2 = (byte*) main::line#1 [phi:main::@8->main::@5#0] -- register_copy + // [5] phi (byte) main::i1#2 = (byte) main::i1#1 [phi:main::@8->main::@5#1] -- register_copy + jmp __b5 + // main::@2 + __b2: + // [24] (byte~) main::$21 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1 + txa + asl + // [25] (byte~) main::$10 ← (byte~) main::$21 + (byte) main::i#2 -- vbuyy=vbuaa_plus_vbuxx + stx.z $ff + clc + adc.z $ff + tay + // [26] *((signed byte*)(const struct Entity*) entities + (byte~) main::$10) ← (signed byte)(byte) main::i#2 -- pbsc1_derefidx_vbuyy=vbsxx + txa + sta entities,y + // [27] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$10) ← (signed byte) main::v#2 -- pbsc1_derefidx_vbuyy=vbsz1 + lda.z v + sta entities+OFFSET_STRUCT_ENTITY_X_VEL,y + // [28] *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$10) ← (byte) main::i#2 -- pbuc1_derefidx_vbuyy=vbuxx + txa + sta entities+OFFSET_STRUCT_ENTITY_SYMBOL,y + // [29] (signed byte) main::v#1 ← - (signed byte) main::v#2 -- vbsz1=_neg_vbsz1 + lda.z v + eor #$ff + clc + adc #1 + sta.z v + // [30] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx + inx + // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1] + __b1_from___b2: + // [1] phi (signed byte) main::v#2 = (signed byte) main::v#1 [phi:main::@2->main::@1#0] -- register_copy + // [1] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#1] -- register_copy + jmp __b1 +} + // File Data + entities: .fill 3*$19, 0 + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp __b1 +Removing instruction jmp __b3 +Removing instruction jmp __b4 +Removing instruction jmp __b5 +Removing instruction jmp __b7 +Removing instruction jmp __b10 +Removing instruction jmp __b9 +Removing instruction jmp __b8 +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction __b1_from_main: +Removing instruction __b4: +Removing instruction __b5_from___b4: +Removing instruction __b7: +Removing instruction __b10: +Removing instruction __b5_from___b8: +Removing instruction __b1_from___b2: +Succesful ASM optimization Pass5UnusedLabelElimination +Fixing long branch [21] bcc __b2 to bcs + +FINAL SYMBOL TABLE +(byte) Entity::symbol +(signed byte) Entity::x_pos +(signed byte) Entity::x_vel +(const byte) OFFSET_STRUCT_ENTITY_SYMBOL = (byte) 2 +(const byte) OFFSET_STRUCT_ENTITY_X_VEL = (byte) 1 +(const nomodify byte*) SCREEN = (byte*) 1024 +(const nomodify byte*) VIC_BG_COLOR = (byte*) 53280 +(const nomodify byte*) VIC_RASTER = (byte*) 53266 +(const struct Entity*) entities[(number) $19] = { fill( $19, 0) } +(void()) main() +(byte~) main::$10 reg byte y 14.666666666666666 +(byte~) main::$13 reg byte x 176.75 +(byte~) main::$16 reg byte a 303.0 +(byte~) main::$18 reg byte x 201.99999999999997 +(byte~) main::$21 reg byte a 22.0 +(byte~) main::$23 reg byte a 202.0 +(byte~) main::$25 reg byte a 202.0 +(byte~) main::$27 reg byte a 202.0 +(signed byte~) main::$8 reg byte a 202.0 +(label) main::@1 +(label) main::@10 +(label) main::@2 +(label) main::@3 +(label) main::@4 +(label) main::@5 +(label) main::@6 +(label) main::@7 +(label) main::@8 +(label) main::@9 +(byte) main::i +(byte) main::i#1 reg byte x 22.0 +(byte) main::i#2 reg byte x 8.25 +(byte) main::i1 +(byte) main::i1#1 i1 zp[1]:3 202.0 +(byte) main::i1#2 i1 zp[1]:3 53.470588235294116 +(byte*) main::line +(byte*) main::line#1 line zp[2]:4 101.0 +(byte*) main::line#2 line zp[2]:4 25.25 +(signed byte) main::v +(signed byte) main::v#1 v zp[1]:2 11.0 +(signed byte) main::v#2 v zp[1]:2 4.714285714285714 + +reg byte x [ main::i#2 main::i#1 ] +zp[1]:2 [ main::v#2 main::v#1 ] +zp[1]:3 [ main::i1#2 main::i1#1 ] +zp[2]:4 [ main::line#2 main::line#1 ] +reg byte a [ main::$23 ] +reg byte x [ main::$13 ] +reg byte a [ main::$27 ] +reg byte x [ main::$18 ] +reg byte a [ main::$8 ] +reg byte a [ main::$25 ] +reg byte a [ main::$16 ] +reg byte a [ main::$21 ] +reg byte y [ main::$10 ] + + +FINAL ASSEMBLER +Score: 20027 + + // File Comments +// Test that the multiplication of a idx*sizeof(element) is reused inside loops + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .const OFFSET_STRUCT_ENTITY_X_VEL = 1 + .const OFFSET_STRUCT_ENTITY_SYMBOL = 2 + .label VIC_RASTER = $d012 + .label VIC_BG_COLOR = $d020 + .label SCREEN = $400 + // main +main: { + // Initialize velocities + .label v = 2 + // Move the entities + .label line = 4 + .label i1 = 3 + // asm + // asm { sei } + sei + // [1] phi from main to main::@1 [phi:main->main::@1] + // [1] phi (signed byte) main::v#2 = (signed byte) -1 [phi:main->main::@1#0] -- vbsz1=vbsc1 + lda #-1 + sta.z v + // [1] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 + ldx #0 + // main::@1 + __b1: + // for(char i=0;i<NUM_ENTITIES;i++) + // [2] if((byte) main::i#2<(byte) $19) goto main::@2 -- vbuxx_lt_vbuc1_then_la1 + cpx #$19 + bcs !__b2+ + jmp __b2 + !__b2: + // Wait for raster refresh + // main::@3 + __b3: + // while(*VIC_RASTER!=0xff) + // [3] if(*((const nomodify byte*) VIC_RASTER)!=(byte) $ff) goto main::@3 -- _deref_pbuc1_neq_vbuc2_then_la1 + lda #$ff + cmp VIC_RASTER + bne __b3 + // main::@4 + // *VIC_BG_COLOR = 0 + // [4] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) 0 -- _deref_pbuc1=vbuc2 + lda #0 + sta VIC_BG_COLOR + // [5] phi from main::@4 to main::@5 [phi:main::@4->main::@5] + // [5] phi (byte*) main::line#2 = (const nomodify byte*) SCREEN [phi:main::@4->main::@5#0] -- pbuz1=pbuc1 + lda #<SCREEN + sta.z line + lda #>SCREEN + sta.z line+1 + // [5] phi (byte) main::i1#2 = (byte) 0 [phi:main::@4->main::@5#1] -- vbuz1=vbuc1 + lda #0 + sta.z i1 + // main::@5 + __b5: + // for(char i=0;i<NUM_ENTITIES;i++) + // [6] if((byte) main::i1#2<(byte) $19) goto main::@6 -- vbuz1_lt_vbuc1_then_la1 + lda.z i1 + cmp #$19 + bcc __b6 + // main::@7 + // *VIC_BG_COLOR = 15 + // [7] *((const nomodify byte*) VIC_BG_COLOR) ← (byte) $f -- _deref_pbuc1=vbuc2 + lda #$f + sta VIC_BG_COLOR + jmp __b3 + // main::@6 + __b6: + // line[entities[i].x_pos] = ' ' + // [8] (byte~) main::$23 ← (byte) main::i1#2 << (byte) 1 -- vbuaa=vbuz1_rol_1 + lda.z i1 + asl + // [9] (byte~) main::$13 ← (byte~) main::$23 + (byte) main::i1#2 -- vbuxx=vbuaa_plus_vbuz1 + clc + adc.z i1 + tax + // [10] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$13)) ← (byte) ' ' -- pbuz1_derefidx_(pbsc1_derefidx_vbuxx)=vbuc2 + // Delete old symbol + lda #' ' + ldy entities,x + sta (line),y + // entities[i].x_pos += entities[i].x_vel + // [11] *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$13) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$13) -- pbsc1_derefidx_vbuxx=pbsc1_derefidx_vbuxx_plus_pbsc2_derefidx_vbuxx + // Move by velocity + clc + lda entities,x + adc entities+OFFSET_STRUCT_ENTITY_X_VEL,x + sta entities,x + // if(entities[i].x_pos<0 || entities[i].x_pos>39) + // [12] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) 0) goto main::@9 -- pbsc1_derefidx_vbuxx_lt_0_then_la1 + lda entities,x + cmp #0 + bmi __b9 + // main::@10 + // [13] if(*((signed byte*)(const struct Entity*) entities + (byte~) main::$13)<(signed byte) $27+(signed byte) 1) goto main::@8 -- pbsc1_derefidx_vbuxx_lt_vbsc2_then_la1 + lda entities,x + sec + sbc #$27+1 + bvc !+ + eor #$80 + !: + bmi __b8 + // main::@9 + __b9: + // -entities[i].x_vel + // [14] (byte~) main::$27 ← (byte) main::i1#2 << (byte) 1 -- vbuaa=vbuz1_rol_1 + lda.z i1 + asl + // [15] (byte~) main::$18 ← (byte~) main::$27 + (byte) main::i1#2 -- vbuxx=vbuaa_plus_vbuz1 + clc + adc.z i1 + tax + // [16] (signed byte~) main::$8 ← - *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) -- vbsaa=_neg_pbsc1_derefidx_vbuxx + lda entities+OFFSET_STRUCT_ENTITY_X_VEL,x + eor #$ff + clc + adc #1 + // entities[i].x_vel = -entities[i].x_vel + // [17] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) ← (signed byte~) main::$8 -- pbsc1_derefidx_vbuxx=vbsaa + sta entities+OFFSET_STRUCT_ENTITY_X_VEL,x + // entities[i].x_pos += entities[i].x_vel + // [18] *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) ← *((signed byte*)(const struct Entity*) entities + (byte~) main::$18) + *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$18) -- pbsc1_derefidx_vbuxx=pbsc1_derefidx_vbuxx_plus_pbsc2_derefidx_vbuxx + clc + lda entities,x + adc entities+OFFSET_STRUCT_ENTITY_X_VEL,x + sta entities,x + // main::@8 + __b8: + // line[entities[i].x_pos] = entities[i].symbol + // [19] (byte~) main::$25 ← (byte) main::i1#2 << (byte) 1 -- vbuaa=vbuz1_rol_1 + lda.z i1 + asl + // [20] (byte~) main::$16 ← (byte~) main::$25 + (byte) main::i1#2 -- vbuaa=vbuaa_plus_vbuz1 + clc + adc.z i1 + // [21] *((byte*) main::line#2 + *((signed byte*)(const struct Entity*) entities + (byte~) main::$16)) ← *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$16) -- pbuz1_derefidx_(pbsc1_derefidx_vbuaa)=pbuc2_derefidx_vbuaa + // Draw symbol + tax + lda entities+OFFSET_STRUCT_ENTITY_SYMBOL,x + ldy entities,x + sta (line),y + // line +=40 + // [22] (byte*) main::line#1 ← (byte*) main::line#2 + (byte) $28 -- pbuz1=pbuz1_plus_vbuc1 + // Next line + lda #$28 + clc + adc.z line + sta.z line + bcc !+ + inc.z line+1 + !: + // for(char i=0;i<NUM_ENTITIES;i++) + // [23] (byte) main::i1#1 ← ++ (byte) main::i1#2 -- vbuz1=_inc_vbuz1 + inc.z i1 + // [5] phi from main::@8 to main::@5 [phi:main::@8->main::@5] + // [5] phi (byte*) main::line#2 = (byte*) main::line#1 [phi:main::@8->main::@5#0] -- register_copy + // [5] phi (byte) main::i1#2 = (byte) main::i1#1 [phi:main::@8->main::@5#1] -- register_copy + jmp __b5 + // main::@2 + __b2: + // entities[i].x_pos = (signed char)i + // [24] (byte~) main::$21 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1 + txa + asl + // [25] (byte~) main::$10 ← (byte~) main::$21 + (byte) main::i#2 -- vbuyy=vbuaa_plus_vbuxx + stx.z $ff + clc + adc.z $ff + tay + // [26] *((signed byte*)(const struct Entity*) entities + (byte~) main::$10) ← (signed byte)(byte) main::i#2 -- pbsc1_derefidx_vbuyy=vbsxx + txa + sta entities,y + // entities[i].x_vel = v + // [27] *((signed byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_X_VEL + (byte~) main::$10) ← (signed byte) main::v#2 -- pbsc1_derefidx_vbuyy=vbsz1 + lda.z v + sta entities+OFFSET_STRUCT_ENTITY_X_VEL,y + // entities[i].symbol = i + // [28] *((byte*)(const struct Entity*) entities+(const byte) OFFSET_STRUCT_ENTITY_SYMBOL + (byte~) main::$10) ← (byte) main::i#2 -- pbuc1_derefidx_vbuyy=vbuxx + txa + sta entities+OFFSET_STRUCT_ENTITY_SYMBOL,y + // v = -v + // [29] (signed byte) main::v#1 ← - (signed byte) main::v#2 -- vbsz1=_neg_vbsz1 + lda.z v + eor #$ff + clc + adc #1 + sta.z v + // for(char i=0;i<NUM_ENTITIES;i++) + // [30] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx + inx + // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1] + // [1] phi (signed byte) main::v#2 = (signed byte) main::v#1 [phi:main::@2->main::@1#0] -- register_copy + // [1] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#1] -- register_copy + jmp __b1 +} + // File Data + entities: .fill 3*$19, 0 + diff --git a/src/test/ref/index-sizeof-reuse.sym b/src/test/ref/index-sizeof-reuse.sym new file mode 100644 index 000000000..a57bcdc2c --- /dev/null +++ b/src/test/ref/index-sizeof-reuse.sym @@ -0,0 +1,55 @@ +(byte) Entity::symbol +(signed byte) Entity::x_pos +(signed byte) Entity::x_vel +(const byte) OFFSET_STRUCT_ENTITY_SYMBOL = (byte) 2 +(const byte) OFFSET_STRUCT_ENTITY_X_VEL = (byte) 1 +(const nomodify byte*) SCREEN = (byte*) 1024 +(const nomodify byte*) VIC_BG_COLOR = (byte*) 53280 +(const nomodify byte*) VIC_RASTER = (byte*) 53266 +(const struct Entity*) entities[(number) $19] = { fill( $19, 0) } +(void()) main() +(byte~) main::$10 reg byte y 14.666666666666666 +(byte~) main::$13 reg byte x 176.75 +(byte~) main::$16 reg byte a 303.0 +(byte~) main::$18 reg byte x 201.99999999999997 +(byte~) main::$21 reg byte a 22.0 +(byte~) main::$23 reg byte a 202.0 +(byte~) main::$25 reg byte a 202.0 +(byte~) main::$27 reg byte a 202.0 +(signed byte~) main::$8 reg byte a 202.0 +(label) main::@1 +(label) main::@10 +(label) main::@2 +(label) main::@3 +(label) main::@4 +(label) main::@5 +(label) main::@6 +(label) main::@7 +(label) main::@8 +(label) main::@9 +(byte) main::i +(byte) main::i#1 reg byte x 22.0 +(byte) main::i#2 reg byte x 8.25 +(byte) main::i1 +(byte) main::i1#1 i1 zp[1]:3 202.0 +(byte) main::i1#2 i1 zp[1]:3 53.470588235294116 +(byte*) main::line +(byte*) main::line#1 line zp[2]:4 101.0 +(byte*) main::line#2 line zp[2]:4 25.25 +(signed byte) main::v +(signed byte) main::v#1 v zp[1]:2 11.0 +(signed byte) main::v#2 v zp[1]:2 4.714285714285714 + +reg byte x [ main::i#2 main::i#1 ] +zp[1]:2 [ main::v#2 main::v#1 ] +zp[1]:3 [ main::i1#2 main::i1#1 ] +zp[2]:4 [ main::line#2 main::line#1 ] +reg byte a [ main::$23 ] +reg byte x [ main::$13 ] +reg byte a [ main::$27 ] +reg byte x [ main::$18 ] +reg byte a [ main::$8 ] +reg byte a [ main::$25 ] +reg byte a [ main::$16 ] +reg byte a [ main::$21 ] +reg byte y [ main::$10 ]