1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-08 17:54:40 +00:00

Added missing fragments for Paul Nelsen

This commit is contained in:
jespergravgaard 2019-08-22 11:13:52 +02:00
parent 1d5cb644ad
commit 5923245630
8 changed files with 444 additions and 0 deletions

View File

@ -0,0 +1,7 @@
clc
lda {c1}
adc #<{c2}
sta {z1}
lda {c1}+1
adc #>{c2}
sta {z1}+1

View File

@ -0,0 +1,7 @@
sec
lda {c1}
sbc #<{c2}
sta {z1}
lda {c1}+1
sbc #>{c2}
sta {z1}+1

View File

@ -37,6 +37,12 @@ public class TestPrograms {
}
@Test
public void testForcedZeropage() throws IOException, URISyntaxException {
compileAndCompare("forced-zeropage");
}
// TODO: Fix float error message https://gitlab.com/camelot/kickc/issues/286
/*
@Test

View File

@ -0,0 +1,12 @@
// Test some forced zeropage access
void main() {
word u = 555;
u = *(word *)0xA0 - u;
*((word*)0x0400) = u;
*(byte **)0xF3 = *(byte **)0xD1 + 0xD400;
}

View File

@ -0,0 +1,31 @@
// Test some forced zeropage access
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
main: {
.label _5 = 4
.label u = 2
sec
lda $a0
sbc #<$22b
sta.z u
lda $a0+1
sbc #>$22b
sta.z u+1
lda.z u
sta $400
lda.z u+1
sta $400+1
clc
lda $d1
adc #<$d400
sta.z _5
lda $d1+1
adc #>$d400
sta.z _5+1
lda.z _5
sta $f3
lda.z _5+1
sta $f3+1
rts
}

View File

@ -0,0 +1,18 @@
@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] (word) main::u#1 ← *((word*) 160) - (word) $22b
[5] *((word*) 1024) ← (word) main::u#1
[6] (byte*~) main::$5 ← *((byte**) 209) + (word) $d400
[7] *((byte**) 243) ← (byte*~) main::$5
to:main::@return
main::@return: scope:[main] from main
[8] return
to:@return

View File

@ -0,0 +1,352 @@
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@1
main: scope:[main] from @1
(word) main::u#0 ← (number) $22b
(word*~) main::$0 ← ((word*)) (number) $a0
(word~) main::$1 ← *((word*~) main::$0) - (word) main::u#0
(word) main::u#1 ← (word~) main::$1
(word*~) main::$2 ← ((word*)) (number) $400
*((word*~) main::$2) ← (word) main::u#1
(byte**~) main::$3 ← ((byte**)) (number) $f3
(byte**~) main::$4 ← ((byte**)) (number) $d1
(byte*~) main::$5 ← *((byte**~) main::$4) + (number) $d400
*((byte**~) main::$3) ← (byte*~) main::$5
to:main::@return
main::@return: scope:[main] from main
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()
(word*~) main::$0
(word~) main::$1
(word*~) main::$2
(byte**~) main::$3
(byte**~) main::$4
(byte*~) main::$5
(label) main::@return
(word) main::u
(word) main::u#0
(word) main::u#1
Adding number conversion cast (unumber) $22b in (word) main::u#0 ← (number) $22b
Adding number conversion cast (unumber) $d400 in (byte*~) main::$5 ← *((byte**~) main::$4) + (number) $d400
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (word) main::u#0 ← (unumber)(number) $22b
Inlining cast (word*~) main::$0 ← (word*)(number) $a0
Inlining cast (word*~) main::$2 ← (word*)(number) $400
Inlining cast (byte**~) main::$3 ← (byte**)(number) $f3
Inlining cast (byte**~) main::$4 ← (byte**)(number) $d1
Successful SSA optimization Pass2InlineCast
Simplifying constant integer cast $22b
Simplifying constant pointer cast (word*) 160
Simplifying constant pointer cast (word*) 1024
Simplifying constant pointer cast (byte**) 243
Simplifying constant pointer cast (byte**) 209
Simplifying constant integer cast $d400
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $22b
Finalized unsigned number type (word) $d400
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (word) main::u#1 = (word~) main::$1
Successful SSA optimization Pass2AliasElimination
Constant (const word) main::u#0 = $22b
Constant (const word*) main::$0 = (word*) 160
Constant (const word*) main::$2 = (word*) 1024
Constant (const byte**) main::$3 = (byte**) 243
Constant (const byte**) main::$4 = (byte**) 209
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings (const word) main::u#0
Constant inlined main::$3 = (byte**) 243
Constant inlined main::$4 = (byte**) 209
Constant inlined main::$2 = (word*) 1024
Constant inlined main::$0 = (word*) 160
Constant inlined main::u#0 = (word) $22b
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
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] (word) main::u#1 ← *((word*) 160) - (word) $22b
[5] *((word*) 1024) ← (word) main::u#1
[6] (byte*~) main::$5 ← *((byte**) 209) + (word) $d400
[7] *((byte**) 243) ← (byte*~) main::$5
to:main::@return
main::@return: scope:[main] from main
[8] return
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
(byte*~) main::$5 4.0
(word) main::u
(word) main::u#1 4.0
Initial phi equivalence classes
Added variable main::u#1 to zero page equivalence class [ main::u#1 ]
Added variable main::$5 to zero page equivalence class [ main::$5 ]
Complete equivalence classes
[ main::u#1 ]
[ main::$5 ]
Allocated zp ZP_WORD:2 [ main::u#1 ]
Allocated zp ZP_WORD:4 [ main::$5 ]
INITIAL ASM
Target platform is c64basic
// File Comments
// Test some forced zeropage access
// Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
// Global Constants & labels
// @begin
bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
jmp b1
// @1
b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
jmp bend
// @end
bend:
// main
main: {
.label _5 = 4
.label u = 2
// [4] (word) main::u#1 ← *((word*) 160) - (word) $22b -- vwuz1=_deref_pwuc1_minus_vwuc2
sec
lda $a0
sbc #<$22b
sta.z u
lda $a0+1
sbc #>$22b
sta.z u+1
// [5] *((word*) 1024) ← (word) main::u#1 -- _deref_pwuc1=vwuz1
lda.z u
sta $400
lda.z u+1
sta $400+1
// [6] (byte*~) main::$5 ← *((byte**) 209) + (word) $d400 -- pbuz1=_deref_pptc1_plus_vwuc2
clc
lda $d1
adc #<$d400
sta.z _5
lda $d1+1
adc #>$d400
sta.z _5+1
// [7] *((byte**) 243) ← (byte*~) main::$5 -- _deref_pptc1=pbuz1
lda.z _5
sta $f3
lda.z _5+1
sta $f3+1
jmp breturn
// main::@return
breturn:
// [8] return
rts
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] (word) main::u#1 ← *((word*) 160) - (word) $22b [ main::u#1 ] ( main:2 [ main::u#1 ] ) always clobbers reg byte a
Statement [5] *((word*) 1024) ← (word) main::u#1 [ ] ( main:2 [ ] ) always clobbers reg byte a
Statement [6] (byte*~) main::$5 ← *((byte**) 209) + (word) $d400 [ main::$5 ] ( main:2 [ main::$5 ] ) always clobbers reg byte a
Statement [7] *((byte**) 243) ← (byte*~) main::$5 [ ] ( main:2 [ ] ) always clobbers reg byte a
Potential registers zp ZP_WORD:2 [ main::u#1 ] : zp ZP_WORD:2 ,
Potential registers zp ZP_WORD:4 [ main::$5 ] : zp ZP_WORD:4 ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 4: zp ZP_WORD:2 [ main::u#1 ] 4: zp ZP_WORD:4 [ main::$5 ]
Uplift Scope []
Uplifting [main] best 89 combination zp ZP_WORD:2 [ main::u#1 ] zp ZP_WORD:4 [ main::$5 ]
Uplifting [] best 89 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test some forced zeropage access
// Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
// Global Constants & labels
// @begin
bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
jmp b1
// @1
b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
jmp bend
// @end
bend:
// main
main: {
.label _5 = 4
.label u = 2
// [4] (word) main::u#1 ← *((word*) 160) - (word) $22b -- vwuz1=_deref_pwuc1_minus_vwuc2
sec
lda $a0
sbc #<$22b
sta.z u
lda $a0+1
sbc #>$22b
sta.z u+1
// [5] *((word*) 1024) ← (word) main::u#1 -- _deref_pwuc1=vwuz1
lda.z u
sta $400
lda.z u+1
sta $400+1
// [6] (byte*~) main::$5 ← *((byte**) 209) + (word) $d400 -- pbuz1=_deref_pptc1_plus_vwuc2
clc
lda $d1
adc #<$d400
sta.z _5
lda $d1+1
adc #>$d400
sta.z _5+1
// [7] *((byte**) 243) ← (byte*~) main::$5 -- _deref_pptc1=pbuz1
lda.z _5
sta $f3
lda.z _5+1
sta $f3+1
jmp breturn
// main::@return
breturn:
// [8] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction bend_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
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
(void()) main()
(byte*~) main::$5 $5 zp ZP_WORD:4 4.0
(label) main::@return
(word) main::u
(word) main::u#1 u zp ZP_WORD:2 4.0
zp ZP_WORD:2 [ main::u#1 ]
zp ZP_WORD:4 [ main::$5 ]
FINAL ASSEMBLER
Score: 74
// File Comments
// Test some forced zeropage access
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
// @begin
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
.label _5 = 4
.label u = 2
// u = *(word *)0xA0 - u
// [4] (word) main::u#1 ← *((word*) 160) - (word) $22b -- vwuz1=_deref_pwuc1_minus_vwuc2
sec
lda $a0
sbc #<$22b
sta.z u
lda $a0+1
sbc #>$22b
sta.z u+1
// *((word*)0x0400) = u
// [5] *((word*) 1024) ← (word) main::u#1 -- _deref_pwuc1=vwuz1
lda.z u
sta $400
lda.z u+1
sta $400+1
// *(byte **)0xD1 + 0xD400
// [6] (byte*~) main::$5 ← *((byte**) 209) + (word) $d400 -- pbuz1=_deref_pptc1_plus_vwuc2
clc
lda $d1
adc #<$d400
sta.z _5
lda $d1+1
adc #>$d400
sta.z _5+1
// *(byte **)0xF3 = *(byte **)0xD1 + 0xD400
// [7] *((byte**) 243) ← (byte*~) main::$5 -- _deref_pptc1=pbuz1
lda.z _5
sta $f3
lda.z _5+1
sta $f3+1
// main::@return
// }
// [8] return
rts
}
// File Data

View File

@ -0,0 +1,11 @@
(label) @1
(label) @begin
(label) @end
(void()) main()
(byte*~) main::$5 $5 zp ZP_WORD:4 4.0
(label) main::@return
(word) main::u
(word) main::u#1 u zp ZP_WORD:2 4.0
zp ZP_WORD:2 [ main::u#1 ]
zp ZP_WORD:4 [ main::$5 ]