1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-04-03 08:30:49 +00:00

Improved sign extension in fragments.

This commit is contained in:
jespergravgaard 2021-06-23 09:40:48 +02:00
parent 4628870166
commit 822d168dd8
29 changed files with 194 additions and 13230 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
//KICKC FRAGMENT CACHE f6e6ad792 f6e6af7f9
//KICKC FRAGMENT CACHE e4a172d7a e4a174de3
//FRAGMENT _deref_pbuc1=vbuc2
lda #{c2}
sta {c1}

View File

@ -1,4 +1,4 @@
//KICKC FRAGMENT CACHE f6e6ad792 f6e6af7f9
//KICKC FRAGMENT CACHE e4a172d7a e4a174de3
//FRAGMENT vbuz1=vbuc1
lda #{c1}
sta {z1}

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
//KICKC FRAGMENT CACHE f6e6ad792 f6e6af7f9
//KICKC FRAGMENT CACHE e4a172d7a e4a174de3
//FRAGMENT _deref_pbuc1=_inc__deref_pbuc1
inc {c1}
//FRAGMENT isr_hardware_all_entry
@ -792,401 +792,3 @@ iny
tax
//FRAGMENT vbuyy=vbuaa
tay
//FRAGMENT vbuz1=vbuz2_band_vbuc1
lda #{c1}
and {z2}
sta {z1}
//FRAGMENT _deref_pbuc1=_dec__deref_pbuc1
dec {c1}
//FRAGMENT pbuz1=pbuc1_plus_vbuz2
lda {z2}
clc
adc #<{c1}
sta {z1}
lda #>{c1}
adc #0
sta {z1}+1
//FRAGMENT pvoz1=pvoz2
lda {z2}
sta {z1}
lda {z2}+1
sta {z1}+1
//FRAGMENT vbuz1=vbuz1_plus_2
lda {z1}
clc
adc #2
sta {z1}
//FRAGMENT vbuz1=pbuz2_derefidx_vbuc1
ldy #{c1}
lda ({z2}),y
sta {z1}
//FRAGMENT pbuz1=pbuz2_plus_vbuc1
lda #{c1}
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1
//FRAGMENT pbuz1_neq_pbuc1_then_la1
lda {z1}+1
cmp #>{c1}
bne {la1}
lda {z1}
cmp #<{c1}
bne {la1}
//FRAGMENT _deref_pbuz1=_deref_pbuz2
ldy #0
lda ({z2}),y
ldy #0
sta ({z1}),y
//FRAGMENT vbuz1=vbuaa_band_vbuc1
and #{c1}
sta {z1}
//FRAGMENT vbuz1=vbuxx_band_vbuc1
lda #{c1}
sax {z1}
//FRAGMENT vbuz1=vbuyy_band_vbuc1
tya
and #{c1}
sta {z1}
//FRAGMENT vbuaa=vbuz1_band_vbuc1
lda #{c1}
and {z1}
//FRAGMENT vbuaa=vbuaa_band_vbuc1
and #{c1}
//FRAGMENT vbuaa=vbuxx_band_vbuc1
txa
and #{c1}
//FRAGMENT vbuaa=vbuyy_band_vbuc1
tya
and #{c1}
//FRAGMENT vbuxx=vbuz1_band_vbuc1
lda #{c1}
and {z1}
tax
//FRAGMENT vbuxx=vbuaa_band_vbuc1
ldx #{c1}
axs #0
//FRAGMENT vbuyy=vbuz1_band_vbuc1
lda #{c1}
and {z1}
tay
//FRAGMENT pbuz1=pbuc1_plus_vbuaa
clc
adc #<{c1}
sta {z1}
lda #>{c1}
adc #0
sta {z1}+1
//FRAGMENT pbuz1=pbuc1_plus_vbuxx
txa
clc
adc #<{c1}
sta {z1}
lda #>{c1}
adc #0
sta {z1}+1
//FRAGMENT pbuz1=pbuc1_plus_vbuyy
tya
clc
adc #<{c1}
sta {z1}
lda #>{c1}
adc #0
sta {z1}+1
//FRAGMENT vbuxx=vbuxx_plus_2
inx
inx
//FRAGMENT vbuaa=pbuz1_derefidx_vbuc1
ldy #{c1}
lda ({z1}),y
//FRAGMENT vbuxx=pbuz1_derefidx_vbuc1
ldy #{c1}
lda ({z1}),y
tax
//FRAGMENT vbuyy=pbuz1_derefidx_vbuc1
ldy #{c1}
lda ({z1}),y
tay
//FRAGMENT pbuz1=pbuz1_plus_vbuc1
lda #{c1}
clc
adc {z1}
sta {z1}
bcc !+
inc {z1}+1
!:
//FRAGMENT vbuz1=_dec_vbuz1
dec {z1}
//FRAGMENT pbuz1=pbuz2
lda {z2}
sta {z1}
lda {z2}+1
sta {z1}+1
//FRAGMENT _deref_pbuz1=pbuc1_derefidx_vbuz2
ldy {z2}
lda {c1},y
ldy #0
sta ({z1}),y
//FRAGMENT pbuz1=_inc_pbuz2
clc
lda {z2}
adc #1
sta {z1}
lda {z2}+1
adc #0
sta {z1}+1
//FRAGMENT _deref_pbuz1=vbuc1
lda #{c1}
ldy #0
sta ({z1}),y
//FRAGMENT vbuz1=pbuc1_derefidx_vbuz2
ldy {z2}
lda {c1},y
sta {z1}
//FRAGMENT vbuz1_ge_vbuz2_then_la1
lda {z1}
cmp {z2}
bcs {la1}
//FRAGMENT vbuz1=vbuz1_minus_vbuz2
lda {z1}
sec
sbc {z2}
sta {z1}
//FRAGMENT vwuz1=_word_vbuz2
lda {z2}
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=vwuz2_rol_5
lda {z2}
asl
sta {z1}
lda {z2}+1
rol
sta {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
//FRAGMENT pbuz1=pbuc1_plus_vwuz2
clc
lda {z2}
adc #<{c1}
sta {z1}
lda {z2}+1
adc #>{c1}
sta {z1}+1
//FRAGMENT pbuz1=pbuz2_plus_vbuz3
lda {z3}
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1
//FRAGMENT pbuz1=pbuz1_minus_vbuc1
sec
lda {z1}
sbc #{c1}
sta {z1}
lda {z1}+1
sbc #0
sta {z1}+1
//FRAGMENT vbuz1=_deref_pbuc1
lda {c1}
sta {z1}
//FRAGMENT _deref_pbuz1=vbuz2
lda {z2}
ldy #0
sta ({z1}),y
//FRAGMENT vbuxx=vbuxx_band_vbuc1
lda #{c1}
axs #0
//FRAGMENT vbuyy=vbuxx_band_vbuc1
txa
and #{c1}
tay
//FRAGMENT vbuxx=vbuyy_band_vbuc1
ldx #{c1}
tya
axs #0
//FRAGMENT vbuyy=vbuyy_band_vbuc1
tya
and #{c1}
tay
//FRAGMENT _deref_pbuz1=pbuc1_derefidx_vbuaa
tay
lda {c1},y
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=pbuc1_derefidx_vbuxx
lda {c1},x
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=pbuc1_derefidx_vbuyy
lda {c1},y
ldy #0
sta ({z1}),y
//FRAGMENT vbuaa=pbuc1_derefidx_vbuz1
ldy {z1}
lda {c1},y
//FRAGMENT vbuxx=pbuc1_derefidx_vbuz1
ldy {z1}
ldx {c1},y
//FRAGMENT vbuyy=pbuc1_derefidx_vbuz1
ldx {z1}
ldy {c1},x
//FRAGMENT vbuz1=pbuc1_derefidx_vbuaa
tay
lda {c1},y
sta {z1}
//FRAGMENT vbuaa=pbuc1_derefidx_vbuaa
tay
lda {c1},y
//FRAGMENT vbuxx=pbuc1_derefidx_vbuaa
tay
ldx {c1},y
//FRAGMENT vbuyy=pbuc1_derefidx_vbuaa
tax
ldy {c1},x
//FRAGMENT vbuz1=pbuc1_derefidx_vbuxx
lda {c1},x
sta {z1}
//FRAGMENT 0_neq_vbuaa_then_la1
cmp #0
bne {la1}
//FRAGMENT vbuaa_ge_vbuz1_then_la1
cmp {z1}
bcs {la1}
//FRAGMENT vbuxx=vbuxx_minus_vbuz1
txa
sec
sbc {z1}
tax
//FRAGMENT vbuz1=vbuz1_minus_vbuaa
eor #$ff
sec
adc {z1}
sta {z1}
//FRAGMENT vbuxx=vbuxx_minus_vbuaa
sta $ff
txa
sec
sbc $ff
tax
//FRAGMENT vbuz1=vbuz1_minus_vbuxx
txa
eor #$ff
sec
adc {z1}
sta {z1}
//FRAGMENT vbuxx=vbuxx_minus_vbuxx
lda #0
tax
//FRAGMENT vbuz1=vbuz1_minus_vbuyy
tya
eor #$ff
sec
adc {z1}
sta {z1}
//FRAGMENT vbuxx=vbuxx_minus_vbuyy
txa
sty $ff
sec
sbc $ff
tax
//FRAGMENT vwuz1=_word_vbuaa
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=_word_vbuxx
txa
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=_word_vbuyy
tya
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vbuaa_eq_vbuc1_then_la1
cmp #{c1}
beq {la1}
//FRAGMENT vbuaa=_deref_pbuc1
lda {c1}
//FRAGMENT vbuxx=_deref_pbuc1
ldx {c1}
//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 vbuxx_ge_vbuz1_then_la1
cpx {z1}
bcs {la1}
//FRAGMENT vbuxx_eq_vbuc1_then_la1
cpx #{c1}
beq {la1}
//FRAGMENT vbuyy=_deref_pbuc1
ldy {c1}
//FRAGMENT vbuz1_ge_vbuxx_then_la1
lda {z1}
stx $ff
cmp $ff
bcs {la1}
//FRAGMENT vbuz1_ge_vbuyy_then_la1
lda {z1}
sty $ff
cmp $ff
bcs {la1}
//FRAGMENT vbuxx_ge_vbuyy_then_la1
sty $ff
cpx $ff
bcs {la1}
//FRAGMENT vbuaa=vbuxx
txa
//FRAGMENT vbuyy=vbuxx
txa
tay
//FRAGMENT vbuyy_eq_vbuc1_then_la1
cpy #{c1}
beq {la1}
//FRAGMENT vbuaa=vbuyy
tya
//FRAGMENT vbuxx=vbuyy
tya
tax
//FRAGMENT vbuyy_ge_vbuz1_then_la1
cpy {z1}
bcs {la1}
//FRAGMENT vwuz1=vwuz1_rol_5
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
//FRAGMENT pbuz1=pbuc1_plus_vwuz1
clc
lda {z1}
adc #<{c1}
sta {z1}
lda {z1}+1
adc #>{c1}
sta {z1}+1

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,14 @@
lda ({z1}),y
sta $fe
sta $ff
ldy #{c1}
clc
adc ({z1}),y
sta ({z1}),y
iny
lda $ff
ora #$7f
bmi !+
lda #0
!:
sta $ff
ldy #{c1}
clc
lda ({z1}),y
adc $fe
sta ({z1}),y
iny
lda ({z1}),y
adc $fe
adc ({z1}),y
sta ({z1}),y

View File

@ -1,17 +1,16 @@
clc
lda {m2}
adc #<{c1}
sta {m1}
lda {m2}+1
adc #>{c1}
sta {m1}+1
lda {m2}+1
ora #$7f
bmi !+
lda #0
!:
sta $ff
lda {m2}
clc
adc #<{c1}
sta {m1}
lda {m2}+1
adc #>{c1}
sta {m1}+1
lda $ff
adc #<{c1}>>$10
sta {m1}+2
lda $ff

View File

@ -1,19 +1,18 @@
clc
lda {m2}
adc {m1}
sta {m1}
lda {m2}+1
adc {m1}+1
sta {m1}+1
lda {m2}+1
ora #$7f
bmi !+
lda #0
!:
sta $ff
lda {m1}
clc
adc {m2}
sta {m1}
lda {m1}+1
adc {m2}+1
sta {m1}+1
lda {m1}+2
adc $ff
adc {m1}+2
sta {m1}+2
lda {m1}+3
adc $ff
lda $ff
adc {m1}+3
sta {m1}+3

View File

@ -1,19 +1,18 @@
pha
sta $ff
clc
adc {m2}
sta {m1}
lda $ff
ora #$7f
bmi !+
lda #0
!:
sta $ff
clc
pla
adc {m2}
sta {m1}
lda {m2}+1
adc $ff
adc {m2}+1
sta {m1}+1
lda {m2}+2
adc $ff
lda $ff
adc {m2}+2
sta {m1}+2
lda {m2}+3
adc $ff
lda $ff
adc {m2}+3
sta {m1}+3

View File

@ -1,19 +1,18 @@
clc
lda {m3}
adc {m2}
sta {m1}
lda {m3}+1
adc {m2}+1
sta {m1}+1
lda {m3}+1
ora #$7f
bmi !+
lda #0
!:
sta $ff
clc
lda {m2}
adc {m3}
sta {m1}
lda {m2}+1
adc {m3}+1
sta {m1}+1
lda {m2}+2
adc $ff
adc {m2}+2
sta {m1}+2
lda {m2}+3
adc $ff
lda $ff
adc {m2}+3
sta {m1}+3

View File

@ -1,3 +1,10 @@
clc
lda {m2}
adc {m3}
sta {m1}
lda {m2}+1
adc {m3}+1
sta {m1}+1
lda {m3}+1
ora #$7f
bmi !+
@ -10,14 +17,6 @@ bmi !+
lda #0
!:
sta $fe
clc
lda {m2}
adc {m3}
sta {m1}
lda {m2}+1
adc {m3}+1
sta {m1}+1
lda $fe
adc $ff
sta {m1}+2
lda $fe

View File

@ -1,9 +1,3 @@
lda {m2}+1
ora #$7f
bmi !+
lda #0
!:
sta $ff
clc
lda {m2}
adc #<{c1}
@ -11,7 +5,12 @@ sta {m1}
lda {m2}+1
adc #>{c1}
sta {m1}+1
lda $ff
lda {m2}+1
ora #$7f
bmi !+
lda #0
!:
sta $ff
adc #<{c1}>>$10
sta {m1}+2
lda $ff

View File

@ -1,9 +1,3 @@
lda {m2}+1
ora #$7f
bmi !+
lda #0
!:
sta $ff
clc
lda {m1}
adc {m2}
@ -11,9 +5,14 @@ sta {m1}
lda {m1}+1
adc {m2}+1
sta {m1}+1
lda {m1}+2
adc $ff
lda {m2}+1
ora #$7f
bmi !+
lda #0
!:
sta $ff
adc {m1}+2
sta {m1}+2
lda {m1}+3
adc $ff
lda $ff
adc {m1}+3
sta {m1}+3

View File

@ -1,14 +1,13 @@
pha
sta $ff
clc
adc {m2}
sta {m1}
lda $ff
ora #$7f
bmi !+
lda #0
!:
sta $ff
pla
clc
adc {m2}
sta {m1}
lda $ff
adc {m2}+1
sta {m1}+1
lda $ff

View File

@ -1,19 +1,18 @@
clc
lda {m3}
adc {m2}
sta {m1}
lda {m3}+1
adc {m2}+1
sta {m1}+1
lda {m3}+1
ora #$7f
bmi !+
lda #0
!:
sta $ff
clc
lda {m2}
adc {m3}
sta {m1}
lda {m2}+1
adc {m3}+1
sta {m1}+1
lda {m2}+2
adc $ff
adc {m2}+2
sta {m1}+2
lda {m2}+3
adc $ff
lda $ff
adc {m2}+3
sta {m1}+3

View File

@ -1,15 +1,11 @@
sta $ff
clc
adc #{c1}
sta {m1}
// sign-extend the byte
lda $ff
ora #$7f
bmi !+
lda #0
!:
sta {m1}+1
// add the constant
lda {m1}
clc
adc #{c1}
sta {m1}
lda {m1}+1
adc #0
sta {m1}+1
sta {m1}+1

View File

@ -1,11 +1,11 @@
tax
sta $ff
clc
adc #<{c1}
sta {m1}
txa
lda $ff
ora #$7f
bmi !+
lda #0
!:
adc #>{c1}
sta {m1}+1
sta {m1}+1

View File

@ -0,0 +1,11 @@
clc
lda ({z2}),y
adc {m1}
sta {m1}
lda ({z2}),y
ora #$7f
bmi !+
lda #0
!:
adc {m1}+1
sta {m1}+1

View File

@ -1,8 +1,8 @@
pha
sta $ff
clc
adc {m2}
sta {m1}
pla
lda $ff
ora #$7f
bmi !+
lda #0

View File

@ -1,8 +1,8 @@
pha
sta $ff
clc
adc #<{c1}
sta {m1}
pla
lda $ff
ora #$7f
bmi !+
lda #0

View File

@ -1,5 +1,5 @@
lda {m2}
clc
lda {m2}
adc #<{c1}
sta {m1}
lda {m2}

View File

@ -1,8 +1,8 @@
pha
sta $ff
clc
adc {m1}
sta {m1}
pla
lda $ff
ora #$7f
bmi !+
lda #0

View File

@ -1,8 +1,8 @@
pha
sta $ff
clc
adc {m2}
sta {m1}
pla
lda $ff
ora #$7f
bmi !+
lda #0

View File

@ -551,7 +551,7 @@ public class AsmFragmentInstanceSpecBuilder {
} else if(baseType instanceof SymbolTypeProcedure) {
return "pr";
} else {
throw new InternalError("Not implemented " + baseType);
throw new CompileError("Type not supported in fragments " + baseType);
}
}

View File

@ -19,11 +19,11 @@ main: {
__b1:
// sw += (signed byte)i
txa
pha
sta.z $ff
clc
adc.z sw
sta.z sw
pla
lda.z $ff
ora #$7f
bmi !+
lda #0

View File

@ -147,8 +147,8 @@ REGISTER UPLIFT SCOPES
Uplift Scope [main] 28.6: zp[2]:3 [ main::sw#2 main::sw#1 ] 24.75: zp[1]:2 [ main::i#2 main::i#1 ] 22: zp[1]:5 [ main::$1 ]
Uplift Scope []
Uplifting [main] best 796 combination zp[2]:3 [ main::sw#2 main::sw#1 ] reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$1 ]
Uplifting [] best 796 combination
Uplifting [main] best 786 combination zp[2]:3 [ main::sw#2 main::sw#1 ] reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$1 ]
Uplifting [] best 786 combination
Allocated (was zp[2]:3) zp[2]:2 [ main::sw#2 main::sw#1 ]
ASSEMBLER BEFORE OPTIMIZATION
@ -188,11 +188,11 @@ main: {
__b1:
// [2] main::sw#1 = main::sw#2 + (signed byte)main::i#2 -- vwsz1=vwsz1_plus_vbsxx
txa
pha
sta.z $ff
clc
adc.z sw
sta.z sw
pla
lda.z $ff
ora #$7f
bmi !+
lda #0
@ -251,7 +251,7 @@ reg byte a [ main::$1 ]
FINAL ASSEMBLER
Score: 706
Score: 696
// File Comments
// Test elimination of noop-casts (signed byte to byte)
@ -286,11 +286,11 @@ main: {
// sw += (signed byte)i
// [2] main::sw#1 = main::sw#2 + (signed byte)main::i#2 -- vwsz1=vwsz1_plus_vbsxx
txa
pha
sta.z $ff
clc
adc.z sw
sta.z sw
pla
lda.z $ff
ora #$7f
bmi !+
lda #0

View File

@ -88,8 +88,8 @@ benchmarkLandscape: {
rts
__b4:
// char *screenAddress = lms + x
lda.z x
clc
lda.z x
adc #<lms
sta.z screenAddress
lda.z x

View File

@ -798,8 +798,8 @@ benchmarkLandscape: {
// benchmarkLandscape::@4
__b4:
// [25] benchmarkLandscape::screenAddress#0 = lms + benchmarkLandscape::x#2 -- pbuz1=pbuc1_plus_vbsz2
lda.z x
clc
lda.z x
adc #<lms
sta.z screenAddress
lda.z x
@ -1147,8 +1147,8 @@ benchmarkLandscape: {
__b4:
// char *screenAddress = lms + x
// [25] benchmarkLandscape::screenAddress#0 = lms + benchmarkLandscape::x#2 -- pbuz1=pbuc1_plus_vbsz2
lda.z x
clc
lda.z x
adc #<lms
sta.z screenAddress
lda.z x