From 599aaf4d673cf315dc94e1402b31be5c64155f04 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Mon, 19 Oct 2020 23:59:26 +0200 Subject: [PATCH] Added test for macro-based struct addressing vs. const-pointer based. --- .../dk/camelot64/kickc/test/TestPrograms.java | 5 + src/test/kc/chipset-test.c | 28 +++ src/test/ref/chipset-test.asm | 15 ++ src/test/ref/chipset-test.cfg | 9 + src/test/ref/chipset-test.log | 159 ++++++++++++++++++ src/test/ref/chipset-test.sym | 3 + 6 files changed, 219 insertions(+) create mode 100644 src/test/kc/chipset-test.c create mode 100644 src/test/ref/chipset-test.asm create mode 100644 src/test/ref/chipset-test.cfg create mode 100644 src/test/ref/chipset-test.log create mode 100644 src/test/ref/chipset-test.sym diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 0dc1de883..8c9c47c24 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -44,6 +44,11 @@ public class TestPrograms { public TestPrograms() { } + @Test + public void testChipsetTest() throws IOException, URISyntaxException { + compileAndCompare("chipset-test.c"); + } + @Test public void testConstRefNotLiteralProblem() throws IOException, URISyntaxException { compileAndCompare("constref-not-literal-problem.c"); diff --git a/src/test/kc/chipset-test.c b/src/test/kc/chipset-test.c new file mode 100644 index 000000000..cb9000c59 --- /dev/null +++ b/src/test/kc/chipset-test.c @@ -0,0 +1,28 @@ +// Test ATARI chipset variations +// Pointer to struct versus MAcro pointer to struct + +// CC65 macro pointer to struct + +struct __pia { + unsigned char porta; /* port A data r/w */ + unsigned char portb; /* port B data r/w */ + unsigned char pactl; /* port A control */ + unsigned char pbctl; /* port B control */ +}; + +struct ATARI_PIA { + unsigned char PORTA; /* port A data r/w */ + unsigned char PORTB; /* port B data r/w */ + unsigned char PACTL; /* port A control */ + unsigned char PBCTL; /* port B control */ +}; + +#define PIA1 (*(struct __pia*)0xD300) + +struct ATARI_PIA * const PIA2 = 0xD300; + + +void main() { + PIA1.porta = 7; + PIA2->PORTA = 7; +} \ No newline at end of file diff --git a/src/test/ref/chipset-test.asm b/src/test/ref/chipset-test.asm new file mode 100644 index 000000000..ac9f92fb2 --- /dev/null +++ b/src/test/ref/chipset-test.asm @@ -0,0 +1,15 @@ +// Test ATARI chipset variations +// Pointer to struct versus MAcro pointer to struct +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + .label PIA2 = $d300 +main: { + // PIA1.porta = 7 + lda #7 + sta $d300 + // PIA2->PORTA = 7 + sta PIA2 + // } + rts +} diff --git a/src/test/ref/chipset-test.cfg b/src/test/ref/chipset-test.cfg new file mode 100644 index 000000000..775eaf2de --- /dev/null +++ b/src/test/ref/chipset-test.cfg @@ -0,0 +1,9 @@ + +void main() +main: scope:[main] from + [0] *((byte*)(struct __pia*) 54016) = 7 + [1] *((byte*)PIA2) = 7 + to:main::@return +main::@return: scope:[main] from main + [2] return + to:@return diff --git a/src/test/ref/chipset-test.log b/src/test/ref/chipset-test.log new file mode 100644 index 000000000..7c2e0c2be --- /dev/null +++ b/src/test/ref/chipset-test.log @@ -0,0 +1,159 @@ + +CONTROL FLOW GRAPH SSA + +void main() +main: scope:[main] from __start + *((byte*)(struct __pia*)$d300+OFFSET_STRUCT___PIA_PORTA) = 7 + *((byte*)PIA2+OFFSET_STRUCT_ATARI_PIA_PORTA) = 7 + to:main::@return +main::@return: scope:[main] from main + 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 +const byte OFFSET_STRUCT_ATARI_PIA_PORTA = 0 +const byte OFFSET_STRUCT___PIA_PORTA = 0 +const nomodify struct ATARI_PIA* PIA2 = (struct ATARI_PIA*)$d300 +void __start() +void main() + +Adding number conversion cast (unumber) 7 in *((byte*)(struct __pia*)$d300+OFFSET_STRUCT___PIA_PORTA) = 7 +Adding number conversion cast (unumber) 7 in *((byte*)PIA2+OFFSET_STRUCT_ATARI_PIA_PORTA) = 7 +Successful SSA optimization PassNAddNumberTypeConversions +Inlining cast *((byte*)(struct __pia*)$d300+OFFSET_STRUCT___PIA_PORTA) = (unumber)7 +Inlining cast *((byte*)PIA2+OFFSET_STRUCT_ATARI_PIA_PORTA) = (unumber)7 +Successful SSA optimization Pass2InlineCast +Simplifying constant pointer cast (struct ATARI_PIA*) 54016 +Simplifying constant integer cast 7 +Simplifying constant pointer cast (struct __pia*) 54016 +Simplifying constant integer cast 7 +Successful SSA optimization PassNCastSimplification +Finalized unsigned number type 7 +Finalized unsigned number type 7 +Successful SSA optimization PassNFinalizeNumberTypeConversions +Simplifying expression containing zero (byte*)(struct __pia*) 54016 in [0] *((byte*)(struct __pia*) 54016+OFFSET_STRUCT___PIA_PORTA) = 7 +Simplifying expression containing zero (byte*)PIA2 in [1] *((byte*)PIA2+OFFSET_STRUCT_ATARI_PIA_PORTA) = 7 +Successful SSA optimization PassNSimplifyExpressionWithZero +Eliminating unused constant OFFSET_STRUCT___PIA_PORTA +Eliminating unused constant OFFSET_STRUCT_ATARI_PIA_PORTA +Successful SSA optimization PassNEliminateUnusedVars +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 +CALL GRAPH + +Created 0 initial phi equivalence classes +Coalesced down to 0 phi equivalence classes + +FINAL CONTROL FLOW GRAPH + +void main() +main: scope:[main] from + [0] *((byte*)(struct __pia*) 54016) = 7 + [1] *((byte*)PIA2) = 7 + to:main::@return +main::@return: scope:[main] from main + [2] return + to:@return + + +VARIABLE REGISTER WEIGHTS +void main() + +Initial phi equivalence classes +Complete equivalence classes +REGISTER UPLIFT POTENTIAL REGISTERS +Statement [0] *((byte*)(struct __pia*) 54016) = 7 [ ] ( [ ] { } ) always clobbers reg byte a +Statement [1] *((byte*)PIA2) = 7 [ ] ( [ ] { } ) always clobbers reg byte a + +REGISTER UPLIFT SCOPES +Uplift Scope [__pia] +Uplift Scope [ATARI_PIA] +Uplift Scope [main] +Uplift Scope [] + +Uplifting [__pia] best 21 combination +Uplifting [ATARI_PIA] best 21 combination +Uplifting [main] best 21 combination +Uplifting [] best 21 combination + +ASSEMBLER BEFORE OPTIMIZATION + // File Comments +// Test ATARI chipset variations +// Pointer to struct versus MAcro pointer to struct + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .label PIA2 = $d300 + // main +main: { + // [0] *((byte*)(struct __pia*) 54016) = 7 -- _deref_pbuc1=vbuc2 + lda #7 + sta $d300 + // [1] *((byte*)PIA2) = 7 -- _deref_pbuc1=vbuc2 + lda #7 + sta PIA2 + jmp __breturn + // main::@return + __breturn: + // [2] return + rts +} + // File Data + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp __breturn +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction lda #7 +Succesful ASM optimization Pass5UnnecesaryLoadElimination +Removing instruction __breturn: +Succesful ASM optimization Pass5UnusedLabelElimination + +FINAL SYMBOL TABLE +const nomodify struct ATARI_PIA* PIA2 = (struct ATARI_PIA*) 54016 +void main() + + + +FINAL ASSEMBLER +Score: 16 + + // File Comments +// Test ATARI chipset variations +// Pointer to struct versus MAcro pointer to struct + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .label PIA2 = $d300 + // main +main: { + // PIA1.porta = 7 + // [0] *((byte*)(struct __pia*) 54016) = 7 -- _deref_pbuc1=vbuc2 + lda #7 + sta $d300 + // PIA2->PORTA = 7 + // [1] *((byte*)PIA2) = 7 -- _deref_pbuc1=vbuc2 + sta PIA2 + // main::@return + // } + // [2] return + rts +} + // File Data + diff --git a/src/test/ref/chipset-test.sym b/src/test/ref/chipset-test.sym new file mode 100644 index 000000000..4b6e84eea --- /dev/null +++ b/src/test/ref/chipset-test.sym @@ -0,0 +1,3 @@ +const nomodify struct ATARI_PIA* PIA2 = (struct ATARI_PIA*) 54016 +void main() +