From 4e93f0b056440f1bbcb08ddd3f26d558d3b0a75a Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Fri, 19 Apr 2019 11:25:29 +0200 Subject: [PATCH] Fixing more tests with word arrays/pointers. Preparing for #139 --- src/test/kc/test-comparisons-sword.kc | 4 +- src/test/kc/test-comparisons-word.kc | 4 +- src/test/ref/test-comparisons-sword.cfg | 8 +- src/test/ref/test-comparisons-sword.log | 148 ++++++++++++------------ src/test/ref/test-comparisons-sword.sym | 8 +- src/test/ref/test-comparisons-word.cfg | 8 +- src/test/ref/test-comparisons-word.log | 148 ++++++++++++------------ src/test/ref/test-comparisons-word.sym | 8 +- src/test/ref/wfragment1.asm | 15 +-- src/test/ref/wfragment1.cfg | 5 +- src/test/ref/wfragment1.log | 99 ++++++++++------ src/test/ref/wfragment1.sym | 4 +- 12 files changed, 247 insertions(+), 212 deletions(-) diff --git a/src/test/kc/test-comparisons-sword.kc b/src/test/kc/test-comparisons-sword.kc index 60e7b228b..cd883359e 100644 --- a/src/test/kc/test-comparisons-sword.kc +++ b/src/test/kc/test-comparisons-sword.kc @@ -10,9 +10,9 @@ void main() { print_cls(); byte s = 0; for( byte i: 0..2) { - signed word w1 = swords[i*2]; + signed word w1 = swords[i]; for( byte j: 0..2) { - signed word w2 = swords[j*2]; + signed word w2 = swords[j]; for( byte op: 0..5 ) { compare(w1,w2,op); if(++s==3) { diff --git a/src/test/kc/test-comparisons-word.kc b/src/test/kc/test-comparisons-word.kc index 0fde61290..6f21a4279 100644 --- a/src/test/kc/test-comparisons-word.kc +++ b/src/test/kc/test-comparisons-word.kc @@ -8,9 +8,9 @@ void main() { print_cls(); byte s = 0; for( byte i: 0..2) { - word w1 = words[i*2]; + word w1 = words[i]; for( byte j: 0..2) { - word w2 = words[j*2]; + word w2 = words[j]; for( byte op: 0..5 ) { compare(w1,w2,op); if(++s==3) { diff --git a/src/test/ref/test-comparisons-sword.cfg b/src/test/ref/test-comparisons-sword.cfg index 6ff96f339..11146706c 100644 --- a/src/test/ref/test-comparisons-sword.cfg +++ b/src/test/ref/test-comparisons-sword.cfg @@ -16,16 +16,16 @@ main::@1: scope:[main] from main main::@7 [6] (byte) main::s#7 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::s#10 ) [6] (byte*) print_char_cursor#81 ← phi( main/((byte*))(word/signed word/dword/signed dword) $400 main::@7/(byte*) print_char_cursor#76 ) [6] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::i#1 ) - [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 - [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte~) main::$1) + [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte) main::$8) to:main::@2 main::@2: scope:[main] from main::@1 main::@6 [9] (byte*) print_line_cursor#30 ← phi( main::@1/(byte*) print_line_cursor#32 main::@6/(byte*) print_line_cursor#24 ) [9] (byte) main::s#5 ← phi( main::@1/(byte) main::s#7 main::@6/(byte) main::s#10 ) [9] (byte*) print_char_cursor#75 ← phi( main::@1/(byte*) print_char_cursor#81 main::@6/(byte*) print_char_cursor#76 ) [9] (byte) main::j#2 ← phi( main::@1/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@6/(byte) main::j#1 ) - [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 - [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte~) main::$2) + [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte) main::$9) to:main::@3 main::@3: scope:[main] from main::@2 main::@4 [12] (byte*) print_line_cursor#19 ← phi( main::@2/(byte*) print_line_cursor#30 main::@4/(byte*) print_line_cursor#24 ) diff --git a/src/test/ref/test-comparisons-sword.log b/src/test/ref/test-comparisons-sword.log index a9b17bde0..22fbe3f5f 100644 --- a/src/test/ref/test-comparisons-sword.log +++ b/src/test/ref/test-comparisons-sword.log @@ -1,3 +1,5 @@ +Fixing pointer array-indexing *((signed word[]) swords + (byte) main::i) +Fixing pointer array-indexing *((signed word[]) swords + (byte) main::j) Inlined call (byte~) vicSelectGfxBank::$0 ← call toDd00 (byte*) vicSelectGfxBank::gfx CONTROL FLOW GRAPH SSA @@ -205,8 +207,8 @@ main::@1: scope:[main] from main::@15 main::@7 (byte) main::s#7 ← phi( main::@15/(byte) main::s#0 main::@7/(byte) main::s#10 ) (byte*) print_char_cursor#81 ← phi( main::@15/(byte*) print_char_cursor#18 main::@7/(byte*) print_char_cursor#78 ) (byte) main::i#2 ← phi( main::@15/(byte) main::i#0 main::@7/(byte) main::i#1 ) - (byte/signed word/word/dword/signed dword~) main::$1 ← (byte) main::i#2 * (byte/signed byte/word/signed word/dword/signed dword) 2 - (signed word) main::w1#0 ← *((signed word[]) swords#0 + (byte/signed word/word/dword/signed dword~) main::$1) + (byte) main::$8 ← (byte) main::i#2 * (const byte) SIZEOF_SIGNED_WORD + (signed word) main::w1#0 ← *((signed word[]) swords#0 + (byte) main::$8) (byte) main::j#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 to:main::@2 main::@2: scope:[main] from main::@1 main::@6 @@ -216,8 +218,8 @@ main::@2: scope:[main] from main::@1 main::@6 (byte*) print_char_cursor#75 ← phi( main::@1/(byte*) print_char_cursor#81 main::@6/(byte*) print_char_cursor#82 ) (signed word) main::w1#2 ← phi( main::@1/(signed word) main::w1#0 main::@6/(signed word) main::w1#4 ) (byte) main::j#2 ← phi( main::@1/(byte) main::j#0 main::@6/(byte) main::j#1 ) - (byte/signed word/word/dword/signed dword~) main::$2 ← (byte) main::j#2 * (byte/signed byte/word/signed word/dword/signed dword) 2 - (signed word) main::w2#0 ← *((signed word[]) swords#0 + (byte/signed word/word/dword/signed dword~) main::$2) + (byte) main::$9 ← (byte) main::j#2 * (const byte) SIZEOF_SIGNED_WORD + (signed word) main::w2#0 ← *((signed word[]) swords#0 + (byte) main::$9) (byte) main::op#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 to:main::@3 main::@3: scope:[main] from main::@2 main::@4 @@ -245,9 +247,9 @@ main::@16: scope:[main] from main::@3 (byte*) print_char_cursor#47 ← phi( main::@3/(byte*) print_char_cursor#28 ) (byte*) print_char_cursor#19 ← (byte*) print_char_cursor#47 (byte) main::s#1 ← ++ (byte) main::s#3 - (bool~) main::$4 ← (byte) main::s#1 == (byte/signed byte/word/signed word/dword/signed dword) 3 - (bool~) main::$5 ← ! (bool~) main::$4 - if((bool~) main::$5) goto main::@4 + (bool~) main::$2 ← (byte) main::s#1 == (byte/signed byte/word/signed word/dword/signed dword) 3 + (bool~) main::$3 ← ! (bool~) main::$2 + if((bool~) main::$3) goto main::@4 to:main::@5 main::@4: scope:[main] from main::@16 main::@17 (byte*) print_line_cursor#31 ← phi( main::@16/(byte*) print_line_cursor#22 main::@17/(byte*) print_line_cursor#6 ) @@ -259,8 +261,8 @@ main::@4: scope:[main] from main::@16 main::@17 (signed word) main::w1#3 ← phi( main::@16/(signed word) main::w1#5 main::@17/(signed word) main::w1#6 ) (byte) main::op#3 ← phi( main::@16/(byte) main::op#4 main::@17/(byte) main::op#5 ) (byte) main::op#1 ← (byte) main::op#3 + rangenext(0,5) - (bool~) main::$7 ← (byte) main::op#1 != rangelast(0,5) - if((bool~) main::$7) goto main::@3 + (bool~) main::$5 ← (byte) main::op#1 != rangelast(0,5) + if((bool~) main::$5) goto main::@3 to:main::@6 main::@5: scope:[main] from main::@16 (byte) main::i#9 ← phi( main::@16/(byte) main::i#6 ) @@ -293,8 +295,8 @@ main::@6: scope:[main] from main::@4 (byte) main::i#4 ← phi( main::@4/(byte) main::i#5 ) (byte) main::j#3 ← phi( main::@4/(byte) main::j#4 ) (byte) main::j#1 ← (byte) main::j#3 + rangenext(0,2) - (bool~) main::$8 ← (byte) main::j#1 != rangelast(0,2) - if((bool~) main::$8) goto main::@2 + (bool~) main::$6 ← (byte) main::j#1 != rangelast(0,2) + if((bool~) main::$6) goto main::@2 to:main::@7 main::@7: scope:[main] from main::@6 (byte) main::s#10 ← phi( main::@6/(byte) main::s#8 ) @@ -302,8 +304,8 @@ main::@7: scope:[main] from main::@6 (byte*) print_line_cursor#24 ← phi( main::@6/(byte*) print_line_cursor#27 ) (byte) main::i#3 ← phi( main::@6/(byte) main::i#4 ) (byte) main::i#1 ← (byte) main::i#3 + rangenext(0,2) - (bool~) main::$9 ← (byte) main::i#1 != rangelast(0,2) - if((bool~) main::$9) goto main::@1 + (bool~) main::$7 ← (byte) main::i#1 != rangelast(0,2) + if((bool~) main::$7) goto main::@1 to:main::@9 main::@9: scope:[main] from main::@10 main::@7 (byte*) print_char_cursor#69 ← phi( main::@10/(byte*) print_char_cursor#77 main::@7/(byte*) print_char_cursor#78 ) @@ -663,6 +665,7 @@ SYMBOL TABLE SSA (byte) LT#0 (byte) NE (byte) NE#0 +(const byte) SIZEOF_SIGNED_WORD = (byte/signed byte/word/signed word/dword/signed dword) 2 (byte) TT (byte) TT#0 (void()) compare((signed word) compare::w1 , (signed word) compare::w2 , (byte) compare::op) @@ -862,13 +865,13 @@ SYMBOL TABLE SSA (signed word) compare::w2#8 (signed word) compare::w2#9 (void()) main() -(byte/signed word/word/dword/signed dword~) main::$1 -(byte/signed word/word/dword/signed dword~) main::$2 -(bool~) main::$4 +(bool~) main::$2 +(bool~) main::$3 (bool~) main::$5 +(bool~) main::$6 (bool~) main::$7 -(bool~) main::$8 -(bool~) main::$9 +(byte) main::$8 +(byte) main::$9 (label) main::@1 (label) main::@10 (label) main::@15 @@ -1177,7 +1180,7 @@ SYMBOL TABLE SSA (signed word[]) swords#0 Inversing boolean not [28] (bool~) print_sword::$1 ← (signed word) print_sword::w#3 >= (byte/signed byte/word/signed word/dword/signed dword) 0 from [27] (bool~) print_sword::$0 ← (signed word) print_sword::w#3 < (byte/signed byte/word/signed word/dword/signed dword) 0 -Inversing boolean not [124] (bool~) main::$5 ← (byte) main::s#1 != (byte/signed byte/word/signed word/dword/signed dword) 3 from [123] (bool~) main::$4 ← (byte) main::s#1 == (byte/signed byte/word/signed word/dword/signed dword) 3 +Inversing boolean not [124] (bool~) main::$3 ← (byte) main::s#1 != (byte/signed byte/word/signed word/dword/signed dword) 3 from [123] (bool~) main::$2 ← (byte) main::s#1 == (byte/signed byte/word/signed word/dword/signed dword) 3 Inversing boolean not [167] (bool~) compare::$28 ← (signed word) compare::w1#1 >= (signed word) compare::w2#1 from [166] (bool~) compare::$27 ← (signed word) compare::w1#1 < (signed word) compare::w2#1 Inversing boolean not [174] (bool~) compare::$26 ← (signed word) compare::w1#2 > (signed word) compare::w2#2 from [173] (bool~) compare::$25 ← (signed word) compare::w1#2 <= (signed word) compare::w2#2 Inversing boolean not [181] (bool~) compare::$24 ← (signed word) compare::w1#3 <= (signed word) compare::w2#3 from [180] (bool~) compare::$23 ← (signed word) compare::w1#3 > (signed word) compare::w2#3 @@ -1325,10 +1328,10 @@ Simple Condition (bool~) print_str::$0 [6] if(*((byte*) print_str::str#2)!=(byte Simple Condition (bool~) print_ln::$1 [19] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#14) goto print_ln::@1 Simple Condition (bool~) print_sword::$1 [29] if((signed word) print_sword::w#3>=(byte/signed byte/word/signed word/dword/signed dword) 0) goto print_sword::@1 Simple Condition (bool~) print_cls::$1 [89] if((byte*) print_cls::sc#1!=(byte*~) print_cls::$0) goto print_cls::@1 -Simple Condition (bool~) main::$5 [125] if((byte) main::s#1!=(byte/signed byte/word/signed word/dword/signed dword) 3) goto main::@4 -Simple Condition (bool~) main::$7 [129] if((byte) main::op#1!=rangelast(0,5)) goto main::@3 -Simple Condition (bool~) main::$8 [139] if((byte) main::j#1!=rangelast(0,2)) goto main::@2 -Simple Condition (bool~) main::$9 [143] if((byte) main::i#1!=rangelast(0,2)) goto main::@1 +Simple Condition (bool~) main::$3 [125] if((byte) main::s#1!=(byte/signed byte/word/signed word/dword/signed dword) 3) goto main::@4 +Simple Condition (bool~) main::$5 [129] if((byte) main::op#1!=rangelast(0,5)) goto main::@3 +Simple Condition (bool~) main::$6 [139] if((byte) main::j#1!=rangelast(0,2)) goto main::@2 +Simple Condition (bool~) main::$7 [143] if((byte) main::i#1!=rangelast(0,2)) goto main::@1 Simple Condition (bool~) compare::$0 [164] if((byte) compare::op#0==(byte) LT#0) goto compare::@1 Simple Condition (bool~) compare::$28 [168] if((signed word) compare::w1#0>=(signed word) compare::w2#0) goto compare::@38 Simple Condition (bool~) compare::$1 [171] if((byte) compare::op#0==(byte) LE#0) goto compare::@2 @@ -1394,8 +1397,8 @@ Resolved ranged next value main::j#1 ← ++ main::j#2 to ++ Resolved ranged comparison value if(main::j#1!=rangelast(0,2)) goto main::@2 to (byte/signed byte/word/signed word/dword/signed dword) 3 Resolved ranged next value main::i#1 ← ++ main::i#10 to ++ Resolved ranged comparison value if(main::i#1!=rangelast(0,2)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) 3 -Rewriting multiplication to use shift (byte/signed word/word/dword/signed dword~) main::$1 ← (byte) main::i#2 * (byte/signed byte/word/signed word/dword/signed dword) 2 -Rewriting multiplication to use shift (byte/signed word/word/dword/signed dword~) main::$2 ← (byte) main::j#2 * (byte/signed byte/word/signed word/dword/signed dword) 2 +Rewriting multiplication to use shift (byte) main::$8 ← (byte) main::i#2 * (const byte) SIZEOF_SIGNED_WORD +Rewriting multiplication to use shift (byte) main::$9 ← (byte) main::j#2 * (const byte) SIZEOF_SIGNED_WORD Successful SSA optimization Pass2MultiplyToShiftRewriting Culled Empty Block (label) @4 Culled Empty Block (label) print_ln::@2 @@ -1421,8 +1424,7 @@ Successful SSA optimization Pass2SelfPhiElimination Redundant Phi (signed word) main::w1#2 (signed word) main::w1#0 Redundant Phi (byte) main::i#10 (byte) main::i#2 Successful SSA optimization Pass2RedundantPhiElimination -Inferred type updated to byte in [41] (byte/signed word/word/dword/signed dword~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -Inferred type updated to byte in [44] (byte/signed word/word/dword/signed dword~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 +Successful SSA optimization PassNEliminateUnusedVars Inlining constant with var siblings (const byte) print_char::ch#0 Inlining constant with var siblings (const byte) print_char::ch#3 Inlining constant with var siblings (const byte) print_char::ch#5 @@ -1657,16 +1659,16 @@ main::@1: scope:[main] from main main::@7 [6] (byte) main::s#7 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::s#10 ) [6] (byte*) print_char_cursor#81 ← phi( main/((byte*))(word/signed word/dword/signed dword) $400 main::@7/(byte*) print_char_cursor#76 ) [6] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::i#1 ) - [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 - [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte~) main::$1) + [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte) main::$8) to:main::@2 main::@2: scope:[main] from main::@1 main::@6 [9] (byte*) print_line_cursor#30 ← phi( main::@1/(byte*) print_line_cursor#32 main::@6/(byte*) print_line_cursor#24 ) [9] (byte) main::s#5 ← phi( main::@1/(byte) main::s#7 main::@6/(byte) main::s#10 ) [9] (byte*) print_char_cursor#75 ← phi( main::@1/(byte*) print_char_cursor#81 main::@6/(byte*) print_char_cursor#76 ) [9] (byte) main::j#2 ← phi( main::@1/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@6/(byte) main::j#1 ) - [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 - [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte~) main::$2) + [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte) main::$9) to:main::@3 main::@3: scope:[main] from main::@2 main::@4 [12] (byte*) print_line_cursor#19 ← phi( main::@2/(byte*) print_line_cursor#30 main::@4/(byte*) print_line_cursor#24 ) @@ -1937,8 +1939,8 @@ VARIABLE REGISTER WEIGHTS (signed word) compare::w2 (signed word) compare::w2#0 26.076923076923077 (void()) main() -(byte~) main::$1 22.0 -(byte~) main::$2 202.0 +(byte) main::$8 22.0 +(byte) main::$9 202.0 (byte) main::i (byte) main::i#1 16.5 (byte) main::i#2 1.5714285714285716 @@ -2030,9 +2032,9 @@ Initial phi equivalence classes [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] [ print_str::str#2 print_str::str#1 print_str::str#0 ] [ print_cls::sc#2 print_cls::sc#1 ] -Added variable main::$1 to zero page equivalence class [ main::$1 ] +Added variable main::$8 to zero page equivalence class [ main::$8 ] Added variable main::w1#0 to zero page equivalence class [ main::w1#0 ] -Added variable main::$2 to zero page equivalence class [ main::$2 ] +Added variable main::$9 to zero page equivalence class [ main::$9 ] Added variable main::w2#0 to zero page equivalence class [ main::w2#0 ] Added variable compare::w1#0 to zero page equivalence class [ compare::w1#0 ] Added variable compare::w2#0 to zero page equivalence class [ compare::w2#0 ] @@ -2053,9 +2055,9 @@ Complete equivalence classes [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] [ print_str::str#2 print_str::str#1 print_str::str#0 ] [ print_cls::sc#2 print_cls::sc#1 ] -[ main::$1 ] +[ main::$8 ] [ main::w1#0 ] -[ main::$2 ] +[ main::$9 ] [ main::w2#0 ] [ compare::w1#0 ] [ compare::w2#0 ] @@ -2075,9 +2077,9 @@ Allocated zp ZP_WORD:14 [ print_char_cursor#60 print_char_cursor#43 print_char_c Allocated zp ZP_BYTE:16 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] Allocated zp ZP_WORD:17 [ print_str::str#2 print_str::str#1 print_str::str#0 ] Allocated zp ZP_WORD:19 [ print_cls::sc#2 print_cls::sc#1 ] -Allocated zp ZP_BYTE:21 [ main::$1 ] +Allocated zp ZP_BYTE:21 [ main::$8 ] Allocated zp ZP_WORD:22 [ main::w1#0 ] -Allocated zp ZP_BYTE:24 [ main::$2 ] +Allocated zp ZP_BYTE:24 [ main::$9 ] Allocated zp ZP_WORD:25 [ main::w2#0 ] Allocated zp ZP_WORD:27 [ compare::w1#0 ] Allocated zp ZP_WORD:29 [ compare::w2#0 ] @@ -2123,8 +2125,8 @@ bend_from_b1: bend: //SEG10 main main: { - .label _1 = $15 - .label _2 = $18 + .label _8 = $15 + .label _9 = $18 .label w1 = $16 .label w2 = $19 .label s = 5 @@ -2163,12 +2165,12 @@ main: { jmp b1 //SEG23 main::@1 b1: - //SEG24 [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1 + //SEG24 [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1 lda i asl - sta _1 - //SEG25 [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte~) main::$1) -- vwsz1=pwsc1_derefidx_vbuz2 - ldy _1 + sta _8 + //SEG25 [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte) main::$8) -- vwsz1=pwsc1_derefidx_vbuz2 + ldy _8 lda swords,y sta w1 lda swords+1,y @@ -2191,12 +2193,12 @@ main: { jmp b2 //SEG36 main::@2 b2: - //SEG37 [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1 + //SEG37 [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1 lda j asl - sta _2 - //SEG38 [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte~) main::$2) -- vwsz1=pwsc1_derefidx_vbuz2 - ldy _2 + sta _9 + //SEG38 [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte) main::$9) -- vwsz1=pwsc1_derefidx_vbuz2 + ldy _9 lda swords,y sta w2 lda swords+1,y @@ -2975,13 +2977,13 @@ print_cls: { swords: .word -$6fed, $12, $7fed REGISTER UPLIFT POTENTIAL REGISTERS -Statement [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::$1 ] ( main:2 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::$1 ] ) always clobbers reg byte a +Statement [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::$8 ] ( main:2 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::$8 ] ) always clobbers reg byte a Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ] Removing always clobbered register reg byte a as potential for zp ZP_BYTE:5 [ main::s#3 main::s#5 main::s#7 main::s#10 main::s#1 ] -Statement [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte~) main::$1) [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::w1#0 ] ( main:2 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::w1#0 ] ) always clobbers reg byte a -Statement [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::$2 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::$2 ] ) always clobbers reg byte a +Statement [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte) main::$8) [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::w1#0 ] ( main:2 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::w1#0 ] ) always clobbers reg byte a +Statement [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::$9 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::$9 ] ) always clobbers reg byte a Removing always clobbered register reg byte a as potential for zp ZP_BYTE:3 [ main::j#2 main::j#1 ] -Statement [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte~) main::$2) [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::w2#0 ] ) always clobbers reg byte a +Statement [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte) main::$9) [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::w2#0 ] ) always clobbers reg byte a Statement [13] (signed word) compare::w1#0 ← (signed word) main::w1#0 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#67 main::s#3 print_line_cursor#19 compare::w1#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#67 main::s#3 print_line_cursor#19 compare::w1#0 ] ) always clobbers reg byte a Removing always clobbered register reg byte a as potential for zp ZP_BYTE:4 [ main::op#2 main::op#1 ] Statement [14] (signed word) compare::w2#0 ← (signed word) main::w2#0 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#67 main::s#3 print_line_cursor#19 compare::w1#0 compare::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#67 main::s#3 print_line_cursor#19 compare::w1#0 compare::w2#0 ] ) always clobbers reg byte a @@ -3018,10 +3020,10 @@ Statement [104] if(*((byte*) print_str::str#2)!=(byte) '@') goto print_str::@2 [ Statement [106] *((byte*) print_char_cursor#2) ← *((byte*) print_str::str#2) [ print_char_cursor#2 print_str::str#2 ] ( main:2::compare:16::print_str:52 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 main::s#3 print_line_cursor#19 compare::w2#0 compare::r#10 print_char_cursor#2 print_str::str#2 ] ) always clobbers reg byte a reg byte y Statement [111] *((byte*) print_cls::sc#2) ← (byte) ' ' [ print_cls::sc#2 ] ( main:2::print_cls:5 [ print_cls::sc#2 ] ) always clobbers reg byte a reg byte y Statement [113] if((byte*) print_cls::sc#1!=((byte*))(word/signed word/dword/signed dword) $400+(word/signed word/dword/signed dword) $3e8) goto print_cls::@1 [ print_cls::sc#1 ] ( main:2::print_cls:5 [ print_cls::sc#1 ] ) always clobbers reg byte a -Statement [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::$1 ] ( main:2 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::$1 ] ) always clobbers reg byte a -Statement [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte~) main::$1) [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::w1#0 ] ( main:2 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::w1#0 ] ) always clobbers reg byte a -Statement [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::$2 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::$2 ] ) always clobbers reg byte a -Statement [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte~) main::$2) [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::w2#0 ] ) always clobbers reg byte a +Statement [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::$8 ] ( main:2 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::$8 ] ) always clobbers reg byte a +Statement [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte) main::$8) [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::w1#0 ] ( main:2 [ main::i#2 print_char_cursor#81 main::s#7 print_line_cursor#32 main::w1#0 ] ) always clobbers reg byte a +Statement [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::$9 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::$9 ] ) always clobbers reg byte a +Statement [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte) main::$9) [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#75 main::s#5 print_line_cursor#30 main::w2#0 ] ) always clobbers reg byte a Statement [13] (signed word) compare::w1#0 ← (signed word) main::w1#0 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#67 main::s#3 print_line_cursor#19 compare::w1#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#67 main::s#3 print_line_cursor#19 compare::w1#0 ] ) always clobbers reg byte a Statement [14] (signed word) compare::w2#0 ← (signed word) main::w2#0 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#67 main::s#3 print_line_cursor#19 compare::w1#0 compare::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#67 main::s#3 print_line_cursor#19 compare::w1#0 compare::w2#0 ] ) always clobbers reg byte a Statement [21] (byte*~) print_char_cursor#116 ← (byte*) print_line_cursor#1 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#116 print_line_cursor#1 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#116 print_line_cursor#1 ] ) always clobbers reg byte a @@ -3062,9 +3064,9 @@ Potential registers zp ZP_WORD:14 [ print_char_cursor#60 print_char_cursor#43 pr Potential registers zp ZP_BYTE:16 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] : zp ZP_BYTE:16 , reg byte x , Potential registers zp ZP_WORD:17 [ print_str::str#2 print_str::str#1 print_str::str#0 ] : zp ZP_WORD:17 , Potential registers zp ZP_WORD:19 [ print_cls::sc#2 print_cls::sc#1 ] : zp ZP_WORD:19 , -Potential registers zp ZP_BYTE:21 [ main::$1 ] : zp ZP_BYTE:21 , reg byte a , reg byte x , reg byte y , +Potential registers zp ZP_BYTE:21 [ main::$8 ] : zp ZP_BYTE:21 , reg byte a , reg byte x , reg byte y , Potential registers zp ZP_WORD:22 [ main::w1#0 ] : zp ZP_WORD:22 , -Potential registers zp ZP_BYTE:24 [ main::$2 ] : zp ZP_BYTE:24 , reg byte a , reg byte x , reg byte y , +Potential registers zp ZP_BYTE:24 [ main::$9 ] : zp ZP_BYTE:24 , reg byte a , reg byte x , reg byte y , Potential registers zp ZP_WORD:25 [ main::w2#0 ] : zp ZP_WORD:25 , Potential registers zp ZP_WORD:27 [ compare::w1#0 ] : zp ZP_WORD:27 , Potential registers zp ZP_WORD:29 [ compare::w2#0 ] : zp ZP_WORD:29 , @@ -3075,7 +3077,7 @@ Potential registers zp ZP_BYTE:33 [ print_byte::$2 ] : zp ZP_BYTE:33 , reg byte REGISTER UPLIFT SCOPES Uplift Scope [] 27,162.22: zp ZP_WORD:6 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#30 print_line_cursor#32 print_line_cursor#24 print_line_cursor#1 ] 17,214.99: zp ZP_WORD:14 [ print_char_cursor#60 print_char_cursor#43 print_char_cursor#71 print_char_cursor#2 print_char_cursor#70 print_char_cursor#67 print_char_cursor#75 print_char_cursor#81 print_char_cursor#76 print_char_cursor#14 print_char_cursor#116 print_char_cursor#63 print_char_cursor#61 print_char_cursor#1 ] Uplift Scope [print_str] 30,005.5: zp ZP_WORD:17 [ print_str::str#2 print_str::str#1 print_str::str#0 ] -Uplift Scope [main] 2,302.43: zp ZP_BYTE:5 [ main::s#3 main::s#5 main::s#7 main::s#10 main::s#1 ] 1,774.5: zp ZP_BYTE:4 [ main::op#2 main::op#1 ] 202: zp ZP_BYTE:24 [ main::$2 ] 170.44: zp ZP_BYTE:3 [ main::j#2 main::j#1 ] 78.71: zp ZP_WORD:25 [ main::w2#0 ] 53.26: zp ZP_WORD:22 [ main::w1#0 ] 22: zp ZP_BYTE:21 [ main::$1 ] 18.07: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] +Uplift Scope [main] 2,302.43: zp ZP_BYTE:5 [ main::s#3 main::s#5 main::s#7 main::s#10 main::s#1 ] 1,774.5: zp ZP_BYTE:4 [ main::op#2 main::op#1 ] 202: zp ZP_BYTE:24 [ main::$9 ] 170.44: zp ZP_BYTE:3 [ main::j#2 main::j#1 ] 78.71: zp ZP_WORD:25 [ main::w2#0 ] 53.26: zp ZP_WORD:22 [ main::w1#0 ] 22: zp ZP_BYTE:21 [ main::$8 ] 18.07: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] Uplift Scope [compare] 168.83: zp ZP_BYTE:31 [ compare::op#0 ] 31.78: zp ZP_WORD:27 [ compare::w1#0 ] 26.08: zp ZP_WORD:29 [ compare::w2#0 ] 12.93: zp ZP_BYTE:10 [ compare::r#10 compare::r#16 compare::r#17 compare::r#18 compare::r#19 compare::r#20 compare::r#21 ] 0.29: zp ZP_WORD:8 [ compare::ops#10 ] Uplift Scope [print_cls] 33: zp ZP_WORD:19 [ print_cls::sc#2 print_cls::sc#1 ] Uplift Scope [print_char] 20: zp ZP_BYTE:11 [ print_char::ch#6 print_char::ch#4 print_char::ch#1 print_char::ch#2 ] @@ -3086,7 +3088,7 @@ Uplift Scope [print_word] Uplifting [] best 1156370 combination zp ZP_WORD:6 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#30 print_line_cursor#32 print_line_cursor#24 print_line_cursor#1 ] zp ZP_WORD:14 [ print_char_cursor#60 print_char_cursor#43 print_char_cursor#71 print_char_cursor#2 print_char_cursor#70 print_char_cursor#67 print_char_cursor#75 print_char_cursor#81 print_char_cursor#76 print_char_cursor#14 print_char_cursor#116 print_char_cursor#63 print_char_cursor#61 print_char_cursor#1 ] Uplifting [print_str] best 1156370 combination zp ZP_WORD:17 [ print_str::str#2 print_str::str#1 print_str::str#0 ] -Uplifting [main] best 1143930 combination zp ZP_BYTE:5 [ main::s#3 main::s#5 main::s#7 main::s#10 main::s#1 ] reg byte x [ main::op#2 main::op#1 ] reg byte a [ main::$2 ] zp ZP_BYTE:3 [ main::j#2 main::j#1 ] zp ZP_WORD:25 [ main::w2#0 ] zp ZP_WORD:22 [ main::w1#0 ] reg byte a [ main::$1 ] zp ZP_BYTE:2 [ main::i#2 main::i#1 ] +Uplifting [main] best 1143930 combination zp ZP_BYTE:5 [ main::s#3 main::s#5 main::s#7 main::s#10 main::s#1 ] reg byte x [ main::op#2 main::op#1 ] reg byte a [ main::$9 ] zp ZP_BYTE:3 [ main::j#2 main::j#1 ] zp ZP_WORD:25 [ main::w2#0 ] zp ZP_WORD:22 [ main::w1#0 ] reg byte a [ main::$8 ] zp ZP_BYTE:2 [ main::i#2 main::i#1 ] Limited combination testing to 100 combinations of 256 possible. Uplifting [compare] best 1140912 combination reg byte x [ compare::op#0 ] zp ZP_WORD:27 [ compare::w1#0 ] zp ZP_WORD:29 [ compare::w2#0 ] zp ZP_BYTE:10 [ compare::r#10 compare::r#16 compare::r#17 compare::r#18 compare::r#19 compare::r#20 compare::r#21 ] zp ZP_WORD:8 [ compare::ops#10 ] Uplifting [print_cls] best 1140912 combination zp ZP_WORD:19 [ print_cls::sc#2 print_cls::sc#1 ] @@ -3194,10 +3196,10 @@ main: { jmp b1 //SEG23 main::@1 b1: - //SEG24 [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 + //SEG24 [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 lda i asl - //SEG25 [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte~) main::$1) -- vwsz1=pwsc1_derefidx_vbuaa + //SEG25 [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte) main::$8) -- vwsz1=pwsc1_derefidx_vbuaa tay lda swords,y sta w1 @@ -3221,10 +3223,10 @@ main: { jmp b2 //SEG36 main::@2 b2: - //SEG37 [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 + //SEG37 [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 lda j asl - //SEG38 [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte~) main::$2) -- vwsz1=pwsc1_derefidx_vbuaa + //SEG38 [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte) main::$9) -- vwsz1=pwsc1_derefidx_vbuaa tay lda swords,y sta w2 @@ -4238,8 +4240,8 @@ FINAL SYMBOL TABLE (signed word) compare::w2 (signed word) compare::w2#0 w2 zp ZP_WORD:17 26.076923076923077 (void()) main() -(byte~) main::$1 reg byte a 22.0 -(byte~) main::$2 reg byte a 202.0 +(byte) main::$8 reg byte a 22.0 +(byte) main::$9 reg byte a 202.0 (label) main::@1 (label) main::@2 (label) main::@3 @@ -4355,9 +4357,9 @@ reg byte a [ print_char::ch#6 print_char::ch#4 print_char::ch#1 print_char::ch#2 zp ZP_WORD:10 [ print_sword::w#4 print_sword::w#3 print_sword::w#1 print_sword::w#2 print_sword::w#0 compare::w1#0 ] zp ZP_WORD:12 [ print_char_cursor#60 print_char_cursor#43 print_char_cursor#71 print_char_cursor#2 print_char_cursor#70 print_char_cursor#67 print_char_cursor#75 print_char_cursor#81 print_char_cursor#76 print_char_cursor#14 print_char_cursor#116 print_char_cursor#63 print_char_cursor#61 print_char_cursor#1 ] zp ZP_BYTE:14 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] -reg byte a [ main::$1 ] +reg byte a [ main::$8 ] zp ZP_WORD:15 [ main::w1#0 ] -reg byte a [ main::$2 ] +reg byte a [ main::$9 ] zp ZP_WORD:17 [ main::w2#0 compare::w2#0 ] reg byte x [ compare::op#0 ] reg byte a [ print_byte::$0 ] @@ -4427,10 +4429,10 @@ main: { //SEG22 [6] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@7->main::@1#3] -- register_copy //SEG23 main::@1 b1: - //SEG24 [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 + //SEG24 [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 lda i asl - //SEG25 [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte~) main::$1) -- vwsz1=pwsc1_derefidx_vbuaa + //SEG25 [8] (signed word) main::w1#0 ← *((const signed word[]) swords#0 + (byte) main::$8) -- vwsz1=pwsc1_derefidx_vbuaa tay lda swords,y sta w1 @@ -4450,10 +4452,10 @@ main: { //SEG35 [9] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@6->main::@2#3] -- register_copy //SEG36 main::@2 b2: - //SEG37 [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 + //SEG37 [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 lda j asl - //SEG38 [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte~) main::$2) -- vwsz1=pwsc1_derefidx_vbuaa + //SEG38 [11] (signed word) main::w2#0 ← *((const signed word[]) swords#0 + (byte) main::$9) -- vwsz1=pwsc1_derefidx_vbuaa tay lda swords,y sta w2 diff --git a/src/test/ref/test-comparisons-sword.sym b/src/test/ref/test-comparisons-sword.sym index fe353e152..b251b595c 100644 --- a/src/test/ref/test-comparisons-sword.sym +++ b/src/test/ref/test-comparisons-sword.sym @@ -73,8 +73,8 @@ (signed word) compare::w2 (signed word) compare::w2#0 w2 zp ZP_WORD:17 26.076923076923077 (void()) main() -(byte~) main::$1 reg byte a 22.0 -(byte~) main::$2 reg byte a 202.0 +(byte) main::$8 reg byte a 22.0 +(byte) main::$9 reg byte a 202.0 (label) main::@1 (label) main::@2 (label) main::@3 @@ -190,9 +190,9 @@ reg byte a [ print_char::ch#6 print_char::ch#4 print_char::ch#1 print_char::ch#2 zp ZP_WORD:10 [ print_sword::w#4 print_sword::w#3 print_sword::w#1 print_sword::w#2 print_sword::w#0 compare::w1#0 ] zp ZP_WORD:12 [ print_char_cursor#60 print_char_cursor#43 print_char_cursor#71 print_char_cursor#2 print_char_cursor#70 print_char_cursor#67 print_char_cursor#75 print_char_cursor#81 print_char_cursor#76 print_char_cursor#14 print_char_cursor#116 print_char_cursor#63 print_char_cursor#61 print_char_cursor#1 ] zp ZP_BYTE:14 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] -reg byte a [ main::$1 ] +reg byte a [ main::$8 ] zp ZP_WORD:15 [ main::w1#0 ] -reg byte a [ main::$2 ] +reg byte a [ main::$9 ] zp ZP_WORD:17 [ main::w2#0 compare::w2#0 ] reg byte x [ compare::op#0 ] reg byte a [ print_byte::$0 ] diff --git a/src/test/ref/test-comparisons-word.cfg b/src/test/ref/test-comparisons-word.cfg index dd8fed2d0..dbe963576 100644 --- a/src/test/ref/test-comparisons-word.cfg +++ b/src/test/ref/test-comparisons-word.cfg @@ -16,16 +16,16 @@ main::@1: scope:[main] from main main::@7 [6] (byte) main::s#7 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::s#10 ) [6] (byte*) print_char_cursor#73 ← phi( main/((byte*))(word/signed word/dword/signed dword) $400 main::@7/(byte*) print_char_cursor#62 ) [6] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::i#1 ) - [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 - [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte~) main::$1) + [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte) main::$8) to:main::@2 main::@2: scope:[main] from main::@1 main::@6 [9] (byte*) print_line_cursor#30 ← phi( main::@1/(byte*) print_line_cursor#32 main::@6/(byte*) print_line_cursor#24 ) [9] (byte) main::s#5 ← phi( main::@1/(byte) main::s#7 main::@6/(byte) main::s#10 ) [9] (byte*) print_char_cursor#61 ← phi( main::@1/(byte*) print_char_cursor#73 main::@6/(byte*) print_char_cursor#62 ) [9] (byte) main::j#2 ← phi( main::@1/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@6/(byte) main::j#1 ) - [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 - [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte~) main::$2) + [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte) main::$9) to:main::@3 main::@3: scope:[main] from main::@2 main::@4 [12] (byte*) print_line_cursor#19 ← phi( main::@2/(byte*) print_line_cursor#30 main::@4/(byte*) print_line_cursor#24 ) diff --git a/src/test/ref/test-comparisons-word.log b/src/test/ref/test-comparisons-word.log index 3f00c0fc1..35586cd33 100644 --- a/src/test/ref/test-comparisons-word.log +++ b/src/test/ref/test-comparisons-word.log @@ -1,3 +1,5 @@ +Fixing pointer array-indexing *((word[]) words + (byte) main::i) +Fixing pointer array-indexing *((word[]) words + (byte) main::j) Inlined call (byte~) vicSelectGfxBank::$0 ← call toDd00 (byte*) vicSelectGfxBank::gfx CONTROL FLOW GRAPH SSA @@ -168,8 +170,8 @@ main::@1: scope:[main] from main::@15 main::@7 (byte) main::s#7 ← phi( main::@15/(byte) main::s#0 main::@7/(byte) main::s#10 ) (byte*) print_char_cursor#73 ← phi( main::@15/(byte*) print_char_cursor#15 main::@7/(byte*) print_char_cursor#64 ) (byte) main::i#2 ← phi( main::@15/(byte) main::i#0 main::@7/(byte) main::i#1 ) - (byte/signed word/word/dword/signed dword~) main::$1 ← (byte) main::i#2 * (byte/signed byte/word/signed word/dword/signed dword) 2 - (word) main::w1#0 ← *((word[]) words#0 + (byte/signed word/word/dword/signed dword~) main::$1) + (byte) main::$8 ← (byte) main::i#2 * (const byte) SIZEOF_WORD + (word) main::w1#0 ← *((word[]) words#0 + (byte) main::$8) (byte) main::j#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 to:main::@2 main::@2: scope:[main] from main::@1 main::@6 @@ -179,8 +181,8 @@ main::@2: scope:[main] from main::@1 main::@6 (byte*) print_char_cursor#61 ← phi( main::@1/(byte*) print_char_cursor#73 main::@6/(byte*) print_char_cursor#74 ) (word) main::w1#2 ← phi( main::@1/(word) main::w1#0 main::@6/(word) main::w1#4 ) (byte) main::j#2 ← phi( main::@1/(byte) main::j#0 main::@6/(byte) main::j#1 ) - (byte/signed word/word/dword/signed dword~) main::$2 ← (byte) main::j#2 * (byte/signed byte/word/signed word/dword/signed dword) 2 - (word) main::w2#0 ← *((word[]) words#0 + (byte/signed word/word/dword/signed dword~) main::$2) + (byte) main::$9 ← (byte) main::j#2 * (const byte) SIZEOF_WORD + (word) main::w2#0 ← *((word[]) words#0 + (byte) main::$9) (byte) main::op#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 to:main::@3 main::@3: scope:[main] from main::@2 main::@4 @@ -208,9 +210,9 @@ main::@16: scope:[main] from main::@3 (byte*) print_char_cursor#40 ← phi( main::@3/(byte*) print_char_cursor#24 ) (byte*) print_char_cursor#16 ← (byte*) print_char_cursor#40 (byte) main::s#1 ← ++ (byte) main::s#3 - (bool~) main::$4 ← (byte) main::s#1 == (byte/signed byte/word/signed word/dword/signed dword) 3 - (bool~) main::$5 ← ! (bool~) main::$4 - if((bool~) main::$5) goto main::@4 + (bool~) main::$2 ← (byte) main::s#1 == (byte/signed byte/word/signed word/dword/signed dword) 3 + (bool~) main::$3 ← ! (bool~) main::$2 + if((bool~) main::$3) goto main::@4 to:main::@5 main::@4: scope:[main] from main::@16 main::@17 (byte*) print_line_cursor#31 ← phi( main::@16/(byte*) print_line_cursor#22 main::@17/(byte*) print_line_cursor#6 ) @@ -222,8 +224,8 @@ main::@4: scope:[main] from main::@16 main::@17 (word) main::w1#3 ← phi( main::@16/(word) main::w1#5 main::@17/(word) main::w1#6 ) (byte) main::op#3 ← phi( main::@16/(byte) main::op#4 main::@17/(byte) main::op#5 ) (byte) main::op#1 ← (byte) main::op#3 + rangenext(0,5) - (bool~) main::$7 ← (byte) main::op#1 != rangelast(0,5) - if((bool~) main::$7) goto main::@3 + (bool~) main::$5 ← (byte) main::op#1 != rangelast(0,5) + if((bool~) main::$5) goto main::@3 to:main::@6 main::@5: scope:[main] from main::@16 (byte) main::i#9 ← phi( main::@16/(byte) main::i#6 ) @@ -256,8 +258,8 @@ main::@6: scope:[main] from main::@4 (byte) main::i#4 ← phi( main::@4/(byte) main::i#5 ) (byte) main::j#3 ← phi( main::@4/(byte) main::j#4 ) (byte) main::j#1 ← (byte) main::j#3 + rangenext(0,2) - (bool~) main::$8 ← (byte) main::j#1 != rangelast(0,2) - if((bool~) main::$8) goto main::@2 + (bool~) main::$6 ← (byte) main::j#1 != rangelast(0,2) + if((bool~) main::$6) goto main::@2 to:main::@7 main::@7: scope:[main] from main::@6 (byte) main::s#10 ← phi( main::@6/(byte) main::s#8 ) @@ -265,8 +267,8 @@ main::@7: scope:[main] from main::@6 (byte*) print_line_cursor#24 ← phi( main::@6/(byte*) print_line_cursor#27 ) (byte) main::i#3 ← phi( main::@6/(byte) main::i#4 ) (byte) main::i#1 ← (byte) main::i#3 + rangenext(0,2) - (bool~) main::$9 ← (byte) main::i#1 != rangelast(0,2) - if((bool~) main::$9) goto main::@1 + (bool~) main::$7 ← (byte) main::i#1 != rangelast(0,2) + if((bool~) main::$7) goto main::@1 to:main::@9 main::@9: scope:[main] from main::@10 main::@7 (byte*) print_char_cursor#57 ← phi( main::@10/(byte*) print_char_cursor#63 main::@7/(byte*) print_char_cursor#64 ) @@ -565,6 +567,7 @@ SYMBOL TABLE SSA (label) @end (byte) FF (byte) FF#0 +(const byte) SIZEOF_WORD = (byte/signed byte/word/signed word/dword/signed dword) 2 (byte) TT (byte) TT#0 (void()) compare((word) compare::w1 , (word) compare::w2 , (byte) compare::op) @@ -737,13 +740,13 @@ SYMBOL TABLE SSA (word) compare::w2#8 (word) compare::w2#9 (void()) main() -(byte/signed word/word/dword/signed dword~) main::$1 -(byte/signed word/word/dword/signed dword~) main::$2 -(bool~) main::$4 +(bool~) main::$2 +(bool~) main::$3 (bool~) main::$5 +(bool~) main::$6 (bool~) main::$7 -(bool~) main::$8 -(bool~) main::$9 +(byte) main::$8 +(byte) main::$9 (label) main::@1 (label) main::@10 (label) main::@15 @@ -1017,7 +1020,7 @@ SYMBOL TABLE SSA (word[]) words (word[]) words#0 -Inversing boolean not [103] (bool~) main::$5 ← (byte) main::s#1 != (byte/signed byte/word/signed word/dword/signed dword) 3 from [102] (bool~) main::$4 ← (byte) main::s#1 == (byte/signed byte/word/signed word/dword/signed dword) 3 +Inversing boolean not [103] (bool~) main::$3 ← (byte) main::s#1 != (byte/signed byte/word/signed word/dword/signed dword) 3 from [102] (bool~) main::$2 ← (byte) main::s#1 == (byte/signed byte/word/signed word/dword/signed dword) 3 Inversing boolean not [140] (bool~) compare::$23 ← (word) compare::w1#1 >= (word) compare::w2#1 from [139] (bool~) compare::$22 ← (word) compare::w1#1 < (word) compare::w2#1 Inversing boolean not [147] (bool~) compare::$21 ← (word) compare::w1#2 > (word) compare::w2#2 from [146] (bool~) compare::$20 ← (word) compare::w1#2 <= (word) compare::w2#2 Inversing boolean not [154] (bool~) compare::$19 ← (word) compare::w1#3 <= (word) compare::w2#3 from [153] (bool~) compare::$18 ← (word) compare::w1#3 > (word) compare::w2#3 @@ -1140,10 +1143,10 @@ Successful SSA optimization Pass2RedundantPhiElimination Simple Condition (bool~) print_str::$0 [6] if(*((byte*) print_str::str#2)!=(byte) '@') goto print_str::@2 Simple Condition (bool~) print_ln::$1 [19] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#11) goto print_ln::@1 Simple Condition (bool~) print_cls::$1 [69] if((byte*) print_cls::sc#1!=(byte*~) print_cls::$0) goto print_cls::@1 -Simple Condition (bool~) main::$5 [104] if((byte) main::s#1!=(byte/signed byte/word/signed word/dword/signed dword) 3) goto main::@4 -Simple Condition (bool~) main::$7 [108] if((byte) main::op#1!=rangelast(0,5)) goto main::@3 -Simple Condition (bool~) main::$8 [118] if((byte) main::j#1!=rangelast(0,2)) goto main::@2 -Simple Condition (bool~) main::$9 [122] if((byte) main::i#1!=rangelast(0,2)) goto main::@1 +Simple Condition (bool~) main::$3 [104] if((byte) main::s#1!=(byte/signed byte/word/signed word/dword/signed dword) 3) goto main::@4 +Simple Condition (bool~) main::$5 [108] if((byte) main::op#1!=rangelast(0,5)) goto main::@3 +Simple Condition (bool~) main::$6 [118] if((byte) main::j#1!=rangelast(0,2)) goto main::@2 +Simple Condition (bool~) main::$7 [122] if((byte) main::i#1!=rangelast(0,2)) goto main::@1 Simple Condition (bool~) compare::$0 [137] if((byte) compare::op#0==(byte/signed byte/word/signed word/dword/signed dword) 0) goto compare::@1 Simple Condition (bool~) compare::$23 [141] if((word) compare::w1#0>=(word) compare::w2#0) goto compare::@34 Simple Condition (bool~) compare::$1 [144] if((byte) compare::op#0==(byte/signed byte/word/signed word/dword/signed dword) 1) goto compare::@2 @@ -1196,8 +1199,8 @@ Resolved ranged next value main::j#1 ← ++ main::j#2 to ++ Resolved ranged comparison value if(main::j#1!=rangelast(0,2)) goto main::@2 to (byte/signed byte/word/signed word/dword/signed dword) 3 Resolved ranged next value main::i#1 ← ++ main::i#10 to ++ Resolved ranged comparison value if(main::i#1!=rangelast(0,2)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) 3 -Rewriting multiplication to use shift (byte/signed word/word/dword/signed dword~) main::$1 ← (byte) main::i#2 * (byte/signed byte/word/signed word/dword/signed dword) 2 -Rewriting multiplication to use shift (byte/signed word/word/dword/signed dword~) main::$2 ← (byte) main::j#2 * (byte/signed byte/word/signed word/dword/signed dword) 2 +Rewriting multiplication to use shift (byte) main::$8 ← (byte) main::i#2 * (const byte) SIZEOF_WORD +Rewriting multiplication to use shift (byte) main::$9 ← (byte) main::j#2 * (const byte) SIZEOF_WORD Successful SSA optimization Pass2MultiplyToShiftRewriting Culled Empty Block (label) @4 Culled Empty Block (label) print_ln::@2 @@ -1220,8 +1223,7 @@ Successful SSA optimization Pass2SelfPhiElimination Redundant Phi (word) main::w1#2 (word) main::w1#0 Redundant Phi (byte) main::i#10 (byte) main::i#2 Successful SSA optimization Pass2RedundantPhiElimination -Inferred type updated to byte in [35] (byte/signed word/word/dword/signed dword~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -Inferred type updated to byte in [38] (byte/signed word/word/dword/signed dword~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 +Successful SSA optimization PassNEliminateUnusedVars Inlining constant with var siblings (const byte) print_char::ch#3 Inlining constant with var siblings (const byte*) print_cls::sc#0 Inlining constant with var siblings (const byte) main::s#0 @@ -1428,16 +1430,16 @@ main::@1: scope:[main] from main main::@7 [6] (byte) main::s#7 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::s#10 ) [6] (byte*) print_char_cursor#73 ← phi( main/((byte*))(word/signed word/dword/signed dword) $400 main::@7/(byte*) print_char_cursor#62 ) [6] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::i#1 ) - [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 - [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte~) main::$1) + [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte) main::$8) to:main::@2 main::@2: scope:[main] from main::@1 main::@6 [9] (byte*) print_line_cursor#30 ← phi( main::@1/(byte*) print_line_cursor#32 main::@6/(byte*) print_line_cursor#24 ) [9] (byte) main::s#5 ← phi( main::@1/(byte) main::s#7 main::@6/(byte) main::s#10 ) [9] (byte*) print_char_cursor#61 ← phi( main::@1/(byte*) print_char_cursor#73 main::@6/(byte*) print_char_cursor#62 ) [9] (byte) main::j#2 ← phi( main::@1/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@6/(byte) main::j#1 ) - [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 - [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte~) main::$2) + [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte) main::$9) to:main::@3 main::@3: scope:[main] from main::@2 main::@4 [12] (byte*) print_line_cursor#19 ← phi( main::@2/(byte*) print_line_cursor#30 main::@4/(byte*) print_line_cursor#24 ) @@ -1672,8 +1674,8 @@ VARIABLE REGISTER WEIGHTS (word) compare::w2 (word) compare::w2#0 32.741935483870954 (void()) main() -(byte~) main::$1 22.0 -(byte~) main::$2 202.0 +(byte) main::$8 22.0 +(byte) main::$9 202.0 (byte) main::i (byte) main::i#1 16.5 (byte) main::i#2 1.5714285714285716 @@ -1758,9 +1760,9 @@ Initial phi equivalence classes [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] [ print_str::str#2 print_str::str#1 print_str::str#0 ] [ print_cls::sc#2 print_cls::sc#1 ] -Added variable main::$1 to zero page equivalence class [ main::$1 ] +Added variable main::$8 to zero page equivalence class [ main::$8 ] Added variable main::w1#0 to zero page equivalence class [ main::w1#0 ] -Added variable main::$2 to zero page equivalence class [ main::$2 ] +Added variable main::$9 to zero page equivalence class [ main::$9 ] Added variable main::w2#0 to zero page equivalence class [ main::w2#0 ] Added variable compare::w1#0 to zero page equivalence class [ compare::w1#0 ] Added variable compare::w2#0 to zero page equivalence class [ compare::w2#0 ] @@ -1781,9 +1783,9 @@ Complete equivalence classes [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] [ print_str::str#2 print_str::str#1 print_str::str#0 ] [ print_cls::sc#2 print_cls::sc#1 ] -[ main::$1 ] +[ main::$8 ] [ main::w1#0 ] -[ main::$2 ] +[ main::$9 ] [ main::w2#0 ] [ compare::w1#0 ] [ compare::w2#0 ] @@ -1803,9 +1805,9 @@ Allocated zp ZP_WORD:14 [ print_char_cursor#52 print_char_cursor#36 print_char_c Allocated zp ZP_BYTE:16 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] Allocated zp ZP_WORD:17 [ print_str::str#2 print_str::str#1 print_str::str#0 ] Allocated zp ZP_WORD:19 [ print_cls::sc#2 print_cls::sc#1 ] -Allocated zp ZP_BYTE:21 [ main::$1 ] +Allocated zp ZP_BYTE:21 [ main::$8 ] Allocated zp ZP_WORD:22 [ main::w1#0 ] -Allocated zp ZP_BYTE:24 [ main::$2 ] +Allocated zp ZP_BYTE:24 [ main::$9 ] Allocated zp ZP_WORD:25 [ main::w2#0 ] Allocated zp ZP_WORD:27 [ compare::w1#0 ] Allocated zp ZP_WORD:29 [ compare::w2#0 ] @@ -1844,8 +1846,8 @@ bend_from_b1: bend: //SEG10 main main: { - .label _1 = $15 - .label _2 = $18 + .label _8 = $15 + .label _9 = $18 .label w1 = $16 .label w2 = $19 .label s = 5 @@ -1884,12 +1886,12 @@ main: { jmp b1 //SEG23 main::@1 b1: - //SEG24 [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1 + //SEG24 [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1 lda i asl - sta _1 - //SEG25 [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte~) main::$1) -- vwuz1=pwuc1_derefidx_vbuz2 - ldy _1 + sta _8 + //SEG25 [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte) main::$8) -- vwuz1=pwuc1_derefidx_vbuz2 + ldy _8 lda words,y sta w1 lda words+1,y @@ -1912,12 +1914,12 @@ main: { jmp b2 //SEG36 main::@2 b2: - //SEG37 [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1 + //SEG37 [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1 lda j asl - sta _2 - //SEG38 [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte~) main::$2) -- vwuz1=pwuc1_derefidx_vbuz2 - ldy _2 + sta _9 + //SEG38 [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte) main::$9) -- vwuz1=pwuc1_derefidx_vbuz2 + ldy _9 lda words,y sta w2 lda words+1,y @@ -2611,13 +2613,13 @@ print_cls: { words: .word $12, $3f34, $cfed REGISTER UPLIFT POTENTIAL REGISTERS -Statement [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::$1 ] ( main:2 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::$1 ] ) always clobbers reg byte a +Statement [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::$8 ] ( main:2 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::$8 ] ) always clobbers reg byte a Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ] Removing always clobbered register reg byte a as potential for zp ZP_BYTE:5 [ main::s#3 main::s#5 main::s#7 main::s#10 main::s#1 ] -Statement [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte~) main::$1) [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::w1#0 ] ( main:2 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::w1#0 ] ) always clobbers reg byte a -Statement [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::$2 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::$2 ] ) always clobbers reg byte a +Statement [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte) main::$8) [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::w1#0 ] ( main:2 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::w1#0 ] ) always clobbers reg byte a +Statement [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::$9 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::$9 ] ) always clobbers reg byte a Removing always clobbered register reg byte a as potential for zp ZP_BYTE:3 [ main::j#2 main::j#1 ] -Statement [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte~) main::$2) [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::w2#0 ] ) always clobbers reg byte a +Statement [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte) main::$9) [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::w2#0 ] ) always clobbers reg byte a Statement [13] (word) compare::w1#0 ← (word) main::w1#0 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#55 main::s#3 print_line_cursor#19 compare::w1#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#55 main::s#3 print_line_cursor#19 compare::w1#0 ] ) always clobbers reg byte a Removing always clobbered register reg byte a as potential for zp ZP_BYTE:4 [ main::op#2 main::op#1 ] Statement [14] (word) compare::w2#0 ← (word) main::w2#0 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#55 main::s#3 print_line_cursor#19 compare::w1#0 compare::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#55 main::s#3 print_line_cursor#19 compare::w1#0 compare::w2#0 ] ) always clobbers reg byte a @@ -2650,10 +2652,10 @@ Statement [91] if(*((byte*) print_str::str#2)!=(byte) '@') goto print_str::@2 [ Statement [93] *((byte*) print_char_cursor#2) ← *((byte*) print_str::str#2) [ print_char_cursor#2 print_str::str#2 ] ( main:2::compare:16::print_str:48 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 main::s#3 print_line_cursor#19 compare::w2#0 compare::r#10 print_char_cursor#2 print_str::str#2 ] ) always clobbers reg byte a reg byte y Statement [98] *((byte*) print_cls::sc#2) ← (byte) ' ' [ print_cls::sc#2 ] ( main:2::print_cls:5 [ print_cls::sc#2 ] ) always clobbers reg byte a reg byte y Statement [100] if((byte*) print_cls::sc#1!=((byte*))(word/signed word/dword/signed dword) $400+(word/signed word/dword/signed dword) $3e8) goto print_cls::@1 [ print_cls::sc#1 ] ( main:2::print_cls:5 [ print_cls::sc#1 ] ) always clobbers reg byte a -Statement [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::$1 ] ( main:2 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::$1 ] ) always clobbers reg byte a -Statement [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte~) main::$1) [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::w1#0 ] ( main:2 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::w1#0 ] ) always clobbers reg byte a -Statement [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::$2 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::$2 ] ) always clobbers reg byte a -Statement [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte~) main::$2) [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::w2#0 ] ) always clobbers reg byte a +Statement [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::$8 ] ( main:2 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::$8 ] ) always clobbers reg byte a +Statement [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte) main::$8) [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::w1#0 ] ( main:2 [ main::i#2 print_char_cursor#73 main::s#7 print_line_cursor#32 main::w1#0 ] ) always clobbers reg byte a +Statement [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::$9 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::$9 ] ) always clobbers reg byte a +Statement [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte) main::$9) [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 print_char_cursor#61 main::s#5 print_line_cursor#30 main::w2#0 ] ) always clobbers reg byte a Statement [13] (word) compare::w1#0 ← (word) main::w1#0 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#55 main::s#3 print_line_cursor#19 compare::w1#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#55 main::s#3 print_line_cursor#19 compare::w1#0 ] ) always clobbers reg byte a Statement [14] (word) compare::w2#0 ← (word) main::w2#0 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#55 main::s#3 print_line_cursor#19 compare::w1#0 compare::w2#0 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#55 main::s#3 print_line_cursor#19 compare::w1#0 compare::w2#0 ] ) always clobbers reg byte a Statement [21] (byte*~) print_char_cursor#101 ← (byte*) print_line_cursor#1 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#101 print_line_cursor#1 ] ( main:2 [ main::i#2 main::w1#0 main::j#2 main::w2#0 main::op#2 print_char_cursor#101 print_line_cursor#1 ] ) always clobbers reg byte a @@ -2690,9 +2692,9 @@ Potential registers zp ZP_WORD:14 [ print_char_cursor#52 print_char_cursor#36 pr Potential registers zp ZP_BYTE:16 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] : zp ZP_BYTE:16 , reg byte x , Potential registers zp ZP_WORD:17 [ print_str::str#2 print_str::str#1 print_str::str#0 ] : zp ZP_WORD:17 , Potential registers zp ZP_WORD:19 [ print_cls::sc#2 print_cls::sc#1 ] : zp ZP_WORD:19 , -Potential registers zp ZP_BYTE:21 [ main::$1 ] : zp ZP_BYTE:21 , reg byte a , reg byte x , reg byte y , +Potential registers zp ZP_BYTE:21 [ main::$8 ] : zp ZP_BYTE:21 , reg byte a , reg byte x , reg byte y , Potential registers zp ZP_WORD:22 [ main::w1#0 ] : zp ZP_WORD:22 , -Potential registers zp ZP_BYTE:24 [ main::$2 ] : zp ZP_BYTE:24 , reg byte a , reg byte x , reg byte y , +Potential registers zp ZP_BYTE:24 [ main::$9 ] : zp ZP_BYTE:24 , reg byte a , reg byte x , reg byte y , Potential registers zp ZP_WORD:25 [ main::w2#0 ] : zp ZP_WORD:25 , Potential registers zp ZP_WORD:27 [ compare::w1#0 ] : zp ZP_WORD:27 , Potential registers zp ZP_WORD:29 [ compare::w2#0 ] : zp ZP_WORD:29 , @@ -2703,7 +2705,7 @@ Potential registers zp ZP_BYTE:33 [ print_byte::$2 ] : zp ZP_BYTE:33 , reg byte REGISTER UPLIFT SCOPES Uplift Scope [] 27,162.22: zp ZP_WORD:6 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#30 print_line_cursor#32 print_line_cursor#24 print_line_cursor#1 ] 17,968.66: zp ZP_WORD:14 [ print_char_cursor#52 print_char_cursor#36 print_char_cursor#55 print_char_cursor#61 print_char_cursor#73 print_char_cursor#62 print_char_cursor#11 print_char_cursor#101 print_char_cursor#53 print_char_cursor#2 print_char_cursor#1 ] Uplift Scope [print_str] 30,005.5: zp ZP_WORD:17 [ print_str::str#2 print_str::str#1 print_str::str#0 ] -Uplift Scope [main] 2,302.43: zp ZP_BYTE:5 [ main::s#3 main::s#5 main::s#7 main::s#10 main::s#1 ] 1,774.5: zp ZP_BYTE:4 [ main::op#2 main::op#1 ] 202: zp ZP_BYTE:24 [ main::$2 ] 170.44: zp ZP_BYTE:3 [ main::j#2 main::j#1 ] 78.71: zp ZP_WORD:25 [ main::w2#0 ] 53.26: zp ZP_WORD:22 [ main::w1#0 ] 22: zp ZP_BYTE:21 [ main::$1 ] 18.07: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] +Uplift Scope [main] 2,302.43: zp ZP_BYTE:5 [ main::s#3 main::s#5 main::s#7 main::s#10 main::s#1 ] 1,774.5: zp ZP_BYTE:4 [ main::op#2 main::op#1 ] 202: zp ZP_BYTE:24 [ main::$9 ] 170.44: zp ZP_BYTE:3 [ main::j#2 main::j#1 ] 78.71: zp ZP_WORD:25 [ main::w2#0 ] 53.26: zp ZP_WORD:22 [ main::w1#0 ] 22: zp ZP_BYTE:21 [ main::$8 ] 18.07: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] Uplift Scope [compare] 168.83: zp ZP_BYTE:31 [ compare::op#0 ] 36.25: zp ZP_WORD:27 [ compare::w1#0 ] 32.74: zp ZP_WORD:29 [ compare::w2#0 ] 14: zp ZP_BYTE:10 [ compare::r#10 compare::r#11 compare::r#12 compare::r#13 compare::r#14 compare::r#15 compare::r#16 ] 0.67: zp ZP_WORD:8 [ compare::ops#7 ] Uplift Scope [print_cls] 33: zp ZP_WORD:19 [ print_cls::sc#2 print_cls::sc#1 ] Uplift Scope [print_char] 20: zp ZP_BYTE:11 [ print_char::ch#4 print_char::ch#2 print_char::ch#0 print_char::ch#1 ] @@ -2713,7 +2715,7 @@ Uplift Scope [print_ln] Uplifting [] best 1156274 combination zp ZP_WORD:6 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#30 print_line_cursor#32 print_line_cursor#24 print_line_cursor#1 ] zp ZP_WORD:14 [ print_char_cursor#52 print_char_cursor#36 print_char_cursor#55 print_char_cursor#61 print_char_cursor#73 print_char_cursor#62 print_char_cursor#11 print_char_cursor#101 print_char_cursor#53 print_char_cursor#2 print_char_cursor#1 ] Uplifting [print_str] best 1156274 combination zp ZP_WORD:17 [ print_str::str#2 print_str::str#1 print_str::str#0 ] -Uplifting [main] best 1143834 combination zp ZP_BYTE:5 [ main::s#3 main::s#5 main::s#7 main::s#10 main::s#1 ] reg byte x [ main::op#2 main::op#1 ] reg byte a [ main::$2 ] zp ZP_BYTE:3 [ main::j#2 main::j#1 ] zp ZP_WORD:25 [ main::w2#0 ] zp ZP_WORD:22 [ main::w1#0 ] reg byte a [ main::$1 ] zp ZP_BYTE:2 [ main::i#2 main::i#1 ] +Uplifting [main] best 1143834 combination zp ZP_BYTE:5 [ main::s#3 main::s#5 main::s#7 main::s#10 main::s#1 ] reg byte x [ main::op#2 main::op#1 ] reg byte a [ main::$9 ] zp ZP_BYTE:3 [ main::j#2 main::j#1 ] zp ZP_WORD:25 [ main::w2#0 ] zp ZP_WORD:22 [ main::w1#0 ] reg byte a [ main::$8 ] zp ZP_BYTE:2 [ main::i#2 main::i#1 ] Limited combination testing to 100 combinations of 256 possible. Uplifting [compare] best 1140816 combination reg byte x [ compare::op#0 ] zp ZP_WORD:27 [ compare::w1#0 ] zp ZP_WORD:29 [ compare::w2#0 ] zp ZP_BYTE:10 [ compare::r#10 compare::r#11 compare::r#12 compare::r#13 compare::r#14 compare::r#15 compare::r#16 ] zp ZP_WORD:8 [ compare::ops#7 ] Uplifting [print_cls] best 1140816 combination zp ZP_WORD:19 [ print_cls::sc#2 print_cls::sc#1 ] @@ -2813,10 +2815,10 @@ main: { jmp b1 //SEG23 main::@1 b1: - //SEG24 [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 + //SEG24 [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 lda i asl - //SEG25 [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte~) main::$1) -- vwuz1=pwuc1_derefidx_vbuaa + //SEG25 [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte) main::$8) -- vwuz1=pwuc1_derefidx_vbuaa tay lda words,y sta w1 @@ -2840,10 +2842,10 @@ main: { jmp b2 //SEG36 main::@2 b2: - //SEG37 [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 + //SEG37 [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 lda j asl - //SEG38 [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte~) main::$2) -- vwuz1=pwuc1_derefidx_vbuaa + //SEG38 [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte) main::$9) -- vwuz1=pwuc1_derefidx_vbuaa tay lda words,y sta w2 @@ -3734,8 +3736,8 @@ FINAL SYMBOL TABLE (word) compare::w2 (word) compare::w2#0 w2 zp ZP_WORD:17 32.741935483870954 (void()) main() -(byte~) main::$1 reg byte a 22.0 -(byte~) main::$2 reg byte a 202.0 +(byte) main::$8 reg byte a 22.0 +(byte) main::$9 reg byte a 202.0 (label) main::@1 (label) main::@2 (label) main::@3 @@ -3840,9 +3842,9 @@ reg byte a [ print_char::ch#4 print_char::ch#2 print_char::ch#0 print_char::ch#1 zp ZP_WORD:10 [ print_word::w#2 print_word::w#0 print_word::w#1 compare::w1#0 ] zp ZP_WORD:12 [ print_char_cursor#52 print_char_cursor#36 print_char_cursor#55 print_char_cursor#61 print_char_cursor#73 print_char_cursor#62 print_char_cursor#11 print_char_cursor#101 print_char_cursor#53 print_char_cursor#2 print_char_cursor#1 ] zp ZP_BYTE:14 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] -reg byte a [ main::$1 ] +reg byte a [ main::$8 ] zp ZP_WORD:15 [ main::w1#0 ] -reg byte a [ main::$2 ] +reg byte a [ main::$9 ] zp ZP_WORD:17 [ main::w2#0 compare::w2#0 ] reg byte x [ compare::op#0 ] reg byte a [ print_byte::$0 ] @@ -3905,10 +3907,10 @@ main: { //SEG22 [6] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@7->main::@1#3] -- register_copy //SEG23 main::@1 b1: - //SEG24 [7] (byte~) main::$1 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 + //SEG24 [7] (byte) main::$8 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 lda i asl - //SEG25 [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte~) main::$1) -- vwuz1=pwuc1_derefidx_vbuaa + //SEG25 [8] (word) main::w1#0 ← *((const word[]) words#0 + (byte) main::$8) -- vwuz1=pwuc1_derefidx_vbuaa tay lda words,y sta w1 @@ -3928,10 +3930,10 @@ main: { //SEG35 [9] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@6->main::@2#3] -- register_copy //SEG36 main::@2 b2: - //SEG37 [10] (byte~) main::$2 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 + //SEG37 [10] (byte) main::$9 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_rol_1 lda j asl - //SEG38 [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte~) main::$2) -- vwuz1=pwuc1_derefidx_vbuaa + //SEG38 [11] (word) main::w2#0 ← *((const word[]) words#0 + (byte) main::$9) -- vwuz1=pwuc1_derefidx_vbuaa tay lda words,y sta w2 diff --git a/src/test/ref/test-comparisons-word.sym b/src/test/ref/test-comparisons-word.sym index 90e2a8346..c0b102b40 100644 --- a/src/test/ref/test-comparisons-word.sym +++ b/src/test/ref/test-comparisons-word.sym @@ -58,8 +58,8 @@ (word) compare::w2 (word) compare::w2#0 w2 zp ZP_WORD:17 32.741935483870954 (void()) main() -(byte~) main::$1 reg byte a 22.0 -(byte~) main::$2 reg byte a 202.0 +(byte) main::$8 reg byte a 22.0 +(byte) main::$9 reg byte a 202.0 (label) main::@1 (label) main::@2 (label) main::@3 @@ -164,9 +164,9 @@ reg byte a [ print_char::ch#4 print_char::ch#2 print_char::ch#0 print_char::ch#1 zp ZP_WORD:10 [ print_word::w#2 print_word::w#0 print_word::w#1 compare::w1#0 ] zp ZP_WORD:12 [ print_char_cursor#52 print_char_cursor#36 print_char_cursor#55 print_char_cursor#61 print_char_cursor#73 print_char_cursor#62 print_char_cursor#11 print_char_cursor#101 print_char_cursor#53 print_char_cursor#2 print_char_cursor#1 ] zp ZP_BYTE:14 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] -reg byte a [ main::$1 ] +reg byte a [ main::$8 ] zp ZP_WORD:15 [ main::w1#0 ] -reg byte a [ main::$2 ] +reg byte a [ main::$9 ] zp ZP_WORD:17 [ main::w2#0 compare::w2#0 ] reg byte x [ compare::op#0 ] reg byte a [ print_byte::$0 ] diff --git a/src/test/ref/wfragment1.asm b/src/test/ref/wfragment1.asm index b6235c3f6..ce2cf1893 100644 --- a/src/test/ref/wfragment1.asm +++ b/src/test/ref/wfragment1.asm @@ -14,13 +14,14 @@ main: { } // move_enemy(byte register(Y) obj_slot) move_enemy: { - sec - lda OBJ_WORLD_X,y - sbc #1 - sta OBJ_WORLD_X,y - lda OBJ_WORLD_X+1,y - sbc #0 - sta OBJ_WORLD_X+1,y + tya + asl + tax + lda OBJ_WORLD_X,x + bne !+ + dec OBJ_WORLD_X+1,x + !: + dec OBJ_WORLD_X,x rts } OBJ_WORLD_X: .fill 2*MAX_OBJECTS, 0 diff --git a/src/test/ref/wfragment1.cfg b/src/test/ref/wfragment1.cfg index a77b28b42..afac4be53 100644 --- a/src/test/ref/wfragment1.cfg +++ b/src/test/ref/wfragment1.cfg @@ -23,8 +23,9 @@ main::@return: scope:[main] from main::@2 [10] return to:@return move_enemy: scope:[move_enemy] from main::@1 - [11] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) - (byte/signed byte/word/signed word/dword/signed dword) 1 + [11] (byte) move_enemy::$0 ← (byte) move_enemy::obj_slot#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [12] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) - (byte/signed byte/word/signed word/dword/signed dword) 1 to:move_enemy::@return move_enemy::@return: scope:[move_enemy] from move_enemy - [12] return + [13] return to:@return diff --git a/src/test/ref/wfragment1.log b/src/test/ref/wfragment1.log index eedb61f85..e9440d17a 100644 --- a/src/test/ref/wfragment1.log +++ b/src/test/ref/wfragment1.log @@ -1,3 +1,5 @@ +Fixing pointer array-indexing *((word[MAX_OBJECTS]) OBJ_WORLD_X + (byte) move_enemy::obj_slot) +Fixing pointer array-indexing *((word[MAX_OBJECTS]) OBJ_WORLD_X + (byte) move_enemy::obj_slot) CONTROL FLOW GRAPH SSA @begin: scope:[] from @@ -26,7 +28,8 @@ main::@return: scope:[main] from main::@3 to:@return move_enemy: scope:[move_enemy] from main::@1 (byte) move_enemy::obj_slot#1 ← phi( main::@1/(byte) move_enemy::obj_slot#0 ) - *((word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#1) ← *((word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#1) - (byte/signed byte/word/signed word/dword/signed dword) 1 + (byte) move_enemy::$0 ← (byte) move_enemy::obj_slot#1 * (const byte) SIZEOF_WORD + *((word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) ← *((word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) - (byte/signed byte/word/signed word/dword/signed dword) 1 (bool) move_enemy::return#1 ← true to:move_enemy::@return move_enemy::@return: scope:[move_enemy] from move_enemy @@ -51,6 +54,7 @@ SYMBOL TABLE SSA (byte) MAX_OBJECTS#0 (word[MAX_OBJECTS#0]) OBJ_WORLD_X (word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 +(const byte) SIZEOF_WORD = (byte/signed byte/word/signed word/dword/signed dword) 2 (void()) main() (bool~) main::$1 (label) main::@1 @@ -62,6 +66,7 @@ SYMBOL TABLE SSA (byte) main::i#2 (byte) main::i#3 (bool()) move_enemy((byte) move_enemy::obj_slot) +(byte) move_enemy::$0 (label) move_enemy::@return (byte) move_enemy::obj_slot (byte) move_enemy::obj_slot#0 @@ -92,8 +97,11 @@ Successful SSA optimization PassNEliminateUnusedVars Successful SSA optimization PassNEliminateUnusedVars Resolved ranged next value main::i#1 ← ++ main::i#2 to ++ Resolved ranged comparison value if(main::i#1!=rangelast(0,5)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) 6 +Rewriting multiplication to use shift (byte) move_enemy::$0 ← (byte) move_enemy::obj_slot#0 * (const byte) SIZEOF_WORD +Successful SSA optimization Pass2MultiplyToShiftRewriting Culled Empty Block (label) @19 Successful SSA optimization Pass2CullEmptyBlocks +Successful SSA optimization PassNEliminateUnusedVars Inlining constant with var siblings (const byte) main::i#0 Constant inlined main::i#0 = (byte/signed byte/word/signed word/dword/signed dword) 0 Successful SSA optimization Pass2ConstantInlining @@ -143,10 +151,11 @@ main::@return: scope:[main] from main::@2 [10] return to:@return move_enemy: scope:[move_enemy] from main::@1 - [11] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) - (byte/signed byte/word/signed word/dword/signed dword) 1 + [11] (byte) move_enemy::$0 ← (byte) move_enemy::obj_slot#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [12] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) - (byte/signed byte/word/signed word/dword/signed dword) 1 to:move_enemy::@return move_enemy::@return: scope:[move_enemy] from move_enemy - [12] return + [13] return to:@return @@ -158,18 +167,22 @@ VARIABLE REGISTER WEIGHTS (byte) main::i#1 16.5 (byte) main::i#2 11.0 (bool()) move_enemy((byte) move_enemy::obj_slot) +(byte) move_enemy::$0 6.0 (byte) move_enemy::obj_slot -(byte) move_enemy::obj_slot#0 15.0 +(byte) move_enemy::obj_slot#0 13.0 (bool) move_enemy::return Initial phi equivalence classes [ main::i#2 main::i#1 ] Added variable move_enemy::obj_slot#0 to zero page equivalence class [ move_enemy::obj_slot#0 ] +Added variable move_enemy::$0 to zero page equivalence class [ move_enemy::$0 ] Complete equivalence classes [ main::i#2 main::i#1 ] [ move_enemy::obj_slot#0 ] +[ move_enemy::$0 ] Allocated zp ZP_BYTE:2 [ main::i#2 main::i#1 ] Allocated zp ZP_BYTE:3 [ move_enemy::obj_slot#0 ] +Allocated zp ZP_BYTE:4 [ move_enemy::$0 ] INITIAL ASM //SEG0 File Comments @@ -234,37 +247,45 @@ main: { //SEG23 move_enemy // move_enemy(byte zeropage(3) obj_slot) move_enemy: { + .label _0 = 4 .label obj_slot = 3 - //SEG24 [11] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) - (byte/signed byte/word/signed word/dword/signed dword) 1 -- pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz1_minus_1 - ldx obj_slot + //SEG24 [11] (byte) move_enemy::$0 ← (byte) move_enemy::obj_slot#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1 + lda obj_slot + asl + sta _0 + //SEG25 [12] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) - (byte/signed byte/word/signed word/dword/signed dword) 1 -- pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz1_minus_1 + ldx _0 lda OBJ_WORLD_X,x bne !+ dec OBJ_WORLD_X+1,x !: dec OBJ_WORLD_X,x jmp breturn - //SEG25 move_enemy::@return + //SEG26 move_enemy::@return breturn: - //SEG26 [12] return + //SEG27 [13] return rts } OBJ_WORLD_X: .fill 2*MAX_OBJECTS, 0 REGISTER UPLIFT POTENTIAL REGISTERS -Statement [11] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) - (byte/signed byte/word/signed word/dword/signed dword) 1 [ ] ( main:2::move_enemy:7 [ main::i#2 ] ) always clobbers reg byte a +Statement [11] (byte) move_enemy::$0 ← (byte) move_enemy::obj_slot#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ move_enemy::$0 ] ( main:2::move_enemy:7 [ main::i#2 move_enemy::$0 ] ) always clobbers reg byte a Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ] -Statement [11] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) - (byte/signed byte/word/signed word/dword/signed dword) 1 [ ] ( main:2::move_enemy:7 [ main::i#2 ] ) always clobbers reg byte a +Statement [12] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) - (byte/signed byte/word/signed word/dword/signed dword) 1 [ ] ( main:2::move_enemy:7 [ main::i#2 ] ) always clobbers reg byte a +Statement [11] (byte) move_enemy::$0 ← (byte) move_enemy::obj_slot#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ move_enemy::$0 ] ( main:2::move_enemy:7 [ main::i#2 move_enemy::$0 ] ) always clobbers reg byte a +Statement [12] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) - (byte/signed byte/word/signed word/dword/signed dword) 1 [ ] ( main:2::move_enemy:7 [ main::i#2 ] ) always clobbers reg byte a Potential registers zp ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y , Potential registers zp ZP_BYTE:3 [ move_enemy::obj_slot#0 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y , +Potential registers zp ZP_BYTE:4 [ move_enemy::$0 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y , REGISTER UPLIFT SCOPES Uplift Scope [main] 27.5: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] -Uplift Scope [move_enemy] 15: zp ZP_BYTE:3 [ move_enemy::obj_slot#0 ] +Uplift Scope [move_enemy] 13: zp ZP_BYTE:3 [ move_enemy::obj_slot#0 ] 6: zp ZP_BYTE:4 [ move_enemy::$0 ] Uplift Scope [] -Uplifting [main] best 346 combination reg byte y [ main::i#2 main::i#1 ] -Uplifting [move_enemy] best 317 combination reg byte y [ move_enemy::obj_slot#0 ] -Uplifting [] best 317 combination +Uplifting [main] best 354 combination reg byte y [ main::i#2 main::i#1 ] +Uplifting [move_enemy] best 319 combination reg byte y [ move_enemy::obj_slot#0 ] reg byte a [ move_enemy::$0 ] +Uplifting [] best 319 combination ASSEMBLER BEFORE OPTIMIZATION //SEG0 File Comments @@ -324,18 +345,20 @@ main: { //SEG23 move_enemy // move_enemy(byte register(Y) obj_slot) move_enemy: { - //SEG24 [11] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) - (byte/signed byte/word/signed word/dword/signed dword) 1 -- pwuc1_derefidx_vbuyy=pwuc1_derefidx_vbuyy_minus_1 - sec - lda OBJ_WORLD_X,y - sbc #1 - sta OBJ_WORLD_X,y - lda OBJ_WORLD_X+1,y - sbc #0 - sta OBJ_WORLD_X+1,y + //SEG24 [11] (byte) move_enemy::$0 ← (byte) move_enemy::obj_slot#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuyy_rol_1 + tya + asl + //SEG25 [12] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) - (byte/signed byte/word/signed word/dword/signed dword) 1 -- pwuc1_derefidx_vbuaa=pwuc1_derefidx_vbuaa_minus_1 + tax + lda OBJ_WORLD_X,x + bne !+ + dec OBJ_WORLD_X+1,x + !: + dec OBJ_WORLD_X,x jmp breturn - //SEG25 move_enemy::@return + //SEG26 move_enemy::@return breturn: - //SEG26 [12] return + //SEG27 [13] return rts } OBJ_WORLD_X: .fill 2*MAX_OBJECTS, 0 @@ -385,17 +408,19 @@ FINAL SYMBOL TABLE (byte) main::i#1 reg byte y 16.5 (byte) main::i#2 reg byte y 11.0 (bool()) move_enemy((byte) move_enemy::obj_slot) +(byte) move_enemy::$0 reg byte a 6.0 (label) move_enemy::@return (byte) move_enemy::obj_slot -(byte) move_enemy::obj_slot#0 reg byte y 15.0 +(byte) move_enemy::obj_slot#0 reg byte y 13.0 (bool) move_enemy::return reg byte y [ main::i#2 main::i#1 ] reg byte y [ move_enemy::obj_slot#0 ] +reg byte a [ move_enemy::$0 ] FINAL ASSEMBLER -Score: 182 +Score: 184 //SEG0 File Comments // Adding a missing word-fragment for Travis Fisher @@ -437,16 +462,18 @@ main: { //SEG23 move_enemy // move_enemy(byte register(Y) obj_slot) move_enemy: { - //SEG24 [11] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::obj_slot#0) - (byte/signed byte/word/signed word/dword/signed dword) 1 -- pwuc1_derefidx_vbuyy=pwuc1_derefidx_vbuyy_minus_1 - sec - lda OBJ_WORLD_X,y - sbc #1 - sta OBJ_WORLD_X,y - lda OBJ_WORLD_X+1,y - sbc #0 - sta OBJ_WORLD_X+1,y - //SEG25 move_enemy::@return - //SEG26 [12] return + //SEG24 [11] (byte) move_enemy::$0 ← (byte) move_enemy::obj_slot#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuyy_rol_1 + tya + asl + //SEG25 [12] *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) ← *((const word[MAX_OBJECTS#0]) OBJ_WORLD_X#0 + (byte) move_enemy::$0) - (byte/signed byte/word/signed word/dword/signed dword) 1 -- pwuc1_derefidx_vbuaa=pwuc1_derefidx_vbuaa_minus_1 + tax + lda OBJ_WORLD_X,x + bne !+ + dec OBJ_WORLD_X+1,x + !: + dec OBJ_WORLD_X,x + //SEG26 move_enemy::@return + //SEG27 [13] return rts } OBJ_WORLD_X: .fill 2*MAX_OBJECTS, 0 diff --git a/src/test/ref/wfragment1.sym b/src/test/ref/wfragment1.sym index 6182ebacc..f721ab7ad 100644 --- a/src/test/ref/wfragment1.sym +++ b/src/test/ref/wfragment1.sym @@ -13,10 +13,12 @@ (byte) main::i#1 reg byte y 16.5 (byte) main::i#2 reg byte y 11.0 (bool()) move_enemy((byte) move_enemy::obj_slot) +(byte) move_enemy::$0 reg byte a 6.0 (label) move_enemy::@return (byte) move_enemy::obj_slot -(byte) move_enemy::obj_slot#0 reg byte y 15.0 +(byte) move_enemy::obj_slot#0 reg byte y 13.0 (bool) move_enemy::return reg byte y [ main::i#2 main::i#1 ] reg byte y [ move_enemy::obj_slot#0 ] +reg byte a [ move_enemy::$0 ]