1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-08 17:54:40 +00:00

Added test of struct array with 256+ structs.

This commit is contained in:
jespergravgaard 2019-06-10 22:58:15 +02:00
parent 56c33cdac2
commit 69278c458a
6 changed files with 1178 additions and 0 deletions

View File

@ -35,6 +35,11 @@ public class TestPrograms {
public TestPrograms() {
}
@Test
public void testStructPtr10() throws IOException, URISyntaxException {
compileAndCompare("struct-ptr-10");
}
@Test
public void testStructPtr9() throws IOException, URISyntaxException {
compileAndCompare("struct-ptr-9");

View File

@ -0,0 +1,19 @@
// Minimal struct - array with 256+ structs
struct Point {
byte x;
byte y;
};
struct Point[500] points;
void main() {
for( word i: 0..499) {
points[i] = { 2, (byte)i };
}
const struct Point* SCREEN = 0x0400;
for( word i: 0..499) {
SCREEN[i] = points[i];
}
}

View File

@ -0,0 +1,113 @@
// Minimal struct - array with 256+ structs
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.const OFFSET_STRUCT_POINT_Y = 1
main: {
.label SCREEN = $400
.label _3 = 6
.label _4 = $a
.label i = 2
.label i1 = 4
.label _11 = 8
.label _12 = 6
.label _13 = $c
.label _14 = $e
.label _15 = $10
.label _16 = $a
lda #<0
sta i
sta i+1
b1:
lda i
tax
asl
sta _3
lda i+1
rol
sta _3+1
lda _3
clc
adc #<points
sta _11
lda _3+1
adc #>points
sta _11+1
lda #2
ldy #0
sta (_11),y
clc
lda _12
adc #<points+OFFSET_STRUCT_POINT_Y
sta _12
lda _12+1
adc #>points+OFFSET_STRUCT_POINT_Y
sta _12+1
txa
sta (_12),y
inc i
bne !+
inc i+1
!:
lda i+1
cmp #>$1f4
bne b1
lda i
cmp #<$1f4
bne b1
lda #<0
sta i1
sta i1+1
b2:
lda i1
asl
sta _4
lda i1+1
rol
sta _4+1
lda _4
clc
adc #<points
sta _13
lda _4+1
adc #>points
sta _13+1
lda _4
clc
adc #<SCREEN
sta _14
lda _4+1
adc #>SCREEN
sta _14+1
ldy #0
lda (_13),y
sta (_14),y
lda _4
clc
adc #<points+OFFSET_STRUCT_POINT_Y
sta _15
lda _4+1
adc #>points+OFFSET_STRUCT_POINT_Y
sta _15+1
clc
lda _16
adc #<SCREEN+OFFSET_STRUCT_POINT_Y
sta _16
lda _16+1
adc #>SCREEN+OFFSET_STRUCT_POINT_Y
sta _16+1
lda (_15),y
sta (_16),y
inc i1
bne !+
inc i1+1
!:
lda i1+1
cmp #>$1f4
bne b2
lda i1
cmp #<$1f4
bne b2
rts
}
points: .fill 2*$1f4, 0

View File

@ -0,0 +1,38 @@
@begin: scope:[] from
[0] phi()
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
main: scope:[main] from @1
[4] phi()
to:main::@1
main::@1: scope:[main] from main main::@1
[5] (word) main::i#2 ← phi( main/(word) 0 main::@1/(word) main::i#1 )
[6] (byte~) main::$0 ← (byte)(word) main::i#2
[7] (word~) main::$3 ← (word) main::i#2 << (byte) 1
[8] (byte*~) main::$11 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$3
[9] *((byte*~) main::$11) ← (byte) 2
[10] (byte*~) main::$12 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$3
[11] *((byte*~) main::$12) ← (byte~) main::$0
[12] (word) main::i#1 ← ++ (word) main::i#2
[13] if((word) main::i#1!=(word) $1f4) goto main::@1
to:main::@2
main::@2: scope:[main] from main::@1 main::@2
[14] (word) main::i1#2 ← phi( main::@1/(word) 0 main::@2/(word) main::i1#1 )
[15] (word~) main::$4 ← (word) main::i1#2 << (byte) 1
[16] (byte*~) main::$13 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$4
[17] (byte*~) main::$14 ← (byte*)(const struct Point*) main::SCREEN#0 + (word~) main::$4
[18] *((byte*~) main::$14) ← *((byte*~) main::$13)
[19] (byte*~) main::$15 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4
[20] (byte*~) main::$16 ← (byte*)(const struct Point*) main::SCREEN#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4
[21] *((byte*~) main::$16) ← *((byte*~) main::$15)
[22] (word) main::i1#1 ← ++ (word) main::i1#2
[23] if((word) main::i1#1!=(word) $1f4) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@2
[24] return
to:@return

View File

@ -0,0 +1,964 @@
Fixing pointer array-indexing *((struct Point[$1f4]) points + (word) main::i)
Fixing pointer array-indexing *((struct Point[$1f4]) points + (word) main::i1)
Fixing pointer array-indexing *((struct Point*) main::SCREEN + (word) main::i1)
Adding struct value list initializer *((byte*) main::$5 + (word~) main::$3) ← (number) 2
Adding struct value list initializer *((byte*) main::$6 + (word~) main::$3) ← (byte~) main::$0
Adding struct value member variable copy *((byte*) main::$7 + (word~) main::$4) ← *((byte*) main::$8 + (word~) main::$4)
Adding struct value member variable copy *((byte*) main::$9 + (word~) main::$4) ← *((byte*) main::$10 + (word~) main::$4)
Adding pointer type conversion cast (struct Point*) main::SCREEN in (struct Point*) main::SCREEN ← (number) $400
Culled Empty Block (label) main::@4
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
(struct Point[$1f4]) points#0 ← { fill( $1f4, 0) }
to:@1
main: scope:[main] from @1
(word) main::i#0 ← (word) 0
to:main::@1
main::@1: scope:[main] from main main::@1
(word) main::i#2 ← phi( main/(word) main::i#0 main::@1/(word) main::i#1 )
(byte~) main::$0 ← ((byte)) (word) main::i#2
(word~) main::$3 ← (word) main::i#2 * (const byte) SIZEOF_STRUCT_POINT
(byte*) main::$5 ← (byte*)(struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_X
*((byte*) main::$5 + (word~) main::$3) ← (number) 2
(byte*) main::$6 ← (byte*)(struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
*((byte*) main::$6 + (word~) main::$3) ← (byte~) main::$0
(word) main::i#1 ← (word) main::i#2 + rangenext(0,$1f3)
(bool~) main::$1 ← (word) main::i#1 != rangelast(0,$1f3)
if((bool~) main::$1) goto main::@1
to:main::@2
main::@2: scope:[main] from main::@1
(struct Point*) main::SCREEN#0 ← ((struct Point*)) (number) $400
(word) main::i1#0 ← (word) 0
to:main::@3
main::@3: scope:[main] from main::@2 main::@3
(word) main::i1#2 ← phi( main::@2/(word) main::i1#0 main::@3/(word) main::i1#1 )
(word~) main::$4 ← (word) main::i1#2 * (const byte) SIZEOF_STRUCT_POINT
(byte*) main::$7 ← (byte*)(struct Point*) main::SCREEN#0 + (const byte) OFFSET_STRUCT_POINT_X
(byte*) main::$8 ← (byte*)(struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_X
*((byte*) main::$7 + (word~) main::$4) ← *((byte*) main::$8 + (word~) main::$4)
(byte*) main::$9 ← (byte*)(struct Point*) main::SCREEN#0 + (const byte) OFFSET_STRUCT_POINT_Y
(byte*) main::$10 ← (byte*)(struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
*((byte*) main::$9 + (word~) main::$4) ← *((byte*) main::$10 + (word~) main::$4)
(word) main::i1#1 ← (word) main::i1#2 + rangenext(0,$1f3)
(bool~) main::$2 ← (word) main::i1#1 != rangelast(0,$1f3)
if((bool~) main::$2) goto main::@3
to:main::@return
main::@return: scope:[main] from main::@3
return
to:@return
@1: scope:[] from @begin
call main
to:@2
@2: scope:[] from @1
to:@end
@end: scope:[] from @2
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte) OFFSET_STRUCT_POINT_X = (byte) 0
(const byte) OFFSET_STRUCT_POINT_Y = (byte) 1
(byte) Point::x
(byte) Point::y
(const byte) SIZEOF_STRUCT_POINT = (byte) 2
(void()) main()
(byte~) main::$0
(bool~) main::$1
(byte*) main::$10
(bool~) main::$2
(word~) main::$3
(word~) main::$4
(byte*) main::$5
(byte*) main::$6
(byte*) main::$7
(byte*) main::$8
(byte*) main::$9
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(struct Point*) main::SCREEN
(struct Point*) main::SCREEN#0
(word) main::i
(word) main::i#0
(word) main::i#1
(word) main::i#2
(word) main::i1
(word) main::i1#0
(word) main::i1#1
(word) main::i1#2
(struct Point[$1f4]) points
(struct Point[$1f4]) points#0
Adding number conversion cast (unumber) 2 in *((byte*) main::$5 + (word~) main::$3) ← (number) 2
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte~) main::$0 ← (byte)(word) main::i#2
Inlining cast *((byte*) main::$5 + (word~) main::$3) ← (unumber)(number) 2
Inlining cast (struct Point*) main::SCREEN#0 ← (struct Point*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant integer cast 2
Simplifying constant pointer cast (struct Point*) 1024
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition (bool~) main::$1 [11] if((word) main::i#1!=rangelast(0,$1f3)) goto main::@1
Simple Condition (bool~) main::$2 [24] if((word) main::i1#1!=rangelast(0,$1f3)) goto main::@3
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [0] (struct Point[$1f4]) points#0 ← { fill( $1f4, 0) }
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const struct Point[$1f4]) points#0 = { fill( $1f4, 0) }
Constant (const word) main::i#0 = 0
Constant (const struct Point*) main::SCREEN#0 = (struct Point*) 1024
Constant (const word) main::i1#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Constant value identified (byte*)points#0 in [5] (byte*) main::$5 ← (byte*)(const struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_X
Constant value identified (byte*)points#0 in [7] (byte*) main::$6 ← (byte*)(const struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
Constant value identified (byte*)main::SCREEN#0 in [16] (byte*) main::$7 ← (byte*)(const struct Point*) main::SCREEN#0 + (const byte) OFFSET_STRUCT_POINT_X
Constant value identified (byte*)points#0 in [17] (byte*) main::$8 ← (byte*)(const struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_X
Constant value identified (byte*)main::SCREEN#0 in [19] (byte*) main::$9 ← (byte*)(const struct Point*) main::SCREEN#0 + (const byte) OFFSET_STRUCT_POINT_Y
Constant value identified (byte*)points#0 in [20] (byte*) main::$10 ← (byte*)(const struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
Successful SSA optimization Pass2ConstantValues
Resolved ranged next value [9] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [11] if(main::i#1!=rangelast(0,$1f3)) goto main::@1 to (number) $1f4
Resolved ranged next value [22] main::i1#1 ← ++ main::i1#2 to ++
Resolved ranged comparison value [24] if(main::i1#1!=rangelast(0,$1f3)) goto main::@3 to (number) $1f4
De-inlining pointer[w] to *(pointer+w) [6] *((byte*) main::$5 + (word~) main::$3) ← (byte) 2
De-inlining pointer[w] to *(pointer+w) [8] *((byte*) main::$6 + (word~) main::$3) ← (byte~) main::$0
De-inlining pointer[w] to *(pointer+w) [18] *((byte*) main::$7 + (word~) main::$4) ← *((byte*) main::$8 + (word~) main::$4)
De-inlining pointer[w] to *(pointer+w) [18] *((byte*) main::$7 + (word~) main::$4) ← *((byte*~) main::$13)
De-inlining pointer[w] to *(pointer+w) [21] *((byte*) main::$9 + (word~) main::$4) ← *((byte*) main::$10 + (word~) main::$4)
De-inlining pointer[w] to *(pointer+w) [21] *((byte*) main::$9 + (word~) main::$4) ← *((byte*~) main::$15)
Successful SSA optimization Pass2DeInlineWordDerefIdx
Simplifying expression containing zero (byte*)points#0 in [5] (byte*) main::$5 ← (byte*)(const struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_X
Simplifying expression containing zero (byte*)main::SCREEN#0 in [16] (byte*) main::$7 ← (byte*)(const struct Point*) main::SCREEN#0 + (const byte) OFFSET_STRUCT_POINT_X
Simplifying expression containing zero (byte*)points#0 in [17] (byte*) main::$8 ← (byte*)(const struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_X
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant (const byte) OFFSET_STRUCT_POINT_X
Successful SSA optimization PassNEliminateUnusedVars
Adding number conversion cast (unumber) $1f4 in if((word) main::i#1!=(number) $1f4) goto main::@1
Adding number conversion cast (unumber) $1f4 in if((word) main::i1#1!=(number) $1f4) goto main::@3
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $1f4
Simplifying constant integer cast $1f4
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $1f4
Finalized unsigned number type (word) $1f4
Successful SSA optimization PassNFinalizeNumberTypeConversions
Constant right-side identified [6] (byte*) main::$6 ← (byte*)(const struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
Constant right-side identified [18] (byte*) main::$9 ← (byte*)(const struct Point*) main::SCREEN#0 + (const byte) OFFSET_STRUCT_POINT_Y
Constant right-side identified [19] (byte*) main::$10 ← (byte*)(const struct Point[$1f4]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte*) main::$5 = (byte*)points#0
Constant (const byte*) main::$6 = (byte*)points#0+OFFSET_STRUCT_POINT_Y
Constant (const byte*) main::$7 = (byte*)main::SCREEN#0
Constant (const byte*) main::$8 = (byte*)points#0
Constant (const byte*) main::$9 = (byte*)main::SCREEN#0+OFFSET_STRUCT_POINT_Y
Constant (const byte*) main::$10 = (byte*)points#0+OFFSET_STRUCT_POINT_Y
Successful SSA optimization Pass2ConstantIdentification
Rewriting multiplication to use shift [2] (word~) main::$3 ← (word) main::i#2 * (const byte) SIZEOF_STRUCT_POINT
Rewriting multiplication to use shift [10] (word~) main::$4 ← (word) main::i1#2 * (const byte) SIZEOF_STRUCT_POINT
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const word) main::i#0
Inlining constant with var siblings (const word) main::i1#0
Constant inlined main::$5 = (byte*)(const struct Point[$1f4]) points#0
Constant inlined main::i#0 = (word) 0
Constant inlined main::i1#0 = (word) 0
Constant inlined main::$6 = (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y
Constant inlined main::$9 = (byte*)(const struct Point*) main::SCREEN#0+(const byte) OFFSET_STRUCT_POINT_Y
Constant inlined main::$7 = (byte*)(const struct Point*) main::SCREEN#0
Constant inlined main::$10 = (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y
Constant inlined main::$8 = (byte*)(const struct Point[$1f4]) points#0
Successful SSA optimization Pass2ConstantInlining
Eliminating unused constant (const byte) SIZEOF_STRUCT_POINT
Successful SSA optimization PassNEliminateUnusedVars
Added new block during phi lifting main::@5(between main::@1 and main::@1)
Added new block during phi lifting main::@6(between main::@3 and main::@3)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@2
CALL GRAPH
Calls in [] to main:2
Created 2 initial phi equivalence classes
Coalesced [27] main::i1#3 ← main::i1#1
Coalesced [28] main::i#3 ← main::i#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@2
Culled Empty Block (label) main::@6
Culled Empty Block (label) main::@5
Renumbering block main::@3 to main::@2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
[0] phi()
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
main: scope:[main] from @1
[4] phi()
to:main::@1
main::@1: scope:[main] from main main::@1
[5] (word) main::i#2 ← phi( main/(word) 0 main::@1/(word) main::i#1 )
[6] (byte~) main::$0 ← (byte)(word) main::i#2
[7] (word~) main::$3 ← (word) main::i#2 << (byte) 1
[8] (byte*~) main::$11 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$3
[9] *((byte*~) main::$11) ← (byte) 2
[10] (byte*~) main::$12 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$3
[11] *((byte*~) main::$12) ← (byte~) main::$0
[12] (word) main::i#1 ← ++ (word) main::i#2
[13] if((word) main::i#1!=(word) $1f4) goto main::@1
to:main::@2
main::@2: scope:[main] from main::@1 main::@2
[14] (word) main::i1#2 ← phi( main::@1/(word) 0 main::@2/(word) main::i1#1 )
[15] (word~) main::$4 ← (word) main::i1#2 << (byte) 1
[16] (byte*~) main::$13 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$4
[17] (byte*~) main::$14 ← (byte*)(const struct Point*) main::SCREEN#0 + (word~) main::$4
[18] *((byte*~) main::$14) ← *((byte*~) main::$13)
[19] (byte*~) main::$15 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4
[20] (byte*~) main::$16 ← (byte*)(const struct Point*) main::SCREEN#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4
[21] *((byte*~) main::$16) ← *((byte*~) main::$15)
[22] (word) main::i1#1 ← ++ (word) main::i1#2
[23] if((word) main::i1#1!=(word) $1f4) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@2
[24] return
to:@return
VARIABLE REGISTER WEIGHTS
(byte) Point::x
(byte) Point::y
(void()) main()
(byte~) main::$0 4.4
(byte*~) main::$11 22.0
(byte*~) main::$12 22.0
(byte*~) main::$13 11.0
(byte*~) main::$14 22.0
(byte*~) main::$15 11.0
(byte*~) main::$16 22.0
(word~) main::$3 11.0
(word~) main::$4 11.0
(struct Point*) main::SCREEN
(word) main::i
(word) main::i#1 16.5
(word) main::i#2 4.714285714285714
(word) main::i1
(word) main::i1#1 16.5
(word) main::i1#2 4.125
(struct Point[$1f4]) points
Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::i1#2 main::i1#1 ]
Added variable main::$0 to zero page equivalence class [ main::$0 ]
Added variable main::$3 to zero page equivalence class [ main::$3 ]
Added variable main::$11 to zero page equivalence class [ main::$11 ]
Added variable main::$12 to zero page equivalence class [ main::$12 ]
Added variable main::$4 to zero page equivalence class [ main::$4 ]
Added variable main::$13 to zero page equivalence class [ main::$13 ]
Added variable main::$14 to zero page equivalence class [ main::$14 ]
Added variable main::$15 to zero page equivalence class [ main::$15 ]
Added variable main::$16 to zero page equivalence class [ main::$16 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::i1#2 main::i1#1 ]
[ main::$0 ]
[ main::$3 ]
[ main::$11 ]
[ main::$12 ]
[ main::$4 ]
[ main::$13 ]
[ main::$14 ]
[ main::$15 ]
[ main::$16 ]
Allocated zp ZP_WORD:2 [ main::i#2 main::i#1 ]
Allocated zp ZP_WORD:4 [ main::i1#2 main::i1#1 ]
Allocated zp ZP_BYTE:6 [ main::$0 ]
Allocated zp ZP_WORD:7 [ main::$3 ]
Allocated zp ZP_WORD:9 [ main::$11 ]
Allocated zp ZP_WORD:11 [ main::$12 ]
Allocated zp ZP_WORD:13 [ main::$4 ]
Allocated zp ZP_WORD:15 [ main::$13 ]
Allocated zp ZP_WORD:17 [ main::$14 ]
Allocated zp ZP_WORD:19 [ main::$15 ]
Allocated zp ZP_WORD:21 [ main::$16 ]
INITIAL ASM
//SEG0 File Comments
// Minimal struct - array with 256+ structs
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
.const OFFSET_STRUCT_POINT_Y = 1
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
jmp b1
//SEG5 @1
b1:
//SEG6 [2] call main
//SEG7 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
jsr main
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
.label SCREEN = $400
.label _0 = 6
.label _3 = 7
.label _4 = $d
.label i = 2
.label i1 = 4
.label _11 = 9
.label _12 = $b
.label _13 = $f
.label _14 = $11
.label _15 = $13
.label _16 = $15
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
//SEG12 [5] phi (word) main::i#2 = (word) 0 [phi:main->main::@1#0] -- vwuz1=vwuc1
lda #<0
sta i
lda #>0
sta i+1
jmp b1
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
b1_from_b1:
//SEG14 [5] phi (word) main::i#2 = (word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
jmp b1
//SEG15 main::@1
b1:
//SEG16 [6] (byte~) main::$0 ← (byte)(word) main::i#2 -- vbuz1=_byte_vwuz2
lda i
sta _0
//SEG17 [7] (word~) main::$3 ← (word) main::i#2 << (byte) 1 -- vwuz1=vwuz2_rol_1
lda i
asl
sta _3
lda i+1
rol
sta _3+1
//SEG18 [8] (byte*~) main::$11 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$3 -- pbuz1=pbuc1_plus_vwuz2
lda _3
clc
adc #<points
sta _11
lda _3+1
adc #>points
sta _11+1
//SEG19 [9] *((byte*~) main::$11) ← (byte) 2 -- _deref_pbuz1=vbuc1
lda #2
ldy #0
sta (_11),y
//SEG20 [10] (byte*~) main::$12 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$3 -- pbuz1=pbuc1_plus_vwuz2
lda _3
clc
adc #<points+OFFSET_STRUCT_POINT_Y
sta _12
lda _3+1
adc #>points+OFFSET_STRUCT_POINT_Y
sta _12+1
//SEG21 [11] *((byte*~) main::$12) ← (byte~) main::$0 -- _deref_pbuz1=vbuz2
lda _0
ldy #0
sta (_12),y
//SEG22 [12] (word) main::i#1 ← ++ (word) main::i#2 -- vwuz1=_inc_vwuz1
inc i
bne !+
inc i+1
!:
//SEG23 [13] if((word) main::i#1!=(word) $1f4) goto main::@1 -- vwuz1_neq_vwuc1_then_la1
lda i+1
cmp #>$1f4
bne b1_from_b1
lda i
cmp #<$1f4
bne b1_from_b1
//SEG24 [14] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
b2_from_b1:
//SEG25 [14] phi (word) main::i1#2 = (word) 0 [phi:main::@1->main::@2#0] -- vwuz1=vwuc1
lda #<0
sta i1
lda #>0
sta i1+1
jmp b2
//SEG26 [14] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
b2_from_b2:
//SEG27 [14] phi (word) main::i1#2 = (word) main::i1#1 [phi:main::@2->main::@2#0] -- register_copy
jmp b2
//SEG28 main::@2
b2:
//SEG29 [15] (word~) main::$4 ← (word) main::i1#2 << (byte) 1 -- vwuz1=vwuz2_rol_1
lda i1
asl
sta _4
lda i1+1
rol
sta _4+1
//SEG30 [16] (byte*~) main::$13 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz2
lda _4
clc
adc #<points
sta _13
lda _4+1
adc #>points
sta _13+1
//SEG31 [17] (byte*~) main::$14 ← (byte*)(const struct Point*) main::SCREEN#0 + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz2
lda _4
clc
adc #<SCREEN
sta _14
lda _4+1
adc #>SCREEN
sta _14+1
//SEG32 [18] *((byte*~) main::$14) ← *((byte*~) main::$13) -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (_13),y
ldy #0
sta (_14),y
//SEG33 [19] (byte*~) main::$15 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz2
lda _4
clc
adc #<points+OFFSET_STRUCT_POINT_Y
sta _15
lda _4+1
adc #>points+OFFSET_STRUCT_POINT_Y
sta _15+1
//SEG34 [20] (byte*~) main::$16 ← (byte*)(const struct Point*) main::SCREEN#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz2
lda _4
clc
adc #<SCREEN+OFFSET_STRUCT_POINT_Y
sta _16
lda _4+1
adc #>SCREEN+OFFSET_STRUCT_POINT_Y
sta _16+1
//SEG35 [21] *((byte*~) main::$16) ← *((byte*~) main::$15) -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (_15),y
ldy #0
sta (_16),y
//SEG36 [22] (word) main::i1#1 ← ++ (word) main::i1#2 -- vwuz1=_inc_vwuz1
inc i1
bne !+
inc i1+1
!:
//SEG37 [23] if((word) main::i1#1!=(word) $1f4) goto main::@2 -- vwuz1_neq_vwuc1_then_la1
lda i1+1
cmp #>$1f4
bne b2_from_b2
lda i1
cmp #<$1f4
bne b2_from_b2
jmp breturn
//SEG38 main::@return
breturn:
//SEG39 [24] return
rts
}
points: .fill 2*$1f4, 0
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (byte~) main::$0 ← (byte)(word) main::i#2 [ main::i#2 main::$0 ] ( main:2 [ main::i#2 main::$0 ] ) always clobbers reg byte a
Statement [7] (word~) main::$3 ← (word) main::i#2 << (byte) 1 [ main::i#2 main::$0 main::$3 ] ( main:2 [ main::i#2 main::$0 main::$3 ] ) always clobbers reg byte a
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:6 [ main::$0 ]
Statement [8] (byte*~) main::$11 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$3 [ main::i#2 main::$0 main::$3 main::$11 ] ( main:2 [ main::i#2 main::$0 main::$3 main::$11 ] ) always clobbers reg byte a
Statement [9] *((byte*~) main::$11) ← (byte) 2 [ main::i#2 main::$0 main::$3 ] ( main:2 [ main::i#2 main::$0 main::$3 ] ) always clobbers reg byte a reg byte y
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:6 [ main::$0 ]
Statement [10] (byte*~) main::$12 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$3 [ main::i#2 main::$0 main::$12 ] ( main:2 [ main::i#2 main::$0 main::$12 ] ) always clobbers reg byte a
Statement [11] *((byte*~) main::$12) ← (byte~) main::$0 [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a reg byte y
Statement [13] if((word) main::i#1!=(word) $1f4) goto main::@1 [ main::i#1 ] ( main:2 [ main::i#1 ] ) always clobbers reg byte a
Statement [15] (word~) main::$4 ← (word) main::i1#2 << (byte) 1 [ main::i1#2 main::$4 ] ( main:2 [ main::i1#2 main::$4 ] ) always clobbers reg byte a
Statement [16] (byte*~) main::$13 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$4 [ main::i1#2 main::$4 main::$13 ] ( main:2 [ main::i1#2 main::$4 main::$13 ] ) always clobbers reg byte a
Statement [17] (byte*~) main::$14 ← (byte*)(const struct Point*) main::SCREEN#0 + (word~) main::$4 [ main::i1#2 main::$4 main::$13 main::$14 ] ( main:2 [ main::i1#2 main::$4 main::$13 main::$14 ] ) always clobbers reg byte a
Statement [18] *((byte*~) main::$14) ← *((byte*~) main::$13) [ main::i1#2 main::$4 ] ( main:2 [ main::i1#2 main::$4 ] ) always clobbers reg byte a reg byte y
Statement [19] (byte*~) main::$15 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4 [ main::i1#2 main::$4 main::$15 ] ( main:2 [ main::i1#2 main::$4 main::$15 ] ) always clobbers reg byte a
Statement [20] (byte*~) main::$16 ← (byte*)(const struct Point*) main::SCREEN#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4 [ main::i1#2 main::$15 main::$16 ] ( main:2 [ main::i1#2 main::$15 main::$16 ] ) always clobbers reg byte a
Statement [21] *((byte*~) main::$16) ← *((byte*~) main::$15) [ main::i1#2 ] ( main:2 [ main::i1#2 ] ) always clobbers reg byte a reg byte y
Statement [23] if((word) main::i1#1!=(word) $1f4) goto main::@2 [ main::i1#1 ] ( main:2 [ main::i1#1 ] ) always clobbers reg byte a
Statement [6] (byte~) main::$0 ← (byte)(word) main::i#2 [ main::i#2 main::$0 ] ( main:2 [ main::i#2 main::$0 ] ) always clobbers reg byte a
Statement [7] (word~) main::$3 ← (word) main::i#2 << (byte) 1 [ main::i#2 main::$0 main::$3 ] ( main:2 [ main::i#2 main::$0 main::$3 ] ) always clobbers reg byte a
Statement [8] (byte*~) main::$11 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$3 [ main::i#2 main::$0 main::$3 main::$11 ] ( main:2 [ main::i#2 main::$0 main::$3 main::$11 ] ) always clobbers reg byte a
Statement [9] *((byte*~) main::$11) ← (byte) 2 [ main::i#2 main::$0 main::$3 ] ( main:2 [ main::i#2 main::$0 main::$3 ] ) always clobbers reg byte a reg byte y
Statement [10] (byte*~) main::$12 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$3 [ main::i#2 main::$0 main::$12 ] ( main:2 [ main::i#2 main::$0 main::$12 ] ) always clobbers reg byte a
Statement [11] *((byte*~) main::$12) ← (byte~) main::$0 [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a reg byte y
Statement [13] if((word) main::i#1!=(word) $1f4) goto main::@1 [ main::i#1 ] ( main:2 [ main::i#1 ] ) always clobbers reg byte a
Statement [15] (word~) main::$4 ← (word) main::i1#2 << (byte) 1 [ main::i1#2 main::$4 ] ( main:2 [ main::i1#2 main::$4 ] ) always clobbers reg byte a
Statement [16] (byte*~) main::$13 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$4 [ main::i1#2 main::$4 main::$13 ] ( main:2 [ main::i1#2 main::$4 main::$13 ] ) always clobbers reg byte a
Statement [17] (byte*~) main::$14 ← (byte*)(const struct Point*) main::SCREEN#0 + (word~) main::$4 [ main::i1#2 main::$4 main::$13 main::$14 ] ( main:2 [ main::i1#2 main::$4 main::$13 main::$14 ] ) always clobbers reg byte a
Statement [18] *((byte*~) main::$14) ← *((byte*~) main::$13) [ main::i1#2 main::$4 ] ( main:2 [ main::i1#2 main::$4 ] ) always clobbers reg byte a reg byte y
Statement [19] (byte*~) main::$15 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4 [ main::i1#2 main::$4 main::$15 ] ( main:2 [ main::i1#2 main::$4 main::$15 ] ) always clobbers reg byte a
Statement [20] (byte*~) main::$16 ← (byte*)(const struct Point*) main::SCREEN#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4 [ main::i1#2 main::$15 main::$16 ] ( main:2 [ main::i1#2 main::$15 main::$16 ] ) always clobbers reg byte a
Statement [21] *((byte*~) main::$16) ← *((byte*~) main::$15) [ main::i1#2 ] ( main:2 [ main::i1#2 ] ) always clobbers reg byte a reg byte y
Statement [23] if((word) main::i1#1!=(word) $1f4) goto main::@2 [ main::i1#1 ] ( main:2 [ main::i1#1 ] ) always clobbers reg byte a
Potential registers zp ZP_WORD:2 [ main::i#2 main::i#1 ] : zp ZP_WORD:2 ,
Potential registers zp ZP_WORD:4 [ main::i1#2 main::i1#1 ] : zp ZP_WORD:4 ,
Potential registers zp ZP_BYTE:6 [ main::$0 ] : zp ZP_BYTE:6 , reg byte x ,
Potential registers zp ZP_WORD:7 [ main::$3 ] : zp ZP_WORD:7 ,
Potential registers zp ZP_WORD:9 [ main::$11 ] : zp ZP_WORD:9 ,
Potential registers zp ZP_WORD:11 [ main::$12 ] : zp ZP_WORD:11 ,
Potential registers zp ZP_WORD:13 [ main::$4 ] : zp ZP_WORD:13 ,
Potential registers zp ZP_WORD:15 [ main::$13 ] : zp ZP_WORD:15 ,
Potential registers zp ZP_WORD:17 [ main::$14 ] : zp ZP_WORD:17 ,
Potential registers zp ZP_WORD:19 [ main::$15 ] : zp ZP_WORD:19 ,
Potential registers zp ZP_WORD:21 [ main::$16 ] : zp ZP_WORD:21 ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 22: zp ZP_WORD:9 [ main::$11 ] 22: zp ZP_WORD:11 [ main::$12 ] 22: zp ZP_WORD:17 [ main::$14 ] 22: zp ZP_WORD:21 [ main::$16 ] 21.21: zp ZP_WORD:2 [ main::i#2 main::i#1 ] 20.62: zp ZP_WORD:4 [ main::i1#2 main::i1#1 ] 11: zp ZP_WORD:7 [ main::$3 ] 11: zp ZP_WORD:13 [ main::$4 ] 11: zp ZP_WORD:15 [ main::$13 ] 11: zp ZP_WORD:19 [ main::$15 ] 4.4: zp ZP_BYTE:6 [ main::$0 ]
Uplift Scope [Point]
Uplift Scope []
Uplifting [main] best 2878 combination zp ZP_WORD:9 [ main::$11 ] zp ZP_WORD:11 [ main::$12 ] zp ZP_WORD:17 [ main::$14 ] zp ZP_WORD:21 [ main::$16 ] zp ZP_WORD:2 [ main::i#2 main::i#1 ] zp ZP_WORD:4 [ main::i1#2 main::i1#1 ] zp ZP_WORD:7 [ main::$3 ] zp ZP_WORD:13 [ main::$4 ] zp ZP_WORD:15 [ main::$13 ] zp ZP_WORD:19 [ main::$15 ] reg byte x [ main::$0 ]
Uplifting [Point] best 2878 combination
Uplifting [] best 2878 combination
Coalescing zero page register with common assignment [ zp ZP_WORD:7 [ main::$3 ] ] with [ zp ZP_WORD:11 [ main::$12 ] ] - score: 1
Coalescing zero page register with common assignment [ zp ZP_WORD:13 [ main::$4 ] ] with [ zp ZP_WORD:21 [ main::$16 ] ] - score: 1
Allocated (was zp ZP_WORD:7) zp ZP_WORD:6 [ main::$3 main::$12 ]
Allocated (was zp ZP_WORD:9) zp ZP_WORD:8 [ main::$11 ]
Allocated (was zp ZP_WORD:13) zp ZP_WORD:10 [ main::$4 main::$16 ]
Allocated (was zp ZP_WORD:15) zp ZP_WORD:12 [ main::$13 ]
Allocated (was zp ZP_WORD:17) zp ZP_WORD:14 [ main::$14 ]
Allocated (was zp ZP_WORD:19) zp ZP_WORD:16 [ main::$15 ]
ASSEMBLER BEFORE OPTIMIZATION
//SEG0 File Comments
// Minimal struct - array with 256+ structs
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
.const OFFSET_STRUCT_POINT_Y = 1
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
jmp b1
//SEG5 @1
b1:
//SEG6 [2] call main
//SEG7 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
jsr main
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
.label SCREEN = $400
.label _3 = 6
.label _4 = $a
.label i = 2
.label i1 = 4
.label _11 = 8
.label _12 = 6
.label _13 = $c
.label _14 = $e
.label _15 = $10
.label _16 = $a
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
//SEG12 [5] phi (word) main::i#2 = (word) 0 [phi:main->main::@1#0] -- vwuz1=vwuc1
lda #<0
sta i
lda #>0
sta i+1
jmp b1
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
b1_from_b1:
//SEG14 [5] phi (word) main::i#2 = (word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
jmp b1
//SEG15 main::@1
b1:
//SEG16 [6] (byte~) main::$0 ← (byte)(word) main::i#2 -- vbuxx=_byte_vwuz1
lda i
tax
//SEG17 [7] (word~) main::$3 ← (word) main::i#2 << (byte) 1 -- vwuz1=vwuz2_rol_1
lda i
asl
sta _3
lda i+1
rol
sta _3+1
//SEG18 [8] (byte*~) main::$11 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$3 -- pbuz1=pbuc1_plus_vwuz2
lda _3
clc
adc #<points
sta _11
lda _3+1
adc #>points
sta _11+1
//SEG19 [9] *((byte*~) main::$11) ← (byte) 2 -- _deref_pbuz1=vbuc1
lda #2
ldy #0
sta (_11),y
//SEG20 [10] (byte*~) main::$12 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$3 -- pbuz1=pbuc1_plus_vwuz1
clc
lda _12
adc #<points+OFFSET_STRUCT_POINT_Y
sta _12
lda _12+1
adc #>points+OFFSET_STRUCT_POINT_Y
sta _12+1
//SEG21 [11] *((byte*~) main::$12) ← (byte~) main::$0 -- _deref_pbuz1=vbuxx
txa
ldy #0
sta (_12),y
//SEG22 [12] (word) main::i#1 ← ++ (word) main::i#2 -- vwuz1=_inc_vwuz1
inc i
bne !+
inc i+1
!:
//SEG23 [13] if((word) main::i#1!=(word) $1f4) goto main::@1 -- vwuz1_neq_vwuc1_then_la1
lda i+1
cmp #>$1f4
bne b1_from_b1
lda i
cmp #<$1f4
bne b1_from_b1
//SEG24 [14] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
b2_from_b1:
//SEG25 [14] phi (word) main::i1#2 = (word) 0 [phi:main::@1->main::@2#0] -- vwuz1=vwuc1
lda #<0
sta i1
lda #>0
sta i1+1
jmp b2
//SEG26 [14] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
b2_from_b2:
//SEG27 [14] phi (word) main::i1#2 = (word) main::i1#1 [phi:main::@2->main::@2#0] -- register_copy
jmp b2
//SEG28 main::@2
b2:
//SEG29 [15] (word~) main::$4 ← (word) main::i1#2 << (byte) 1 -- vwuz1=vwuz2_rol_1
lda i1
asl
sta _4
lda i1+1
rol
sta _4+1
//SEG30 [16] (byte*~) main::$13 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz2
lda _4
clc
adc #<points
sta _13
lda _4+1
adc #>points
sta _13+1
//SEG31 [17] (byte*~) main::$14 ← (byte*)(const struct Point*) main::SCREEN#0 + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz2
lda _4
clc
adc #<SCREEN
sta _14
lda _4+1
adc #>SCREEN
sta _14+1
//SEG32 [18] *((byte*~) main::$14) ← *((byte*~) main::$13) -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (_13),y
ldy #0
sta (_14),y
//SEG33 [19] (byte*~) main::$15 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz2
lda _4
clc
adc #<points+OFFSET_STRUCT_POINT_Y
sta _15
lda _4+1
adc #>points+OFFSET_STRUCT_POINT_Y
sta _15+1
//SEG34 [20] (byte*~) main::$16 ← (byte*)(const struct Point*) main::SCREEN#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz1
clc
lda _16
adc #<SCREEN+OFFSET_STRUCT_POINT_Y
sta _16
lda _16+1
adc #>SCREEN+OFFSET_STRUCT_POINT_Y
sta _16+1
//SEG35 [21] *((byte*~) main::$16) ← *((byte*~) main::$15) -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (_15),y
ldy #0
sta (_16),y
//SEG36 [22] (word) main::i1#1 ← ++ (word) main::i1#2 -- vwuz1=_inc_vwuz1
inc i1
bne !+
inc i1+1
!:
//SEG37 [23] if((word) main::i1#1!=(word) $1f4) goto main::@2 -- vwuz1_neq_vwuc1_then_la1
lda i1+1
cmp #>$1f4
bne b2_from_b2
lda i1
cmp #<$1f4
bne b2_from_b2
jmp breturn
//SEG38 main::@return
breturn:
//SEG39 [24] return
rts
}
points: .fill 2*$1f4, 0
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #>0
Removing instruction lda i
Removing instruction ldy #0
Removing instruction lda #>0
Removing instruction ldy #0
Removing instruction ldy #0
Removing instruction ldy #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label b1_from_b1 with b1
Replacing label b1_from_b1 with b1
Replacing label b2_from_b2 with b2
Replacing label b2_from_b2 with b2
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b1:
Removing instruction b2_from_b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction b2_from_b1:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp b1
Removing instruction jmp b2
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte) OFFSET_STRUCT_POINT_Y OFFSET_STRUCT_POINT_Y = (byte) 1
(byte) Point::x
(byte) Point::y
(void()) main()
(byte~) main::$0 reg byte x 4.4
(byte*~) main::$11 $11 zp ZP_WORD:8 22.0
(byte*~) main::$12 $12 zp ZP_WORD:6 22.0
(byte*~) main::$13 $13 zp ZP_WORD:12 11.0
(byte*~) main::$14 $14 zp ZP_WORD:14 22.0
(byte*~) main::$15 $15 zp ZP_WORD:16 11.0
(byte*~) main::$16 $16 zp ZP_WORD:10 22.0
(word~) main::$3 $3 zp ZP_WORD:6 11.0
(word~) main::$4 $4 zp ZP_WORD:10 11.0
(label) main::@1
(label) main::@2
(label) main::@return
(struct Point*) main::SCREEN
(const struct Point*) main::SCREEN#0 SCREEN = (struct Point*) 1024
(word) main::i
(word) main::i#1 i zp ZP_WORD:2 16.5
(word) main::i#2 i zp ZP_WORD:2 4.714285714285714
(word) main::i1
(word) main::i1#1 i1 zp ZP_WORD:4 16.5
(word) main::i1#2 i1 zp ZP_WORD:4 4.125
(struct Point[$1f4]) points
(const struct Point[$1f4]) points#0 points = { fill( $1f4, 0) }
zp ZP_WORD:2 [ main::i#2 main::i#1 ]
zp ZP_WORD:4 [ main::i1#2 main::i1#1 ]
reg byte x [ main::$0 ]
zp ZP_WORD:6 [ main::$3 main::$12 ]
zp ZP_WORD:8 [ main::$11 ]
zp ZP_WORD:10 [ main::$4 main::$16 ]
zp ZP_WORD:12 [ main::$13 ]
zp ZP_WORD:14 [ main::$14 ]
zp ZP_WORD:16 [ main::$15 ]
FINAL ASSEMBLER
Score: 2566
//SEG0 File Comments
// Minimal struct - array with 256+ structs
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG2 Global Constants & labels
.const OFFSET_STRUCT_POINT_Y = 1
//SEG3 @begin
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG5 @1
//SEG6 [2] call main
//SEG7 [4] phi from @1 to main [phi:@1->main]
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
//SEG9 @end
//SEG10 main
main: {
.label SCREEN = $400
.label _3 = 6
.label _4 = $a
.label i = 2
.label i1 = 4
.label _11 = 8
.label _12 = 6
.label _13 = $c
.label _14 = $e
.label _15 = $10
.label _16 = $a
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
//SEG12 [5] phi (word) main::i#2 = (word) 0 [phi:main->main::@1#0] -- vwuz1=vwuc1
lda #<0
sta i
sta i+1
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
//SEG14 [5] phi (word) main::i#2 = (word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
//SEG15 main::@1
b1:
//SEG16 [6] (byte~) main::$0 ← (byte)(word) main::i#2 -- vbuxx=_byte_vwuz1
lda i
tax
//SEG17 [7] (word~) main::$3 ← (word) main::i#2 << (byte) 1 -- vwuz1=vwuz2_rol_1
asl
sta _3
lda i+1
rol
sta _3+1
//SEG18 [8] (byte*~) main::$11 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$3 -- pbuz1=pbuc1_plus_vwuz2
lda _3
clc
adc #<points
sta _11
lda _3+1
adc #>points
sta _11+1
//SEG19 [9] *((byte*~) main::$11) ← (byte) 2 -- _deref_pbuz1=vbuc1
lda #2
ldy #0
sta (_11),y
//SEG20 [10] (byte*~) main::$12 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$3 -- pbuz1=pbuc1_plus_vwuz1
clc
lda _12
adc #<points+OFFSET_STRUCT_POINT_Y
sta _12
lda _12+1
adc #>points+OFFSET_STRUCT_POINT_Y
sta _12+1
//SEG21 [11] *((byte*~) main::$12) ← (byte~) main::$0 -- _deref_pbuz1=vbuxx
txa
sta (_12),y
//SEG22 [12] (word) main::i#1 ← ++ (word) main::i#2 -- vwuz1=_inc_vwuz1
inc i
bne !+
inc i+1
!:
//SEG23 [13] if((word) main::i#1!=(word) $1f4) goto main::@1 -- vwuz1_neq_vwuc1_then_la1
lda i+1
cmp #>$1f4
bne b1
lda i
cmp #<$1f4
bne b1
//SEG24 [14] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
//SEG25 [14] phi (word) main::i1#2 = (word) 0 [phi:main::@1->main::@2#0] -- vwuz1=vwuc1
lda #<0
sta i1
sta i1+1
//SEG26 [14] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
//SEG27 [14] phi (word) main::i1#2 = (word) main::i1#1 [phi:main::@2->main::@2#0] -- register_copy
//SEG28 main::@2
b2:
//SEG29 [15] (word~) main::$4 ← (word) main::i1#2 << (byte) 1 -- vwuz1=vwuz2_rol_1
lda i1
asl
sta _4
lda i1+1
rol
sta _4+1
//SEG30 [16] (byte*~) main::$13 ← (byte*)(const struct Point[$1f4]) points#0 + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz2
lda _4
clc
adc #<points
sta _13
lda _4+1
adc #>points
sta _13+1
//SEG31 [17] (byte*~) main::$14 ← (byte*)(const struct Point*) main::SCREEN#0 + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz2
lda _4
clc
adc #<SCREEN
sta _14
lda _4+1
adc #>SCREEN
sta _14+1
//SEG32 [18] *((byte*~) main::$14) ← *((byte*~) main::$13) -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (_13),y
sta (_14),y
//SEG33 [19] (byte*~) main::$15 ← (byte*)(const struct Point[$1f4]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz2
lda _4
clc
adc #<points+OFFSET_STRUCT_POINT_Y
sta _15
lda _4+1
adc #>points+OFFSET_STRUCT_POINT_Y
sta _15+1
//SEG34 [20] (byte*~) main::$16 ← (byte*)(const struct Point*) main::SCREEN#0+(const byte) OFFSET_STRUCT_POINT_Y + (word~) main::$4 -- pbuz1=pbuc1_plus_vwuz1
clc
lda _16
adc #<SCREEN+OFFSET_STRUCT_POINT_Y
sta _16
lda _16+1
adc #>SCREEN+OFFSET_STRUCT_POINT_Y
sta _16+1
//SEG35 [21] *((byte*~) main::$16) ← *((byte*~) main::$15) -- _deref_pbuz1=_deref_pbuz2
lda (_15),y
sta (_16),y
//SEG36 [22] (word) main::i1#1 ← ++ (word) main::i1#2 -- vwuz1=_inc_vwuz1
inc i1
bne !+
inc i1+1
!:
//SEG37 [23] if((word) main::i1#1!=(word) $1f4) goto main::@2 -- vwuz1_neq_vwuc1_then_la1
lda i1+1
cmp #>$1f4
bne b2
lda i1
cmp #<$1f4
bne b2
//SEG38 main::@return
//SEG39 [24] return
rts
}
points: .fill 2*$1f4, 0

View File

@ -0,0 +1,39 @@
(label) @1
(label) @begin
(label) @end
(const byte) OFFSET_STRUCT_POINT_Y OFFSET_STRUCT_POINT_Y = (byte) 1
(byte) Point::x
(byte) Point::y
(void()) main()
(byte~) main::$0 reg byte x 4.4
(byte*~) main::$11 $11 zp ZP_WORD:8 22.0
(byte*~) main::$12 $12 zp ZP_WORD:6 22.0
(byte*~) main::$13 $13 zp ZP_WORD:12 11.0
(byte*~) main::$14 $14 zp ZP_WORD:14 22.0
(byte*~) main::$15 $15 zp ZP_WORD:16 11.0
(byte*~) main::$16 $16 zp ZP_WORD:10 22.0
(word~) main::$3 $3 zp ZP_WORD:6 11.0
(word~) main::$4 $4 zp ZP_WORD:10 11.0
(label) main::@1
(label) main::@2
(label) main::@return
(struct Point*) main::SCREEN
(const struct Point*) main::SCREEN#0 SCREEN = (struct Point*) 1024
(word) main::i
(word) main::i#1 i zp ZP_WORD:2 16.5
(word) main::i#2 i zp ZP_WORD:2 4.714285714285714
(word) main::i1
(word) main::i1#1 i1 zp ZP_WORD:4 16.5
(word) main::i1#2 i1 zp ZP_WORD:4 4.125
(struct Point[$1f4]) points
(const struct Point[$1f4]) points#0 points = { fill( $1f4, 0) }
zp ZP_WORD:2 [ main::i#2 main::i#1 ]
zp ZP_WORD:4 [ main::i1#2 main::i1#1 ]
reg byte x [ main::$0 ]
zp ZP_WORD:6 [ main::$3 main::$12 ]
zp ZP_WORD:8 [ main::$11 ]
zp ZP_WORD:10 [ main::$4 main::$16 ]
zp ZP_WORD:12 [ main::$13 ]
zp ZP_WORD:14 [ main::$14 ]
zp ZP_WORD:16 [ main::$15 ]