mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-27 04:49:27 +00:00
Added test for pointer-to-pointer optimization.
This commit is contained in:
parent
fd259fe47e
commit
5f2b798a8a
2
src/main/fragment/_deref__deref_pptc1=vbuaa.asm
Normal file
2
src/main/fragment/_deref__deref_pptc1=vbuaa.asm
Normal file
@ -0,0 +1,2 @@
|
||||
ldy #0
|
||||
sta ({c1}),y
|
@ -2,4 +2,4 @@ ldy #0
|
||||
lda {z1}
|
||||
sta !+ +1
|
||||
lda {c1},x
|
||||
!: sta ({z1}),y
|
||||
!: sta ($ff),y
|
||||
|
4
src/main/fragment/_deref__deref_pptz1=vbuaa.asm
Normal file
4
src/main/fragment/_deref__deref_pptz1=vbuaa.asm
Normal file
@ -0,0 +1,4 @@
|
||||
ldy {z1}
|
||||
sty !+ +1
|
||||
ldy #0
|
||||
!: sta ($ff),y
|
4
src/main/fragment/_deref_pptc1=_inc__deref_pptc1.asm
Normal file
4
src/main/fragment/_deref_pptc1=_inc__deref_pptc1.asm
Normal file
@ -0,0 +1,4 @@
|
||||
inc {c1}
|
||||
bne !+
|
||||
inc {c1}+1
|
||||
!:
|
@ -63,6 +63,26 @@ public class TestPrograms {
|
||||
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testSubExprOptimize0() throws IOException, URISyntaxException {
|
||||
compileAndCompare("subexpr-optimize-0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPtrPtrOptimize2() throws IOException, URISyntaxException {
|
||||
compileAndCompare("ptrptr-optimize-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPtrPtrOptimize1() throws IOException, URISyntaxException {
|
||||
compileAndCompare("ptrptr-optimize-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPtrPtrOptimize0() throws IOException, URISyntaxException {
|
||||
compileAndCompare("ptrptr-optimize-0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHex2DecPtrPtr() throws IOException, URISyntaxException {
|
||||
compileAndCompare("hex2dec-ptrptr");
|
||||
|
8
src/test/kc/ptrptr-optimize-0.kc
Normal file
8
src/test/kc/ptrptr-optimize-0.kc
Normal file
@ -0,0 +1,8 @@
|
||||
// Tests optimization of constant pointers to pointers
|
||||
void main() {
|
||||
byte* screen = 0x400;
|
||||
byte** pscreen = &screen;
|
||||
**pscreen = 'a';
|
||||
(*pscreen)++;
|
||||
**pscreen = 'b';
|
||||
}
|
11
src/test/kc/ptrptr-optimize-1.kc
Normal file
11
src/test/kc/ptrptr-optimize-1.kc
Normal file
@ -0,0 +1,11 @@
|
||||
// Tests optimization of constant pointers to pointers
|
||||
void main() {
|
||||
byte* screen = 0x400;
|
||||
byte** pscreen = &screen;
|
||||
sub('a',pscreen);
|
||||
sub('b',pscreen);
|
||||
}
|
||||
|
||||
void sub(unsigned char ch, unsigned char **dst) {
|
||||
*(*dst)++ = ch;
|
||||
}
|
11
src/test/kc/ptrptr-optimize-2.kc
Normal file
11
src/test/kc/ptrptr-optimize-2.kc
Normal file
@ -0,0 +1,11 @@
|
||||
// Tests (non-)optimization of constant pointers to pointers
|
||||
// The two examples of &screen is not detected as identical leading to ASM that could be optimized more
|
||||
void main() {
|
||||
byte* screen = 0x400;
|
||||
sub('a',&screen);
|
||||
sub('b',&screen);
|
||||
}
|
||||
|
||||
void sub(unsigned char ch, unsigned char **dst) {
|
||||
*(*dst)++ = ch;
|
||||
}
|
10
src/test/kc/subexpr-optimize-0.kc
Normal file
10
src/test/kc/subexpr-optimize-0.kc
Normal file
@ -0,0 +1,10 @@
|
||||
// Tests (non-)optimization of identical sub-expressions
|
||||
// The two examples of i+1 is not detected as identical leading to ASM that could be optimized more
|
||||
void main() {
|
||||
byte* screen = 0x400;
|
||||
for( byte i: 0..2) {
|
||||
*screen++ = i+1;
|
||||
*screen++ = i+1;
|
||||
}
|
||||
}
|
||||
|
@ -60,48 +60,40 @@ utoa16w: {
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
tax
|
||||
tay
|
||||
lda #<dst
|
||||
sta utoa16n.dst
|
||||
lda #>dst
|
||||
sta utoa16n.dst+1
|
||||
lda #0
|
||||
sta utoa16n.started
|
||||
ldx #0
|
||||
jsr utoa16n
|
||||
lda utoa16n.return
|
||||
tay
|
||||
lda value+1
|
||||
ldx #$f
|
||||
axs #0
|
||||
sty utoa16n.started
|
||||
lda #<dst
|
||||
sta utoa16n.dst
|
||||
lda #>dst
|
||||
sta utoa16n.dst+1
|
||||
jsr utoa16n
|
||||
lda utoa16n.return
|
||||
and #$f
|
||||
tay
|
||||
lda value
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
tax
|
||||
sty utoa16n.started
|
||||
lda #<dst
|
||||
sta utoa16n.dst
|
||||
lda #>dst
|
||||
sta utoa16n.dst+1
|
||||
jsr utoa16n
|
||||
lda value
|
||||
ldx #$f
|
||||
axs #0
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
tay
|
||||
lda #<dst
|
||||
sta utoa16n.dst
|
||||
lda #>dst
|
||||
sta utoa16n.dst+1
|
||||
lda #1
|
||||
sta utoa16n.started
|
||||
jsr utoa16n
|
||||
lda value
|
||||
and #$f
|
||||
tay
|
||||
lda #<dst
|
||||
sta utoa16n.dst
|
||||
lda #>dst
|
||||
sta utoa16n.dst+1
|
||||
ldx #1
|
||||
jsr utoa16n
|
||||
lda #0
|
||||
tay
|
||||
@ -109,25 +101,21 @@ utoa16w: {
|
||||
rts
|
||||
}
|
||||
// Hexadecimal utoa() for a single nybble
|
||||
// utoa16n(byte register(X) nybble, word** zeropage(6) dst, byte zeropage(8) started)
|
||||
// utoa16n(byte register(Y) nybble, word** zeropage(6) dst, byte register(X) started)
|
||||
utoa16n: {
|
||||
.label started = 8
|
||||
.label return = 8
|
||||
.label dst = 6
|
||||
cpx #0
|
||||
cpy #0
|
||||
beq b1
|
||||
lda #1
|
||||
sta return
|
||||
ldx #1
|
||||
b1:
|
||||
lda return
|
||||
cmp #0
|
||||
cpx #0
|
||||
beq breturn
|
||||
lda DIGITS,y
|
||||
ldy dst
|
||||
sty !++1
|
||||
ldy #0
|
||||
lda dst
|
||||
sta !++1
|
||||
lda DIGITS,x
|
||||
!:
|
||||
sta (dst),y
|
||||
sta ($ff),y
|
||||
ldy #0
|
||||
lda (dst),y
|
||||
clc
|
||||
|
23
src/test/ref/ptrptr-optimize-0.asm
Normal file
23
src/test/ref/ptrptr-optimize-0.asm
Normal file
@ -0,0 +1,23 @@
|
||||
// Tests optimization of constant pointers to pointers
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
main: {
|
||||
.label pscreen = screen
|
||||
.label screen = 2
|
||||
lda #<$400
|
||||
sta screen
|
||||
lda #>$400
|
||||
sta screen+1
|
||||
lda #'a'
|
||||
ldy #0
|
||||
sta (pscreen),y
|
||||
inc pscreen
|
||||
bne !+
|
||||
inc pscreen+1
|
||||
!:
|
||||
lda #'b'
|
||||
ldy #0
|
||||
sta (pscreen),y
|
||||
rts
|
||||
}
|
27
src/test/ref/ptrptr-optimize-1.asm
Normal file
27
src/test/ref/ptrptr-optimize-1.asm
Normal file
@ -0,0 +1,27 @@
|
||||
// Tests optimization of constant pointers to pointers
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
main: {
|
||||
.label pscreen = screen
|
||||
.label screen = 2
|
||||
lda #<$400
|
||||
sta screen
|
||||
lda #>$400
|
||||
sta screen+1
|
||||
lda #'a'
|
||||
jsr sub
|
||||
lda #'b'
|
||||
jsr sub
|
||||
rts
|
||||
}
|
||||
// sub(byte register(A) ch)
|
||||
sub: {
|
||||
ldy #0
|
||||
sta (main.pscreen),y
|
||||
inc main.pscreen
|
||||
bne !+
|
||||
inc main.pscreen+1
|
||||
!:
|
||||
rts
|
||||
}
|
41
src/test/ref/ptrptr-optimize-2.asm
Normal file
41
src/test/ref/ptrptr-optimize-2.asm
Normal file
@ -0,0 +1,41 @@
|
||||
// Tests (non-)optimization of constant pointers to pointers
|
||||
// The two examples of &screen is not detected as identical leading to ASM that could be optimized more
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
main: {
|
||||
.label screen = 2
|
||||
lda #<$400
|
||||
sta screen
|
||||
lda #>$400
|
||||
sta screen+1
|
||||
lda #<screen
|
||||
sta sub.dst
|
||||
lda #>screen
|
||||
sta sub.dst+1
|
||||
ldx #'a'
|
||||
jsr sub
|
||||
lda #<screen
|
||||
sta sub.dst
|
||||
lda #>screen
|
||||
sta sub.dst+1
|
||||
ldx #'b'
|
||||
jsr sub
|
||||
rts
|
||||
}
|
||||
// sub(byte register(X) ch, byte** zeropage(2) dst)
|
||||
sub: {
|
||||
.label dst = 2
|
||||
txa
|
||||
ldy dst
|
||||
sty !++1
|
||||
ldy #0
|
||||
!:
|
||||
sta ($ff),y
|
||||
ldy #0
|
||||
lda (dst),y
|
||||
clc
|
||||
adc #1
|
||||
sta (dst),y
|
||||
rts
|
||||
}
|
38
src/test/ref/subexpr-optimize-0.asm
Normal file
38
src/test/ref/subexpr-optimize-0.asm
Normal file
@ -0,0 +1,38 @@
|
||||
// Tests (non-)optimization of identical sub-expressions
|
||||
// The two examples of i+1 is not detected as identical leading to ASM that could be optimized more
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
main: {
|
||||
.label screen = 2
|
||||
lda #<$400
|
||||
sta screen
|
||||
lda #>$400
|
||||
sta screen+1
|
||||
ldx #0
|
||||
b1:
|
||||
txa
|
||||
tay
|
||||
iny
|
||||
tya
|
||||
ldy #0
|
||||
sta (screen),y
|
||||
inc screen
|
||||
bne !+
|
||||
inc screen+1
|
||||
!:
|
||||
txa
|
||||
tay
|
||||
iny
|
||||
tya
|
||||
ldy #0
|
||||
sta (screen),y
|
||||
inc screen
|
||||
bne !+
|
||||
inc screen+1
|
||||
!:
|
||||
inx
|
||||
cpx #3
|
||||
bne b1
|
||||
rts
|
||||
}
|
Loading…
Reference in New Issue
Block a user