2019-09-20 14:27:50 +00:00
|
|
|
Fixing pointer array-indexing *((word*) SCREEN + (number) 0)
|
|
|
|
Culled Empty Block (label) @1
|
|
|
|
Culled Empty Block (label) plus::@1
|
|
|
|
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
|
|
@begin: scope:[] from
|
2019-09-29 18:57:23 +00:00
|
|
|
(word*) SCREEN ← ((word*)) (number) $400
|
2019-09-20 14:27:50 +00:00
|
|
|
to:@2
|
|
|
|
|
|
|
|
(void()) main()
|
|
|
|
main: scope:[main] from @2
|
|
|
|
(word~) main::$0 ← call plus (number) $1234 (number) $2345
|
|
|
|
(number~) main::$1 ← (number) 0 * (const byte) SIZEOF_WORD
|
2019-09-29 18:57:23 +00:00
|
|
|
*((word*) SCREEN + (number~) main::$1) ← (word~) main::$0
|
2019-09-20 14:27:50 +00:00
|
|
|
to:main::@return
|
|
|
|
main::@return: scope:[main] from main
|
|
|
|
return
|
|
|
|
to:@return
|
|
|
|
|
|
|
|
__stackcall (word()) plus((word) plus::a , (word) plus::b)
|
|
|
|
plus: scope:[plus] from
|
|
|
|
(word) plus::a#0 ← param((word) plus::a)
|
|
|
|
(word) plus::b#0 ← param((word) plus::b)
|
|
|
|
(word~) plus::$0 ← (word) plus::a#0 + (word) plus::b#0
|
|
|
|
(word) plus::return#0 ← (word~) plus::$0
|
|
|
|
to:plus::@return
|
|
|
|
plus::@return: scope:[plus] from plus
|
|
|
|
(word) plus::return#1 ← phi( plus/(word) plus::return#0 )
|
|
|
|
return (word) plus::return#1
|
|
|
|
to:@return
|
|
|
|
@2: scope:[] from @begin
|
|
|
|
call main
|
|
|
|
to:@3
|
|
|
|
@3: scope:[] from @2
|
|
|
|
to:@end
|
|
|
|
@end: scope:[] from @3
|
|
|
|
|
|
|
|
SYMBOL TABLE SSA
|
|
|
|
(label) @2
|
|
|
|
(label) @3
|
|
|
|
(label) @begin
|
|
|
|
(label) @end
|
|
|
|
(word*) SCREEN
|
|
|
|
(const byte) SIZEOF_WORD = (byte) 2
|
|
|
|
(void()) main()
|
|
|
|
(word~) main::$0
|
|
|
|
(number~) main::$1
|
|
|
|
(label) main::@return
|
|
|
|
__stackcall (word()) plus((word) plus::a , (word) plus::b)
|
|
|
|
(word~) plus::$0
|
|
|
|
(label) plus::@return
|
|
|
|
(word) plus::a
|
|
|
|
(word) plus::a#0
|
|
|
|
(word) plus::b
|
|
|
|
(word) plus::b#0
|
|
|
|
(word) plus::return
|
|
|
|
(word) plus::return#0
|
|
|
|
(word) plus::return#1
|
|
|
|
|
|
|
|
Adding number conversion cast (unumber) $1234 in (word~) main::$0 ← call plus (number) $1234 (number) $2345
|
|
|
|
Adding number conversion cast (unumber) $2345 in (word~) main::$0 ← call plus (unumber)(number) $1234 (number) $2345
|
|
|
|
Adding number conversion cast (unumber) 0 in (number~) main::$1 ← (number) 0 * (const byte) SIZEOF_WORD
|
|
|
|
Adding number conversion cast (unumber) main::$1 in (number~) main::$1 ← (unumber)(number) 0 * (const byte) SIZEOF_WORD
|
|
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
2019-09-29 18:57:23 +00:00
|
|
|
Inlining cast (word*) SCREEN ← (word*)(number) $400
|
2019-09-20 14:27:50 +00:00
|
|
|
Successful SSA optimization Pass2InlineCast
|
|
|
|
Simplifying constant pointer cast (word*) 1024
|
|
|
|
Simplifying constant integer cast $1234
|
|
|
|
Simplifying constant integer cast $2345
|
|
|
|
Simplifying constant integer cast 0
|
|
|
|
Successful SSA optimization PassNCastSimplification
|
|
|
|
Finalized unsigned number type (word) $1234
|
|
|
|
Finalized unsigned number type (word) $2345
|
|
|
|
Finalized unsigned number type (byte) 0
|
|
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
|
|
Inferred type updated to byte in (unumber~) main::$1 ← (byte) 0 * (const byte) SIZEOF_WORD
|
|
|
|
Alias (word) plus::return#0 = (word~) plus::$0 (word) plus::return#1
|
|
|
|
Successful SSA optimization Pass2AliasElimination
|
|
|
|
Constant right-side identified [2] (byte~) main::$1 ← (byte) 0 * (const byte) SIZEOF_WORD
|
|
|
|
Successful SSA optimization Pass2ConstantRValueConsolidation
|
2019-09-29 18:57:23 +00:00
|
|
|
Constant (const word*) SCREEN = (word*) 1024
|
2019-09-20 14:27:50 +00:00
|
|
|
Constant (const byte) main::$1 = 0*SIZEOF_WORD
|
|
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
|
|
Simplifying constant evaluating to zero (byte) 0*(const byte) SIZEOF_WORD in
|
|
|
|
Successful SSA optimization PassNSimplifyConstantZero
|
2019-09-29 18:57:23 +00:00
|
|
|
Simplifying expression containing zero SCREEN in [3] *((const word*) SCREEN + (const byte) main::$1) ← (word~) main::$0
|
2019-09-20 14:27:50 +00:00
|
|
|
Successful SSA optimization PassNSimplifyExpressionWithZero
|
|
|
|
Eliminating unused constant (const byte) main::$1
|
|
|
|
Eliminating unused constant (const byte) SIZEOF_WORD
|
|
|
|
Successful SSA optimization PassNEliminateUnusedVars
|
|
|
|
Adding NOP phi() at start of @begin
|
|
|
|
Adding NOP phi() at start of @2
|
|
|
|
Adding NOP phi() at start of @3
|
|
|
|
Adding NOP phi() at start of @end
|
|
|
|
Adding NOP phi() at start of main
|
|
|
|
CALL GRAPH
|
|
|
|
Calls in [] to main:2
|
|
|
|
Calls in [main] to plus:6
|
|
|
|
|
|
|
|
Created 0 initial phi equivalence classes
|
|
|
|
Coalesced down to 0 phi equivalence classes
|
|
|
|
Culled Empty Block (label) @3
|
|
|
|
Renumbering block @2 to @1
|
|
|
|
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
|
2019-09-22 20:20:45 +00:00
|
|
|
Calling convention STACK_CALL adding prepare/execute/finalize for [5] (word~) main::$0 ← call plus (word) $1234 (word) $2345
|
2019-09-23 05:42:13 +00:00
|
|
|
Calling convention STACK_CALL replacing param((word) plus::a) with stackidx(word,(const byte) plus::OFFSET_STACK_A)
|
|
|
|
Calling convention STACK_CALL replacing param((word) plus::b) with stackidx(word,(const byte) plus::OFFSET_STACK_B)
|
2019-09-20 14:27:50 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
(void()) main()
|
|
|
|
main: scope:[main] from @1
|
|
|
|
[4] phi()
|
2019-09-22 20:20:45 +00:00
|
|
|
[5] callprepare plus (word) $1234 (word) $2345
|
|
|
|
[6] callexecute plus
|
|
|
|
[7] (word~) main::$0 ← callfinalize plus
|
2019-09-29 18:57:23 +00:00
|
|
|
[8] *((const word*) SCREEN) ← (word~) main::$0
|
2019-09-20 14:27:50 +00:00
|
|
|
to:main::@return
|
|
|
|
main::@return: scope:[main] from main
|
2019-09-22 20:20:45 +00:00
|
|
|
[9] return
|
2019-09-20 14:27:50 +00:00
|
|
|
to:@return
|
|
|
|
|
|
|
|
__stackcall (word()) plus((word) plus::a , (word) plus::b)
|
|
|
|
plus: scope:[plus] from
|
2019-09-23 05:42:13 +00:00
|
|
|
[10] (word) plus::a#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_A)
|
|
|
|
[11] (word) plus::b#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_B)
|
2019-09-22 20:20:45 +00:00
|
|
|
[12] (word) plus::return#0 ← (word) plus::a#0 + (word) plus::b#0
|
2019-09-20 14:27:50 +00:00
|
|
|
to:plus::@return
|
|
|
|
plus::@return: scope:[plus] from plus
|
2019-09-22 20:20:45 +00:00
|
|
|
[13] return (word) plus::return#0
|
2019-09-20 14:27:50 +00:00
|
|
|
to:@return
|
|
|
|
|
|
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
|
|
(void()) main()
|
2019-09-22 20:20:45 +00:00
|
|
|
(word~) main::$0 2.0
|
2019-09-20 14:27:50 +00:00
|
|
|
__stackcall (word()) plus((word) plus::a , (word) plus::b)
|
|
|
|
(word) plus::a
|
|
|
|
(word) plus::a#0 2.0
|
|
|
|
(word) plus::b
|
|
|
|
(word) plus::b#0 4.0
|
|
|
|
(word) plus::return
|
|
|
|
(word) plus::return#0 2.0
|
|
|
|
|
|
|
|
Initial phi equivalence classes
|
|
|
|
Added variable main::$0 to zero page equivalence class [ main::$0 ]
|
|
|
|
Added variable plus::a#0 to zero page equivalence class [ plus::a#0 ]
|
|
|
|
Added variable plus::b#0 to zero page equivalence class [ plus::b#0 ]
|
|
|
|
Added variable plus::return#0 to zero page equivalence class [ plus::return#0 ]
|
|
|
|
Complete equivalence classes
|
|
|
|
[ main::$0 ]
|
|
|
|
[ plus::a#0 ]
|
|
|
|
[ plus::b#0 ]
|
|
|
|
[ plus::return#0 ]
|
|
|
|
Allocated zp ZP_WORD:2 [ main::$0 ]
|
|
|
|
Allocated zp ZP_WORD:4 [ plus::a#0 ]
|
|
|
|
Allocated zp ZP_WORD:6 [ plus::b#0 ]
|
|
|
|
Allocated zp ZP_WORD:8 [ plus::return#0 ]
|
|
|
|
|
|
|
|
INITIAL ASM
|
|
|
|
Target platform is c64basic / MOS6502X
|
|
|
|
// File Comments
|
|
|
|
// Test a procedure with calling convention stack - and enough parameters to use fast ASM for cleaning stack
|
|
|
|
// Upstart
|
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(bbegin)
|
|
|
|
.pc = $80d "Program"
|
|
|
|
// Global Constants & labels
|
|
|
|
.label SCREEN = $400
|
|
|
|
.const STACK_BASE = $103
|
|
|
|
// @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
|
|
|
|
main: {
|
|
|
|
.label _0 = 2
|
2019-09-22 20:20:45 +00:00
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345
|
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
lda #>$1234
|
|
|
|
pha
|
|
|
|
lda #<$1234
|
|
|
|
pha
|
2019-09-22 20:20:45 +00:00
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
lda #>$2345
|
|
|
|
pha
|
|
|
|
lda #<$2345
|
|
|
|
pha
|
2019-09-22 20:20:45 +00:00
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345
|
|
|
|
// [6] callexecute plus -- jsr
|
2019-09-20 14:27:50 +00:00
|
|
|
jsr plus
|
2019-09-22 20:20:45 +00:00
|
|
|
// [7] (word~) main::$0 ← callfinalize plus
|
|
|
|
// [7] (word~) main::$0 ← callfinalize plus -- _stackpullbyte_2
|
|
|
|
pla
|
|
|
|
pla
|
|
|
|
// [7] (word~) main::$0 ← callfinalize plus -- vwuz1=_stackpullword_
|
|
|
|
pla
|
|
|
|
sta.z _0
|
|
|
|
pla
|
|
|
|
sta.z _0+1
|
2019-09-29 18:57:23 +00:00
|
|
|
// [8] *((const word*) SCREEN) ← (word~) main::$0 -- _deref_pwuc1=vwuz1
|
2019-09-20 14:27:50 +00:00
|
|
|
lda.z _0
|
|
|
|
sta SCREEN
|
|
|
|
lda.z _0+1
|
|
|
|
sta SCREEN+1
|
|
|
|
jmp breturn
|
|
|
|
// main::@return
|
|
|
|
breturn:
|
2019-09-22 20:20:45 +00:00
|
|
|
// [9] return
|
2019-09-20 14:27:50 +00:00
|
|
|
rts
|
|
|
|
}
|
|
|
|
// plus
|
|
|
|
// plus(word zeropage(4) a, word zeropage(6) b)
|
|
|
|
plus: {
|
|
|
|
.const OFFSET_STACK_A = 0
|
|
|
|
.const OFFSET_STACK_B = 2
|
2019-09-23 15:53:23 +00:00
|
|
|
.const OFFSET_STACK_RETURN = 2
|
2019-09-20 14:27:50 +00:00
|
|
|
.label a = 4
|
|
|
|
.label b = 6
|
|
|
|
.label return = 8
|
2019-09-23 05:42:13 +00:00
|
|
|
// [10] (word) plus::a#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_A) -- vwuz1=_stackidxword_vbuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
tsx
|
|
|
|
lda STACK_BASE+OFFSET_STACK_A,x
|
|
|
|
sta.z a
|
|
|
|
lda STACK_BASE+OFFSET_STACK_A+1,x
|
|
|
|
sta.z a+1
|
2019-09-23 05:42:13 +00:00
|
|
|
// [11] (word) plus::b#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_B) -- vwuz1=_stackidxword_vbuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
tsx
|
|
|
|
lda STACK_BASE+OFFSET_STACK_B,x
|
|
|
|
sta.z b
|
|
|
|
lda STACK_BASE+OFFSET_STACK_B+1,x
|
|
|
|
sta.z b+1
|
2019-09-22 20:20:45 +00:00
|
|
|
// [12] (word) plus::return#0 ← (word) plus::a#0 + (word) plus::b#0 -- vwuz1=vwuz2_plus_vwuz3
|
2019-09-20 14:27:50 +00:00
|
|
|
lda.z a
|
|
|
|
clc
|
|
|
|
adc.z b
|
|
|
|
sta.z return
|
|
|
|
lda.z a+1
|
|
|
|
adc.z b+1
|
|
|
|
sta.z return+1
|
|
|
|
jmp breturn
|
|
|
|
// plus::@return
|
|
|
|
breturn:
|
2019-09-22 20:20:45 +00:00
|
|
|
// [13] return (word) plus::return#0
|
2019-09-23 05:42:13 +00:00
|
|
|
// [13] return (word) plus::return#0 -- _stackidxword_vbuc1=vwuz1
|
2019-09-22 22:10:44 +00:00
|
|
|
tsx
|
|
|
|
lda.z return
|
2019-09-23 15:53:23 +00:00
|
|
|
sta STACK_BASE+OFFSET_STACK_RETURN,x
|
2019-09-22 22:10:44 +00:00
|
|
|
lda.z return+1
|
2019-09-23 15:53:23 +00:00
|
|
|
sta STACK_BASE+OFFSET_STACK_RETURN+1,x
|
2019-09-20 14:27:50 +00:00
|
|
|
rts
|
|
|
|
}
|
|
|
|
// File Data
|
|
|
|
|
|
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
2019-09-22 20:20:45 +00:00
|
|
|
Statement [5] callprepare plus (word) $1234 (word) $2345 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
|
|
|
Statement [7] (word~) main::$0 ← callfinalize plus [ main::$0 ] ( main:2 [ main::$0 ] ) always clobbers reg byte a
|
2019-09-29 18:57:23 +00:00
|
|
|
Statement [8] *((const word*) SCREEN) ← (word~) main::$0 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
2019-09-23 05:42:13 +00:00
|
|
|
Statement [10] (word) plus::a#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_A) [ plus::a#0 ] ( main:2::plus:6 [ plus::a#0 ] ) always clobbers reg byte a reg byte x
|
|
|
|
Statement [11] (word) plus::b#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_B) [ plus::a#0 plus::b#0 ] ( main:2::plus:6 [ plus::a#0 plus::b#0 ] ) always clobbers reg byte a reg byte x
|
2019-09-22 20:20:45 +00:00
|
|
|
Statement [12] (word) plus::return#0 ← (word) plus::a#0 + (word) plus::b#0 [ plus::return#0 ] ( main:2::plus:6 [ plus::return#0 ] ) always clobbers reg byte a
|
2019-09-22 22:10:44 +00:00
|
|
|
Statement [13] return (word) plus::return#0 [ ] ( main:2::plus:6 [ ] ) always clobbers reg byte a reg byte x
|
2019-09-20 14:27:50 +00:00
|
|
|
Potential registers zp ZP_WORD:2 [ main::$0 ] : zp ZP_WORD:2 ,
|
|
|
|
Potential registers zp ZP_WORD:4 [ plus::a#0 ] : zp ZP_WORD:4 ,
|
|
|
|
Potential registers zp ZP_WORD:6 [ plus::b#0 ] : zp ZP_WORD:6 ,
|
|
|
|
Potential registers zp ZP_WORD:8 [ plus::return#0 ] : zp ZP_WORD:8 ,
|
|
|
|
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
|
|
Uplift Scope [plus] 4: zp ZP_WORD:6 [ plus::b#0 ] 2: zp ZP_WORD:4 [ plus::a#0 ] 2: zp ZP_WORD:8 [ plus::return#0 ]
|
2019-09-22 20:20:45 +00:00
|
|
|
Uplift Scope [main] 2: zp ZP_WORD:2 [ main::$0 ]
|
2019-09-20 14:27:50 +00:00
|
|
|
Uplift Scope []
|
|
|
|
|
2019-09-22 22:10:44 +00:00
|
|
|
Uplifting [plus] best 164 combination zp ZP_WORD:6 [ plus::b#0 ] zp ZP_WORD:4 [ plus::a#0 ] zp ZP_WORD:8 [ plus::return#0 ]
|
|
|
|
Uplifting [main] best 164 combination zp ZP_WORD:2 [ main::$0 ]
|
|
|
|
Uplifting [] best 164 combination
|
2019-09-20 14:27:50 +00:00
|
|
|
Coalescing zero page register [ zp ZP_WORD:4 [ plus::a#0 ] ] with [ zp ZP_WORD:8 [ plus::return#0 ] ] - score: 1
|
2019-09-22 20:20:45 +00:00
|
|
|
Coalescing zero page register [ zp ZP_WORD:4 [ plus::a#0 plus::return#0 ] ] with [ zp ZP_WORD:2 [ main::$0 ] ]
|
|
|
|
Allocated (was zp ZP_WORD:4) zp ZP_WORD:2 [ plus::a#0 plus::return#0 main::$0 ]
|
|
|
|
Allocated (was zp ZP_WORD:6) zp ZP_WORD:4 [ plus::b#0 ]
|
2019-09-20 14:27:50 +00:00
|
|
|
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
|
|
// File Comments
|
|
|
|
// Test a procedure with calling convention stack - and enough parameters to use fast ASM for cleaning stack
|
|
|
|
// Upstart
|
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(bbegin)
|
|
|
|
.pc = $80d "Program"
|
|
|
|
// Global Constants & labels
|
|
|
|
.label SCREEN = $400
|
|
|
|
.const STACK_BASE = $103
|
|
|
|
// @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
|
|
|
|
main: {
|
|
|
|
.label _0 = 2
|
2019-09-22 20:20:45 +00:00
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345
|
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
lda #>$1234
|
|
|
|
pha
|
|
|
|
lda #<$1234
|
|
|
|
pha
|
2019-09-22 20:20:45 +00:00
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
lda #>$2345
|
|
|
|
pha
|
|
|
|
lda #<$2345
|
|
|
|
pha
|
2019-09-22 20:20:45 +00:00
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345
|
|
|
|
// [6] callexecute plus -- jsr
|
2019-09-20 14:27:50 +00:00
|
|
|
jsr plus
|
2019-09-22 20:20:45 +00:00
|
|
|
// [7] (word~) main::$0 ← callfinalize plus
|
|
|
|
// [7] (word~) main::$0 ← callfinalize plus -- _stackpullbyte_2
|
|
|
|
pla
|
|
|
|
pla
|
|
|
|
// [7] (word~) main::$0 ← callfinalize plus -- vwuz1=_stackpullword_
|
|
|
|
pla
|
|
|
|
sta.z _0
|
|
|
|
pla
|
|
|
|
sta.z _0+1
|
2019-09-29 18:57:23 +00:00
|
|
|
// [8] *((const word*) SCREEN) ← (word~) main::$0 -- _deref_pwuc1=vwuz1
|
2019-09-20 14:27:50 +00:00
|
|
|
lda.z _0
|
|
|
|
sta SCREEN
|
|
|
|
lda.z _0+1
|
|
|
|
sta SCREEN+1
|
|
|
|
jmp breturn
|
|
|
|
// main::@return
|
|
|
|
breturn:
|
2019-09-22 20:20:45 +00:00
|
|
|
// [9] return
|
2019-09-20 14:27:50 +00:00
|
|
|
rts
|
|
|
|
}
|
|
|
|
// plus
|
2019-09-22 20:20:45 +00:00
|
|
|
// plus(word zeropage(2) a, word zeropage(4) b)
|
2019-09-20 14:27:50 +00:00
|
|
|
plus: {
|
|
|
|
.const OFFSET_STACK_A = 0
|
|
|
|
.const OFFSET_STACK_B = 2
|
2019-09-23 15:53:23 +00:00
|
|
|
.const OFFSET_STACK_RETURN = 2
|
2019-09-22 20:20:45 +00:00
|
|
|
.label a = 2
|
|
|
|
.label b = 4
|
|
|
|
.label return = 2
|
2019-09-23 05:42:13 +00:00
|
|
|
// [10] (word) plus::a#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_A) -- vwuz1=_stackidxword_vbuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
tsx
|
|
|
|
lda STACK_BASE+OFFSET_STACK_A,x
|
|
|
|
sta.z a
|
|
|
|
lda STACK_BASE+OFFSET_STACK_A+1,x
|
|
|
|
sta.z a+1
|
2019-09-23 05:42:13 +00:00
|
|
|
// [11] (word) plus::b#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_B) -- vwuz1=_stackidxword_vbuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
tsx
|
|
|
|
lda STACK_BASE+OFFSET_STACK_B,x
|
|
|
|
sta.z b
|
|
|
|
lda STACK_BASE+OFFSET_STACK_B+1,x
|
|
|
|
sta.z b+1
|
2019-09-22 20:20:45 +00:00
|
|
|
// [12] (word) plus::return#0 ← (word) plus::a#0 + (word) plus::b#0 -- vwuz1=vwuz1_plus_vwuz2
|
2019-09-20 14:27:50 +00:00
|
|
|
lda.z return
|
|
|
|
clc
|
|
|
|
adc.z b
|
|
|
|
sta.z return
|
|
|
|
lda.z return+1
|
|
|
|
adc.z b+1
|
|
|
|
sta.z return+1
|
|
|
|
jmp breturn
|
|
|
|
// plus::@return
|
|
|
|
breturn:
|
2019-09-22 20:20:45 +00:00
|
|
|
// [13] return (word) plus::return#0
|
2019-09-23 05:42:13 +00:00
|
|
|
// [13] return (word) plus::return#0 -- _stackidxword_vbuc1=vwuz1
|
2019-09-22 22:10:44 +00:00
|
|
|
tsx
|
|
|
|
lda.z return
|
2019-09-23 15:53:23 +00:00
|
|
|
sta STACK_BASE+OFFSET_STACK_RETURN,x
|
2019-09-22 22:10:44 +00:00
|
|
|
lda.z return+1
|
2019-09-23 15:53:23 +00:00
|
|
|
sta STACK_BASE+OFFSET_STACK_RETURN+1,x
|
2019-09-20 14:27:50 +00:00
|
|
|
rts
|
|
|
|
}
|
|
|
|
// File Data
|
|
|
|
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
|
|
Removing instruction jmp b1
|
|
|
|
Removing instruction jmp bend
|
|
|
|
Removing instruction jmp breturn
|
|
|
|
Removing instruction jmp breturn
|
|
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
|
|
Removing instruction b1_from_bbegin:
|
|
|
|
Removing instruction b1:
|
|
|
|
Removing instruction main_from_b1:
|
|
|
|
Removing instruction bend_from_b1:
|
|
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
|
|
Removing instruction bend:
|
|
|
|
Removing instruction breturn:
|
|
|
|
Removing instruction breturn:
|
|
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
Updating BasicUpstart to call main directly
|
|
|
|
Removing instruction jsr main
|
|
|
|
Succesful ASM optimization Pass5SkipBegin
|
|
|
|
Removing instruction bbegin:
|
|
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
|
|
|
|
FINAL SYMBOL TABLE
|
|
|
|
(label) @1
|
|
|
|
(label) @begin
|
|
|
|
(label) @end
|
2019-09-29 18:57:23 +00:00
|
|
|
(const word*) SCREEN SCREEN = (word*) 1024
|
2019-09-20 14:27:50 +00:00
|
|
|
(const word) STACK_BASE STACK_BASE = (word) $103
|
|
|
|
(void()) main()
|
2019-09-22 20:20:45 +00:00
|
|
|
(word~) main::$0 $0 zp ZP_WORD:2 2.0
|
2019-09-20 14:27:50 +00:00
|
|
|
(label) main::@return
|
|
|
|
__stackcall (word()) plus((word) plus::a , (word) plus::b)
|
|
|
|
(label) plus::@return
|
|
|
|
(const byte) plus::OFFSET_STACK_A OFFSET_STACK_A = (byte) 0
|
|
|
|
(const byte) plus::OFFSET_STACK_B OFFSET_STACK_B = (byte) 2
|
2019-09-23 15:53:23 +00:00
|
|
|
(const byte) plus::OFFSET_STACK_RETURN OFFSET_STACK_RETURN = (byte) 2
|
2019-09-20 14:27:50 +00:00
|
|
|
(word) plus::a
|
2019-09-22 20:20:45 +00:00
|
|
|
(word) plus::a#0 a zp ZP_WORD:2 2.0
|
2019-09-20 14:27:50 +00:00
|
|
|
(word) plus::b
|
2019-09-22 20:20:45 +00:00
|
|
|
(word) plus::b#0 b zp ZP_WORD:4 4.0
|
2019-09-20 14:27:50 +00:00
|
|
|
(word) plus::return
|
2019-09-22 20:20:45 +00:00
|
|
|
(word) plus::return#0 return zp ZP_WORD:2 2.0
|
2019-09-20 14:27:50 +00:00
|
|
|
|
2019-09-22 20:20:45 +00:00
|
|
|
zp ZP_WORD:2 [ plus::a#0 plus::return#0 main::$0 ]
|
|
|
|
zp ZP_WORD:4 [ plus::b#0 ]
|
2019-09-20 14:27:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
FINAL ASSEMBLER
|
2019-09-22 22:10:44 +00:00
|
|
|
Score: 146
|
2019-09-20 14:27:50 +00:00
|
|
|
|
|
|
|
// File Comments
|
|
|
|
// Test a procedure with calling convention stack - and enough parameters to use fast ASM for cleaning stack
|
|
|
|
// Upstart
|
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(main)
|
|
|
|
.pc = $80d "Program"
|
|
|
|
// Global Constants & labels
|
|
|
|
.label SCREEN = $400
|
|
|
|
.const STACK_BASE = $103
|
|
|
|
// @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
|
|
|
|
main: {
|
|
|
|
.label _0 = 2
|
|
|
|
// plus(0x1234, 0x2345)
|
2019-09-22 20:20:45 +00:00
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345
|
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
lda #>$1234
|
|
|
|
pha
|
|
|
|
lda #<$1234
|
|
|
|
pha
|
2019-09-22 20:20:45 +00:00
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
lda #>$2345
|
|
|
|
pha
|
|
|
|
lda #<$2345
|
|
|
|
pha
|
2019-09-22 20:20:45 +00:00
|
|
|
// [5] callprepare plus (word) $1234 (word) $2345
|
|
|
|
// [6] callexecute plus -- jsr
|
2019-09-20 14:27:50 +00:00
|
|
|
jsr plus
|
2019-09-22 20:20:45 +00:00
|
|
|
// [7] (word~) main::$0 ← callfinalize plus
|
|
|
|
// [7] (word~) main::$0 ← callfinalize plus -- _stackpullbyte_2
|
|
|
|
pla
|
|
|
|
pla
|
|
|
|
// [7] (word~) main::$0 ← callfinalize plus -- vwuz1=_stackpullword_
|
|
|
|
pla
|
|
|
|
sta.z _0
|
|
|
|
pla
|
|
|
|
sta.z _0+1
|
2019-09-20 14:27:50 +00:00
|
|
|
// SCREEN[0] = plus(0x1234, 0x2345)
|
2019-09-29 18:57:23 +00:00
|
|
|
// [8] *((const word*) SCREEN) ← (word~) main::$0 -- _deref_pwuc1=vwuz1
|
2019-09-20 14:27:50 +00:00
|
|
|
lda.z _0
|
|
|
|
sta SCREEN
|
|
|
|
lda.z _0+1
|
|
|
|
sta SCREEN+1
|
|
|
|
// main::@return
|
|
|
|
// }
|
2019-09-22 20:20:45 +00:00
|
|
|
// [9] return
|
2019-09-20 14:27:50 +00:00
|
|
|
rts
|
|
|
|
}
|
|
|
|
// plus
|
2019-09-22 20:20:45 +00:00
|
|
|
// plus(word zeropage(2) a, word zeropage(4) b)
|
2019-09-20 14:27:50 +00:00
|
|
|
plus: {
|
|
|
|
.const OFFSET_STACK_A = 0
|
|
|
|
.const OFFSET_STACK_B = 2
|
2019-09-23 15:53:23 +00:00
|
|
|
.const OFFSET_STACK_RETURN = 2
|
2019-09-22 20:20:45 +00:00
|
|
|
.label a = 2
|
|
|
|
.label b = 4
|
|
|
|
.label return = 2
|
2019-09-23 05:42:13 +00:00
|
|
|
// [10] (word) plus::a#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_A) -- vwuz1=_stackidxword_vbuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
tsx
|
|
|
|
lda STACK_BASE+OFFSET_STACK_A,x
|
|
|
|
sta.z a
|
|
|
|
lda STACK_BASE+OFFSET_STACK_A+1,x
|
|
|
|
sta.z a+1
|
2019-09-23 05:42:13 +00:00
|
|
|
// [11] (word) plus::b#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_B) -- vwuz1=_stackidxword_vbuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
tsx
|
|
|
|
lda STACK_BASE+OFFSET_STACK_B,x
|
|
|
|
sta.z b
|
|
|
|
lda STACK_BASE+OFFSET_STACK_B+1,x
|
|
|
|
sta.z b+1
|
|
|
|
// return a+b;
|
2019-09-22 20:20:45 +00:00
|
|
|
// [12] (word) plus::return#0 ← (word) plus::a#0 + (word) plus::b#0 -- vwuz1=vwuz1_plus_vwuz2
|
2019-09-20 14:27:50 +00:00
|
|
|
lda.z return
|
|
|
|
clc
|
|
|
|
adc.z b
|
|
|
|
sta.z return
|
|
|
|
lda.z return+1
|
|
|
|
adc.z b+1
|
|
|
|
sta.z return+1
|
|
|
|
// plus::@return
|
|
|
|
// }
|
2019-09-22 20:20:45 +00:00
|
|
|
// [13] return (word) plus::return#0
|
2019-09-23 05:42:13 +00:00
|
|
|
// [13] return (word) plus::return#0 -- _stackidxword_vbuc1=vwuz1
|
2019-09-22 22:10:44 +00:00
|
|
|
tsx
|
|
|
|
lda.z return
|
2019-09-23 15:53:23 +00:00
|
|
|
sta STACK_BASE+OFFSET_STACK_RETURN,x
|
2019-09-22 22:10:44 +00:00
|
|
|
lda.z return+1
|
2019-09-23 15:53:23 +00:00
|
|
|
sta STACK_BASE+OFFSET_STACK_RETURN+1,x
|
2019-09-20 14:27:50 +00:00
|
|
|
rts
|
|
|
|
}
|
|
|
|
// File Data
|
|
|
|
|