1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-16 21:07:56 +00:00
kickc/src/test/ref/array-length-symbolic.log

607 lines
23 KiB
Plaintext
Raw Normal View History

2018-08-22 22:24:32 +00:00
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@1
(void()) main()
main: scope:[main] from @1
(byte*) main::cur_item#0 ← (const byte*) items
(byte) main::item#0 ← (byte) 0
to:main::@1
main::@1: scope:[main] from main main::@3
(byte*) main::cur_item#4 ← phi( main/(byte*) main::cur_item#0 main::@3/(byte*) main::cur_item#1 )
(byte) main::item#4 ← phi( main/(byte) main::item#0 main::@3/(byte) main::item#1 )
(byte) main::sub#0 ← (byte) 0
to:main::@2
main::@2: scope:[main] from main::@1 main::@2
(byte*) main::cur_item#2 ← phi( main::@1/(byte*) main::cur_item#4 main::@2/(byte*) main::cur_item#2 )
(byte) main::sub#2 ← phi( main::@1/(byte) main::sub#0 main::@2/(byte) main::sub#1 )
(byte) main::item#2 ← phi( main::@1/(byte) main::item#4 main::@2/(byte) main::item#2 )
(number~) main::$0 ← (byte) main::item#2 * (number) $10
(number~) main::$1 ← (number~) main::$0 | (byte) main::sub#2
*((byte*) main::cur_item#2 + (byte) main::sub#2) ← (number~) main::$1
(byte) main::sub#1 ← (byte) main::sub#2 + rangenext(0,ITEM_SIZE-1)
(bool~) main::$2 ← (byte) main::sub#1 != rangelast(0,ITEM_SIZE-1)
if((bool~) main::$2) goto main::@2
to:main::@3
main::@3: scope:[main] from main::@2
(byte) main::item#3 ← phi( main::@2/(byte) main::item#2 )
(byte*) main::cur_item#3 ← phi( main::@2/(byte*) main::cur_item#2 )
(byte*) main::cur_item#1 ← (byte*) main::cur_item#3 + (const nomodify byte) ITEM_SIZE
(byte) main::item#1 ← (byte) main::item#3 + rangenext(0,ITEM_COUNT-1)
(bool~) main::$3 ← (byte) main::item#1 != rangelast(0,ITEM_COUNT-1)
if((bool~) main::$3) goto main::@1
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 nomodify byte) ITEM_COUNT = (byte) 3
(const nomodify byte) ITEM_SIZE = (byte) 5
(const byte*) items[(const nomodify byte) ITEM_COUNT*(const nomodify byte) ITEM_SIZE] = { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 }
(void()) main()
2019-05-30 20:29:04 +00:00
(number~) main::$0
(number~) main::$1
(bool~) main::$2
(bool~) main::$3
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte*) main::cur_item
(byte*) main::cur_item#0
(byte*) main::cur_item#1
(byte*) main::cur_item#2
(byte*) main::cur_item#3
(byte*) main::cur_item#4
(byte) main::item
(byte) main::item#0
(byte) main::item#1
(byte) main::item#2
(byte) main::item#3
(byte) main::item#4
(byte) main::sub
(byte) main::sub#0
(byte) main::sub#1
(byte) main::sub#2
Adding number conversion cast (unumber) $10 in (number~) main::$0 ← (byte) main::item#2 * (number) $10
Adding number conversion cast (unumber) main::$0 in (number~) main::$0 ← (byte) main::item#2 * (unumber)(number) $10
Adding number conversion cast (unumber) main::$1 in (number~) main::$1 ← (unumber~) main::$0 | (byte) main::sub#2
Adding number conversion cast (unumber) 1 in (byte) main::sub#1 ← (byte) main::sub#2 + rangenext(0,ITEM_SIZE-1)
Adding number conversion cast (unumber) 1 in (byte) main::item#1 ← (byte) main::item#3 + rangenext(0,ITEM_COUNT-1)
2019-05-30 20:29:04 +00:00
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $10
2019-05-30 20:29:04 +00:00
Simplifying constant integer cast 1
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $10
2019-05-30 20:29:04 +00:00
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$0 ← (byte) main::item#2 * (byte) $10
Inferred type updated to byte in (unumber~) main::$1 ← (byte~) main::$0 | (byte) main::sub#2
Alias main::cur_item#2 = main::cur_item#3
Alias main::item#2 = main::item#3
2018-08-22 20:23:42 +00:00
Successful SSA optimization Pass2AliasElimination
2019-05-30 20:29:04 +00:00
Identical Phi Values (byte) main::item#2 (byte) main::item#4
Identical Phi Values (byte*) main::cur_item#2 (byte*) main::cur_item#4
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$2 [10] if((byte) main::sub#1!=rangelast(0,ITEM_SIZE-1)) goto main::@2
Simple Condition (bool~) main::$3 [14] if((byte) main::item#1!=rangelast(0,ITEM_COUNT-1)) goto main::@1
2018-08-22 20:23:42 +00:00
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) main::cur_item#0 = items
Constant (const byte) main::item#0 = 0
Constant (const byte) main::sub#0 = 0
2018-08-22 20:23:42 +00:00
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [8] main::sub#1 ← ++ main::sub#2 to ++
Resolved ranged comparison value [10] if(main::sub#1!=rangelast(0,ITEM_SIZE-1)) goto main::@2 to (const nomodify byte) ITEM_SIZE-(byte) 1+(number) 1
Resolved ranged next value [12] main::item#1 ← ++ main::item#4 to ++
Resolved ranged comparison value [14] if(main::item#1!=rangelast(0,ITEM_COUNT-1)) goto main::@1 to (const nomodify byte) ITEM_COUNT-(byte) 1+(number) 1
Adding number conversion cast (unumber) ITEM_SIZE-1+1 in if((byte) main::sub#1!=(const nomodify byte) ITEM_SIZE-(byte) 1+(number) 1) goto main::@2
Adding number conversion cast (unumber) 1 in if((byte) main::sub#1!=(unumber)(const nomodify byte) ITEM_SIZE-(byte) 1+(number) 1) goto main::@2
Adding number conversion cast (unumber) ITEM_COUNT-1+1 in if((byte) main::item#1!=(const nomodify byte) ITEM_COUNT-(byte) 1+(number) 1) goto main::@1
Adding number conversion cast (unumber) 1 in if((byte) main::item#1!=(unumber)(const nomodify byte) ITEM_COUNT-(byte) 1+(number) 1) goto main::@1
2019-05-30 20:29:04 +00:00
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast (const nomodify byte) ITEM_SIZE-(byte) 1+(unumber)(number) 1
2019-05-30 20:29:04 +00:00
Simplifying constant integer cast 1
Simplifying constant integer cast (const nomodify byte) ITEM_COUNT-(byte) 1+(unumber)(number) 1
2019-05-30 20:29:04 +00:00
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Rewriting multiplication to use shift [2] (byte~) main::$0 ← (byte) main::item#4 * (byte) $10
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const byte*) main::cur_item#0
Inlining constant with var siblings (const byte) main::item#0
Inlining constant with var siblings (const byte) main::sub#0
2019-05-30 20:29:04 +00:00
Constant inlined main::sub#0 = (byte) 0
Constant inlined main::cur_item#0 = (const byte*) items
2019-05-30 20:29:04 +00:00
Constant inlined main::item#0 = (byte) 0
2018-08-22 20:23:42 +00:00
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@4(between main::@3 and main::@1)
Added new block during phi lifting main::@5(between main::@2 and main::@2)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
2019-05-30 20:29:04 +00:00
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2
Created 3 initial phi equivalence classes
2019-05-30 20:29:04 +00:00
Coalesced [17] main::item#5 ← main::item#1
Coalesced [18] main::cur_item#5 ← main::cur_item#1
Coalesced [19] main::sub#3 ← main::sub#1
Coalesced down to 3 phi equivalence classes
2019-05-30 20:29:04 +00:00
Culled Empty Block (label) @2
Culled Empty Block (label) main::@4
Culled Empty Block (label) main::@5
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
2018-11-11 20:51:36 +00:00
[0] phi()
to:@1
@1: scope:[] from @begin
2018-11-11 20:51:36 +00:00
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
2018-11-11 20:51:36 +00:00
[3] phi()
(void()) main()
main: scope:[main] from @1
2018-11-11 20:51:36 +00:00
[4] phi()
to:main::@1
main::@1: scope:[main] from main main::@3
[5] (byte*) main::cur_item#4 ← phi( main/(const byte*) items main::@3/(byte*) main::cur_item#1 )
2019-05-30 20:29:04 +00:00
[5] (byte) main::item#4 ← phi( main/(byte) 0 main::@3/(byte) main::item#1 )
to:main::@2
main::@2: scope:[main] from main::@1 main::@2
2019-05-30 20:29:04 +00:00
[6] (byte) main::sub#2 ← phi( main::@1/(byte) 0 main::@2/(byte) main::sub#1 )
[7] (byte~) main::$0 ← (byte) main::item#4 << (byte) 4
[8] (byte~) main::$1 ← (byte~) main::$0 | (byte) main::sub#2
[9] *((byte*) main::cur_item#4 + (byte) main::sub#2) ← (byte~) main::$1
2018-11-11 20:51:36 +00:00
[10] (byte) main::sub#1 ← ++ (byte) main::sub#2
[11] if((byte) main::sub#1!=(const nomodify byte) ITEM_SIZE-(byte) 1+(byte) 1) goto main::@2
to:main::@3
main::@3: scope:[main] from main::@2
[12] (byte*) main::cur_item#1 ← (byte*) main::cur_item#4 + (const nomodify byte) ITEM_SIZE
2018-11-11 20:51:36 +00:00
[13] (byte) main::item#1 ← ++ (byte) main::item#4
[14] if((byte) main::item#1!=(const nomodify byte) ITEM_COUNT-(byte) 1+(byte) 1) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@3
2018-11-11 20:51:36 +00:00
[15] return
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$0 2002.0
(byte~) main::$1 2002.0
(byte*) main::cur_item
(byte*) main::cur_item#1 67.33333333333333
(byte*) main::cur_item#4 171.85714285714283
(byte) main::item
(byte) main::item#1 151.5
(byte) main::item#4 150.375
(byte) main::sub
(byte) main::sub#1 1501.5
(byte) main::sub#2 1001.0
Initial phi equivalence classes
[ main::item#4 main::item#1 ]
[ main::cur_item#4 main::cur_item#1 ]
[ main::sub#2 main::sub#1 ]
2019-12-08 15:04:35 +00:00
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Complete equivalence classes
[ main::item#4 main::item#1 ]
[ main::cur_item#4 main::cur_item#1 ]
[ main::sub#2 main::sub#1 ]
[ main::$0 ]
[ main::$1 ]
2019-10-12 09:40:36 +00:00
Allocated zp[1]:2 [ main::item#4 main::item#1 ]
Allocated zp[2]:3 [ main::cur_item#4 main::cur_item#1 ]
Allocated zp[1]:5 [ main::sub#2 main::sub#1 ]
Allocated zp[1]:6 [ main::$0 ]
Allocated zp[1]:7 [ main::$1 ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
2019-02-17 23:12:29 +00:00
// Illustrates symbolic array lengths
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.const ITEM_COUNT = 3
.const ITEM_SIZE = 5
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
main_from___b1:
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
2019-02-17 23:12:29 +00:00
// Fills the array item by item with $is, where i is the item# and s is the sub#
main: {
.label __0 = 6
.label __1 = 7
.label sub = 5
.label cur_item = 3
.label item = 2
// [5] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
// [5] phi (byte*) main::cur_item#4 = (const byte*) items [phi:main->main::@1#0] -- pbuz1=pbuc1
lda #<items
sta.z cur_item
lda #>items
sta.z cur_item+1
// [5] phi (byte) main::item#4 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1
lda #0
sta.z item
jmp __b1
// [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
__b1_from___b3:
// [5] phi (byte*) main::cur_item#4 = (byte*) main::cur_item#1 [phi:main::@3->main::@1#0] -- register_copy
// [5] phi (byte) main::item#4 = (byte) main::item#1 [phi:main::@3->main::@1#1] -- register_copy
jmp __b1
// main::@1
__b1:
// [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
__b2_from___b1:
// [6] phi (byte) main::sub#2 = (byte) 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1
lda #0
sta.z sub
jmp __b2
// [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
__b2_from___b2:
// [6] phi (byte) main::sub#2 = (byte) main::sub#1 [phi:main::@2->main::@2#0] -- register_copy
jmp __b2
// main::@2
__b2:
// [7] (byte~) main::$0 ← (byte) main::item#4 << (byte) 4 -- vbuz1=vbuz2_rol_4
lda.z item
asl
asl
asl
asl
sta.z __0
// [8] (byte~) main::$1 ← (byte~) main::$0 | (byte) main::sub#2 -- vbuz1=vbuz2_bor_vbuz3
lda.z __0
ora.z sub
sta.z __1
// [9] *((byte*) main::cur_item#4 + (byte) main::sub#2) ← (byte~) main::$1 -- pbuz1_derefidx_vbuz2=vbuz3
lda.z __1
ldy.z sub
sta (cur_item),y
// [10] (byte) main::sub#1 ← ++ (byte) main::sub#2 -- vbuz1=_inc_vbuz1
inc.z sub
// [11] if((byte) main::sub#1!=(const nomodify byte) ITEM_SIZE-(byte) 1+(byte) 1) goto main::@2 -- vbuz1_neq_vbuc1_then_la1
lda #ITEM_SIZE-1+1
cmp.z sub
bne __b2_from___b2
jmp __b3
// main::@3
__b3:
// [12] (byte*) main::cur_item#1 ← (byte*) main::cur_item#4 + (const nomodify byte) ITEM_SIZE -- pbuz1=pbuz1_plus_vbuc1
2019-03-18 01:23:29 +00:00
lda #ITEM_SIZE
clc
adc.z cur_item
sta.z cur_item
bcc !+
inc.z cur_item+1
!:
// [13] (byte) main::item#1 ← ++ (byte) main::item#4 -- vbuz1=_inc_vbuz1
inc.z item
// [14] if((byte) main::item#1!=(const nomodify byte) ITEM_COUNT-(byte) 1+(byte) 1) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
lda #ITEM_COUNT-1+1
cmp.z item
bne __b1_from___b3
jmp __breturn
// main::@return
__breturn:
// [15] return
rts
}
// File Data
items: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [7] (byte~) main::$0 ← (byte) main::item#4 << (byte) 4 [ main::item#4 main::cur_item#4 main::sub#2 main::$0 ] ( main:2 [ main::item#4 main::cur_item#4 main::sub#2 main::$0 ] { } ) always clobbers reg byte a
2019-10-12 09:40:36 +00:00
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::item#4 main::item#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:5 [ main::sub#2 main::sub#1 ]
Statement [12] (byte*) main::cur_item#1 ← (byte*) main::cur_item#4 + (const nomodify byte) ITEM_SIZE [ main::item#4 main::cur_item#1 ] ( main:2 [ main::item#4 main::cur_item#1 ] { } ) always clobbers reg byte a
Statement [7] (byte~) main::$0 ← (byte) main::item#4 << (byte) 4 [ main::item#4 main::cur_item#4 main::sub#2 main::$0 ] ( main:2 [ main::item#4 main::cur_item#4 main::sub#2 main::$0 ] { } ) always clobbers reg byte a
Statement [12] (byte*) main::cur_item#1 ← (byte*) main::cur_item#4 + (const nomodify byte) ITEM_SIZE [ main::item#4 main::cur_item#1 ] ( main:2 [ main::item#4 main::cur_item#1 ] { } ) always clobbers reg byte a
2019-10-12 09:40:36 +00:00
Potential registers zp[1]:2 [ main::item#4 main::item#1 ] : zp[1]:2 , reg byte x , reg byte y ,
Potential registers zp[2]:3 [ main::cur_item#4 main::cur_item#1 ] : zp[2]:3 ,
Potential registers zp[1]:5 [ main::sub#2 main::sub#1 ] : zp[1]:5 , reg byte x , reg byte y ,
Potential registers zp[1]:6 [ main::$0 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:7 [ main::$1 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 2,502.5: zp[1]:5 [ main::sub#2 main::sub#1 ] 2,002: zp[1]:6 [ main::$0 ] 2,002: zp[1]:7 [ main::$1 ] 301.88: zp[1]:2 [ main::item#4 main::item#1 ] 239.19: zp[2]:3 [ main::cur_item#4 main::cur_item#1 ]
Uplift Scope []
Uplifting [main] best 4418 combination reg byte y [ main::sub#2 main::sub#1 ] reg byte a [ main::$0 ] reg byte a [ main::$1 ] reg byte x [ main::item#4 main::item#1 ] zp[2]:3 [ main::cur_item#4 main::cur_item#1 ]
Limited combination testing to 100 combinations of 144 possible.
Uplifting [] best 4418 combination
2019-10-12 09:40:36 +00:00
Allocated (was zp[2]:3) zp[2]:2 [ main::cur_item#4 main::cur_item#1 ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
2019-02-17 23:12:29 +00:00
// Illustrates symbolic array lengths
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.const ITEM_COUNT = 3
.const ITEM_SIZE = 5
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
main_from___b1:
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
2019-02-17 23:12:29 +00:00
// Fills the array item by item with $is, where i is the item# and s is the sub#
main: {
.label cur_item = 2
// [5] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
// [5] phi (byte*) main::cur_item#4 = (const byte*) items [phi:main->main::@1#0] -- pbuz1=pbuc1
lda #<items
sta.z cur_item
lda #>items
sta.z cur_item+1
// [5] phi (byte) main::item#4 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1
ldx #0
jmp __b1
// [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
__b1_from___b3:
// [5] phi (byte*) main::cur_item#4 = (byte*) main::cur_item#1 [phi:main::@3->main::@1#0] -- register_copy
// [5] phi (byte) main::item#4 = (byte) main::item#1 [phi:main::@3->main::@1#1] -- register_copy
jmp __b1
// main::@1
__b1:
// [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
__b2_from___b1:
// [6] phi (byte) main::sub#2 = (byte) 0 [phi:main::@1->main::@2#0] -- vbuyy=vbuc1
ldy #0
jmp __b2
// [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
__b2_from___b2:
// [6] phi (byte) main::sub#2 = (byte) main::sub#1 [phi:main::@2->main::@2#0] -- register_copy
jmp __b2
// main::@2
__b2:
// [7] (byte~) main::$0 ← (byte) main::item#4 << (byte) 4 -- vbuaa=vbuxx_rol_4
txa
asl
asl
asl
asl
// [8] (byte~) main::$1 ← (byte~) main::$0 | (byte) main::sub#2 -- vbuaa=vbuaa_bor_vbuyy
sty.z $ff
ora.z $ff
// [9] *((byte*) main::cur_item#4 + (byte) main::sub#2) ← (byte~) main::$1 -- pbuz1_derefidx_vbuyy=vbuaa
sta (cur_item),y
// [10] (byte) main::sub#1 ← ++ (byte) main::sub#2 -- vbuyy=_inc_vbuyy
iny
// [11] if((byte) main::sub#1!=(const nomodify byte) ITEM_SIZE-(byte) 1+(byte) 1) goto main::@2 -- vbuyy_neq_vbuc1_then_la1
cpy #ITEM_SIZE-1+1
bne __b2_from___b2
jmp __b3
// main::@3
__b3:
// [12] (byte*) main::cur_item#1 ← (byte*) main::cur_item#4 + (const nomodify byte) ITEM_SIZE -- pbuz1=pbuz1_plus_vbuc1
2019-03-18 01:23:29 +00:00
lda #ITEM_SIZE
clc
adc.z cur_item
sta.z cur_item
bcc !+
inc.z cur_item+1
!:
// [13] (byte) main::item#1 ← ++ (byte) main::item#4 -- vbuxx=_inc_vbuxx
inx
// [14] if((byte) main::item#1!=(const nomodify byte) ITEM_COUNT-(byte) 1+(byte) 1) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
cpx #ITEM_COUNT-1+1
bne __b1_from___b3
jmp __breturn
// main::@return
__breturn:
// [15] return
rts
}
// File Data
items: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b3
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b2_from___b2 with __b2
Replacing label __b1_from___b3 with __b1
Removing instruction __b1_from___bbegin:
Removing instruction __b1:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b3:
Removing instruction __b2_from___b1:
Removing instruction __b2_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bbegin:
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b3:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp __b1
Removing instruction jmp __b2
Succesful ASM optimization Pass5NextJumpElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const nomodify byte) ITEM_COUNT = (byte) 3
(const nomodify byte) ITEM_SIZE = (byte) 5
(const byte*) items[(const nomodify byte) ITEM_COUNT*(const nomodify byte) ITEM_SIZE] = { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 }
(void()) main()
(byte~) main::$0 reg byte a 2002.0
(byte~) main::$1 reg byte a 2002.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte*) main::cur_item
(byte*) main::cur_item#1 cur_item zp[2]:2 67.33333333333333
(byte*) main::cur_item#4 cur_item zp[2]:2 171.85714285714283
(byte) main::item
(byte) main::item#1 reg byte x 151.5
(byte) main::item#4 reg byte x 150.375
(byte) main::sub
(byte) main::sub#1 reg byte y 1501.5
(byte) main::sub#2 reg byte y 1001.0
reg byte x [ main::item#4 main::item#1 ]
2019-10-12 09:40:36 +00:00
zp[2]:2 [ main::cur_item#4 main::cur_item#1 ]
reg byte y [ main::sub#2 main::sub#1 ]
reg byte a [ main::$0 ]
reg byte a [ main::$1 ]
FINAL ASSEMBLER
Score: 3416
// File Comments
2019-02-17 23:12:29 +00:00
// Illustrates symbolic array lengths
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.const ITEM_COUNT = 3
.const ITEM_SIZE = 5
// @begin
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
2019-02-17 23:12:29 +00:00
// Fills the array item by item with $is, where i is the item# and s is the sub#
main: {
.label cur_item = 2
// [5] phi from main to main::@1 [phi:main->main::@1]
// [5] phi (byte*) main::cur_item#4 = (const byte*) items [phi:main->main::@1#0] -- pbuz1=pbuc1
lda #<items
sta.z cur_item
lda #>items
sta.z cur_item+1
// [5] phi (byte) main::item#4 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1
ldx #0
// [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
// [5] phi (byte*) main::cur_item#4 = (byte*) main::cur_item#1 [phi:main::@3->main::@1#0] -- register_copy
// [5] phi (byte) main::item#4 = (byte) main::item#1 [phi:main::@3->main::@1#1] -- register_copy
// main::@1
__b1:
// [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
// [6] phi (byte) main::sub#2 = (byte) 0 [phi:main::@1->main::@2#0] -- vbuyy=vbuc1
ldy #0
// [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
// [6] phi (byte) main::sub#2 = (byte) main::sub#1 [phi:main::@2->main::@2#0] -- register_copy
// main::@2
__b2:
// item*$10
// [7] (byte~) main::$0 ← (byte) main::item#4 << (byte) 4 -- vbuaa=vbuxx_rol_4
txa
asl
asl
asl
asl
// item*$10|sub
// [8] (byte~) main::$1 ← (byte~) main::$0 | (byte) main::sub#2 -- vbuaa=vbuaa_bor_vbuyy
sty.z $ff
ora.z $ff
// cur_item[sub] = item*$10|sub
// [9] *((byte*) main::cur_item#4 + (byte) main::sub#2) ← (byte~) main::$1 -- pbuz1_derefidx_vbuyy=vbuaa
sta (cur_item),y
// for( byte sub: 0..ITEM_SIZE-1)
// [10] (byte) main::sub#1 ← ++ (byte) main::sub#2 -- vbuyy=_inc_vbuyy
iny
// [11] if((byte) main::sub#1!=(const nomodify byte) ITEM_SIZE-(byte) 1+(byte) 1) goto main::@2 -- vbuyy_neq_vbuc1_then_la1
cpy #ITEM_SIZE-1+1
bne __b2
// main::@3
// cur_item += ITEM_SIZE
// [12] (byte*) main::cur_item#1 ← (byte*) main::cur_item#4 + (const nomodify byte) ITEM_SIZE -- pbuz1=pbuz1_plus_vbuc1
2019-03-18 01:23:29 +00:00
lda #ITEM_SIZE
clc
adc.z cur_item
sta.z cur_item
bcc !+
inc.z cur_item+1
!:
// for( byte item: 0..ITEM_COUNT-1)
// [13] (byte) main::item#1 ← ++ (byte) main::item#4 -- vbuxx=_inc_vbuxx
inx
// [14] if((byte) main::item#1!=(const nomodify byte) ITEM_COUNT-(byte) 1+(byte) 1) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
cpx #ITEM_COUNT-1+1
bne __b1
// main::@return
// }
// [15] return
rts
}
// File Data
items: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0