1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-18 08:30:18 +00:00

Added test for direct increment of constant numberic pointer ++*$d020;

This commit is contained in:
jespergravgaard 2017-11-13 22:14:11 +01:00
parent 788f3d63a2
commit 5ed20ccc76
8 changed files with 106 additions and 38 deletions

View File

@ -259,6 +259,13 @@ public class AsmFragmentSignature {
return bind(deref.getPointer()) + "_derefidx_" + bind(deref.getIndex());
}
if (value instanceof VariableRef) {
value = program.getSymbolInfos().getVariable((VariableRef) value);
}
if (value instanceof ConstantRef) {
value = program.getScope().getConstant((ConstantRef) value);
}
// Find value if it is already bound
for (String name : bindings.keySet()) {
Value bound = bindings.get(name);
@ -266,12 +273,6 @@ public class AsmFragmentSignature {
return name;
}
if (value instanceof VariableRef) {
value = program.getSymbolInfos().getVariable((VariableRef) value);
}
if (value instanceof ConstantRef) {
value = program.getScope().getConstant((ConstantRef) value);
}
if (value instanceof Variable) {
Variable variable = (Variable) value;
Registers.Register register = variable.getAllocation();

View File

@ -2,8 +2,8 @@
void main() {
byte* screen = $0400;
// RValue pointer expression (constant)
byte* screen = $0400;
byte a = *(screen+80);
// RValue pointer expression (variable)
@ -27,7 +27,9 @@ void main() {
++*$d020;
--*($d000+$21);
// Increment on a const named pointer
byte* BGCOL = $d020;
++*BGCOL;
}

View File

@ -4,6 +4,7 @@
jsr main
main: {
.const screen = $400
.const BGCOL = $d020
.const sc2 = screen+$51
.label _2 = 2
.label _9 = 2
@ -52,5 +53,6 @@ main: {
bne b2
inc $d020
dec $d000+$21
inc BGCOL
rts
}

View File

@ -29,7 +29,8 @@ main::@2: scope:[main] from main::@2 main::@3
main::@4: scope:[main] from main::@2
[15] *((word) 53280) ← ++ *((word) 53280) [ ] ( main:0 [ ] )
[16] *((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33) [ ] ( main:0 [ ] )
[17] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) [ ] ( main:0 [ ] )
to:main::@return
main::@return: scope:[main] from main::@4
[17] return [ ] ( main:0 [ ] )
[18] return [ ] ( main:0 [ ] )
to:@return

View File

@ -2,8 +2,8 @@
void main() {
byte* screen = $0400;
// RValue pointer expression (constant)
byte* screen = $0400;
byte a = *(screen+80);
// RValue pointer expression (variable)
@ -27,12 +27,15 @@ void main() {
++*$d020;
--*($d000+$21);
// Increment on a const named pointer
byte* BGCOL = $d020;
++*BGCOL;
}
Adding pre/post-modifier *((word) 53280) ← ++ *((word) 53280)
Adding pre/post-modifier *((var) main::$13) ← -- *((var) main::$13)
Adding pre/post-modifier *((byte*) main::BGCOL) ← ++ *((byte*) main::BGCOL)
PROGRAM
proc (void()) main()
(byte*) main::screen ← (word) 1024
@ -68,6 +71,8 @@ main::@2:
*((word~) main::$13) ← -- *((word~) main::$13)
(word~) main::$14 ← (word) 53248 + (byte) 33
(word~) main::$15 ← (word) 53248 + (byte) 33
(byte*) main::BGCOL ← (word) 53280
*((byte*) main::BGCOL) ← ++ *((byte*) main::BGCOL)
main::@return:
return
endproc // main()
@ -94,6 +99,7 @@ SYMBOLS
(label) main::@1
(label) main::@2
(label) main::@return
(byte*) main::BGCOL
(byte) main::a
(byte) main::i
(byte) main::j
@ -143,6 +149,8 @@ main::@4: scope:[main] from main::@2
*((word~) main::$13) ← -- *((word~) main::$13)
(word~) main::$14 ← (word) 53248 + (byte) 33
(word~) main::$15 ← (word) 53248 + (byte) 33
(byte*) main::BGCOL ← (word) 53280
*((byte*) main::BGCOL) ← ++ *((byte*) main::BGCOL)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -197,6 +205,8 @@ main::@4: scope:[main] from main::@2
*((word~) main::$13) ← -- *((word~) main::$13)
(word~) main::$14 ← (word) 53248 + (byte) 33
(word~) main::$15 ← (word) 53248 + (byte) 33
(byte*) main::BGCOL ← (word) 53280
*((byte*) main::BGCOL) ← ++ *((byte*) main::BGCOL)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -257,6 +267,8 @@ main::@4: scope:[main] from main::@2
*((word~) main::$13) ← -- *((word~) main::$13)
(word~) main::$14 ← (word) 53248 + (byte) 33
(word~) main::$15 ← (word) 53248 + (byte) 33
(byte*) main::BGCOL#0 ← (word) 53280
*((byte*) main::BGCOL#0) ← ++ *((byte*) main::BGCOL#0)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -316,6 +328,8 @@ main::@4: scope:[main] from main::@2
*((word~) main::$13) ← -- *((word~) main::$13)
(word~) main::$14 ← (word) 53248 + (byte) 33
(word~) main::$15 ← (word) 53248 + (byte) 33
(byte*) main::BGCOL#0 ← (word) 53280
*((byte*) main::BGCOL#0) ← ++ *((byte*) main::BGCOL#0)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -354,6 +368,8 @@ INITIAL SSA SYMBOL TABLE
(label) main::@3
(label) main::@4
(label) main::@return
(byte*) main::BGCOL
(byte*) main::BGCOL#0
(byte) main::a
(byte) main::a#0
(byte) main::i
@ -422,6 +438,8 @@ main::@4: scope:[main] from main::@2
*((word~) main::$13) ← -- *((word~) main::$13)
(word~) main::$14 ← (word) 53248 + (byte) 33
(word~) main::$15 ← (word) 53248 + (byte) 33
(byte*) main::BGCOL#0 ← (word) 53280
*((byte*) main::BGCOL#0) ← ++ *((byte*) main::BGCOL#0)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -481,6 +499,8 @@ main::@4: scope:[main] from main::@2
*((word~) main::$13) ← -- *((word~) main::$13)
(word~) main::$14 ← (word) 53248 + (byte) 33
(word~) main::$15 ← (word) 53248 + (byte) 33
(byte*) main::BGCOL#0 ← (word) 53280
*((byte*) main::BGCOL#0) ← ++ *((byte*) main::BGCOL#0)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -540,6 +560,8 @@ main::@4: scope:[main] from main::@2
*((word~) main::$13) ← -- *((word~) main::$13)
(word~) main::$14 ← (word) 53248 + (byte) 33
(word~) main::$15 ← (word) 53248 + (byte) 33
(byte*) main::BGCOL#0 ← (word) 53280
*((byte*) main::BGCOL#0) ← ++ *((byte*) main::BGCOL#0)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -596,6 +618,8 @@ main::@4: scope:[main] from main::@2
*((word~) main::$13) ← -- *((word~) main::$13)
(word~) main::$14 ← (word) 53248 + (byte) 33
(word~) main::$15 ← (word) 53248 + (byte) 33
(byte*) main::BGCOL#0 ← (word) 53280
*((byte*) main::BGCOL#0) ← ++ *((byte*) main::BGCOL#0)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -650,6 +674,8 @@ main::@4: scope:[main] from main::@2
*((word~) main::$13) ← -- *((word~) main::$13)
(word~) main::$14 ← (word) 53248 + (byte) 33
(word~) main::$15 ← (word) 53248 + (byte) 33
(byte*) main::BGCOL#0 ← (word) 53280
*((byte*) main::BGCOL#0) ← ++ *((byte*) main::BGCOL#0)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -665,6 +691,7 @@ Constant (const byte) main::j#0 = 0
Constant (const word) main::$13 = 53248+33
Constant (const word) main::$14 = 53248+33
Constant (const word) main::$15 = 53248+33
Constant (const byte*) main::BGCOL#0 = 53280
Succesful SSA optimization Pass2ConstantIdentification
CONTROL FLOW GRAPH
@begin: scope:[] from
@ -702,6 +729,7 @@ main::@2: scope:[main] from main::@2 main::@3
main::@4: scope:[main] from main::@2
*((word) 53280) ← ++ *((word) 53280)
*((const word) main::$13) ← -- *((const word) main::$13)
*((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -748,6 +776,7 @@ main::@2: scope:[main] from main::@2 main::@3
main::@4: scope:[main] from main::@2
*((word) 53280) ← ++ *((word) 53280)
*((const word) main::$13) ← -- *((const word) main::$13)
*((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -810,6 +839,7 @@ main::@2: scope:[main] from main::@2 main::@3
main::@4: scope:[main] from main::@2
*((word) 53280) ← ++ *((word) 53280)
*((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33)
*((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -832,6 +862,8 @@ FINAL SYMBOL TABLE
(label) main::@3
(label) main::@4
(label) main::@return
(byte*) main::BGCOL
(const byte*) main::BGCOL#0 = (word) 53280
(byte) main::a
(byte) main::a#0
(byte) main::i
@ -881,6 +913,7 @@ main::@2: scope:[main] from main::@3 main::@6
main::@4: scope:[main] from main::@2
*((word) 53280) ← ++ *((word) 53280)
*((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33)
*((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0)
to:main::@return
main::@return: scope:[main] from main::@4
return
@ -930,20 +963,21 @@ main::@2: scope:[main] from main::@3 main::@6
main::@4: scope:[main] from main::@2
[15] *((word) 53280) ← ++ *((word) 53280) [ ]
[16] *((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33) [ ]
[17] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) [ ]
to:main::@return
main::@return: scope:[main] from main::@4
[17] return [ ]
[18] return [ ]
to:@return
main::@6: scope:[main] from main::@2
[18] (byte~) main::j#3 ← (byte) main::j#1 [ main::j#3 ]
[19] (byte~) main::j#3 ← (byte) main::j#1 [ main::j#3 ]
to:main::@2
main::@5: scope:[main] from main::@1
[19] (byte~) main::i#3 ← (byte) main::i#1 [ main::i#3 ]
[20] (byte~) main::i#3 ← (byte) main::i#1 [ main::i#3 ]
to:main::@1
Created 2 initial phi equivalence classes
Coalesced [18] main::j#3 ← main::j#1
Coalesced [19] main::i#3 ← main::i#1
Coalesced [19] main::j#3 ← main::j#1
Coalesced [20] main::i#3 ← main::i#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) main::@6
Culled Empty Block (label) main::@5
@ -983,9 +1017,10 @@ main::@2: scope:[main] from main::@2 main::@3
main::@4: scope:[main] from main::@2
[15] *((word) 53280) ← ++ *((word) 53280) [ ]
[16] *((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33) [ ]
[17] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) [ ]
to:main::@return
main::@return: scope:[main] from main::@4
[17] return [ ]
[18] return [ ]
to:@return
CONTROL FLOW GRAPH - PHI MEM COALESCED
@ -1020,9 +1055,10 @@ main::@2: scope:[main] from main::@2 main::@3
main::@4: scope:[main] from main::@2
[15] *((word) 53280) ← ++ *((word) 53280) [ ] ( main:0 [ ] )
[16] *((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33) [ ] ( main:0 [ ] )
[17] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) [ ] ( main:0 [ ] )
to:main::@return
main::@return: scope:[main] from main::@4
[17] return [ ] ( main:0 [ ] )
[18] return [ ] ( main:0 [ ] )
to:@return
DOMINATORS
@ -1058,6 +1094,7 @@ VARIABLE REGISTER WEIGHTS
(byte*~) main::$11 11.0
(byte*~) main::$2 11.0
(byte*~) main::$9 11.0
(byte*) main::BGCOL
(byte) main::a
(byte) main::a#0 20.0
(byte) main::i
@ -1108,6 +1145,7 @@ bend:
//SEG6 main
main: {
.const screen = $400
.const BGCOL = $d020
.const sc2 = screen+$51
.label _2 = 5
.label _9 = 7
@ -1204,10 +1242,12 @@ main: {
inc $d020
//SEG32 [16] *((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33) [ ] ( main:0 [ ] ) -- _deref_cowo1=_dec__deref_cowo1
dec $d000+$21
//SEG33 [17] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) [ ] ( main:0 [ ] ) -- _deref_cowo1=_inc__deref_cowo1
inc BGCOL
jmp breturn
//SEG33 main::@return
//SEG34 main::@return
breturn:
//SEG34 [17] return [ ] ( main:0 [ ] )
//SEG35 [18] return [ ] ( main:0 [ ] )
rts
}
@ -1254,8 +1294,8 @@ REGISTER UPLIFT SCOPES
Uplift Scope [main] 31.17: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 27.5: zp ZP_BYTE:3 [ main::j#2 main::j#1 ] 20: zp ZP_BYTE:4 [ main::a#0 ] 11: zp ZP_PTR_BYTE:5 [ main::$2 ] 11: zp ZP_PTR_BYTE:7 [ main::$9 ] 11: zp ZP_PTR_BYTE:9 [ main::$11 ]
Uplift Scope []
Uplifting [main] best 1190 combination reg byte x [ main::i#2 main::i#1 ] reg byte x [ main::j#2 main::j#1 ] reg byte a [ main::a#0 ] zp ZP_PTR_BYTE:5 [ main::$2 ] zp ZP_PTR_BYTE:7 [ main::$9 ] zp ZP_PTR_BYTE:9 [ main::$11 ]
Uplifting [] best 1190 combination
Uplifting [main] best 1196 combination reg byte x [ main::i#2 main::i#1 ] reg byte x [ main::j#2 main::j#1 ] reg byte a [ main::a#0 ] zp ZP_PTR_BYTE:5 [ main::$2 ] zp ZP_PTR_BYTE:7 [ main::$9 ] zp ZP_PTR_BYTE:9 [ main::$11 ]
Uplifting [] best 1196 combination
Coalescing zero page register [ zp ZP_PTR_BYTE:5 [ main::$2 ] ] with [ zp ZP_PTR_BYTE:7 [ main::$9 ] ]
Allocated (was zp ZP_PTR_BYTE:5) zp ZP_PTR_BYTE:2 [ main::$2 main::$9 ]
Allocated (was zp ZP_PTR_BYTE:9) zp ZP_PTR_BYTE:4 [ main::$11 ]
@ -1284,6 +1324,7 @@ bend:
//SEG6 main
main: {
.const screen = $400
.const BGCOL = $d020
.const sc2 = screen+$51
.label _2 = 2
.label _9 = 2
@ -1367,9 +1408,11 @@ main: {
inc $d020
//SEG32 [16] *((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33) [ ] ( main:0 [ ] ) -- _deref_cowo1=_dec__deref_cowo1
dec $d000+$21
//SEG33 main::@return
//SEG33 [17] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) [ ] ( main:0 [ ] ) -- _deref_cowo1=_inc__deref_cowo1
inc BGCOL
//SEG34 main::@return
breturn:
//SEG34 [17] return [ ] ( main:0 [ ] )
//SEG35 [18] return [ ] ( main:0 [ ] )
rts
}
@ -1392,6 +1435,7 @@ bend:
//SEG6 main
main: {
.const screen = $400
.const BGCOL = $d020
.const sc2 = screen+$51
.label _2 = 2
.label _9 = 2
@ -1474,9 +1518,11 @@ main: {
inc $d020
//SEG32 [16] *((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33) [ ] ( main:0 [ ] ) -- _deref_cowo1=_dec__deref_cowo1
dec $d000+$21
//SEG33 main::@return
//SEG33 [17] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) [ ] ( main:0 [ ] ) -- _deref_cowo1=_inc__deref_cowo1
inc BGCOL
//SEG34 main::@return
breturn:
//SEG34 [17] return [ ] ( main:0 [ ] )
//SEG35 [18] return [ ] ( main:0 [ ] )
rts
}
@ -1502,6 +1548,7 @@ bend:
//SEG6 main
main: {
.const screen = $400
.const BGCOL = $d020
.const sc2 = screen+$51
.label _2 = 2
.label _9 = 2
@ -1582,9 +1629,11 @@ main: {
inc $d020
//SEG32 [16] *((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33) [ ] ( main:0 [ ] ) -- _deref_cowo1=_dec__deref_cowo1
dec $d000+$21
//SEG33 main::@return
//SEG33 [17] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) [ ] ( main:0 [ ] ) -- _deref_cowo1=_inc__deref_cowo1
inc BGCOL
//SEG34 main::@return
breturn:
//SEG34 [17] return [ ] ( main:0 [ ] )
//SEG35 [18] return [ ] ( main:0 [ ] )
rts
}
@ -1610,6 +1659,7 @@ ASSEMBLER
//SEG6 main
main: {
.const screen = $400
.const BGCOL = $d020
.const sc2 = screen+$51
.label _2 = 2
.label _9 = 2
@ -1686,8 +1736,10 @@ main: {
inc $d020
//SEG32 [16] *((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33) [ ] ( main:0 [ ] ) -- _deref_cowo1=_dec__deref_cowo1
dec $d000+$21
//SEG33 main::@return
//SEG34 [17] return [ ] ( main:0 [ ] )
//SEG33 [17] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) [ ] ( main:0 [ ] ) -- _deref_cowo1=_inc__deref_cowo1
inc BGCOL
//SEG34 main::@return
//SEG35 [18] return [ ] ( main:0 [ ] )
rts
}
@ -1708,6 +1760,7 @@ ASSEMBLER
//SEG6 main
main: {
.const screen = $400
.const BGCOL = $d020
.const sc2 = screen+$51
.label _2 = 2
.label _9 = 2
@ -1782,8 +1835,10 @@ main: {
inc $d020
//SEG32 [16] *((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33) [ ] ( main:0 [ ] ) -- _deref_cowo1=_dec__deref_cowo1
dec $d000+$21
//SEG33 main::@return
//SEG34 [17] return [ ] ( main:0 [ ] )
//SEG33 [17] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) [ ] ( main:0 [ ] ) -- _deref_cowo1=_inc__deref_cowo1
inc BGCOL
//SEG34 main::@return
//SEG35 [18] return [ ] ( main:0 [ ] )
rts
}
@ -1800,6 +1855,8 @@ FINAL SYMBOL TABLE
(label) main::@3
(label) main::@4
(label) main::@return
(byte*) main::BGCOL
(const byte*) main::BGCOL#0 BGCOL = (word) 53280
(byte) main::a
(byte) main::a#0 reg byte a 20.0
(byte) main::i
@ -1833,6 +1890,7 @@ FINAL CODE
//SEG6 main
main: {
.const screen = $400
.const BGCOL = $d020
.const sc2 = screen+$51
.label _2 = 2
.label _9 = 2
@ -1907,8 +1965,10 @@ main: {
inc $d020
//SEG32 [16] *((word) 53248+(byte) 33) ← -- *((word) 53248+(byte) 33) [ ] ( main:0 [ ] ) -- _deref_cowo1=_dec__deref_cowo1
dec $d000+$21
//SEG33 main::@return
//SEG34 [17] return [ ] ( main:0 [ ] )
//SEG33 [17] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) [ ] ( main:0 [ ] ) -- _deref_cowo1=_inc__deref_cowo1
inc BGCOL
//SEG34 main::@return
//SEG35 [18] return [ ] ( main:0 [ ] )
rts
}

View File

@ -10,6 +10,8 @@
(label) main::@3
(label) main::@4
(label) main::@return
(byte*) main::BGCOL
(const byte*) main::BGCOL#0 BGCOL = (word) 53280
(byte) main::a
(byte) main::a#0 reg byte a 20.0
(byte) main::i

View File

@ -13,7 +13,7 @@ void main() {
// Wait for raster
do {} while(*RASTER!=$fe);
do {} while(*RASTER!=$ff);
(*BGCOL)++;
++*BGCOL;
// Soft scroll
if(--scroll==$ff) {
scroll = 7;
@ -31,7 +31,7 @@ void main() {
nxt++;
}
*SCROLL = scroll;
(*BGCOL)--;
--*BGCOL;
} while(true);
}

View File

@ -13,7 +13,7 @@ void main() {
// Wait for raster
do {} while(*RASTER!=$fe);
do {} while(*RASTER!=$ff);
(*BGCOL)++;
++*BGCOL;
// Soft scroll
if(--scroll==$ff) {
scroll = 7;
@ -31,7 +31,7 @@ void main() {
nxt++;
}
*SCROLL = scroll;
(*BGCOL)--;
--*BGCOL;
} while(true);
}