1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-01-11 20:30:08 +00:00

Added test for #525 demonstrating problem with reuse of index*sizeof(). Added a fragment.

This commit is contained in:
jespergravgaard 2020-09-29 00:42:25 +02:00
parent 0a31136651
commit 8abaa95008
12 changed files with 2509 additions and 752 deletions

View File

@ -1,4 +1,4 @@
//KICKC FRAGMENT CACHE 12b00eb139 12b00ecab9
//KICKC FRAGMENT CACHE 132c9fe4d5 132c9ffe57
//FRAGMENT vbuz1=vbuc1
lda #{c1}
sta {z1}

View File

@ -1,4 +1,4 @@
//KICKC FRAGMENT CACHE 12b00eb139 12b00ecab9
//KICKC FRAGMENT CACHE 132c9fe4d5 132c9ffe57
//FRAGMENT _deref_pbuc1=vbuc2
lda #{c2}
sta {c1}

View File

@ -1,4 +1,4 @@
//KICKC FRAGMENT CACHE 12b00eb139 12b00ecab9
//KICKC FRAGMENT CACHE 132c9fe4d5 132c9ffe57
//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 12b00eb139 12b00ecab9
//KICKC FRAGMENT CACHE 132c9fe4d5 132c9ffe57
//FRAGMENT vbuz1=_deref_pbuc1
lda {c1}
sta {z1}

View File

@ -0,0 +1,2 @@
ldy {c1},x
sta ({z1}),y

View File

@ -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");

View File

@ -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;
}
}

View File

@ -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

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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 ]