mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-06-02 00:41:42 +00:00
513 lines
22 KiB
Plaintext
513 lines
22 KiB
Plaintext
|
|
CONTROL FLOW GRAPH SSA
|
|
|
|
void main()
|
|
main: scope:[main] from __start
|
|
main::idx#0 = 0
|
|
to:main::@1
|
|
main::@1: scope:[main] from main main::@2
|
|
main::idx#2 = phi( main/main::idx#0, main::@2/main::idx#1 )
|
|
getValue::index#0 = main::idx#2
|
|
call getValue
|
|
getValue::return#0 = getValue::return#2
|
|
to:main::@2
|
|
main::@2: scope:[main] from main::@1
|
|
main::idx#3 = phi( main::@1/main::idx#2 )
|
|
getValue::return#3 = phi( main::@1/getValue::return#0 )
|
|
main::$0 = getValue::return#3
|
|
main::$2 = main::idx#3 * SIZEOF_UNSIGNED_INT
|
|
main::SCREEN[main::$2] = main::$0
|
|
main::idx#1 = main::idx#3 + rangenext(0,$80)
|
|
main::$1 = main::idx#1 != rangelast(0,$80)
|
|
if(main::$1) goto main::@1
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@2
|
|
return
|
|
to:@return
|
|
|
|
unsigned int getValue(unsigned int index)
|
|
getValue: scope:[getValue] from main::@1
|
|
getValue::index#1 = phi( main::@1/getValue::index#0 )
|
|
getValue::$0 = getValue::index#1 & $7f
|
|
getValue::$3 = getValue::$0 * SIZEOF_UNSIGNED_INT
|
|
getValue::$1 = arr16[getValue::$3] & $ff
|
|
getValue::$2 = getValue::$1 >> 1
|
|
getValue::return#1 = (unsigned int)getValue::$2
|
|
to:getValue::@return
|
|
getValue::@return: scope:[getValue] from getValue
|
|
getValue::return#4 = phi( getValue/getValue::return#1 )
|
|
getValue::return#2 = getValue::return#4
|
|
return
|
|
to:@return
|
|
|
|
void __start()
|
|
__start: scope:[__start] from
|
|
call main
|
|
to:__start::@1
|
|
__start::@1: scope:[__start] from __start
|
|
to:__start::@return
|
|
__start::@return: scope:[__start] from __start::@1
|
|
return
|
|
to:@return
|
|
|
|
SYMBOL TABLE SSA
|
|
__constant char SIZEOF_UNSIGNED_INT = 2
|
|
void __start()
|
|
__constant unsigned int arr16[$80] = { fill( $80, 0) }
|
|
unsigned int getValue(unsigned int index)
|
|
number getValue::$0
|
|
number getValue::$1
|
|
number getValue::$2
|
|
number getValue::$3
|
|
unsigned int getValue::index
|
|
unsigned int getValue::index#0
|
|
unsigned int getValue::index#1
|
|
unsigned int getValue::return
|
|
unsigned int getValue::return#0
|
|
unsigned int getValue::return#1
|
|
unsigned int getValue::return#2
|
|
unsigned int getValue::return#3
|
|
unsigned int getValue::return#4
|
|
void main()
|
|
unsigned int main::$0
|
|
bool main::$1
|
|
char main::$2
|
|
__constant unsigned int *main::SCREEN = (unsigned int *)$400
|
|
char main::idx
|
|
char main::idx#0
|
|
char main::idx#1
|
|
char main::idx#2
|
|
char main::idx#3
|
|
|
|
Adding number conversion cast (unumber) $7f in getValue::$0 = getValue::index#1 & $7f
|
|
Adding number conversion cast (unumber) getValue::$0 in getValue::$0 = getValue::index#1 & (unumber)$7f
|
|
Adding number conversion cast (unumber) getValue::$3 in getValue::$3 = getValue::$0 * SIZEOF_UNSIGNED_INT
|
|
Adding number conversion cast (unumber) $ff in getValue::$1 = arr16[getValue::$3] & $ff
|
|
Adding number conversion cast (unumber) getValue::$1 in getValue::$1 = arr16[getValue::$3] & (unumber)$ff
|
|
Adding number conversion cast (unumber) 1 in getValue::$2 = getValue::$1 >> 1
|
|
Adding number conversion cast (unumber) getValue::$2 in getValue::$2 = getValue::$1 >> (unumber)1
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Simplifying constant pointer cast (unsigned int *) 1024
|
|
Simplifying constant integer cast $7f
|
|
Simplifying constant integer cast $ff
|
|
Simplifying constant integer cast 1
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (char) $7f
|
|
Finalized unsigned number type (char) $ff
|
|
Finalized unsigned number type (char) 1
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Inferred type updated to char in getValue::$0 = getValue::index#1 & $7f
|
|
Inferred type updated to char in getValue::$3 = getValue::$0 * SIZEOF_UNSIGNED_INT
|
|
Inferred type updated to char in getValue::$1 = arr16[getValue::$3] & $ff
|
|
Inferred type updated to char in getValue::$2 = getValue::$1 >> 1
|
|
Alias getValue::return#0 = getValue::return#3
|
|
Alias main::idx#2 = main::idx#3
|
|
Alias getValue::return#1 = getValue::return#4 getValue::return#2
|
|
Successful SSA optimization Pass2AliasElimination
|
|
Identical Phi Values getValue::index#1 getValue::index#0
|
|
Successful SSA optimization Pass2IdenticalPhiElimination
|
|
Simple Condition main::$1 [10] if(main::idx#1!=rangelast(0,$80)) goto main::@1
|
|
Successful SSA optimization Pass2ConditionalJumpSimplification
|
|
Constant main::idx#0 = 0
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Resolved ranged next value [8] main::idx#1 = ++ main::idx#2 to ++
|
|
Resolved ranged comparison value [10] if(main::idx#1!=rangelast(0,$80)) goto main::@1 to $81
|
|
Removing unused procedure __start
|
|
Removing unused procedure block __start
|
|
Removing unused procedure block __start::@1
|
|
Removing unused procedure block __start::@return
|
|
Successful SSA optimization PassNEliminateEmptyStart
|
|
Adding number conversion cast (unumber) $81 in [8] if(main::idx#1!=$81) goto main::@1
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Simplifying constant integer cast $81
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (char) $81
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Rewriting multiplication to use shift [5] main::$2 = main::idx#2 * SIZEOF_UNSIGNED_INT
|
|
Rewriting multiplication to use shift [11] getValue::$3 = getValue::$0 * SIZEOF_UNSIGNED_INT
|
|
Successful SSA optimization Pass2MultiplyToShiftRewriting
|
|
Inlining constant with var siblings main::idx#0
|
|
Constant inlined main::idx#0 = 0
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
Eliminating unused constant SIZEOF_UNSIGNED_INT
|
|
Successful SSA optimization PassNEliminateUnusedVars
|
|
Finalized unsigned number type (char) $80
|
|
Finalized unsigned number type (char) $80
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Added new block during phi lifting main::@3(between main::@2 and main::@1)
|
|
Adding NOP phi() at start of main
|
|
CALL GRAPH
|
|
Calls in [main] to getValue:3
|
|
|
|
Created 1 initial phi equivalence classes
|
|
Coalesced [11] main::idx#4 = main::idx#1
|
|
Coalesced down to 1 phi equivalence classes
|
|
Culled Empty Block label main::@3
|
|
Adding NOP phi() at start of main
|
|
|
|
FINAL CONTROL FLOW GRAPH
|
|
|
|
void main()
|
|
main: scope:[main] from
|
|
[0] phi()
|
|
to:main::@1
|
|
main::@1: scope:[main] from main main::@2
|
|
[1] main::idx#2 = phi( main/0, main::@2/main::idx#1 )
|
|
[2] getValue::index#0 = main::idx#2
|
|
[3] call getValue
|
|
[4] getValue::return#0 = getValue::return#1
|
|
to:main::@2
|
|
main::@2: scope:[main] from main::@1
|
|
[5] main::$0 = getValue::return#0
|
|
[6] main::$2 = main::idx#2 << 1
|
|
[7] main::SCREEN[main::$2] = main::$0
|
|
[8] main::idx#1 = ++ main::idx#2
|
|
[9] if(main::idx#1!=$81) goto main::@1
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@2
|
|
[10] return
|
|
to:@return
|
|
|
|
unsigned int getValue(unsigned int index)
|
|
getValue: scope:[getValue] from main::@1
|
|
[11] getValue::$0 = getValue::index#0 & $7f
|
|
[12] getValue::$3 = getValue::$0 << 1
|
|
[13] getValue::$1 = arr16[getValue::$3] & $ff
|
|
[14] getValue::$2 = getValue::$1 >> 1
|
|
[15] getValue::return#1 = (unsigned int)getValue::$2
|
|
to:getValue::@return
|
|
getValue::@return: scope:[getValue] from getValue
|
|
[16] return
|
|
to:@return
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
unsigned int getValue(unsigned int index)
|
|
char getValue::$0 // 202.0
|
|
char getValue::$1 // 202.0
|
|
char getValue::$2 // 101.0
|
|
char getValue::$3 // 202.0
|
|
unsigned int getValue::index
|
|
unsigned int getValue::index#0 // 112.0
|
|
unsigned int getValue::return
|
|
unsigned int getValue::return#0 // 22.0
|
|
unsigned int getValue::return#1 // 37.33333333333333
|
|
void main()
|
|
unsigned int main::$0 // 11.0
|
|
char main::$2 // 22.0
|
|
char main::idx
|
|
char main::idx#1 // 16.5
|
|
char main::idx#2 // 6.285714285714286
|
|
|
|
Initial phi equivalence classes
|
|
[ main::idx#2 main::idx#1 ]
|
|
Added variable getValue::index#0 to live range equivalence class [ getValue::index#0 ]
|
|
Added variable getValue::return#0 to live range equivalence class [ getValue::return#0 ]
|
|
Added variable main::$0 to live range equivalence class [ main::$0 ]
|
|
Added variable main::$2 to live range equivalence class [ main::$2 ]
|
|
Added variable getValue::$0 to live range equivalence class [ getValue::$0 ]
|
|
Added variable getValue::$3 to live range equivalence class [ getValue::$3 ]
|
|
Added variable getValue::$1 to live range equivalence class [ getValue::$1 ]
|
|
Added variable getValue::$2 to live range equivalence class [ getValue::$2 ]
|
|
Added variable getValue::return#1 to live range equivalence class [ getValue::return#1 ]
|
|
Complete equivalence classes
|
|
[ main::idx#2 main::idx#1 ]
|
|
[ getValue::index#0 ]
|
|
[ getValue::return#0 ]
|
|
[ main::$0 ]
|
|
[ main::$2 ]
|
|
[ getValue::$0 ]
|
|
[ getValue::$3 ]
|
|
[ getValue::$1 ]
|
|
[ getValue::$2 ]
|
|
[ getValue::return#1 ]
|
|
Allocated zp[1]:2 [ getValue::$0 ]
|
|
Allocated zp[1]:3 [ getValue::$3 ]
|
|
Allocated zp[1]:4 [ getValue::$1 ]
|
|
Allocated zp[2]:5 [ getValue::index#0 ]
|
|
Allocated zp[1]:7 [ getValue::$2 ]
|
|
Allocated zp[2]:8 [ getValue::return#1 ]
|
|
Allocated zp[1]:10 [ main::idx#2 main::idx#1 ]
|
|
Allocated zp[2]:11 [ getValue::return#0 ]
|
|
Allocated zp[1]:13 [ main::$2 ]
|
|
Allocated zp[2]:14 [ main::$0 ]
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [2] getValue::index#0 = main::idx#2 [ main::idx#2 getValue::index#0 ] ( [ main::idx#2 getValue::index#0 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Removing always clobbered register reg byte a as potential for zp[1]:10 [ main::idx#2 main::idx#1 ]
|
|
Statement [4] getValue::return#0 = getValue::return#1 [ main::idx#2 getValue::return#0 ] ( [ main::idx#2 getValue::return#0 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [5] main::$0 = getValue::return#0 [ main::idx#2 main::$0 ] ( [ main::idx#2 main::$0 ] { } ) always clobbers reg byte a
|
|
Statement [6] main::$2 = main::idx#2 << 1 [ main::idx#2 main::$0 main::$2 ] ( [ main::idx#2 main::$0 main::$2 ] { } ) always clobbers reg byte a
|
|
Statement [7] main::SCREEN[main::$2] = main::$0 [ main::idx#2 ] ( [ main::idx#2 ] { } ) always clobbers reg byte a
|
|
Statement [11] getValue::$0 = getValue::index#0 & $7f [ getValue::$0 ] ( getValue:3 [ main::idx#2 getValue::$0 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [12] getValue::$3 = getValue::$0 << 1 [ getValue::$3 ] ( getValue:3 [ main::idx#2 getValue::$3 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [13] getValue::$1 = arr16[getValue::$3] & $ff [ getValue::$1 ] ( getValue:3 [ main::idx#2 getValue::$1 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [14] getValue::$2 = getValue::$1 >> 1 [ getValue::$2 ] ( getValue:3 [ main::idx#2 getValue::$2 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [15] getValue::return#1 = (unsigned int)getValue::$2 [ getValue::return#1 ] ( getValue:3 [ main::idx#2 getValue::return#1 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [2] getValue::index#0 = main::idx#2 [ main::idx#2 getValue::index#0 ] ( [ main::idx#2 getValue::index#0 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [4] getValue::return#0 = getValue::return#1 [ main::idx#2 getValue::return#0 ] ( [ main::idx#2 getValue::return#0 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [5] main::$0 = getValue::return#0 [ main::idx#2 main::$0 ] ( [ main::idx#2 main::$0 ] { } ) always clobbers reg byte a
|
|
Statement [6] main::$2 = main::idx#2 << 1 [ main::idx#2 main::$0 main::$2 ] ( [ main::idx#2 main::$0 main::$2 ] { } ) always clobbers reg byte a
|
|
Statement [7] main::SCREEN[main::$2] = main::$0 [ main::idx#2 ] ( [ main::idx#2 ] { } ) always clobbers reg byte a
|
|
Statement [11] getValue::$0 = getValue::index#0 & $7f [ getValue::$0 ] ( getValue:3 [ main::idx#2 getValue::$0 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [12] getValue::$3 = getValue::$0 << 1 [ getValue::$3 ] ( getValue:3 [ main::idx#2 getValue::$3 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [13] getValue::$1 = arr16[getValue::$3] & $ff [ getValue::$1 ] ( getValue:3 [ main::idx#2 getValue::$1 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [14] getValue::$2 = getValue::$1 >> 1 [ getValue::$2 ] ( getValue:3 [ main::idx#2 getValue::$2 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Statement [15] getValue::return#1 = (unsigned int)getValue::$2 [ getValue::return#1 ] ( getValue:3 [ main::idx#2 getValue::return#1 ] { { getValue::index#0 = main::idx#2 } { getValue::return#0 = getValue::return#1 } } ) always clobbers reg byte a
|
|
Potential registers zp[1]:10 [ main::idx#2 main::idx#1 ] : zp[1]:10 , reg byte x , reg byte y ,
|
|
Potential registers zp[2]:5 [ getValue::index#0 ] : zp[2]:5 ,
|
|
Potential registers zp[2]:11 [ getValue::return#0 ] : zp[2]:11 ,
|
|
Potential registers zp[2]:14 [ main::$0 ] : zp[2]:14 ,
|
|
Potential registers zp[1]:13 [ main::$2 ] : zp[1]:13 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp[1]:2 [ getValue::$0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp[1]:3 [ getValue::$3 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp[1]:4 [ getValue::$1 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp[1]:7 [ getValue::$2 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp[2]:8 [ getValue::return#1 ] : zp[2]:8 ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [getValue] 202: zp[1]:2 [ getValue::$0 ] 202: zp[1]:3 [ getValue::$3 ] 202: zp[1]:4 [ getValue::$1 ] 112: zp[2]:5 [ getValue::index#0 ] 101: zp[1]:7 [ getValue::$2 ] 37.33: zp[2]:8 [ getValue::return#1 ] 22: zp[2]:11 [ getValue::return#0 ]
|
|
Uplift Scope [main] 22.79: zp[1]:10 [ main::idx#2 main::idx#1 ] 22: zp[1]:13 [ main::$2 ] 11: zp[2]:14 [ main::$0 ]
|
|
Uplift Scope []
|
|
|
|
Uplifting [getValue] best 1015 combination reg byte a [ getValue::$0 ] reg byte a [ getValue::$3 ] reg byte a [ getValue::$1 ] zp[2]:5 [ getValue::index#0 ] reg byte a [ getValue::$2 ] zp[2]:8 [ getValue::return#1 ] zp[2]:11 [ getValue::return#0 ]
|
|
Limited combination testing to 100 combinations of 256 possible.
|
|
Uplifting [main] best 865 combination reg byte x [ main::idx#2 main::idx#1 ] reg byte a [ main::$2 ] zp[2]:14 [ main::$0 ]
|
|
Uplifting [] best 865 combination
|
|
Coalescing zero page register [ zp[2]:11 [ getValue::return#0 ] ] with [ zp[2]:14 [ main::$0 ] ] - score: 1
|
|
Coalescing zero page register [ zp[2]:11 [ getValue::return#0 main::$0 ] ] with [ zp[2]:8 [ getValue::return#1 ] ] - score: 1
|
|
Allocated (was zp[2]:5) zp[2]:2 [ getValue::index#0 ]
|
|
Allocated (was zp[2]:11) zp[2]:4 [ getValue::return#0 main::$0 getValue::return#1 ]
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Test KickC performance for 16-bit array lookup function from article "Optimizing C array lookups for the 6502"
|
|
// http://8bitworkshop.com/blog/compilers/2019/03/17/cc65-optimization.html
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="array-16bit-lookup.prg", type="prg", segments="Program"]
|
|
.segmentdef Program [segments="Basic, Code, Data"]
|
|
.segmentdef Basic [start=$0801]
|
|
.segmentdef Code [start=$80d]
|
|
.segmentdef Data [startAfter="Code"]
|
|
.segment Basic
|
|
:BasicUpstart(main)
|
|
// Global Constants & labels
|
|
.segment Code
|
|
// main
|
|
main: {
|
|
.label SCREEN = $400
|
|
.label __0 = 4
|
|
// [1] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
// [1] phi main::idx#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
|
ldx #0
|
|
jmp __b1
|
|
// [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
|
|
__b1_from___b2:
|
|
// [1] phi main::idx#2 = main::idx#1 [phi:main::@2->main::@1#0] -- register_copy
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [2] getValue::index#0 = main::idx#2 -- vwuz1=vbuxx
|
|
txa
|
|
sta.z getValue.index
|
|
lda #0
|
|
sta.z getValue.index+1
|
|
// [3] call getValue
|
|
jsr getValue
|
|
// [4] getValue::return#0 = getValue::return#1
|
|
jmp __b2
|
|
// main::@2
|
|
__b2:
|
|
// [5] main::$0 = getValue::return#0
|
|
// [6] main::$2 = main::idx#2 << 1 -- vbuaa=vbuxx_rol_1
|
|
txa
|
|
asl
|
|
// [7] main::SCREEN[main::$2] = main::$0 -- pwuc1_derefidx_vbuaa=vwuz1
|
|
tay
|
|
lda.z __0
|
|
sta SCREEN,y
|
|
lda.z __0+1
|
|
sta SCREEN+1,y
|
|
// [8] main::idx#1 = ++ main::idx#2 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// [9] if(main::idx#1!=$81) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
|
cpx #$81
|
|
bne __b1_from___b2
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [10] return
|
|
rts
|
|
}
|
|
// getValue
|
|
// __zp(4) unsigned int getValue(__zp(2) unsigned int index)
|
|
getValue: {
|
|
.label index = 2
|
|
.label return = 4
|
|
// [11] getValue::$0 = getValue::index#0 & $7f -- vbuaa=vwuz1_band_vbuc1
|
|
lda #$7f
|
|
and.z index
|
|
// [12] getValue::$3 = getValue::$0 << 1 -- vbuaa=vbuaa_rol_1
|
|
asl
|
|
// [13] getValue::$1 = arr16[getValue::$3] & $ff -- vbuaa=pwuc1_derefidx_vbuaa_band_vbuc2
|
|
tay
|
|
lda #$ff
|
|
and arr16,y
|
|
// [14] getValue::$2 = getValue::$1 >> 1 -- vbuaa=vbuaa_ror_1
|
|
lsr
|
|
// [15] getValue::return#1 = (unsigned int)getValue::$2 -- vwuz1=_word_vbuaa
|
|
sta.z return
|
|
lda #0
|
|
sta.z return+1
|
|
jmp __breturn
|
|
// getValue::@return
|
|
__breturn:
|
|
// [16] return
|
|
rts
|
|
}
|
|
// File Data
|
|
.segment Data
|
|
arr16: .fill 2*$80, 0
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __b2
|
|
Removing instruction jmp __breturn
|
|
Removing instruction jmp __breturn
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Replacing label __b1_from___b2 with __b1
|
|
Removing instruction __b1_from___b2:
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
Removing instruction __b1_from_main:
|
|
Removing instruction __b2:
|
|
Removing instruction __breturn:
|
|
Removing instruction __breturn:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
Removing instruction jmp __b1
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
|
|
FINAL SYMBOL TABLE
|
|
__constant unsigned int arr16[$80] = { fill( $80, 0) }
|
|
unsigned int getValue(unsigned int index)
|
|
char getValue::$0 // reg byte a 202.0
|
|
char getValue::$1 // reg byte a 202.0
|
|
char getValue::$2 // reg byte a 101.0
|
|
char getValue::$3 // reg byte a 202.0
|
|
unsigned int getValue::index
|
|
unsigned int getValue::index#0 // index zp[2]:2 112.0
|
|
unsigned int getValue::return
|
|
unsigned int getValue::return#0 // return zp[2]:4 22.0
|
|
unsigned int getValue::return#1 // return zp[2]:4 37.33333333333333
|
|
void main()
|
|
unsigned int main::$0 // zp[2]:4 11.0
|
|
char main::$2 // reg byte a 22.0
|
|
__constant unsigned int *main::SCREEN = (unsigned int *) 1024
|
|
char main::idx
|
|
char main::idx#1 // reg byte x 16.5
|
|
char main::idx#2 // reg byte x 6.285714285714286
|
|
|
|
reg byte x [ main::idx#2 main::idx#1 ]
|
|
zp[2]:2 [ getValue::index#0 ]
|
|
zp[2]:4 [ getValue::return#0 main::$0 getValue::return#1 ]
|
|
reg byte a [ main::$2 ]
|
|
reg byte a [ getValue::$0 ]
|
|
reg byte a [ getValue::$3 ]
|
|
reg byte a [ getValue::$1 ]
|
|
reg byte a [ getValue::$2 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 502
|
|
|
|
// File Comments
|
|
// Test KickC performance for 16-bit array lookup function from article "Optimizing C array lookups for the 6502"
|
|
// http://8bitworkshop.com/blog/compilers/2019/03/17/cc65-optimization.html
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="array-16bit-lookup.prg", type="prg", segments="Program"]
|
|
.segmentdef Program [segments="Basic, Code, Data"]
|
|
.segmentdef Basic [start=$0801]
|
|
.segmentdef Code [start=$80d]
|
|
.segmentdef Data [startAfter="Code"]
|
|
.segment Basic
|
|
:BasicUpstart(main)
|
|
// Global Constants & labels
|
|
.segment Code
|
|
// main
|
|
main: {
|
|
.label SCREEN = $400
|
|
.label __0 = 4
|
|
// [1] phi from main to main::@1 [phi:main->main::@1]
|
|
// [1] phi main::idx#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
|
ldx #0
|
|
// [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
|
|
// [1] phi main::idx#2 = main::idx#1 [phi:main::@2->main::@1#0] -- register_copy
|
|
// main::@1
|
|
__b1:
|
|
// getValue(idx)
|
|
// [2] getValue::index#0 = main::idx#2 -- vwuz1=vbuxx
|
|
txa
|
|
sta.z getValue.index
|
|
lda #0
|
|
sta.z getValue.index+1
|
|
// [3] call getValue
|
|
jsr getValue
|
|
// [4] getValue::return#0 = getValue::return#1
|
|
// main::@2
|
|
// [5] main::$0 = getValue::return#0
|
|
// SCREEN[idx] = getValue(idx)
|
|
// [6] main::$2 = main::idx#2 << 1 -- vbuaa=vbuxx_rol_1
|
|
txa
|
|
asl
|
|
// [7] main::SCREEN[main::$2] = main::$0 -- pwuc1_derefidx_vbuaa=vwuz1
|
|
tay
|
|
lda.z __0
|
|
sta SCREEN,y
|
|
lda.z __0+1
|
|
sta SCREEN+1,y
|
|
// for(unsigned char idx : 0..128)
|
|
// [8] main::idx#1 = ++ main::idx#2 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// [9] if(main::idx#1!=$81) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
|
cpx #$81
|
|
bne __b1
|
|
// main::@return
|
|
// }
|
|
// [10] return
|
|
rts
|
|
}
|
|
// getValue
|
|
// __zp(4) unsigned int getValue(__zp(2) unsigned int index)
|
|
getValue: {
|
|
.label index = 2
|
|
.label return = 4
|
|
// index & 0x7f
|
|
// [11] getValue::$0 = getValue::index#0 & $7f -- vbuaa=vwuz1_band_vbuc1
|
|
lda #$7f
|
|
and.z index
|
|
// arr16[index & 0x7f] & 0xff
|
|
// [12] getValue::$3 = getValue::$0 << 1 -- vbuaa=vbuaa_rol_1
|
|
asl
|
|
// [13] getValue::$1 = arr16[getValue::$3] & $ff -- vbuaa=pwuc1_derefidx_vbuaa_band_vbuc2
|
|
tay
|
|
lda #$ff
|
|
and arr16,y
|
|
// (arr16[index & 0x7f] & 0xff) >> 1
|
|
// [14] getValue::$2 = getValue::$1 >> 1 -- vbuaa=vbuaa_ror_1
|
|
lsr
|
|
// return (unsigned int)((arr16[index & 0x7f] & 0xff) >> 1);
|
|
// [15] getValue::return#1 = (unsigned int)getValue::$2 -- vwuz1=_word_vbuaa
|
|
sta.z return
|
|
lda #0
|
|
sta.z return+1
|
|
// getValue::@return
|
|
// }
|
|
// [16] return
|
|
rts
|
|
}
|
|
// File Data
|
|
.segment Data
|
|
arr16: .fill 2*$80, 0
|
|
|