mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-21 14:30:21 +00:00
Closes #807 bug when rewriting multiplication with power of 2, where the constant is the left operand.
This commit is contained in:
parent
95aa5ec6c4
commit
63932ef555
@ -76,6 +76,7 @@ public class Pass2MultiplyToShiftRewriting extends Pass2SsaOptimization {
|
||||
getLog().append("Rewriting multiplication to use shift " + assignment.toString(getProgram(), false));
|
||||
assignment.setOperator(Operators.SHIFT_LEFT);
|
||||
assignment.setrValue2(new ConstantInteger((long) power2, SymbolType.BYTE));
|
||||
assignment.setrValue1(varValue);
|
||||
optimized = true;
|
||||
} else if(Operators.MULTIPLY.equals(assignment.getOperator())) {
|
||||
// Multiplication by constant
|
||||
|
@ -3354,6 +3354,11 @@ public class TestProgramsFast extends TestPrograms {
|
||||
compileAndCompare("multiply-2s.c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiply2sLeft() throws IOException {
|
||||
compileAndCompare("multiply-2s-left.c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiplyNs() throws IOException {
|
||||
compileAndCompare("multiply-ns.c");
|
||||
|
18
src/test/kc/multiply-2s-left.c
Normal file
18
src/test/kc/multiply-2s-left.c
Normal file
@ -0,0 +1,18 @@
|
||||
// Check that multiplication by factors of 2 on the left side is converted to shifts
|
||||
|
||||
void main() {
|
||||
byte* const SCREEN = (char*)$400;
|
||||
|
||||
for(byte i: 0..10) {
|
||||
(SCREEN+0*40)[i] = 1*i;
|
||||
(SCREEN+1*40)[i] = 2*i;
|
||||
(SCREEN+2*40)[i] = 4*i;
|
||||
(SCREEN+3*40)[i] = 8*i;
|
||||
// And a single signed byte
|
||||
signed byte sb = -(signed byte)i;
|
||||
(SCREEN+5*40)[i] = (byte)(2*sb);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
52
src/test/ref/multiply-2s-left.asm
Normal file
52
src/test/ref/multiply-2s-left.asm
Normal file
@ -0,0 +1,52 @@
|
||||
// Check that multiplication by factors of 2 on the left side is converted to shifts
|
||||
// Commodore 64 PRG executable file
|
||||
.file [name="multiply-2s-left.prg", type="prg", segments="Program"]
|
||||
.segmentdef Program [segments="Basic, Code, Data"]
|
||||
.segmentdef Basic [start=$0801]
|
||||
.segmentdef Code [start=$80d]
|
||||
.segmentdef Data [startAfter="Code"]
|
||||
.segment Basic
|
||||
:BasicUpstart(main)
|
||||
.segment Code
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
ldx #0
|
||||
__b1:
|
||||
// (SCREEN+0*40)[i] = 1*i
|
||||
txa
|
||||
sta SCREEN,x
|
||||
// 2*i
|
||||
txa
|
||||
asl
|
||||
// (SCREEN+1*40)[i] = 2*i
|
||||
sta SCREEN+1*$28,x
|
||||
// 4*i
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
// (SCREEN+2*40)[i] = 4*i
|
||||
sta SCREEN+2*$28,x
|
||||
// 8*i
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
asl
|
||||
// (SCREEN+3*40)[i] = 8*i
|
||||
sta SCREEN+3*$28,x
|
||||
// signed byte sb = -(signed byte)i
|
||||
// And a single signed byte
|
||||
txa
|
||||
eor #$ff
|
||||
clc
|
||||
adc #1
|
||||
// 2*sb
|
||||
asl
|
||||
// (SCREEN+5*40)[i] = (byte)(2*sb)
|
||||
sta SCREEN+5*$28,x
|
||||
// for(byte i: 0..10)
|
||||
inx
|
||||
cpx #$b
|
||||
bne __b1
|
||||
// }
|
||||
rts
|
||||
}
|
23
src/test/ref/multiply-2s-left.cfg
Normal file
23
src/test/ref/multiply-2s-left.cfg
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
void main()
|
||||
main: scope:[main] from
|
||||
[0] phi()
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
[1] main::i#2 = phi( main/0, main::@1/main::i#1 )
|
||||
[2] main::SCREEN[main::i#2] = main::i#2
|
||||
[3] main::$1 = main::i#2 << 1
|
||||
[4] (main::SCREEN+1*$28)[main::i#2] = main::$1
|
||||
[5] main::$2 = main::i#2 << 2
|
||||
[6] (main::SCREEN+2*$28)[main::i#2] = main::$2
|
||||
[7] main::$3 = main::i#2 << 3
|
||||
[8] (main::SCREEN+3*$28)[main::i#2] = main::$3
|
||||
[9] main::sb#0 = - (signed char)main::i#2
|
||||
[10] main::$5 = main::sb#0 << 1
|
||||
[11] (main::SCREEN+5*$28)[main::i#2] = (char)main::$5
|
||||
[12] main::i#1 = ++ main::i#2
|
||||
[13] if(main::i#1!=$b) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[14] return
|
||||
to:@return
|
422
src/test/ref/multiply-2s-left.log
Normal file
422
src/test/ref/multiply-2s-left.log
Normal file
@ -0,0 +1,422 @@
|
||||
Eliminating unused variable with no statement main::$4
|
||||
|
||||
CONTROL FLOW GRAPH SSA
|
||||
|
||||
void main()
|
||||
main: scope:[main] from __start
|
||||
main::i#0 = 0
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
main::i#2 = phi( main/main::i#0, main::@1/main::i#1 )
|
||||
main::$0 = 1 * main::i#2
|
||||
(main::SCREEN+0*$28)[main::i#2] = main::$0
|
||||
main::$1 = 2 * main::i#2
|
||||
(main::SCREEN+1*$28)[main::i#2] = main::$1
|
||||
main::$2 = 4 * main::i#2
|
||||
(main::SCREEN+2*$28)[main::i#2] = main::$2
|
||||
main::$3 = 8 * main::i#2
|
||||
(main::SCREEN+3*$28)[main::i#2] = main::$3
|
||||
main::sb#0 = - (signed char)main::i#2
|
||||
main::$5 = 2 * main::sb#0
|
||||
(main::SCREEN+5*$28)[main::i#2] = (char)main::$5
|
||||
main::i#1 = main::i#2 + rangenext(0,$a)
|
||||
main::$6 = main::i#1 != rangelast(0,$a)
|
||||
if(main::$6) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
return
|
||||
to:@return
|
||||
|
||||
void __start()
|
||||
__start: scope:[__start] from
|
||||
call main
|
||||
to:__start::@1
|
||||
__start::@1: scope:[__start] from __start
|
||||
to:__start::@return
|
||||
__start::@return: scope:[__start] from __start::@1
|
||||
return
|
||||
to:@return
|
||||
|
||||
SYMBOL TABLE SSA
|
||||
void __start()
|
||||
void main()
|
||||
number main::$0
|
||||
number main::$1
|
||||
number main::$2
|
||||
number main::$3
|
||||
number main::$5
|
||||
bool main::$6
|
||||
__constant char * const main::SCREEN = (char *)$400
|
||||
char main::i
|
||||
char main::i#0
|
||||
char main::i#1
|
||||
char main::i#2
|
||||
signed char main::sb
|
||||
signed char main::sb#0
|
||||
|
||||
Adding number conversion cast (unumber) 1 in main::$0 = 1 * main::i#2
|
||||
Adding number conversion cast (unumber) main::$0 in main::$0 = (unumber)1 * main::i#2
|
||||
Adding number conversion cast (unumber) 0*$28 in (main::SCREEN+0*$28)[main::i#2] = main::$0
|
||||
Adding number conversion cast (unumber) 2 in main::$1 = 2 * main::i#2
|
||||
Adding number conversion cast (unumber) main::$1 in main::$1 = (unumber)2 * main::i#2
|
||||
Adding number conversion cast (unumber) 1*$28 in (main::SCREEN+1*$28)[main::i#2] = main::$1
|
||||
Adding number conversion cast (unumber) 4 in main::$2 = 4 * main::i#2
|
||||
Adding number conversion cast (unumber) main::$2 in main::$2 = (unumber)4 * main::i#2
|
||||
Adding number conversion cast (unumber) 2*$28 in (main::SCREEN+2*$28)[main::i#2] = main::$2
|
||||
Adding number conversion cast (unumber) 8 in main::$3 = 8 * main::i#2
|
||||
Adding number conversion cast (unumber) main::$3 in main::$3 = (unumber)8 * main::i#2
|
||||
Adding number conversion cast (unumber) 3*$28 in (main::SCREEN+3*$28)[main::i#2] = main::$3
|
||||
Adding number conversion cast (snumber) 2 in main::$5 = 2 * main::sb#0
|
||||
Adding number conversion cast (snumber) main::$5 in main::$5 = (snumber)2 * main::sb#0
|
||||
Adding number conversion cast (unumber) 5*$28 in (main::SCREEN+5*$28)[main::i#2] = (char)main::$5
|
||||
Successful SSA optimization PassNAddNumberTypeConversions
|
||||
Simplifying constant pointer cast (char *) 1024
|
||||
Simplifying constant integer cast 1
|
||||
Simplifying constant integer cast 2
|
||||
Simplifying constant integer cast 4
|
||||
Simplifying constant integer cast 8
|
||||
Simplifying constant integer cast 2
|
||||
Successful SSA optimization PassNCastSimplification
|
||||
Finalized unsigned number type (char) 1
|
||||
Finalized unsigned number type (char) 2
|
||||
Finalized unsigned number type (char) 4
|
||||
Finalized unsigned number type (char) 8
|
||||
Finalized signed number type (signed char) 2
|
||||
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
Inferred type updated to char in main::$0 = 1 * main::i#2
|
||||
Inferred type updated to char in main::$1 = 2 * main::i#2
|
||||
Inferred type updated to char in main::$2 = 4 * main::i#2
|
||||
Inferred type updated to char in main::$3 = 8 * main::i#2
|
||||
Inferred type updated to signed char in main::$5 = 2 * main::sb#0
|
||||
Simple Condition main::$6 [15] if(main::i#1!=rangelast(0,$a)) goto main::@1
|
||||
Successful SSA optimization Pass2ConditionalJumpSimplification
|
||||
Constant main::i#0 = 0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Resolved ranged next value [13] main::i#1 = ++ main::i#2 to ++
|
||||
Resolved ranged comparison value [15] if(main::i#1!=rangelast(0,$a)) goto main::@1 to $b
|
||||
Simplifying constant evaluating to zero (char)0*$28 in [3] (main::SCREEN+(char)0*$28)[main::i#2] = main::$0
|
||||
Successful SSA optimization PassNSimplifyConstantZero
|
||||
Simplifying expression containing zero main::SCREEN in [3] (main::SCREEN+0)[main::i#2] = main::$0
|
||||
Successful SSA optimization PassNSimplifyExpressionWithZero
|
||||
Removing unused procedure __start
|
||||
Removing unused procedure block __start
|
||||
Removing unused procedure block __start::@1
|
||||
Removing unused procedure block __start::@return
|
||||
Successful SSA optimization PassNEliminateEmptyStart
|
||||
Adding number conversion cast (unumber) $b in [13] if(main::i#1!=$b) goto main::@1
|
||||
Successful SSA optimization PassNAddNumberTypeConversions
|
||||
Simplifying constant integer cast $b
|
||||
Successful SSA optimization PassNCastSimplification
|
||||
Finalized unsigned number type (char) $b
|
||||
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
Rewriting multiplication to remove identity multiply [1] main::$0 = 1 * main::i#2
|
||||
Rewriting multiplication to use shift [3] main::$1 = 2 * main::i#2
|
||||
Rewriting multiplication to use shift [5] main::$2 = 4 * main::i#2
|
||||
Rewriting multiplication to use shift [7] main::$3 = 8 * main::i#2
|
||||
Rewriting multiplication to use shift [10] main::$5 = 2 * main::sb#0
|
||||
Successful SSA optimization Pass2MultiplyToShiftRewriting
|
||||
Inlining constant with var siblings main::i#0
|
||||
Constant inlined main::i#0 = 0
|
||||
Successful SSA optimization Pass2ConstantInlining
|
||||
Alias main::i#2 = main::$0
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Finalized unsigned number type (char) 1
|
||||
Finalized unsigned number type (char) $28
|
||||
Finalized unsigned number type (char) 2
|
||||
Finalized unsigned number type (char) $28
|
||||
Finalized unsigned number type (char) 3
|
||||
Finalized unsigned number type (char) $28
|
||||
Finalized unsigned number type (char) 5
|
||||
Finalized unsigned number type (char) $28
|
||||
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
Simplifying constant integer cast 1*$28
|
||||
Simplifying constant integer cast 2*$28
|
||||
Simplifying constant integer cast 3*$28
|
||||
Simplifying constant integer cast 5*$28
|
||||
Successful SSA optimization PassNCastSimplification
|
||||
Added new block during phi lifting main::@2(between main::@1 and main::@1)
|
||||
Adding NOP phi() at start of main
|
||||
CALL GRAPH
|
||||
|
||||
Created 1 initial phi equivalence classes
|
||||
Coalesced [15] main::i#3 = main::i#1
|
||||
Coalesced down to 1 phi equivalence classes
|
||||
Culled Empty Block label main::@2
|
||||
Adding NOP phi() at start of main
|
||||
|
||||
FINAL CONTROL FLOW GRAPH
|
||||
|
||||
void main()
|
||||
main: scope:[main] from
|
||||
[0] phi()
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
[1] main::i#2 = phi( main/0, main::@1/main::i#1 )
|
||||
[2] main::SCREEN[main::i#2] = main::i#2
|
||||
[3] main::$1 = main::i#2 << 1
|
||||
[4] (main::SCREEN+1*$28)[main::i#2] = main::$1
|
||||
[5] main::$2 = main::i#2 << 2
|
||||
[6] (main::SCREEN+2*$28)[main::i#2] = main::$2
|
||||
[7] main::$3 = main::i#2 << 3
|
||||
[8] (main::SCREEN+3*$28)[main::i#2] = main::$3
|
||||
[9] main::sb#0 = - (signed char)main::i#2
|
||||
[10] main::$5 = main::sb#0 << 1
|
||||
[11] (main::SCREEN+5*$28)[main::i#2] = (char)main::$5
|
||||
[12] main::i#1 = ++ main::i#2
|
||||
[13] if(main::i#1!=$b) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[14] return
|
||||
to:@return
|
||||
|
||||
|
||||
VARIABLE REGISTER WEIGHTS
|
||||
void main()
|
||||
char main::$1 // 22.0
|
||||
char main::$2 // 22.0
|
||||
char main::$3 // 22.0
|
||||
signed char main::$5 // 11.0
|
||||
char main::i
|
||||
char main::i#1 // 16.5
|
||||
char main::i#2 // 11.0
|
||||
signed char main::sb
|
||||
signed char main::sb#0 // 22.0
|
||||
|
||||
Initial phi equivalence classes
|
||||
[ main::i#2 main::i#1 ]
|
||||
Added variable main::$1 to live range equivalence class [ main::$1 ]
|
||||
Added variable main::$2 to live range equivalence class [ main::$2 ]
|
||||
Added variable main::$3 to live range equivalence class [ main::$3 ]
|
||||
Added variable main::sb#0 to live range equivalence class [ main::sb#0 ]
|
||||
Added variable main::$5 to live range equivalence class [ main::$5 ]
|
||||
Complete equivalence classes
|
||||
[ main::i#2 main::i#1 ]
|
||||
[ main::$1 ]
|
||||
[ main::$2 ]
|
||||
[ main::$3 ]
|
||||
[ main::sb#0 ]
|
||||
[ main::$5 ]
|
||||
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
|
||||
Allocated zp[1]:3 [ main::$1 ]
|
||||
Allocated zp[1]:4 [ main::$2 ]
|
||||
Allocated zp[1]:5 [ main::$3 ]
|
||||
Allocated zp[1]:6 [ main::sb#0 ]
|
||||
Allocated zp[1]:7 [ main::$5 ]
|
||||
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||
Statement [3] main::$1 = main::i#2 << 1 [ main::i#2 main::$1 ] ( [ main::i#2 main::$1 ] { } ) always clobbers reg byte a
|
||||
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
|
||||
Statement [5] main::$2 = main::i#2 << 2 [ main::i#2 main::$2 ] ( [ main::i#2 main::$2 ] { } ) always clobbers reg byte a
|
||||
Statement [7] main::$3 = main::i#2 << 3 [ main::i#2 main::$3 ] ( [ main::i#2 main::$3 ] { } ) always clobbers reg byte a
|
||||
Statement [9] main::sb#0 = - (signed char)main::i#2 [ main::i#2 main::sb#0 ] ( [ main::i#2 main::sb#0 ] { } ) always clobbers reg byte a
|
||||
Statement [10] main::$5 = main::sb#0 << 1 [ main::i#2 main::$5 ] ( [ main::i#2 main::$5 ] { } ) always clobbers reg byte a
|
||||
Statement [2] main::SCREEN[main::i#2] = main::i#2 [ main::i#2 ] ( [ main::i#2 ] { } ) always clobbers reg byte a
|
||||
Statement [3] main::$1 = main::i#2 << 1 [ main::i#2 main::$1 ] ( [ main::i#2 main::$1 ] { } ) always clobbers reg byte a
|
||||
Statement [5] main::$2 = main::i#2 << 2 [ main::i#2 main::$2 ] ( [ main::i#2 main::$2 ] { } ) always clobbers reg byte a
|
||||
Statement [7] main::$3 = main::i#2 << 3 [ main::i#2 main::$3 ] ( [ main::i#2 main::$3 ] { } ) always clobbers reg byte a
|
||||
Statement [9] main::sb#0 = - (signed char)main::i#2 [ main::i#2 main::sb#0 ] ( [ main::i#2 main::sb#0 ] { } ) always clobbers reg byte a
|
||||
Statement [10] main::$5 = main::sb#0 << 1 [ main::i#2 main::$5 ] ( [ main::i#2 main::$5 ] { } ) always clobbers reg byte a
|
||||
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , reg byte y ,
|
||||
Potential registers zp[1]:3 [ main::$1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp[1]:4 [ main::$2 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp[1]:5 [ main::$3 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp[1]:6 [ main::sb#0 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp[1]:7 [ main::$5 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y ,
|
||||
|
||||
REGISTER UPLIFT SCOPES
|
||||
Uplift Scope [main] 27.5: zp[1]:2 [ main::i#2 main::i#1 ] 22: zp[1]:3 [ main::$1 ] 22: zp[1]:4 [ main::$2 ] 22: zp[1]:5 [ main::$3 ] 22: zp[1]:6 [ main::sb#0 ] 11: zp[1]:7 [ main::$5 ]
|
||||
Uplift Scope []
|
||||
|
||||
Uplifting [main] best 851 combination reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$1 ] reg byte a [ main::$2 ] reg byte a [ main::$3 ] zp[1]:6 [ main::sb#0 ] zp[1]:7 [ main::$5 ]
|
||||
Limited combination testing to 100 combinations of 3072 possible.
|
||||
Uplifting [] best 851 combination
|
||||
Attempting to uplift remaining variables inzp[1]:6 [ main::sb#0 ]
|
||||
Uplifting [main] best 791 combination reg byte a [ main::sb#0 ]
|
||||
Attempting to uplift remaining variables inzp[1]:7 [ main::$5 ]
|
||||
Uplifting [main] best 731 combination reg byte a [ main::$5 ]
|
||||
|
||||
ASSEMBLER BEFORE OPTIMIZATION
|
||||
// File Comments
|
||||
// Check that multiplication by factors of 2 on the left side is converted to shifts
|
||||
// Upstart
|
||||
// Commodore 64 PRG executable file
|
||||
.file [name="multiply-2s-left.prg", type="prg", segments="Program"]
|
||||
.segmentdef Program [segments="Basic, Code, Data"]
|
||||
.segmentdef Basic [start=$0801]
|
||||
.segmentdef Code [start=$80d]
|
||||
.segmentdef Data [startAfter="Code"]
|
||||
.segment Basic
|
||||
:BasicUpstart(main)
|
||||
// Global Constants & labels
|
||||
.segment Code
|
||||
// main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
// [1] phi from main to main::@1 [phi:main->main::@1]
|
||||
__b1_from_main:
|
||||
// [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
jmp __b1
|
||||
// [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
|
||||
__b1_from___b1:
|
||||
// [1] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy
|
||||
jmp __b1
|
||||
// main::@1
|
||||
__b1:
|
||||
// [2] main::SCREEN[main::i#2] = main::i#2 -- pbuc1_derefidx_vbuxx=vbuxx
|
||||
txa
|
||||
sta SCREEN,x
|
||||
// [3] main::$1 = main::i#2 << 1 -- vbuaa=vbuxx_rol_1
|
||||
txa
|
||||
asl
|
||||
// [4] (main::SCREEN+1*$28)[main::i#2] = main::$1 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+1*$28,x
|
||||
// [5] main::$2 = main::i#2 << 2 -- vbuaa=vbuxx_rol_2
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
// [6] (main::SCREEN+2*$28)[main::i#2] = main::$2 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+2*$28,x
|
||||
// [7] main::$3 = main::i#2 << 3 -- vbuaa=vbuxx_rol_3
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
asl
|
||||
// [8] (main::SCREEN+3*$28)[main::i#2] = main::$3 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+3*$28,x
|
||||
// [9] main::sb#0 = - (signed char)main::i#2 -- vbsaa=_neg_vbsxx
|
||||
// And a single signed byte
|
||||
txa
|
||||
eor #$ff
|
||||
clc
|
||||
adc #1
|
||||
// [10] main::$5 = main::sb#0 << 1 -- vbsaa=vbsaa_rol_1
|
||||
asl
|
||||
// [11] (main::SCREEN+5*$28)[main::i#2] = (char)main::$5 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+5*$28,x
|
||||
// [12] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
// [13] if(main::i#1!=$b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #$b
|
||||
bne __b1_from___b1
|
||||
jmp __breturn
|
||||
// main::@return
|
||||
__breturn:
|
||||
// [14] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
|
||||
ASSEMBLER OPTIMIZATIONS
|
||||
Removing instruction jmp __b1
|
||||
Removing instruction jmp __breturn
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Replacing label __b1_from___b1 with __b1
|
||||
Removing instruction __b1_from___b1:
|
||||
Succesful ASM optimization Pass5RedundantLabelElimination
|
||||
Removing instruction __b1_from_main:
|
||||
Removing instruction __breturn:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
Removing instruction jmp __b1
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
|
||||
FINAL SYMBOL TABLE
|
||||
void main()
|
||||
char main::$1 // reg byte a 22.0
|
||||
char main::$2 // reg byte a 22.0
|
||||
char main::$3 // reg byte a 22.0
|
||||
signed char main::$5 // reg byte a 11.0
|
||||
__constant char * const main::SCREEN = (char *) 1024
|
||||
char main::i
|
||||
char main::i#1 // reg byte x 16.5
|
||||
char main::i#2 // reg byte x 11.0
|
||||
signed char main::sb
|
||||
signed char main::sb#0 // reg byte a 22.0
|
||||
|
||||
reg byte x [ main::i#2 main::i#1 ]
|
||||
reg byte a [ main::$1 ]
|
||||
reg byte a [ main::$2 ]
|
||||
reg byte a [ main::$3 ]
|
||||
reg byte a [ main::sb#0 ]
|
||||
reg byte a [ main::$5 ]
|
||||
|
||||
|
||||
FINAL ASSEMBLER
|
||||
Score: 641
|
||||
|
||||
// File Comments
|
||||
// Check that multiplication by factors of 2 on the left side is converted to shifts
|
||||
// Upstart
|
||||
// Commodore 64 PRG executable file
|
||||
.file [name="multiply-2s-left.prg", type="prg", segments="Program"]
|
||||
.segmentdef Program [segments="Basic, Code, Data"]
|
||||
.segmentdef Basic [start=$0801]
|
||||
.segmentdef Code [start=$80d]
|
||||
.segmentdef Data [startAfter="Code"]
|
||||
.segment Basic
|
||||
:BasicUpstart(main)
|
||||
// Global Constants & labels
|
||||
.segment Code
|
||||
// main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
// [1] phi from main to main::@1 [phi:main->main::@1]
|
||||
// [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
// [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
|
||||
// [1] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy
|
||||
// main::@1
|
||||
__b1:
|
||||
// (SCREEN+0*40)[i] = 1*i
|
||||
// [2] main::SCREEN[main::i#2] = main::i#2 -- pbuc1_derefidx_vbuxx=vbuxx
|
||||
txa
|
||||
sta SCREEN,x
|
||||
// 2*i
|
||||
// [3] main::$1 = main::i#2 << 1 -- vbuaa=vbuxx_rol_1
|
||||
txa
|
||||
asl
|
||||
// (SCREEN+1*40)[i] = 2*i
|
||||
// [4] (main::SCREEN+1*$28)[main::i#2] = main::$1 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+1*$28,x
|
||||
// 4*i
|
||||
// [5] main::$2 = main::i#2 << 2 -- vbuaa=vbuxx_rol_2
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
// (SCREEN+2*40)[i] = 4*i
|
||||
// [6] (main::SCREEN+2*$28)[main::i#2] = main::$2 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+2*$28,x
|
||||
// 8*i
|
||||
// [7] main::$3 = main::i#2 << 3 -- vbuaa=vbuxx_rol_3
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
asl
|
||||
// (SCREEN+3*40)[i] = 8*i
|
||||
// [8] (main::SCREEN+3*$28)[main::i#2] = main::$3 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+3*$28,x
|
||||
// signed byte sb = -(signed byte)i
|
||||
// [9] main::sb#0 = - (signed char)main::i#2 -- vbsaa=_neg_vbsxx
|
||||
// And a single signed byte
|
||||
txa
|
||||
eor #$ff
|
||||
clc
|
||||
adc #1
|
||||
// 2*sb
|
||||
// [10] main::$5 = main::sb#0 << 1 -- vbsaa=vbsaa_rol_1
|
||||
asl
|
||||
// (SCREEN+5*40)[i] = (byte)(2*sb)
|
||||
// [11] (main::SCREEN+5*$28)[main::i#2] = (char)main::$5 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+5*$28,x
|
||||
// for(byte i: 0..10)
|
||||
// [12] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
// [13] if(main::i#1!=$b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #$b
|
||||
bne __b1
|
||||
// main::@return
|
||||
// }
|
||||
// [14] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
|
18
src/test/ref/multiply-2s-left.sym
Normal file
18
src/test/ref/multiply-2s-left.sym
Normal file
@ -0,0 +1,18 @@
|
||||
void main()
|
||||
char main::$1 // reg byte a 22.0
|
||||
char main::$2 // reg byte a 22.0
|
||||
char main::$3 // reg byte a 22.0
|
||||
signed char main::$5 // reg byte a 11.0
|
||||
__constant char * const main::SCREEN = (char *) 1024
|
||||
char main::i
|
||||
char main::i#1 // reg byte x 16.5
|
||||
char main::i#2 // reg byte x 11.0
|
||||
signed char main::sb
|
||||
signed char main::sb#0 // reg byte a 22.0
|
||||
|
||||
reg byte x [ main::i#2 main::i#1 ]
|
||||
reg byte a [ main::$1 ]
|
||||
reg byte a [ main::$2 ]
|
||||
reg byte a [ main::$3 ]
|
||||
reg byte a [ main::sb#0 ]
|
||||
reg byte a [ main::$5 ]
|
Loading…
Reference in New Issue
Block a user