1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-27 19:50:10 +00:00

Added missing fragments for rolling variable amounts - and a few tests.

This commit is contained in:
jespergravgaard 2019-01-12 13:58:12 +01:00
parent 7b65dfedfb
commit a6fc9c157e
14 changed files with 2022 additions and 0 deletions

View File

@ -0,0 +1,7 @@
cpx #0
beq !e+
!:
asl
dex
bne !-
!e:

View File

@ -0,0 +1,7 @@
cpy #0
beq !e+
!:
asl
dey
bne !-
!e:

View File

@ -0,0 +1,9 @@
tax
lda #{c1}
cpx #0
beq !e+
!:
asl
dex
bne !-
!e:

View File

@ -44,6 +44,16 @@ public class TestPrograms {
AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false);
}
@Test
public void testRollSpriteMsb() throws IOException, URISyntaxException {
compileAndCompare("roll-sprite-msb");
}
@Test
public void testRollVariable() throws IOException, URISyntaxException {
compileAndCompare("roll-variable");
}
@Test
public void testWordsizeArrays() throws IOException, URISyntaxException {
compileAndCompare("test-word-size-arrays");

View File

@ -0,0 +1,21 @@
// Tests rolling sprite MSB by variable amount
import "c64"
void main() {
word xpos = 200;
for(byte s: 0..7) {
position_sprite(s, xpos, 50);
xpos += 10;
}
}
void position_sprite(byte spriteno, word x, byte y) {
SPRITES_YPOS[spriteno << 1] = y;
SPRITES_XPOS[spriteno << 1] = <x;
if (x > 255) {
*SPRITES_XMSB |= 1 << spriteno;
} else {
*SPRITES_XMSB &= (1 << spriteno) ^ $ff;
}
}

View File

@ -0,0 +1,9 @@
// Rolling constants by a variable amount
void main() {
byte* screen = $400;
for( byte b: 0..7) {
screen[b] = $55 << b;
}
}

View File

@ -0,0 +1,77 @@
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label SPRITES_XPOS = $d000
.label SPRITES_YPOS = $d001
.label SPRITES_XMSB = $d010
main: {
.label xpos = 2
lda #<$c8
sta xpos
lda #>$c8
sta xpos+1
ldx #0
b1:
stx position_sprite.spriteno
jsr position_sprite
clc
lda xpos
adc #<$a
sta xpos
lda xpos+1
adc #>$a
sta xpos+1
inx
cpx #8
bne b1
rts
}
position_sprite: {
.const y = $32
.label spriteno = 4
.label x = 2
lda spriteno
asl
tay
lda #y
sta SPRITES_YPOS,y
lda spriteno
asl
tay
lda x
sta SPRITES_XPOS,y
lda x+1
bne b1
lda x
cmp #$ff
beq !+
bcs b1
!:
lda #1
ldy spriteno
cpy #0
beq !e+
!:
asl
dey
bne !-
!e:
eor #$ff
and SPRITES_XMSB
sta SPRITES_XMSB
breturn:
rts
b1:
lda #1
ldy spriteno
cpy #0
beq !e+
!:
asl
dey
bne !-
!e:
ora SPRITES_XMSB
sta SPRITES_XMSB
jmp breturn
}

View File

@ -0,0 +1,47 @@
@begin: scope:[] from
[0] phi()
to:@6
@6: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @6
[3] phi()
main: scope:[main] from @6
[4] phi()
to:main::@1
main::@1: scope:[main] from main main::@3
[5] (word) main::xpos#2 ← phi( main/(byte/word/signed word/dword/signed dword) 200 main::@3/(word) main::xpos#1 )
[5] (byte) main::s#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@3/(byte) main::s#1 )
[6] (byte) position_sprite::spriteno#0 ← (byte) main::s#2
[7] (word) position_sprite::x#0 ← (word) main::xpos#2
[8] call position_sprite
to:main::@3
main::@3: scope:[main] from main::@1
[9] (word) main::xpos#1 ← (word) main::xpos#2 + (byte/signed byte/word/signed word/dword/signed dword) 10
[10] (byte) main::s#1 ← ++ (byte) main::s#2
[11] if((byte) main::s#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@3
[12] return
to:@return
position_sprite: scope:[position_sprite] from main::@1
[13] (byte~) position_sprite::$0 ← (byte) position_sprite::spriteno#0 << (byte/signed byte/word/signed word/dword/signed dword) 1
[14] *((const byte*) SPRITES_YPOS#0 + (byte~) position_sprite::$0) ← (const byte) position_sprite::y#0
[15] (byte~) position_sprite::$1 ← (byte) position_sprite::spriteno#0 << (byte/signed byte/word/signed word/dword/signed dword) 1
[16] (byte~) position_sprite::$2 ← < (word) position_sprite::x#0
[17] *((const byte*) SPRITES_XPOS#0 + (byte~) position_sprite::$1) ← (byte~) position_sprite::$2
[18] if((word) position_sprite::x#0>(byte/word/signed word/dword/signed dword) 255) goto position_sprite::@1
to:position_sprite::@3
position_sprite::@3: scope:[position_sprite] from position_sprite
[19] (byte/signed byte/word/signed word/dword/signed dword~) position_sprite::$4 ← (byte/signed byte/word/signed word/dword/signed dword) 1 << (byte) position_sprite::spriteno#0
[20] (byte/word/dword~) position_sprite::$5 ← (byte/signed byte/word/signed word/dword/signed dword~) position_sprite::$4 ^ (byte/word/signed word/dword/signed dword) 255
[21] *((const byte*) SPRITES_XMSB#0) ← *((const byte*) SPRITES_XMSB#0) & (byte/word/dword~) position_sprite::$5
to:position_sprite::@return
position_sprite::@return: scope:[position_sprite] from position_sprite::@1 position_sprite::@3
[22] return
to:@return
position_sprite::@1: scope:[position_sprite] from position_sprite
[23] (byte/signed byte/word/signed word/dword/signed dword~) position_sprite::$6 ← (byte/signed byte/word/signed word/dword/signed dword) 1 << (byte) position_sprite::spriteno#0
[24] *((const byte*) SPRITES_XMSB#0) ← *((const byte*) SPRITES_XMSB#0) | (byte/signed byte/word/signed word/dword/signed dword~) position_sprite::$6
to:position_sprite::@return

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,121 @@
(label) @6
(label) @begin
(label) @end
(byte*) BGCOL
(byte*) BGCOL1
(byte*) BGCOL2
(byte*) BGCOL3
(byte*) BGCOL4
(byte) BLACK
(byte) BLUE
(byte*) BORDERCOL
(byte) BROWN
(byte*) CHARGEN
(byte*) CIA1_INTERRUPT
(byte*) CIA1_PORT_A
(byte*) CIA1_PORT_A_DDR
(byte*) CIA1_PORT_B
(byte*) CIA1_PORT_B_DDR
(byte*) CIA2_INTERRUPT
(byte*) CIA2_PORT_A
(byte*) CIA2_PORT_A_DDR
(byte*) CIA2_PORT_B
(byte*) CIA2_PORT_B_DDR
(byte) CIA_INTERRUPT_CLEAR
(byte*) COLS
(byte) CYAN
(byte*) D011
(byte*) D016
(byte*) D018
(byte) DARK_GREY
(byte) GREEN
(byte) GREY
(void()**) HARDWARE_IRQ
(byte) IRQ_COLLISION_BG
(byte) IRQ_COLLISION_SPRITE
(byte*) IRQ_ENABLE
(byte) IRQ_LIGHTPEN
(byte) IRQ_RASTER
(byte*) IRQ_STATUS
(void()**) KERNEL_IRQ
(byte*) LIGHTPEN_X
(byte*) LIGHTPEN_Y
(byte) LIGHT_BLUE
(byte) LIGHT_GREEN
(byte) LIGHT_GREY
(byte) ORANGE
(byte) PINK
(byte*) PROCPORT
(byte) PROCPORT_BASIC_KERNEL_IO
(byte*) PROCPORT_DDR
(byte) PROCPORT_DDR_MEMORY_MASK
(byte) PROCPORT_KERNEL_IO
(byte) PROCPORT_RAM_ALL
(byte) PROCPORT_RAM_CHARROM
(byte) PROCPORT_RAM_IO
(byte) PURPLE
(byte*) RASTER
(byte) RED
(byte*) SPRITES_COLS
(byte*) SPRITES_ENABLE
(byte*) SPRITES_EXPAND_X
(byte*) SPRITES_EXPAND_Y
(byte*) SPRITES_MC
(byte*) SPRITES_MC1
(byte*) SPRITES_MC2
(byte*) SPRITES_PRIORITY
(byte*) SPRITES_XMSB
(const byte*) SPRITES_XMSB#0 SPRITES_XMSB = ((byte*))(word/dword/signed dword) 53264
(byte*) SPRITES_XPOS
(const byte*) SPRITES_XPOS#0 SPRITES_XPOS = ((byte*))(word/dword/signed dword) 53248
(byte*) SPRITES_YPOS
(const byte*) SPRITES_YPOS#0 SPRITES_YPOS = ((byte*))(word/dword/signed dword) 53249
(word) SPRITE_PTRS
(byte) VIC_BMM
(byte*) VIC_CONTROL
(byte*) VIC_CONTROL2
(byte) VIC_CSEL
(byte) VIC_DEN
(byte) VIC_ECM
(byte) VIC_MCM
(byte*) VIC_MEMORY
(byte) VIC_RSEL
(byte) VIC_RST8
(byte) WHITE
(byte) YELLOW
(void()) main()
(label) main::@1
(label) main::@3
(label) main::@return
(byte) main::s
(byte) main::s#1 reg byte x 16.5
(byte) main::s#2 reg byte x 6.6000000000000005
(word) main::xpos
(word) main::xpos#1 xpos zp ZP_WORD:2 7.333333333333333
(word) main::xpos#2 xpos zp ZP_WORD:2 8.25
(void()) position_sprite((byte) position_sprite::spriteno , (word) position_sprite::x , (byte) position_sprite::y)
(byte~) position_sprite::$0 reg byte a 4.0
(byte~) position_sprite::$1 reg byte y 2.0
(byte~) position_sprite::$2 reg byte a 4.0
(byte/signed byte/word/signed word/dword/signed dword~) position_sprite::$4 reg byte a 4.0
(byte/word/dword~) position_sprite::$5 reg byte a 4.0
(byte/signed byte/word/signed word/dword/signed dword~) position_sprite::$6 reg byte a 4.0
(label) position_sprite::@1
(label) position_sprite::@3
(label) position_sprite::@return
(byte) position_sprite::spriteno
(byte) position_sprite::spriteno#0 spriteno zp ZP_BYTE:4 2.375
(word) position_sprite::x
(word) position_sprite::x#0 x zp ZP_WORD:2 2.5
(byte) position_sprite::y
(const byte) position_sprite::y#0 y = (byte/signed byte/word/signed word/dword/signed dword) 50
reg byte x [ main::s#2 main::s#1 ]
zp ZP_WORD:2 [ main::xpos#2 main::xpos#1 position_sprite::x#0 ]
zp ZP_BYTE:4 [ position_sprite::spriteno#0 ]
reg byte a [ position_sprite::$0 ]
reg byte y [ position_sprite::$1 ]
reg byte a [ position_sprite::$2 ]
reg byte a [ position_sprite::$4 ]
reg byte a [ position_sprite::$5 ]
reg byte a [ position_sprite::$6 ]

View File

@ -0,0 +1,26 @@
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
main: {
.label screen = $400
.label b = 2
lda #0
sta b
b1:
lda #$55
ldy b
cpy #0
beq !e+
!:
asl
dey
bne !-
!e:
ldy b
sta screen,y
inc b
lda b
cmp #8
bne b1
rts
}

View File

@ -0,0 +1,22 @@
@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] (byte) main::b#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@1/(byte) main::b#1 )
[6] (byte/signed byte/word/signed word/dword/signed dword~) main::$0 ← (byte/signed byte/word/signed word/dword/signed dword) 85 << (byte) main::b#2
[7] *((const byte*) main::screen#0 + (byte) main::b#2) ← (byte/signed byte/word/signed word/dword/signed dword~) main::$0
[8] (byte) main::b#1 ← ++ (byte) main::b#2
[9] if((byte) main::b#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@1
[10] return
to:@return

View File

@ -0,0 +1,361 @@
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@1
main: scope:[main] from @1
(byte*) main::screen#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
(byte) main::b#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
to:main::@1
main::@1: scope:[main] from main main::@1
(byte*) main::screen#1 ← phi( main/(byte*) main::screen#0 main::@1/(byte*) main::screen#1 )
(byte) main::b#2 ← phi( main/(byte) main::b#0 main::@1/(byte) main::b#1 )
(byte/signed byte/word/signed word/dword/signed dword~) main::$0 ← (byte/signed byte/word/signed word/dword/signed dword) 85 << (byte) main::b#2
*((byte*) main::screen#1 + (byte) main::b#2) ← (byte/signed byte/word/signed word/dword/signed dword~) main::$0
(byte) main::b#1 ← (byte) main::b#2 + rangenext(0,7)
(bool~) main::$1 ← (byte) main::b#1 != rangelast(0,7)
if((bool~) main::$1) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@1
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
(void()) main()
(byte/signed byte/word/signed word/dword/signed dword~) main::$0
(bool~) main::$1
(label) main::@1
(label) main::@return
(byte) main::b
(byte) main::b#0
(byte) main::b#1
(byte) main::b#2
(byte*) main::screen
(byte*) main::screen#0
(byte*) main::screen#1
Culled Empty Block (label) @2
Successful SSA optimization Pass2CullEmptyBlocks
Self Phi Eliminated (byte*) main::screen#1
Successful SSA optimization Pass2SelfPhiElimination
Redundant Phi (byte*) main::screen#1 (byte*) main::screen#0
Successful SSA optimization Pass2RedundantPhiElimination
Simple Condition (bool~) main::$1 [7] if((byte) main::b#1!=rangelast(0,7)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) main::screen#0 = ((byte*))1024
Constant (const byte) main::b#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value main::b#1 ← ++ main::b#2 to ++
Resolved ranged comparison value if(main::b#1!=rangelast(0,7)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) 8
Inlining constant with var siblings (const byte) main::b#0
Constant inlined main::b#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@3(between main::@1 and main::@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
CALL GRAPH
Calls in [] to main:2
Created 1 initial phi equivalence classes
Coalesced [11] main::b#3 ← main::b#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) main::@3
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] (byte) main::b#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@1/(byte) main::b#1 )
[6] (byte/signed byte/word/signed word/dword/signed dword~) main::$0 ← (byte/signed byte/word/signed word/dword/signed dword) 85 << (byte) main::b#2
[7] *((const byte*) main::screen#0 + (byte) main::b#2) ← (byte/signed byte/word/signed word/dword/signed dword~) main::$0
[8] (byte) main::b#1 ← ++ (byte) main::b#2
[9] if((byte) main::b#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@1
[10] return
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
(byte/signed byte/word/signed word/dword/signed dword~) main::$0 22.0
(byte) main::b
(byte) main::b#1 16.5
(byte) main::b#2 14.666666666666666
(byte*) main::screen
Initial phi equivalence classes
[ main::b#2 main::b#1 ]
Added variable main::$0 to zero page equivalence class [ main::$0 ]
Complete equivalence classes
[ main::b#2 main::b#1 ]
[ main::$0 ]
Allocated zp ZP_BYTE:2 [ main::b#2 main::b#1 ]
Allocated zp ZP_BYTE:3 [ main::$0 ]
INITIAL ASM
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG1 Global Constants & labels
//SEG2 @begin
bbegin:
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
jmp b1
//SEG4 @1
b1:
//SEG5 [2] call main
//SEG6 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
jsr main
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
jmp bend
//SEG8 @end
bend:
//SEG9 main
main: {
.label screen = $400
.label _0 = 3
.label b = 2
//SEG10 [5] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
//SEG11 [5] phi (byte) main::b#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
lda #0
sta b
jmp b1
//SEG12 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
b1_from_b1:
//SEG13 [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@1->main::@1#0] -- register_copy
jmp b1
//SEG14 main::@1
b1:
//SEG15 [6] (byte/signed byte/word/signed word/dword/signed dword~) main::$0 ← (byte/signed byte/word/signed word/dword/signed dword) 85 << (byte) main::b#2 -- vbuz1=vbuc1_rol_vbuz2
lda #$55
ldy b
cpy #0
beq !e+
!:
asl
dey
bne !-
!e:
sta _0
//SEG16 [7] *((const byte*) main::screen#0 + (byte) main::b#2) ← (byte/signed byte/word/signed word/dword/signed dword~) main::$0 -- pbuc1_derefidx_vbuz1=vbuz2
lda _0
ldy b
sta screen,y
//SEG17 [8] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuz1=_inc_vbuz1
inc b
//SEG18 [9] if((byte) main::b#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
lda b
cmp #8
bne b1_from_b1
jmp breturn
//SEG19 main::@return
breturn:
//SEG20 [10] return
rts
}
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (byte/signed byte/word/signed word/dword/signed dword~) main::$0 ← (byte/signed byte/word/signed word/dword/signed dword) 85 << (byte) main::b#2 [ main::b#2 main::$0 ] ( main:2 [ main::b#2 main::$0 ] ) always clobbers reg byte a
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::b#2 main::b#1 ]
Statement [6] (byte/signed byte/word/signed word/dword/signed dword~) main::$0 ← (byte/signed byte/word/signed word/dword/signed dword) 85 << (byte) main::b#2 [ main::b#2 main::$0 ] ( main:2 [ main::b#2 main::$0 ] ) always clobbers reg byte a
Potential registers zp ZP_BYTE:2 [ main::b#2 main::b#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y ,
Potential registers zp ZP_BYTE:3 [ main::$0 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 31.17: zp ZP_BYTE:2 [ main::b#2 main::b#1 ] 22: zp ZP_BYTE:3 [ main::$0 ]
Uplift Scope []
Uplifting [main] best 523 combination zp ZP_BYTE:2 [ main::b#2 main::b#1 ] reg byte a [ main::$0 ]
Uplifting [] best 523 combination
Attempting to uplift remaining variables inzp ZP_BYTE:2 [ main::b#2 main::b#1 ]
Uplifting [main] best 523 combination zp ZP_BYTE:2 [ main::b#2 main::b#1 ]
ASSEMBLER BEFORE OPTIMIZATION
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG1 Global Constants & labels
//SEG2 @begin
bbegin:
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
jmp b1
//SEG4 @1
b1:
//SEG5 [2] call main
//SEG6 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
jsr main
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
jmp bend
//SEG8 @end
bend:
//SEG9 main
main: {
.label screen = $400
.label b = 2
//SEG10 [5] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
//SEG11 [5] phi (byte) main::b#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
lda #0
sta b
jmp b1
//SEG12 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
b1_from_b1:
//SEG13 [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@1->main::@1#0] -- register_copy
jmp b1
//SEG14 main::@1
b1:
//SEG15 [6] (byte/signed byte/word/signed word/dword/signed dword~) main::$0 ← (byte/signed byte/word/signed word/dword/signed dword) 85 << (byte) main::b#2 -- vbuaa=vbuc1_rol_vbuz1
lda #$55
ldy b
cpy #0
beq !e+
!:
asl
dey
bne !-
!e:
//SEG16 [7] *((const byte*) main::screen#0 + (byte) main::b#2) ← (byte/signed byte/word/signed word/dword/signed dword~) main::$0 -- pbuc1_derefidx_vbuz1=vbuaa
ldy b
sta screen,y
//SEG17 [8] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuz1=_inc_vbuz1
inc b
//SEG18 [9] if((byte) main::b#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
lda b
cmp #8
bne b1_from_b1
jmp breturn
//SEG19 main::@return
breturn:
//SEG20 [10] return
rts
}
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
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
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(byte/signed byte/word/signed word/dword/signed dword~) main::$0 reg byte a 22.0
(label) main::@1
(label) main::@return
(byte) main::b
(byte) main::b#1 b zp ZP_BYTE:2 16.5
(byte) main::b#2 b zp ZP_BYTE:2 14.666666666666666
(byte*) main::screen
(const byte*) main::screen#0 screen = ((byte*))(word/signed word/dword/signed dword) 1024
zp ZP_BYTE:2 [ main::b#2 main::b#1 ]
reg byte a [ main::$0 ]
FINAL ASSEMBLER
Score: 421
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
//SEG2 @begin
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG4 @1
//SEG5 [2] call main
//SEG6 [4] phi from @1 to main [phi:@1->main]
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
//SEG8 @end
//SEG9 main
main: {
.label screen = $400
.label b = 2
//SEG10 [5] phi from main to main::@1 [phi:main->main::@1]
//SEG11 [5] phi (byte) main::b#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
lda #0
sta b
//SEG12 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
//SEG13 [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@1->main::@1#0] -- register_copy
//SEG14 main::@1
b1:
//SEG15 [6] (byte/signed byte/word/signed word/dword/signed dword~) main::$0 ← (byte/signed byte/word/signed word/dword/signed dword) 85 << (byte) main::b#2 -- vbuaa=vbuc1_rol_vbuz1
lda #$55
ldy b
cpy #0
beq !e+
!:
asl
dey
bne !-
!e:
//SEG16 [7] *((const byte*) main::screen#0 + (byte) main::b#2) ← (byte/signed byte/word/signed word/dword/signed dword~) main::$0 -- pbuc1_derefidx_vbuz1=vbuaa
ldy b
sta screen,y
//SEG17 [8] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuz1=_inc_vbuz1
inc b
//SEG18 [9] if((byte) main::b#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
lda b
cmp #8
bne b1
//SEG19 main::@return
//SEG20 [10] return
rts
}

View File

@ -0,0 +1,15 @@
(label) @1
(label) @begin
(label) @end
(void()) main()
(byte/signed byte/word/signed word/dword/signed dword~) main::$0 reg byte a 22.0
(label) main::@1
(label) main::@return
(byte) main::b
(byte) main::b#1 b zp ZP_BYTE:2 16.5
(byte) main::b#2 b zp ZP_BYTE:2 14.666666666666666
(byte*) main::screen
(const byte*) main::screen#0 screen = ((byte*))(word/signed word/dword/signed dword) 1024
zp ZP_BYTE:2 [ main::b#2 main::b#1 ]
reg byte a [ main::$0 ]