mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-06-03 07:29:37 +00:00
435 lines
14 KiB
Plaintext
435 lines
14 KiB
Plaintext
Resolved forward reference irq to __interrupt(rom_min_c64) void irq()
|
|
Resolved forward reference framedone to framedone
|
|
Inlined call call __init
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
|
|
void main()
|
|
main: scope:[main] from __start::@1
|
|
asm { sei }
|
|
*CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR_ALL
|
|
*VICII_CONTROL1 = *VICII_CONTROL1 & $7f
|
|
*RASTER = $fd
|
|
*IRQ_ENABLE = IRQ_RASTER
|
|
*KERNEL_IRQ = &irq
|
|
asm { cli }
|
|
to:main::@1
|
|
main::@1: scope:[main] from main main::@2 main::@3
|
|
if(true) goto main::@2
|
|
to:main::@return
|
|
main::@2: scope:[main] from main::@1
|
|
main::$0 = *RASTER < $14
|
|
main::$1 = ! main::$0
|
|
if(main::$1) goto main::@1
|
|
to:main::@3
|
|
main::@3: scope:[main] from main::@2
|
|
to:main::@1
|
|
main::@return: scope:[main] from main::@1
|
|
return
|
|
to:@return
|
|
|
|
__interrupt(rom_min_c64) void irq()
|
|
irq: scope:[irq] from
|
|
*BG_COLOR = ++ *BG_COLOR
|
|
*IRQ_STATUS = IRQ_RASTER
|
|
irq::$1 = *RASTER > $32
|
|
irq::$2 = ! irq::$1
|
|
if(irq::$2) goto irq::@1
|
|
to:irq::@2
|
|
irq::@1: scope:[irq] from irq irq::@2
|
|
*BG_COLOR = -- *BG_COLOR
|
|
to:irq::@return
|
|
irq::@2: scope:[irq] from irq
|
|
to:irq::@1
|
|
irq::@return: scope:[irq] from irq::@1
|
|
return
|
|
to:@return
|
|
|
|
void __start()
|
|
__start: scope:[__start] from
|
|
to:__start::__init1
|
|
__start::__init1: scope:[__start] from __start
|
|
to:__start::@1
|
|
__start::@1: scope:[__start] from __start::__init1
|
|
call main
|
|
to:__start::@2
|
|
__start::@2: scope:[__start] from __start::@1
|
|
to:__start::@return
|
|
__start::@return: scope:[__start] from __start::@2
|
|
return
|
|
to:@return
|
|
|
|
SYMBOL TABLE SSA
|
|
__constant char * const BG_COLOR = (char *)$d020
|
|
__constant char * const CIA1_INTERRUPT = (char *)$dc0d
|
|
__constant const char CIA_INTERRUPT_CLEAR_ALL = $7f
|
|
__constant char * const IRQ_ENABLE = (char *)$d01a
|
|
__constant const char IRQ_RASTER = 1
|
|
__constant char * const IRQ_STATUS = (char *)$d019
|
|
__constant void (** const KERNEL_IRQ)() = (void (**)())$314
|
|
__constant char * const RASTER = (char *)$d012
|
|
__constant char * const VICII_CONTROL1 = (char *)$d011
|
|
void __start()
|
|
__interrupt(rom_min_c64) void irq()
|
|
bool irq::$1
|
|
bool irq::$2
|
|
void main()
|
|
bool main::$0
|
|
bool main::$1
|
|
|
|
Adding number conversion cast (unumber) $7f in *VICII_CONTROL1 = *VICII_CONTROL1 & $7f
|
|
Adding number conversion cast (unumber) $fd in *RASTER = $fd
|
|
Adding number conversion cast (unumber) $14 in main::$0 = *RASTER < $14
|
|
Adding number conversion cast (unumber) $32 in irq::$1 = *RASTER > $32
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Inlining cast *RASTER = (unumber)$fd
|
|
Successful SSA optimization Pass2InlineCast
|
|
Simplifying constant pointer cast (void (**)()) 788
|
|
Simplifying constant pointer cast (char *) 53266
|
|
Simplifying constant pointer cast (char *) 53265
|
|
Simplifying constant pointer cast (char *) 53273
|
|
Simplifying constant pointer cast (char *) 53274
|
|
Simplifying constant pointer cast (char *) 53280
|
|
Simplifying constant pointer cast (char *) 56333
|
|
Simplifying constant integer cast $7f
|
|
Simplifying constant integer cast $fd
|
|
Simplifying constant integer cast $14
|
|
Simplifying constant integer cast $32
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (char) $7f
|
|
Finalized unsigned number type (char) $fd
|
|
Finalized unsigned number type (char) $14
|
|
Finalized unsigned number type (char) $32
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Inversing boolean not [9] main::$1 = *RASTER >= $14 from [8] main::$0 = *RASTER < $14
|
|
Inversing boolean not [15] irq::$2 = *RASTER <= $32 from [14] irq::$1 = *RASTER > $32
|
|
Successful SSA optimization Pass2UnaryNotSimplification
|
|
Simple Condition main::$1 [9] if(*RASTER>=$14) goto main::@1
|
|
Simple Condition irq::$2 [14] if(*RASTER<=$32) goto irq::@1
|
|
Successful SSA optimization Pass2ConditionalJumpSimplification
|
|
if() condition always true - replacing block destination [7] if(true) goto main::@2
|
|
Successful SSA optimization Pass2ConstantIfs
|
|
Rewriting conditional comparison [14] if(*RASTER<=$32) goto irq::@1
|
|
Removing unused block main::@return
|
|
Successful SSA optimization Pass2EliminateUnusedBlocks
|
|
Removing unused procedure __start
|
|
Removing unused procedure block __start
|
|
Removing unused procedure block __start::__init1
|
|
Removing unused procedure block __start::@1
|
|
Removing unused procedure block __start::@2
|
|
Removing unused procedure block __start::@return
|
|
Successful SSA optimization PassNEliminateEmptyStart
|
|
Adding number conversion cast (unumber) $32+1 in [10] if(*RASTER<$32+1) goto irq::@1
|
|
Adding number conversion cast (unumber) 1 in [10] if(*RASTER<(unumber)$32+1) goto irq::@1
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Simplifying constant integer cast $32+(unumber)1
|
|
Simplifying constant integer cast 1
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (char) 1
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Adding NOP phi() at start of irq::@2
|
|
Adding NOP phi() at start of main::@1
|
|
Adding NOP phi() at start of main::@3
|
|
CALL GRAPH
|
|
|
|
Created 0 initial phi equivalence classes
|
|
Coalesced down to 0 phi equivalence classes
|
|
Culled Empty Block label main::@1
|
|
Renumbering block main::@2 to main::@1
|
|
Renumbering block main::@3 to main::@2
|
|
Adding NOP phi() at start of irq::@2
|
|
Adding NOP phi() at start of main::@2
|
|
|
|
FINAL CONTROL FLOW GRAPH
|
|
|
|
__interrupt(rom_min_c64) void irq()
|
|
irq: scope:[irq] from
|
|
[0] *BG_COLOR = ++ *BG_COLOR
|
|
[1] *IRQ_STATUS = IRQ_RASTER
|
|
[2] if(*RASTER<$32+1) goto irq::@1
|
|
to:irq::@2
|
|
irq::@2: scope:[irq] from irq
|
|
[3] phi()
|
|
to:irq::@1
|
|
irq::@1: scope:[irq] from irq irq::@2
|
|
[4] *BG_COLOR = -- *BG_COLOR
|
|
to:irq::@return
|
|
irq::@return: scope:[irq] from irq::@1
|
|
[5] return
|
|
to:@return
|
|
|
|
void main()
|
|
main: scope:[main] from
|
|
asm { sei }
|
|
[7] *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR_ALL
|
|
[8] *VICII_CONTROL1 = *VICII_CONTROL1 & $7f
|
|
[9] *RASTER = $fd
|
|
[10] *IRQ_ENABLE = IRQ_RASTER
|
|
[11] *KERNEL_IRQ = &irq
|
|
asm { cli }
|
|
to:main::@1
|
|
main::@1: scope:[main] from main main::@1 main::@2
|
|
[13] if(*RASTER>=$14) goto main::@1
|
|
to:main::@2
|
|
main::@2: scope:[main] from main::@1
|
|
[14] phi()
|
|
to:main::@1
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
__interrupt(rom_min_c64) void irq()
|
|
void main()
|
|
|
|
Initial phi equivalence classes
|
|
Complete equivalence classes
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [1] *IRQ_STATUS = IRQ_RASTER [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Statement [2] if(*RASTER<$32+1) goto irq::@1 [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Statement [7] *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR_ALL [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Statement [8] *VICII_CONTROL1 = *VICII_CONTROL1 & $7f [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Statement [9] *RASTER = $fd [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Statement [10] *IRQ_ENABLE = IRQ_RASTER [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Statement [11] *KERNEL_IRQ = &irq [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Statement [13] if(*RASTER>=$14) goto main::@1 [ ] ( [ ] { } ) always clobbers reg byte a
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [main]
|
|
Uplift Scope [irq]
|
|
Uplift Scope []
|
|
|
|
Uplifting [main] best 1049 combination
|
|
Uplifting [irq] best 1049 combination
|
|
Uplifting [] best 1049 combination
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Illustrates a problem where a volatile bool modified at the end of an IRQ is not stored properly
|
|
// because it is assigned to the A register
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="irq-volatile-bool-problem.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
|
|
.const IRQ_RASTER = 1
|
|
.const CIA_INTERRUPT_CLEAR_ALL = $7f
|
|
.label KERNEL_IRQ = $314
|
|
.label RASTER = $d012
|
|
.label VICII_CONTROL1 = $d011
|
|
.label IRQ_STATUS = $d019
|
|
.label IRQ_ENABLE = $d01a
|
|
.label BG_COLOR = $d020
|
|
.label CIA1_INTERRUPT = $dc0d
|
|
.segment Code
|
|
// irq
|
|
irq: {
|
|
// interrupt(isr_rom_min_c64_entry) -- isr_rom_min_c64_entry
|
|
// [0] *BG_COLOR = ++ *BG_COLOR -- _deref_pbuc1=_inc__deref_pbuc1
|
|
inc BG_COLOR
|
|
// [1] *IRQ_STATUS = IRQ_RASTER -- _deref_pbuc1=vbuc2
|
|
lda #IRQ_RASTER
|
|
sta IRQ_STATUS
|
|
// [2] if(*RASTER<$32+1) goto irq::@1 -- _deref_pbuc1_lt_vbuc2_then_la1
|
|
lda RASTER
|
|
cmp #$32+1
|
|
bcc __b1
|
|
// [3] phi from irq to irq::@2 [phi:irq->irq::@2]
|
|
__b2_from_irq:
|
|
jmp __b2
|
|
// irq::@2
|
|
__b2:
|
|
jmp __b1
|
|
// irq::@1
|
|
__b1:
|
|
// [4] *BG_COLOR = -- *BG_COLOR -- _deref_pbuc1=_dec__deref_pbuc1
|
|
dec BG_COLOR
|
|
jmp __breturn
|
|
// irq::@return
|
|
__breturn:
|
|
// [5] return
|
|
// interrupt(isr_rom_min_c64_exit) -- isr_rom_min_c64_exit
|
|
jmp $ea81
|
|
}
|
|
// main
|
|
main: {
|
|
// asm { sei }
|
|
sei
|
|
// [7] *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR_ALL -- _deref_pbuc1=vbuc2
|
|
// Disable CIA 1 Timer IRQ
|
|
lda #CIA_INTERRUPT_CLEAR_ALL
|
|
sta CIA1_INTERRUPT
|
|
// [8] *VICII_CONTROL1 = *VICII_CONTROL1 & $7f -- _deref_pbuc1=_deref_pbuc1_band_vbuc2
|
|
// Set raster line to $0fd
|
|
lda #$7f
|
|
and VICII_CONTROL1
|
|
sta VICII_CONTROL1
|
|
// [9] *RASTER = $fd -- _deref_pbuc1=vbuc2
|
|
lda #$fd
|
|
sta RASTER
|
|
// [10] *IRQ_ENABLE = IRQ_RASTER -- _deref_pbuc1=vbuc2
|
|
// Enable Raster Interrupt
|
|
lda #IRQ_RASTER
|
|
sta IRQ_ENABLE
|
|
// [11] *KERNEL_IRQ = &irq -- _deref_qprc1=pprc2
|
|
// Set the IRQ routine
|
|
lda #<irq
|
|
sta KERNEL_IRQ
|
|
lda #>irq
|
|
sta KERNEL_IRQ+1
|
|
// asm { cli }
|
|
cli
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [13] if(*RASTER>=$14) goto main::@1 -- _deref_pbuc1_ge_vbuc2_then_la1
|
|
lda RASTER
|
|
cmp #$14
|
|
bcs __b1
|
|
// [14] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
|
|
__b2_from___b1:
|
|
jmp __b2
|
|
// main::@2
|
|
__b2:
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __b2
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __breturn
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __b2
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Removing instruction __b2_from_irq:
|
|
Removing instruction __b2:
|
|
Removing instruction __b2_from___b1:
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
Removing instruction __breturn:
|
|
Removing instruction __b2:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
Removing instruction bcc __b1
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Removing instruction __b1:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
FINAL SYMBOL TABLE
|
|
__constant char * const BG_COLOR = (char *) 53280
|
|
__constant char * const CIA1_INTERRUPT = (char *) 56333
|
|
__constant const char CIA_INTERRUPT_CLEAR_ALL = $7f
|
|
__constant char * const IRQ_ENABLE = (char *) 53274
|
|
__constant const char IRQ_RASTER = 1
|
|
__constant char * const IRQ_STATUS = (char *) 53273
|
|
__constant void (** const KERNEL_IRQ)() = (void (**)()) 788
|
|
__constant char * const RASTER = (char *) 53266
|
|
__constant char * const VICII_CONTROL1 = (char *) 53265
|
|
__interrupt(rom_min_c64) void irq()
|
|
void main()
|
|
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 978
|
|
|
|
// File Comments
|
|
// Illustrates a problem where a volatile bool modified at the end of an IRQ is not stored properly
|
|
// because it is assigned to the A register
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="irq-volatile-bool-problem.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
|
|
.const IRQ_RASTER = 1
|
|
.const CIA_INTERRUPT_CLEAR_ALL = $7f
|
|
.label KERNEL_IRQ = $314
|
|
.label RASTER = $d012
|
|
.label VICII_CONTROL1 = $d011
|
|
.label IRQ_STATUS = $d019
|
|
.label IRQ_ENABLE = $d01a
|
|
.label BG_COLOR = $d020
|
|
.label CIA1_INTERRUPT = $dc0d
|
|
.segment Code
|
|
// irq
|
|
irq: {
|
|
// interrupt(isr_rom_min_c64_entry) -- isr_rom_min_c64_entry
|
|
// (*BG_COLOR)++;
|
|
// [0] *BG_COLOR = ++ *BG_COLOR -- _deref_pbuc1=_inc__deref_pbuc1
|
|
inc BG_COLOR
|
|
// *IRQ_STATUS = IRQ_RASTER
|
|
// [1] *IRQ_STATUS = IRQ_RASTER -- _deref_pbuc1=vbuc2
|
|
lda #IRQ_RASTER
|
|
sta IRQ_STATUS
|
|
// if (*RASTER>50)
|
|
// [2] if(*RASTER<$32+1) goto irq::@1 -- _deref_pbuc1_lt_vbuc2_then_la1
|
|
lda RASTER
|
|
cmp #$32+1
|
|
// [3] phi from irq to irq::@2 [phi:irq->irq::@2]
|
|
// irq::@2
|
|
// irq::@1
|
|
// (*BG_COLOR)--;
|
|
// [4] *BG_COLOR = -- *BG_COLOR -- _deref_pbuc1=_dec__deref_pbuc1
|
|
dec BG_COLOR
|
|
// irq::@return
|
|
// }
|
|
// [5] return
|
|
// interrupt(isr_rom_min_c64_exit) -- isr_rom_min_c64_exit
|
|
jmp $ea81
|
|
}
|
|
// main
|
|
main: {
|
|
// asm
|
|
// asm { sei }
|
|
sei
|
|
// *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR_ALL
|
|
// [7] *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR_ALL -- _deref_pbuc1=vbuc2
|
|
// Disable CIA 1 Timer IRQ
|
|
lda #CIA_INTERRUPT_CLEAR_ALL
|
|
sta CIA1_INTERRUPT
|
|
// *VICII_CONTROL1 &=$7f
|
|
// [8] *VICII_CONTROL1 = *VICII_CONTROL1 & $7f -- _deref_pbuc1=_deref_pbuc1_band_vbuc2
|
|
// Set raster line to $0fd
|
|
lda #$7f
|
|
and VICII_CONTROL1
|
|
sta VICII_CONTROL1
|
|
// *RASTER = $fd
|
|
// [9] *RASTER = $fd -- _deref_pbuc1=vbuc2
|
|
lda #$fd
|
|
sta RASTER
|
|
// *IRQ_ENABLE = IRQ_RASTER
|
|
// [10] *IRQ_ENABLE = IRQ_RASTER -- _deref_pbuc1=vbuc2
|
|
// Enable Raster Interrupt
|
|
lda #IRQ_RASTER
|
|
sta IRQ_ENABLE
|
|
// *KERNEL_IRQ = &irq
|
|
// [11] *KERNEL_IRQ = &irq -- _deref_qprc1=pprc2
|
|
// Set the IRQ routine
|
|
lda #<irq
|
|
sta KERNEL_IRQ
|
|
lda #>irq
|
|
sta KERNEL_IRQ+1
|
|
// asm
|
|
// asm { cli }
|
|
cli
|
|
// main::@1
|
|
__b1:
|
|
// if(*RASTER<20)
|
|
// [13] if(*RASTER>=$14) goto main::@1 -- _deref_pbuc1_ge_vbuc2_then_la1
|
|
lda RASTER
|
|
cmp #$14
|
|
bcs __b1
|
|
// [14] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
|
|
// main::@2
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
|