From 68b4794049d72b384e25dbb3ebab1b5a6254f434 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Mon, 20 Jan 2020 00:30:05 +0100 Subject: [PATCH] Optimized 32-bit plus 8-bit constant fragment. --- .../mos6502-common/vdum1=vdum1_plus_vbuc1.asm | 11 +++ src/test/ref/sqr-delta.asm | 20 +++--- src/test/ref/sqr-delta.log | 68 +++++++++---------- 3 files changed, 51 insertions(+), 48 deletions(-) create mode 100644 src/main/fragment/mos6502-common/vdum1=vdum1_plus_vbuc1.asm diff --git a/src/main/fragment/mos6502-common/vdum1=vdum1_plus_vbuc1.asm b/src/main/fragment/mos6502-common/vdum1=vdum1_plus_vbuc1.asm new file mode 100644 index 000000000..47aa820d7 --- /dev/null +++ b/src/main/fragment/mos6502-common/vdum1=vdum1_plus_vbuc1.asm @@ -0,0 +1,11 @@ +lda {m1} +clc +adc #{c1} +sta {m1} +bcc !+ +inc {m1}+1 +bne !+ +inc {m1}+2 +bne !+ +inc {m1}+3 +!: \ No newline at end of file diff --git a/src/test/ref/sqr-delta.asm b/src/test/ref/sqr-delta.asm index dbdb66ab1..a755a2218 100644 --- a/src/test/ref/sqr-delta.asm +++ b/src/test/ref/sqr-delta.asm @@ -98,18 +98,16 @@ ifunc: { lda.z xsqr+3 adc.z delta+3 sta.z xsqr+3 - lda #2 + lda.z delta clc - adc.z delta + adc #2 sta.z delta - lda.z delta+1 - adc #0 - sta.z delta+1 - lda.z delta+2 - adc #0 - sta.z delta+2 - lda.z delta+3 - adc #0 - sta.z delta+3 + bcc !+ + inc.z delta+1 + bne !+ + inc.z delta+2 + bne !+ + inc.z delta+3 + !: jmp __b1 } diff --git a/src/test/ref/sqr-delta.log b/src/test/ref/sqr-delta.log index dedd0ca21..fe6c5a451 100644 --- a/src/test/ref/sqr-delta.log +++ b/src/test/ref/sqr-delta.log @@ -450,19 +450,17 @@ ifunc: { adc.z delta+3 sta.z xsqr+3 // [17] (dword) ifunc::delta#1 ← (dword) ifunc::delta#2 + (byte) 2 -- vduz1=vduz1_plus_vbuc1 - lda #2 + lda.z delta clc - adc.z delta + adc #2 sta.z delta - lda.z delta+1 - adc #0 - sta.z delta+1 - lda.z delta+2 - adc #0 - sta.z delta+2 - lda.z delta+3 - adc #0 - sta.z delta+3 + bcc !+ + inc.z delta+1 + bne !+ + inc.z delta+2 + bne !+ + inc.z delta+3 + !: // [11] phi from ifunc::@2 to ifunc::@1 [phi:ifunc::@2->ifunc::@1] __b1_from___b2: // [11] phi (dword) ifunc::delta#2 = (dword) ifunc::delta#1 [phi:ifunc::@2->ifunc::@1#0] -- register_copy @@ -500,19 +498,19 @@ Missing ASM fragment Fragment not found vduz1=_dec_vduz2. Attempted variations v File /Users/jespergravgaard/c64/kickc/src/test/kc/sqr-delta.kc Line 10 return --x; -Uplifting [ifunc] best 2175 combination zp[4]:10 [ ifunc::delta#2 ifunc::delta#1 ] zp[4]:2 [ ifunc::xsqr#2 ifunc::xsqr#1 ] zp[4]:6 [ ifunc::x#3 ifunc::x#1 ] zp[4]:14 [ ifunc::return#2 ] zp[4]:22 [ ifunc::return#0 ] +Uplifting [ifunc] best 2160 combination zp[4]:10 [ ifunc::delta#2 ifunc::delta#1 ] zp[4]:2 [ ifunc::xsqr#2 ifunc::xsqr#1 ] zp[4]:6 [ ifunc::x#3 ifunc::x#1 ] zp[4]:14 [ ifunc::return#2 ] zp[4]:22 [ ifunc::return#0 ] Warning! Unknown fragment for statement [13] (dword) ifunc::return#0 ← -- (dword) ifunc::x#3 Missing ASM fragment Fragment not found vduz1=_dec_vduz2. Attempted variations vduz1=_dec_vduz2 File /Users/jespergravgaard/c64/kickc/src/test/kc/sqr-delta.kc Line 10 return --x; -Uplifting [main] best 2175 combination zp[4]:18 [ main::$0 ] +Uplifting [main] best 2160 combination zp[4]:18 [ main::$0 ] Warning! Unknown fragment for statement [13] (dword) ifunc::return#0 ← -- (dword) ifunc::x#3 Missing ASM fragment Fragment not found vduz1=_dec_vduz2. Attempted variations vduz1=_dec_vduz2 File /Users/jespergravgaard/c64/kickc/src/test/kc/sqr-delta.kc Line 10 return --x; -Uplifting [] best 2175 combination +Uplifting [] best 2160 combination Coalescing zero page register [ zp[4]:6 [ ifunc::x#3 ifunc::x#1 ] ] with [ zp[4]:22 [ ifunc::return#0 ] ] - score: 1 Coalescing zero page register [ zp[4]:14 [ ifunc::return#2 ] ] with [ zp[4]:18 [ main::$0 ] ] - score: 1 Coalescing zero page register [ zp[4]:6 [ ifunc::x#3 ifunc::x#1 ifunc::return#0 ] ] with [ zp[4]:14 [ ifunc::return#2 main::$0 ] ] - score: 1 @@ -672,19 +670,17 @@ ifunc: { adc.z delta+3 sta.z xsqr+3 // [17] (dword) ifunc::delta#1 ← (dword) ifunc::delta#2 + (byte) 2 -- vduz1=vduz1_plus_vbuc1 - lda #2 + lda.z delta clc - adc.z delta + adc #2 sta.z delta - lda.z delta+1 - adc #0 - sta.z delta+1 - lda.z delta+2 - adc #0 - sta.z delta+2 - lda.z delta+3 - adc #0 - sta.z delta+3 + bcc !+ + inc.z delta+1 + bne !+ + inc.z delta+2 + bne !+ + inc.z delta+3 + !: // [11] phi from ifunc::@2 to ifunc::@1 [phi:ifunc::@2->ifunc::@1] __b1_from___b2: // [11] phi (dword) ifunc::delta#2 = (dword) ifunc::delta#1 [phi:ifunc::@2->ifunc::@1#0] -- register_copy @@ -759,7 +755,7 @@ zp[4]:10 [ ifunc::delta#2 ifunc::delta#1 ] FINAL ASSEMBLER -Score: 2080 +Score: 2065 // File Comments // Upstart @@ -905,19 +901,17 @@ ifunc: { sta.z xsqr+3 // delta += 2 // [17] (dword) ifunc::delta#1 ← (dword) ifunc::delta#2 + (byte) 2 -- vduz1=vduz1_plus_vbuc1 - lda #2 + lda.z delta clc - adc.z delta + adc #2 sta.z delta - lda.z delta+1 - adc #0 - sta.z delta+1 - lda.z delta+2 - adc #0 - sta.z delta+2 - lda.z delta+3 - adc #0 - sta.z delta+3 + bcc !+ + inc.z delta+1 + bne !+ + inc.z delta+2 + bne !+ + inc.z delta+3 + !: // [11] phi from ifunc::@2 to ifunc::@1 [phi:ifunc::@2->ifunc::@1] // [11] phi (dword) ifunc::delta#2 = (dword) ifunc::delta#1 [phi:ifunc::@2->ifunc::@1#0] -- register_copy // [11] phi (dword) ifunc::x#3 = (dword) ifunc::x#1 [phi:ifunc::@2->ifunc::@1#1] -- register_copy