mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-02 05:30:53 +00:00
Implemented rewriting of multiply/divide by powers of 2 to shifts. Closes #165
This commit is contained in:
parent
c61b1556cd
commit
5f1496e33d
1
src/main/fragment/vbsaa=vbsaa_rol_1.asm
Normal file
1
src/main/fragment/vbsaa=vbsaa_rol_1.asm
Normal file
@ -0,0 +1 @@
|
||||
asl
|
2
src/main/fragment/vbsaa=vbsaa_rol_2.asm
Normal file
2
src/main/fragment/vbsaa=vbsaa_rol_2.asm
Normal file
@ -0,0 +1,2 @@
|
||||
asl
|
||||
asl
|
3
src/main/fragment/vbsaa=vbsaa_rol_3.asm
Normal file
3
src/main/fragment/vbsaa=vbsaa_rol_3.asm
Normal file
@ -0,0 +1,3 @@
|
||||
asl
|
||||
asl
|
||||
asl
|
4
src/main/fragment/vbsaa=vbsaa_rol_4.asm
Normal file
4
src/main/fragment/vbsaa=vbsaa_rol_4.asm
Normal file
@ -0,0 +1,4 @@
|
||||
asl
|
||||
asl
|
||||
asl
|
||||
asl
|
@ -251,6 +251,7 @@ public class Compiler {
|
||||
optimizations.add(new Pass2RangeResolving(program));
|
||||
optimizations.add(new Pass2ComparisonOptimization(program));
|
||||
optimizations.add(new Pass2ConstantCallPointerIdentification(program));
|
||||
optimizations.add(new Pass2Multiply2sRewriting(program));
|
||||
pass2Execute(optimizations);
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import dk.camelot64.kickc.model.values.*;
|
||||
|
||||
import java.util.ListIterator;
|
||||
|
||||
/** Pass that identified indirect calls to constant function pointers */
|
||||
/** Pass that identifies indirect calls to constant function pointers */
|
||||
public class Pass2ConstantCallPointerIdentification extends Pass2SsaOptimization {
|
||||
|
||||
public Pass2ConstantCallPointerIdentification(Program program) {
|
||||
|
@ -0,0 +1,82 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.ConstantNotLiteral;
|
||||
import dk.camelot64.kickc.model.ControlFlowBlock;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.operators.Operators;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
||||
import dk.camelot64.kickc.model.statements.StatementCall;
|
||||
import dk.camelot64.kickc.model.statements.StatementCallPointer;
|
||||
import dk.camelot64.kickc.model.symbols.ConstantVar;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeProcedure;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
import kickass.pass.expressions.expr.Constant;
|
||||
|
||||
import java.util.ListIterator;
|
||||
|
||||
/** Pass that replaces multiplications with factors of 2 with shifts */
|
||||
public class Pass2Multiply2sRewriting extends Pass2SsaOptimization {
|
||||
|
||||
public Pass2Multiply2sRewriting(Program program) {
|
||||
super(program);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean step() {
|
||||
boolean optimized = false;
|
||||
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
|
||||
ListIterator<Statement> statementsIt = block.getStatements().listIterator();
|
||||
while(statementsIt.hasNext()) {
|
||||
Statement statement = statementsIt.next();
|
||||
if(statement instanceof StatementAssignment) {
|
||||
StatementAssignment assignment = (StatementAssignment) statement;
|
||||
if(Operators.MULTIPLY.equals(assignment.getOperator()) || Operators.DIVIDE.equals(assignment.getOperator())) {
|
||||
ConstantLiteral constantLiteral = getConstantLiteral(assignment);
|
||||
if(constantLiteral instanceof ConstantInteger) {
|
||||
Long constantInt = ((ConstantInteger)constantLiteral).getInteger();
|
||||
double power2 = Math.log(constantInt) / Math.log(2);
|
||||
if(Math.round(power2)==power2) {
|
||||
// Found a whole power of 2
|
||||
if(Operators.MULTIPLY.equals(assignment.getOperator())) {
|
||||
getLog().append("Rewriting multiplication to use shift "+statement.toString(getProgram(), false));
|
||||
assignment.setOperator(Operators.SHIFT_LEFT);
|
||||
assignment.setrValue2(new ConstantInteger((long)power2));
|
||||
optimized = true;
|
||||
} else if(Operators.DIVIDE.equals(assignment.getOperator())) {
|
||||
getLog().append("Rewriting division to use shift "+statement.toString(getProgram(), false));
|
||||
assignment.setOperator(Operators.SHIFT_RIGHT);
|
||||
assignment.setrValue2(new ConstantInteger((long)power2));
|
||||
optimized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return optimized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the constant literal value for RValue2 - or null if not possible
|
||||
* @param assignment The Assignment
|
||||
* @return The constant literal value for RValue2 (or null)
|
||||
*/
|
||||
private ConstantLiteral getConstantLiteral(StatementAssignment assignment) {
|
||||
if(assignment.getrValue2() instanceof ConstantValue) {
|
||||
ConstantValue constantValue = (ConstantValue) assignment.getrValue2();
|
||||
try {
|
||||
return constantValue.calculateLiteral(getScope());
|
||||
} catch(ConstantNotLiteral e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -37,6 +37,16 @@ public class TestPrograms {
|
||||
// compileAndCompare("pointer-cast-3");
|
||||
//}
|
||||
|
||||
@Test
|
||||
public void testDivide2s() throws IOException, URISyntaxException {
|
||||
compileAndCompare("divide-2s");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiply2s() throws IOException, URISyntaxException {
|
||||
compileAndCompare("multiply-2s");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPointerCast2() throws IOException, URISyntaxException {
|
||||
compileAndCompare("pointer-cast-2");
|
||||
|
16
src/test/kc/divide-2s.kc
Normal file
16
src/test/kc/divide-2s.kc
Normal file
@ -0,0 +1,16 @@
|
||||
// Check that division by factors of 2 is converted to shifts
|
||||
|
||||
void main() {
|
||||
const byte* SCREEN = $400;
|
||||
|
||||
for(byte i: 0..10) {
|
||||
SCREEN[i] = i/2;
|
||||
(SCREEN+40)[i] = i/4;
|
||||
(SCREEN+80)[i] = i/8;
|
||||
// And a single signed byte
|
||||
signed byte sb = -(signed byte)i;
|
||||
(SCREEN+160)[i] = (byte)(sb/2);
|
||||
}
|
||||
|
||||
}
|
||||
|
17
src/test/kc/multiply-2s.kc
Normal file
17
src/test/kc/multiply-2s.kc
Normal file
@ -0,0 +1,17 @@
|
||||
// Check that multiplication by factors of 2 is converted to shifts
|
||||
|
||||
void main() {
|
||||
const byte* SCREEN = $400;
|
||||
|
||||
for(byte i: 0..10) {
|
||||
SCREEN[i] = i*2;
|
||||
(SCREEN+40)[i] = i*4;
|
||||
(SCREEN+80)[i] = i*8;
|
||||
// And a single signed byte
|
||||
signed byte sb = -(signed byte)i;
|
||||
(SCREEN+160)[i] = (byte)(sb*2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
32
src/test/ref/divide-2s.asm
Normal file
32
src/test/ref/divide-2s.asm
Normal file
@ -0,0 +1,32 @@
|
||||
// Check that division by factors of 2 is converted to shifts
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
ldx #0
|
||||
b1:
|
||||
txa
|
||||
lsr
|
||||
sta SCREEN,x
|
||||
txa
|
||||
lsr
|
||||
lsr
|
||||
sta SCREEN+$28,x
|
||||
txa
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
sta SCREEN+$50,x
|
||||
txa
|
||||
eor #$ff
|
||||
clc
|
||||
adc #1
|
||||
cmp #$80
|
||||
ror
|
||||
sta SCREEN+$a0,x
|
||||
inx
|
||||
cpx #$b
|
||||
bne b1
|
||||
rts
|
||||
}
|
29
src/test/ref/divide-2s.cfg
Normal file
29
src/test/ref/divide-2s.cfg
Normal file
@ -0,0 +1,29 @@
|
||||
@begin: scope:[] from
|
||||
[0] phi()
|
||||
to:@1
|
||||
@1: scope:[] from @begin
|
||||
[1] phi()
|
||||
[2] call main
|
||||
to:@end
|
||||
@end: scope:[] from @1
|
||||
[3] phi()
|
||||
main: scope:[main] from @1
|
||||
[4] phi()
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
[5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@1/(byte) main::i#1 )
|
||||
[6] (byte~) main::$0 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
[7] *((const byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0
|
||||
[8] (byte~) main::$2 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
[9] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28 + (byte) main::i#2) ← (byte~) main::$2
|
||||
[10] (byte~) main::$4 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 3
|
||||
[11] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50 + (byte) main::i#2) ← (byte~) main::$4
|
||||
[12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2
|
||||
[13] (signed byte~) main::$8 ← (signed byte) main::sb#0 >> (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
[14] *((const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0 + (byte) main::i#2) ← (byte)(signed byte~) main::$8
|
||||
[15] (byte) main::i#1 ← ++ (byte) main::i#2
|
||||
[16] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) $b) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[17] return
|
||||
to:@return
|
509
src/test/ref/divide-2s.log
Normal file
509
src/test/ref/divide-2s.log
Normal file
@ -0,0 +1,509 @@
|
||||
|
||||
CONTROL FLOW GRAPH SSA
|
||||
@begin: scope:[] from
|
||||
to:@1
|
||||
main: scope:[main] from @1
|
||||
(byte*) main::SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) $400
|
||||
(byte) main::i#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
(byte) main::i#2 ← phi( main/(byte) main::i#0 main::@1/(byte) main::i#1 )
|
||||
(byte/signed word/word/dword/signed dword~) main::$0 ← (byte) main::i#2 / (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
*((byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte/signed word/word/dword/signed dword~) main::$0
|
||||
(byte*~) main::$1 ← (byte*) main::SCREEN#0 + (byte/signed byte/word/signed word/dword/signed dword) $28
|
||||
(byte/signed word/word/dword/signed dword~) main::$2 ← (byte) main::i#2 / (byte/signed byte/word/signed word/dword/signed dword) 4
|
||||
*((byte*~) main::$1 + (byte) main::i#2) ← (byte/signed word/word/dword/signed dword~) main::$2
|
||||
(byte*~) main::$3 ← (byte*) main::SCREEN#0 + (byte/signed byte/word/signed word/dword/signed dword) $50
|
||||
(byte/signed word/word/dword/signed dword~) main::$4 ← (byte) main::i#2 / (byte/signed byte/word/signed word/dword/signed dword) 8
|
||||
*((byte*~) main::$3 + (byte) main::i#2) ← (byte/signed word/word/dword/signed dword~) main::$4
|
||||
(signed byte~) main::$5 ← ((signed byte)) (byte) main::i#2
|
||||
(signed byte~) main::$6 ← - (signed byte~) main::$5
|
||||
(signed byte) main::sb#0 ← (signed byte~) main::$6
|
||||
(byte*~) main::$7 ← (byte*) main::SCREEN#0 + (byte/word/signed word/dword/signed dword) $a0
|
||||
(signed word/signed byte/signed dword~) main::$8 ← (signed byte) main::sb#0 / (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
(byte~) main::$9 ← ((byte)) (signed word/signed byte/signed dword~) main::$8
|
||||
*((byte*~) main::$7 + (byte) main::i#2) ← (byte~) main::$9
|
||||
(byte) main::i#1 ← (byte) main::i#2 + rangenext(0,$a)
|
||||
(bool~) main::$10 ← (byte) main::i#1 != rangelast(0,$a)
|
||||
if((bool~) main::$10) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
return
|
||||
to:@return
|
||||
@1: scope:[] from @begin
|
||||
call main
|
||||
to:@2
|
||||
@2: scope:[] from @1
|
||||
to:@end
|
||||
@end: scope:[] from @2
|
||||
|
||||
SYMBOL TABLE SSA
|
||||
(label) @1
|
||||
(label) @2
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(void()) main()
|
||||
(byte/signed word/word/dword/signed dword~) main::$0
|
||||
(byte*~) main::$1
|
||||
(bool~) main::$10
|
||||
(byte/signed word/word/dword/signed dword~) main::$2
|
||||
(byte*~) main::$3
|
||||
(byte/signed word/word/dword/signed dword~) main::$4
|
||||
(signed byte~) main::$5
|
||||
(signed byte~) main::$6
|
||||
(byte*~) main::$7
|
||||
(signed word/signed byte/signed dword~) main::$8
|
||||
(byte~) main::$9
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(byte*) main::SCREEN#0
|
||||
(byte) main::i
|
||||
(byte) main::i#0
|
||||
(byte) main::i#1
|
||||
(byte) main::i#2
|
||||
(signed byte) main::sb
|
||||
(signed byte) main::sb#0
|
||||
|
||||
Culled Empty Block (label) @2
|
||||
Successful SSA optimization Pass2CullEmptyBlocks
|
||||
Alias (signed byte) main::sb#0 = (signed byte~) main::$6
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Simple Condition (bool~) main::$10 [20] if((byte) main::i#1!=rangelast(0,$a)) goto main::@1
|
||||
Successful SSA optimization Pass2ConditionalJumpSimplification
|
||||
Constant (const byte*) main::SCREEN#0 = ((byte*))$400
|
||||
Constant (const byte) main::i#0 = 0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Constant (const byte*) main::$1 = main::SCREEN#0+$28
|
||||
Constant (const byte*) main::$3 = main::SCREEN#0+$50
|
||||
Constant (const byte*) main::$7 = main::SCREEN#0+$a0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Eliminating Noop Cast (signed byte~) main::$5 ← ((signed byte)) (byte) main::i#2
|
||||
Eliminating Noop Cast (byte~) main::$9 ← ((byte)) (signed word/signed byte/signed dword~) main::$8
|
||||
Successful SSA optimization Pass2NopCastElimination
|
||||
Resolved ranged next value main::i#1 ← ++ main::i#2 to ++
|
||||
Resolved ranged comparison value if(main::i#1!=rangelast(0,$a)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) $b
|
||||
Rewriting division to use shift (byte/signed word/word/dword/signed dword~) main::$0 ← (byte) main::i#2 / (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
Rewriting division to use shift (byte/signed word/word/dword/signed dword~) main::$2 ← (byte) main::i#2 / (byte/signed byte/word/signed word/dword/signed dword) 4
|
||||
Rewriting division to use shift (byte/signed word/word/dword/signed dword~) main::$4 ← (byte) main::i#2 / (byte/signed byte/word/signed word/dword/signed dword) 8
|
||||
Rewriting division to use shift (signed word/signed byte/signed dword~) main::$8 ← (signed byte) main::sb#0 / (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
Successful SSA optimization Pass2Multiply2sRewriting
|
||||
Inferred type updated to byte in [1] (byte/signed word/word/dword/signed dword~) main::$0 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
Inferred type updated to byte in [3] (byte/signed word/word/dword/signed dword~) main::$2 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
Inferred type updated to byte in [5] (byte/signed word/word/dword/signed dword~) main::$4 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 3
|
||||
Inferred type updated to signed byte in [8] (signed word/signed byte/signed dword~) main::$8 ← (signed byte) main::sb#0 >> (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
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
|
||||
Constant inlined main::$3 = (const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50
|
||||
Constant inlined main::$1 = (const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28
|
||||
Constant inlined main::$7 = (const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0
|
||||
Successful SSA optimization Pass2ConstantInlining
|
||||
Added new block during phi lifting main::@3(between main::@1 and main::@1)
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @1
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
CALL GRAPH
|
||||
Calls in [] to main:2
|
||||
|
||||
Created 1 initial phi equivalence classes
|
||||
Coalesced [18] main::i#3 ← main::i#1
|
||||
Coalesced down to 1 phi equivalence classes
|
||||
Culled Empty Block (label) main::@3
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @1
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
|
||||
FINAL CONTROL FLOW GRAPH
|
||||
@begin: scope:[] from
|
||||
[0] phi()
|
||||
to:@1
|
||||
@1: scope:[] from @begin
|
||||
[1] phi()
|
||||
[2] call main
|
||||
to:@end
|
||||
@end: scope:[] from @1
|
||||
[3] phi()
|
||||
main: scope:[main] from @1
|
||||
[4] phi()
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
[5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@1/(byte) main::i#1 )
|
||||
[6] (byte~) main::$0 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
[7] *((const byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0
|
||||
[8] (byte~) main::$2 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
[9] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28 + (byte) main::i#2) ← (byte~) main::$2
|
||||
[10] (byte~) main::$4 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 3
|
||||
[11] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50 + (byte) main::i#2) ← (byte~) main::$4
|
||||
[12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2
|
||||
[13] (signed byte~) main::$8 ← (signed byte) main::sb#0 >> (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
[14] *((const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0 + (byte) main::i#2) ← (byte)(signed byte~) main::$8
|
||||
[15] (byte) main::i#1 ← ++ (byte) main::i#2
|
||||
[16] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) $b) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[17] return
|
||||
to:@return
|
||||
|
||||
|
||||
VARIABLE REGISTER WEIGHTS
|
||||
(void()) main()
|
||||
(byte~) main::$0 22.0
|
||||
(byte~) main::$2 22.0
|
||||
(byte~) main::$4 22.0
|
||||
(signed byte~) main::$8 11.0
|
||||
(byte*) main::SCREEN
|
||||
(byte) main::i
|
||||
(byte) main::i#1 16.5
|
||||
(byte) main::i#2 9.899999999999999
|
||||
(signed byte) main::sb
|
||||
(signed byte) main::sb#0 22.0
|
||||
|
||||
Initial phi equivalence classes
|
||||
[ main::i#2 main::i#1 ]
|
||||
Added variable main::$0 to zero page equivalence class [ main::$0 ]
|
||||
Added variable main::$2 to zero page equivalence class [ main::$2 ]
|
||||
Added variable main::$4 to zero page equivalence class [ main::$4 ]
|
||||
Added variable main::sb#0 to zero page equivalence class [ main::sb#0 ]
|
||||
Added variable main::$8 to zero page equivalence class [ main::$8 ]
|
||||
Complete equivalence classes
|
||||
[ main::i#2 main::i#1 ]
|
||||
[ main::$0 ]
|
||||
[ main::$2 ]
|
||||
[ main::$4 ]
|
||||
[ main::sb#0 ]
|
||||
[ main::$8 ]
|
||||
Allocated zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
|
||||
Allocated zp ZP_BYTE:3 [ main::$0 ]
|
||||
Allocated zp ZP_BYTE:4 [ main::$2 ]
|
||||
Allocated zp ZP_BYTE:5 [ main::$4 ]
|
||||
Allocated zp ZP_BYTE:6 [ main::sb#0 ]
|
||||
Allocated zp ZP_BYTE:7 [ main::$8 ]
|
||||
|
||||
INITIAL ASM
|
||||
//SEG0 File Comments
|
||||
// Check that division by factors of 2 is converted to shifts
|
||||
//SEG1 Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(bbegin)
|
||||
.pc = $80d "Program"
|
||||
//SEG2 Global Constants & labels
|
||||
//SEG3 @begin
|
||||
bbegin:
|
||||
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
b1_from_bbegin:
|
||||
jmp b1
|
||||
//SEG5 @1
|
||||
b1:
|
||||
//SEG6 [2] call main
|
||||
//SEG7 [4] phi from @1 to main [phi:@1->main]
|
||||
main_from_b1:
|
||||
jsr main
|
||||
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
|
||||
bend_from_b1:
|
||||
jmp bend
|
||||
//SEG9 @end
|
||||
bend:
|
||||
//SEG10 main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
.label _0 = 3
|
||||
.label _2 = 4
|
||||
.label _4 = 5
|
||||
.label _8 = 7
|
||||
.label sb = 6
|
||||
.label i = 2
|
||||
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
|
||||
b1_from_main:
|
||||
//SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
|
||||
lda #0
|
||||
sta i
|
||||
jmp b1
|
||||
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
|
||||
b1_from_b1:
|
||||
//SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
|
||||
jmp b1
|
||||
//SEG15 main::@1
|
||||
b1:
|
||||
//SEG16 [6] (byte~) main::$0 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_ror_1
|
||||
lda i
|
||||
lsr
|
||||
sta _0
|
||||
//SEG17 [7] *((const byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda _0
|
||||
ldy i
|
||||
sta SCREEN,y
|
||||
//SEG18 [8] (byte~) main::$2 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuz1=vbuz2_ror_2
|
||||
lda i
|
||||
lsr
|
||||
lsr
|
||||
sta _2
|
||||
//SEG19 [9] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28 + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda _2
|
||||
ldy i
|
||||
sta SCREEN+$28,y
|
||||
//SEG20 [10] (byte~) main::$4 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 3 -- vbuz1=vbuz2_ror_3
|
||||
lda i
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
sta _4
|
||||
//SEG21 [11] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50 + (byte) main::i#2) ← (byte~) main::$4 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda _4
|
||||
ldy i
|
||||
sta SCREEN+$50,y
|
||||
//SEG22 [12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2 -- vbsz1=_neg_vbsz2
|
||||
lda i
|
||||
eor #$ff
|
||||
clc
|
||||
adc #1
|
||||
sta sb
|
||||
//SEG23 [13] (signed byte~) main::$8 ← (signed byte) main::sb#0 >> (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbsz1=vbsz2_ror_1
|
||||
lda sb
|
||||
cmp #$80
|
||||
ror
|
||||
sta _8
|
||||
//SEG24 [14] *((const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0 + (byte) main::i#2) ← (byte)(signed byte~) main::$8 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda _8
|
||||
ldy i
|
||||
sta SCREEN+$a0,y
|
||||
//SEG25 [15] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1
|
||||
inc i
|
||||
//SEG26 [16] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) $b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
|
||||
lda #$b
|
||||
cmp i
|
||||
bne b1_from_b1
|
||||
jmp breturn
|
||||
//SEG27 main::@return
|
||||
breturn:
|
||||
//SEG28 [17] return
|
||||
rts
|
||||
}
|
||||
|
||||
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||
Statement [6] (byte~) main::$0 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::$0 ] ( main:2 [ main::i#2 main::$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 [8] (byte~) main::$2 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 2 [ main::i#2 main::$2 ] ( main:2 [ main::i#2 main::$2 ] ) always clobbers reg byte a
|
||||
Statement [10] (byte~) main::$4 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 3 [ main::i#2 main::$4 ] ( main:2 [ main::i#2 main::$4 ] ) always clobbers reg byte a
|
||||
Statement [12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2 [ main::i#2 main::sb#0 ] ( main:2 [ main::i#2 main::sb#0 ] ) always clobbers reg byte a
|
||||
Statement [13] (signed byte~) main::$8 ← (signed byte) main::sb#0 >> (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::$8 ] ( main:2 [ main::i#2 main::$8 ] ) always clobbers reg byte a
|
||||
Statement [6] (byte~) main::$0 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::$0 ] ( main:2 [ main::i#2 main::$0 ] ) always clobbers reg byte a
|
||||
Statement [8] (byte~) main::$2 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 2 [ main::i#2 main::$2 ] ( main:2 [ main::i#2 main::$2 ] ) always clobbers reg byte a
|
||||
Statement [10] (byte~) main::$4 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 3 [ main::i#2 main::$4 ] ( main:2 [ main::i#2 main::$4 ] ) always clobbers reg byte a
|
||||
Statement [12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2 [ main::i#2 main::sb#0 ] ( main:2 [ main::i#2 main::sb#0 ] ) always clobbers reg byte a
|
||||
Statement [13] (signed byte~) main::$8 ← (signed byte) main::sb#0 >> (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::$8 ] ( main:2 [ main::i#2 main::$8 ] ) 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 [ main::$0 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:4 [ main::$2 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:5 [ main::$4 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:6 [ main::sb#0 ] : zp ZP_BYTE:6 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:7 [ main::$8 ] : zp ZP_BYTE:7 , reg byte a , reg byte x , reg byte y ,
|
||||
|
||||
REGISTER UPLIFT SCOPES
|
||||
Uplift Scope [main] 26.4: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 22: zp ZP_BYTE:3 [ main::$0 ] 22: zp ZP_BYTE:4 [ main::$2 ] 22: zp ZP_BYTE:5 [ main::$4 ] 22: zp ZP_BYTE:6 [ main::sb#0 ] 11: zp ZP_BYTE:7 [ main::$8 ]
|
||||
Uplift Scope []
|
||||
|
||||
Uplifting [main] best 813 combination reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$0 ] reg byte a [ main::$2 ] reg byte a [ main::$4 ] zp ZP_BYTE:6 [ main::sb#0 ] zp ZP_BYTE:7 [ main::$8 ]
|
||||
Limited combination testing to 100 combinations of 3072 possible.
|
||||
Uplifting [] best 813 combination
|
||||
Attempting to uplift remaining variables inzp ZP_BYTE:6 [ main::sb#0 ]
|
||||
Uplifting [main] best 753 combination reg byte a [ main::sb#0 ]
|
||||
Attempting to uplift remaining variables inzp ZP_BYTE:7 [ main::$8 ]
|
||||
Uplifting [main] best 693 combination reg byte a [ main::$8 ]
|
||||
|
||||
ASSEMBLER BEFORE OPTIMIZATION
|
||||
//SEG0 File Comments
|
||||
// Check that division by factors of 2 is converted to shifts
|
||||
//SEG1 Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(bbegin)
|
||||
.pc = $80d "Program"
|
||||
//SEG2 Global Constants & labels
|
||||
//SEG3 @begin
|
||||
bbegin:
|
||||
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
b1_from_bbegin:
|
||||
jmp b1
|
||||
//SEG5 @1
|
||||
b1:
|
||||
//SEG6 [2] call main
|
||||
//SEG7 [4] phi from @1 to main [phi:@1->main]
|
||||
main_from_b1:
|
||||
jsr main
|
||||
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
|
||||
bend_from_b1:
|
||||
jmp bend
|
||||
//SEG9 @end
|
||||
bend:
|
||||
//SEG10 main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
|
||||
b1_from_main:
|
||||
//SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
jmp b1
|
||||
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
|
||||
b1_from_b1:
|
||||
//SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
|
||||
jmp b1
|
||||
//SEG15 main::@1
|
||||
b1:
|
||||
//SEG16 [6] (byte~) main::$0 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuxx_ror_1
|
||||
txa
|
||||
lsr
|
||||
//SEG17 [7] *((const byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN,x
|
||||
//SEG18 [8] (byte~) main::$2 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuaa=vbuxx_ror_2
|
||||
txa
|
||||
lsr
|
||||
lsr
|
||||
//SEG19 [9] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28 + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$28,x
|
||||
//SEG20 [10] (byte~) main::$4 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 3 -- vbuaa=vbuxx_ror_3
|
||||
txa
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
//SEG21 [11] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50 + (byte) main::i#2) ← (byte~) main::$4 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$50,x
|
||||
//SEG22 [12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2 -- vbsaa=_neg_vbsxx
|
||||
txa
|
||||
eor #$ff
|
||||
clc
|
||||
adc #1
|
||||
//SEG23 [13] (signed byte~) main::$8 ← (signed byte) main::sb#0 >> (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbsaa=vbsaa_ror_1
|
||||
cmp #$80
|
||||
ror
|
||||
//SEG24 [14] *((const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0 + (byte) main::i#2) ← (byte)(signed byte~) main::$8 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$a0,x
|
||||
//SEG25 [15] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
//SEG26 [16] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) $b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #$b
|
||||
bne b1_from_b1
|
||||
jmp breturn
|
||||
//SEG27 main::@return
|
||||
breturn:
|
||||
//SEG28 [17] return
|
||||
rts
|
||||
}
|
||||
|
||||
ASSEMBLER OPTIMIZATIONS
|
||||
Removing instruction jmp b1
|
||||
Removing instruction jmp bend
|
||||
Removing instruction jmp b1
|
||||
Removing instruction jmp breturn
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Replacing label b1_from_b1 with b1
|
||||
Removing instruction b1_from_bbegin:
|
||||
Removing instruction b1:
|
||||
Removing instruction main_from_b1:
|
||||
Removing instruction bend_from_b1:
|
||||
Removing instruction b1_from_b1:
|
||||
Succesful ASM optimization Pass5RedundantLabelElimination
|
||||
Removing instruction bend:
|
||||
Removing instruction b1_from_main:
|
||||
Removing instruction breturn:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
Updating BasicUpstart to call main directly
|
||||
Removing instruction jsr main
|
||||
Succesful ASM optimization Pass5SkipBegin
|
||||
Removing instruction jmp b1
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Removing instruction bbegin:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
|
||||
FINAL SYMBOL TABLE
|
||||
(label) @1
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(void()) main()
|
||||
(byte~) main::$0 reg byte a 22.0
|
||||
(byte~) main::$2 reg byte a 22.0
|
||||
(byte~) main::$4 reg byte a 22.0
|
||||
(signed byte~) main::$8 reg byte a 11.0
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(const byte*) main::SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) $400
|
||||
(byte) main::i
|
||||
(byte) main::i#1 reg byte x 16.5
|
||||
(byte) main::i#2 reg byte x 9.899999999999999
|
||||
(signed byte) main::sb
|
||||
(signed byte) main::sb#0 reg byte a 22.0
|
||||
|
||||
reg byte x [ main::i#2 main::i#1 ]
|
||||
reg byte a [ main::$0 ]
|
||||
reg byte a [ main::$2 ]
|
||||
reg byte a [ main::$4 ]
|
||||
reg byte a [ main::sb#0 ]
|
||||
reg byte a [ main::$8 ]
|
||||
|
||||
|
||||
FINAL ASSEMBLER
|
||||
Score: 591
|
||||
|
||||
//SEG0 File Comments
|
||||
// Check that division by factors of 2 is converted to shifts
|
||||
//SEG1 Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
//SEG2 Global Constants & labels
|
||||
//SEG3 @begin
|
||||
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
//SEG5 @1
|
||||
//SEG6 [2] call main
|
||||
//SEG7 [4] phi from @1 to main [phi:@1->main]
|
||||
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
|
||||
//SEG9 @end
|
||||
//SEG10 main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
|
||||
//SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
|
||||
//SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
|
||||
//SEG15 main::@1
|
||||
b1:
|
||||
//SEG16 [6] (byte~) main::$0 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuxx_ror_1
|
||||
txa
|
||||
lsr
|
||||
//SEG17 [7] *((const byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN,x
|
||||
//SEG18 [8] (byte~) main::$2 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuaa=vbuxx_ror_2
|
||||
txa
|
||||
lsr
|
||||
lsr
|
||||
//SEG19 [9] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28 + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$28,x
|
||||
//SEG20 [10] (byte~) main::$4 ← (byte) main::i#2 >> (byte/signed byte/word/signed word/dword/signed dword) 3 -- vbuaa=vbuxx_ror_3
|
||||
txa
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
//SEG21 [11] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50 + (byte) main::i#2) ← (byte~) main::$4 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$50,x
|
||||
//SEG22 [12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2 -- vbsaa=_neg_vbsxx
|
||||
txa
|
||||
eor #$ff
|
||||
clc
|
||||
adc #1
|
||||
//SEG23 [13] (signed byte~) main::$8 ← (signed byte) main::sb#0 >> (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbsaa=vbsaa_ror_1
|
||||
cmp #$80
|
||||
ror
|
||||
//SEG24 [14] *((const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0 + (byte) main::i#2) ← (byte)(signed byte~) main::$8 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$a0,x
|
||||
//SEG25 [15] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
//SEG26 [16] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) $b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #$b
|
||||
bne b1
|
||||
//SEG27 main::@return
|
||||
//SEG28 [17] return
|
||||
rts
|
||||
}
|
||||
|
24
src/test/ref/divide-2s.sym
Normal file
24
src/test/ref/divide-2s.sym
Normal file
@ -0,0 +1,24 @@
|
||||
(label) @1
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(void()) main()
|
||||
(byte~) main::$0 reg byte a 22.0
|
||||
(byte~) main::$2 reg byte a 22.0
|
||||
(byte~) main::$4 reg byte a 22.0
|
||||
(signed byte~) main::$8 reg byte a 11.0
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(const byte*) main::SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) $400
|
||||
(byte) main::i
|
||||
(byte) main::i#1 reg byte x 16.5
|
||||
(byte) main::i#2 reg byte x 9.899999999999999
|
||||
(signed byte) main::sb
|
||||
(signed byte) main::sb#0 reg byte a 22.0
|
||||
|
||||
reg byte x [ main::i#2 main::i#1 ]
|
||||
reg byte a [ main::$0 ]
|
||||
reg byte a [ main::$2 ]
|
||||
reg byte a [ main::$4 ]
|
||||
reg byte a [ main::sb#0 ]
|
||||
reg byte a [ main::$8 ]
|
31
src/test/ref/multiply-2s.asm
Normal file
31
src/test/ref/multiply-2s.asm
Normal file
@ -0,0 +1,31 @@
|
||||
// Check that multiplication by factors of 2 is converted to shifts
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
ldx #0
|
||||
b1:
|
||||
txa
|
||||
asl
|
||||
sta SCREEN,x
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
sta SCREEN+$28,x
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
asl
|
||||
sta SCREEN+$50,x
|
||||
txa
|
||||
eor #$ff
|
||||
clc
|
||||
adc #1
|
||||
asl
|
||||
sta SCREEN+$a0,x
|
||||
inx
|
||||
cpx #$b
|
||||
bne b1
|
||||
rts
|
||||
}
|
29
src/test/ref/multiply-2s.cfg
Normal file
29
src/test/ref/multiply-2s.cfg
Normal file
@ -0,0 +1,29 @@
|
||||
@begin: scope:[] from
|
||||
[0] phi()
|
||||
to:@1
|
||||
@1: scope:[] from @begin
|
||||
[1] phi()
|
||||
[2] call main
|
||||
to:@end
|
||||
@end: scope:[] from @1
|
||||
[3] phi()
|
||||
main: scope:[main] from @1
|
||||
[4] phi()
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
[5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@1/(byte) main::i#1 )
|
||||
[6] (byte~) main::$0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
[7] *((const byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0
|
||||
[8] (byte~) main::$2 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
[9] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28 + (byte) main::i#2) ← (byte~) main::$2
|
||||
[10] (byte~) main::$4 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 3
|
||||
[11] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50 + (byte) main::i#2) ← (byte~) main::$4
|
||||
[12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2
|
||||
[13] (signed byte~) main::$8 ← (signed byte) main::sb#0 << (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
[14] *((const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0 + (byte) main::i#2) ← (byte)(signed byte~) main::$8
|
||||
[15] (byte) main::i#1 ← ++ (byte) main::i#2
|
||||
[16] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) $b) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[17] return
|
||||
to:@return
|
506
src/test/ref/multiply-2s.log
Normal file
506
src/test/ref/multiply-2s.log
Normal file
@ -0,0 +1,506 @@
|
||||
|
||||
CONTROL FLOW GRAPH SSA
|
||||
@begin: scope:[] from
|
||||
to:@1
|
||||
main: scope:[main] from @1
|
||||
(byte*) main::SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) $400
|
||||
(byte) main::i#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
(byte) main::i#2 ← phi( main/(byte) main::i#0 main::@1/(byte) main::i#1 )
|
||||
(byte/signed word/word/dword/signed dword~) main::$0 ← (byte) main::i#2 * (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
*((byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte/signed word/word/dword/signed dword~) main::$0
|
||||
(byte*~) main::$1 ← (byte*) main::SCREEN#0 + (byte/signed byte/word/signed word/dword/signed dword) $28
|
||||
(byte/signed word/word/dword/signed dword~) main::$2 ← (byte) main::i#2 * (byte/signed byte/word/signed word/dword/signed dword) 4
|
||||
*((byte*~) main::$1 + (byte) main::i#2) ← (byte/signed word/word/dword/signed dword~) main::$2
|
||||
(byte*~) main::$3 ← (byte*) main::SCREEN#0 + (byte/signed byte/word/signed word/dword/signed dword) $50
|
||||
(byte/signed word/word/dword/signed dword~) main::$4 ← (byte) main::i#2 * (byte/signed byte/word/signed word/dword/signed dword) 8
|
||||
*((byte*~) main::$3 + (byte) main::i#2) ← (byte/signed word/word/dword/signed dword~) main::$4
|
||||
(signed byte~) main::$5 ← ((signed byte)) (byte) main::i#2
|
||||
(signed byte~) main::$6 ← - (signed byte~) main::$5
|
||||
(signed byte) main::sb#0 ← (signed byte~) main::$6
|
||||
(byte*~) main::$7 ← (byte*) main::SCREEN#0 + (byte/word/signed word/dword/signed dword) $a0
|
||||
(signed word/signed byte/signed dword~) main::$8 ← (signed byte) main::sb#0 * (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
(byte~) main::$9 ← ((byte)) (signed word/signed byte/signed dword~) main::$8
|
||||
*((byte*~) main::$7 + (byte) main::i#2) ← (byte~) main::$9
|
||||
(byte) main::i#1 ← (byte) main::i#2 + rangenext(0,$a)
|
||||
(bool~) main::$10 ← (byte) main::i#1 != rangelast(0,$a)
|
||||
if((bool~) main::$10) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
return
|
||||
to:@return
|
||||
@1: scope:[] from @begin
|
||||
call main
|
||||
to:@2
|
||||
@2: scope:[] from @1
|
||||
to:@end
|
||||
@end: scope:[] from @2
|
||||
|
||||
SYMBOL TABLE SSA
|
||||
(label) @1
|
||||
(label) @2
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(void()) main()
|
||||
(byte/signed word/word/dword/signed dword~) main::$0
|
||||
(byte*~) main::$1
|
||||
(bool~) main::$10
|
||||
(byte/signed word/word/dword/signed dword~) main::$2
|
||||
(byte*~) main::$3
|
||||
(byte/signed word/word/dword/signed dword~) main::$4
|
||||
(signed byte~) main::$5
|
||||
(signed byte~) main::$6
|
||||
(byte*~) main::$7
|
||||
(signed word/signed byte/signed dword~) main::$8
|
||||
(byte~) main::$9
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(byte*) main::SCREEN#0
|
||||
(byte) main::i
|
||||
(byte) main::i#0
|
||||
(byte) main::i#1
|
||||
(byte) main::i#2
|
||||
(signed byte) main::sb
|
||||
(signed byte) main::sb#0
|
||||
|
||||
Culled Empty Block (label) @2
|
||||
Successful SSA optimization Pass2CullEmptyBlocks
|
||||
Alias (signed byte) main::sb#0 = (signed byte~) main::$6
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Simple Condition (bool~) main::$10 [20] if((byte) main::i#1!=rangelast(0,$a)) goto main::@1
|
||||
Successful SSA optimization Pass2ConditionalJumpSimplification
|
||||
Constant (const byte*) main::SCREEN#0 = ((byte*))$400
|
||||
Constant (const byte) main::i#0 = 0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Constant (const byte*) main::$1 = main::SCREEN#0+$28
|
||||
Constant (const byte*) main::$3 = main::SCREEN#0+$50
|
||||
Constant (const byte*) main::$7 = main::SCREEN#0+$a0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Eliminating Noop Cast (signed byte~) main::$5 ← ((signed byte)) (byte) main::i#2
|
||||
Eliminating Noop Cast (byte~) main::$9 ← ((byte)) (signed word/signed byte/signed dword~) main::$8
|
||||
Successful SSA optimization Pass2NopCastElimination
|
||||
Resolved ranged next value main::i#1 ← ++ main::i#2 to ++
|
||||
Resolved ranged comparison value if(main::i#1!=rangelast(0,$a)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) $b
|
||||
Rewriting multiplication to use shift (byte/signed word/word/dword/signed dword~) main::$0 ← (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::i#2 * (byte/signed byte/word/signed word/dword/signed dword) 4
|
||||
Rewriting multiplication to use shift (byte/signed word/word/dword/signed dword~) main::$4 ← (byte) main::i#2 * (byte/signed byte/word/signed word/dword/signed dword) 8
|
||||
Rewriting multiplication to use shift (signed word/signed byte/signed dword~) main::$8 ← (signed byte) main::sb#0 * (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
Successful SSA optimization Pass2Multiply2sRewriting
|
||||
Inferred type updated to byte in [1] (byte/signed word/word/dword/signed dword~) main::$0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
Inferred type updated to byte in [3] (byte/signed word/word/dword/signed dword~) main::$2 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
Inferred type updated to byte in [5] (byte/signed word/word/dword/signed dword~) main::$4 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 3
|
||||
Inferred type updated to signed byte in [8] (signed word/signed byte/signed dword~) main::$8 ← (signed byte) main::sb#0 << (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
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
|
||||
Constant inlined main::$3 = (const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50
|
||||
Constant inlined main::$1 = (const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28
|
||||
Constant inlined main::$7 = (const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0
|
||||
Successful SSA optimization Pass2ConstantInlining
|
||||
Added new block during phi lifting main::@3(between main::@1 and main::@1)
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @1
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
CALL GRAPH
|
||||
Calls in [] to main:2
|
||||
|
||||
Created 1 initial phi equivalence classes
|
||||
Coalesced [18] main::i#3 ← main::i#1
|
||||
Coalesced down to 1 phi equivalence classes
|
||||
Culled Empty Block (label) main::@3
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @1
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
|
||||
FINAL CONTROL FLOW GRAPH
|
||||
@begin: scope:[] from
|
||||
[0] phi()
|
||||
to:@1
|
||||
@1: scope:[] from @begin
|
||||
[1] phi()
|
||||
[2] call main
|
||||
to:@end
|
||||
@end: scope:[] from @1
|
||||
[3] phi()
|
||||
main: scope:[main] from @1
|
||||
[4] phi()
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
[5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@1/(byte) main::i#1 )
|
||||
[6] (byte~) main::$0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
[7] *((const byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0
|
||||
[8] (byte~) main::$2 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 2
|
||||
[9] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28 + (byte) main::i#2) ← (byte~) main::$2
|
||||
[10] (byte~) main::$4 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 3
|
||||
[11] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50 + (byte) main::i#2) ← (byte~) main::$4
|
||||
[12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2
|
||||
[13] (signed byte~) main::$8 ← (signed byte) main::sb#0 << (byte/signed byte/word/signed word/dword/signed dword) 1
|
||||
[14] *((const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0 + (byte) main::i#2) ← (byte)(signed byte~) main::$8
|
||||
[15] (byte) main::i#1 ← ++ (byte) main::i#2
|
||||
[16] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) $b) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[17] return
|
||||
to:@return
|
||||
|
||||
|
||||
VARIABLE REGISTER WEIGHTS
|
||||
(void()) main()
|
||||
(byte~) main::$0 22.0
|
||||
(byte~) main::$2 22.0
|
||||
(byte~) main::$4 22.0
|
||||
(signed byte~) main::$8 11.0
|
||||
(byte*) main::SCREEN
|
||||
(byte) main::i
|
||||
(byte) main::i#1 16.5
|
||||
(byte) main::i#2 9.899999999999999
|
||||
(signed byte) main::sb
|
||||
(signed byte) main::sb#0 22.0
|
||||
|
||||
Initial phi equivalence classes
|
||||
[ main::i#2 main::i#1 ]
|
||||
Added variable main::$0 to zero page equivalence class [ main::$0 ]
|
||||
Added variable main::$2 to zero page equivalence class [ main::$2 ]
|
||||
Added variable main::$4 to zero page equivalence class [ main::$4 ]
|
||||
Added variable main::sb#0 to zero page equivalence class [ main::sb#0 ]
|
||||
Added variable main::$8 to zero page equivalence class [ main::$8 ]
|
||||
Complete equivalence classes
|
||||
[ main::i#2 main::i#1 ]
|
||||
[ main::$0 ]
|
||||
[ main::$2 ]
|
||||
[ main::$4 ]
|
||||
[ main::sb#0 ]
|
||||
[ main::$8 ]
|
||||
Allocated zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
|
||||
Allocated zp ZP_BYTE:3 [ main::$0 ]
|
||||
Allocated zp ZP_BYTE:4 [ main::$2 ]
|
||||
Allocated zp ZP_BYTE:5 [ main::$4 ]
|
||||
Allocated zp ZP_BYTE:6 [ main::sb#0 ]
|
||||
Allocated zp ZP_BYTE:7 [ main::$8 ]
|
||||
|
||||
INITIAL ASM
|
||||
//SEG0 File Comments
|
||||
// Check that multiplication by factors of 2 is converted to shifts
|
||||
//SEG1 Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(bbegin)
|
||||
.pc = $80d "Program"
|
||||
//SEG2 Global Constants & labels
|
||||
//SEG3 @begin
|
||||
bbegin:
|
||||
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
b1_from_bbegin:
|
||||
jmp b1
|
||||
//SEG5 @1
|
||||
b1:
|
||||
//SEG6 [2] call main
|
||||
//SEG7 [4] phi from @1 to main [phi:@1->main]
|
||||
main_from_b1:
|
||||
jsr main
|
||||
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
|
||||
bend_from_b1:
|
||||
jmp bend
|
||||
//SEG9 @end
|
||||
bend:
|
||||
//SEG10 main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
.label _0 = 3
|
||||
.label _2 = 4
|
||||
.label _4 = 5
|
||||
.label _8 = 7
|
||||
.label sb = 6
|
||||
.label i = 2
|
||||
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
|
||||
b1_from_main:
|
||||
//SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
|
||||
lda #0
|
||||
sta i
|
||||
jmp b1
|
||||
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
|
||||
b1_from_b1:
|
||||
//SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
|
||||
jmp b1
|
||||
//SEG15 main::@1
|
||||
b1:
|
||||
//SEG16 [6] (byte~) main::$0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1
|
||||
lda i
|
||||
asl
|
||||
sta _0
|
||||
//SEG17 [7] *((const byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda _0
|
||||
ldy i
|
||||
sta SCREEN,y
|
||||
//SEG18 [8] (byte~) main::$2 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuz1=vbuz2_rol_2
|
||||
lda i
|
||||
asl
|
||||
asl
|
||||
sta _2
|
||||
//SEG19 [9] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28 + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda _2
|
||||
ldy i
|
||||
sta SCREEN+$28,y
|
||||
//SEG20 [10] (byte~) main::$4 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 3 -- vbuz1=vbuz2_rol_3
|
||||
lda i
|
||||
asl
|
||||
asl
|
||||
asl
|
||||
sta _4
|
||||
//SEG21 [11] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50 + (byte) main::i#2) ← (byte~) main::$4 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda _4
|
||||
ldy i
|
||||
sta SCREEN+$50,y
|
||||
//SEG22 [12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2 -- vbsz1=_neg_vbsz2
|
||||
lda i
|
||||
eor #$ff
|
||||
clc
|
||||
adc #1
|
||||
sta sb
|
||||
//SEG23 [13] (signed byte~) main::$8 ← (signed byte) main::sb#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbsz1=vbsz2_rol_1
|
||||
lda sb
|
||||
asl
|
||||
sta _8
|
||||
//SEG24 [14] *((const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0 + (byte) main::i#2) ← (byte)(signed byte~) main::$8 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda _8
|
||||
ldy i
|
||||
sta SCREEN+$a0,y
|
||||
//SEG25 [15] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1
|
||||
inc i
|
||||
//SEG26 [16] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) $b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
|
||||
lda #$b
|
||||
cmp i
|
||||
bne b1_from_b1
|
||||
jmp breturn
|
||||
//SEG27 main::@return
|
||||
breturn:
|
||||
//SEG28 [17] return
|
||||
rts
|
||||
}
|
||||
|
||||
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||
Statement [6] (byte~) main::$0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::$0 ] ( main:2 [ main::i#2 main::$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 [8] (byte~) main::$2 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 2 [ main::i#2 main::$2 ] ( main:2 [ main::i#2 main::$2 ] ) always clobbers reg byte a
|
||||
Statement [10] (byte~) main::$4 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 3 [ main::i#2 main::$4 ] ( main:2 [ main::i#2 main::$4 ] ) always clobbers reg byte a
|
||||
Statement [12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2 [ main::i#2 main::sb#0 ] ( main:2 [ main::i#2 main::sb#0 ] ) always clobbers reg byte a
|
||||
Statement [13] (signed byte~) main::$8 ← (signed byte) main::sb#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::$8 ] ( main:2 [ main::i#2 main::$8 ] ) always clobbers reg byte a
|
||||
Statement [6] (byte~) main::$0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::$0 ] ( main:2 [ main::i#2 main::$0 ] ) always clobbers reg byte a
|
||||
Statement [8] (byte~) main::$2 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 2 [ main::i#2 main::$2 ] ( main:2 [ main::i#2 main::$2 ] ) always clobbers reg byte a
|
||||
Statement [10] (byte~) main::$4 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 3 [ main::i#2 main::$4 ] ( main:2 [ main::i#2 main::$4 ] ) always clobbers reg byte a
|
||||
Statement [12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2 [ main::i#2 main::sb#0 ] ( main:2 [ main::i#2 main::sb#0 ] ) always clobbers reg byte a
|
||||
Statement [13] (signed byte~) main::$8 ← (signed byte) main::sb#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::$8 ] ( main:2 [ main::i#2 main::$8 ] ) 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 [ main::$0 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:4 [ main::$2 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:5 [ main::$4 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:6 [ main::sb#0 ] : zp ZP_BYTE:6 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:7 [ main::$8 ] : zp ZP_BYTE:7 , reg byte a , reg byte x , reg byte y ,
|
||||
|
||||
REGISTER UPLIFT SCOPES
|
||||
Uplift Scope [main] 26.4: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 22: zp ZP_BYTE:3 [ main::$0 ] 22: zp ZP_BYTE:4 [ main::$2 ] 22: zp ZP_BYTE:5 [ main::$4 ] 22: zp ZP_BYTE:6 [ main::sb#0 ] 11: zp ZP_BYTE:7 [ main::$8 ]
|
||||
Uplift Scope []
|
||||
|
||||
Uplifting [main] best 793 combination reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$0 ] reg byte a [ main::$2 ] reg byte a [ main::$4 ] zp ZP_BYTE:6 [ main::sb#0 ] zp ZP_BYTE:7 [ main::$8 ]
|
||||
Limited combination testing to 100 combinations of 3072 possible.
|
||||
Uplifting [] best 793 combination
|
||||
Attempting to uplift remaining variables inzp ZP_BYTE:6 [ main::sb#0 ]
|
||||
Uplifting [main] best 733 combination reg byte a [ main::sb#0 ]
|
||||
Attempting to uplift remaining variables inzp ZP_BYTE:7 [ main::$8 ]
|
||||
Uplifting [main] best 673 combination reg byte a [ main::$8 ]
|
||||
|
||||
ASSEMBLER BEFORE OPTIMIZATION
|
||||
//SEG0 File Comments
|
||||
// Check that multiplication by factors of 2 is converted to shifts
|
||||
//SEG1 Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(bbegin)
|
||||
.pc = $80d "Program"
|
||||
//SEG2 Global Constants & labels
|
||||
//SEG3 @begin
|
||||
bbegin:
|
||||
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
b1_from_bbegin:
|
||||
jmp b1
|
||||
//SEG5 @1
|
||||
b1:
|
||||
//SEG6 [2] call main
|
||||
//SEG7 [4] phi from @1 to main [phi:@1->main]
|
||||
main_from_b1:
|
||||
jsr main
|
||||
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
|
||||
bend_from_b1:
|
||||
jmp bend
|
||||
//SEG9 @end
|
||||
bend:
|
||||
//SEG10 main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
|
||||
b1_from_main:
|
||||
//SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
jmp b1
|
||||
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
|
||||
b1_from_b1:
|
||||
//SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
|
||||
jmp b1
|
||||
//SEG15 main::@1
|
||||
b1:
|
||||
//SEG16 [6] (byte~) main::$0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuxx_rol_1
|
||||
txa
|
||||
asl
|
||||
//SEG17 [7] *((const byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN,x
|
||||
//SEG18 [8] (byte~) main::$2 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuaa=vbuxx_rol_2
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
//SEG19 [9] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28 + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$28,x
|
||||
//SEG20 [10] (byte~) main::$4 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 3 -- vbuaa=vbuxx_rol_3
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
asl
|
||||
//SEG21 [11] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50 + (byte) main::i#2) ← (byte~) main::$4 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$50,x
|
||||
//SEG22 [12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2 -- vbsaa=_neg_vbsxx
|
||||
txa
|
||||
eor #$ff
|
||||
clc
|
||||
adc #1
|
||||
//SEG23 [13] (signed byte~) main::$8 ← (signed byte) main::sb#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbsaa=vbsaa_rol_1
|
||||
asl
|
||||
//SEG24 [14] *((const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0 + (byte) main::i#2) ← (byte)(signed byte~) main::$8 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$a0,x
|
||||
//SEG25 [15] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
//SEG26 [16] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) $b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #$b
|
||||
bne b1_from_b1
|
||||
jmp breturn
|
||||
//SEG27 main::@return
|
||||
breturn:
|
||||
//SEG28 [17] return
|
||||
rts
|
||||
}
|
||||
|
||||
ASSEMBLER OPTIMIZATIONS
|
||||
Removing instruction jmp b1
|
||||
Removing instruction jmp bend
|
||||
Removing instruction jmp b1
|
||||
Removing instruction jmp breturn
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Replacing label b1_from_b1 with b1
|
||||
Removing instruction b1_from_bbegin:
|
||||
Removing instruction b1:
|
||||
Removing instruction main_from_b1:
|
||||
Removing instruction bend_from_b1:
|
||||
Removing instruction b1_from_b1:
|
||||
Succesful ASM optimization Pass5RedundantLabelElimination
|
||||
Removing instruction bend:
|
||||
Removing instruction b1_from_main:
|
||||
Removing instruction breturn:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
Updating BasicUpstart to call main directly
|
||||
Removing instruction jsr main
|
||||
Succesful ASM optimization Pass5SkipBegin
|
||||
Removing instruction jmp b1
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Removing instruction bbegin:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
|
||||
FINAL SYMBOL TABLE
|
||||
(label) @1
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(void()) main()
|
||||
(byte~) main::$0 reg byte a 22.0
|
||||
(byte~) main::$2 reg byte a 22.0
|
||||
(byte~) main::$4 reg byte a 22.0
|
||||
(signed byte~) main::$8 reg byte a 11.0
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(const byte*) main::SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) $400
|
||||
(byte) main::i
|
||||
(byte) main::i#1 reg byte x 16.5
|
||||
(byte) main::i#2 reg byte x 9.899999999999999
|
||||
(signed byte) main::sb
|
||||
(signed byte) main::sb#0 reg byte a 22.0
|
||||
|
||||
reg byte x [ main::i#2 main::i#1 ]
|
||||
reg byte a [ main::$0 ]
|
||||
reg byte a [ main::$2 ]
|
||||
reg byte a [ main::$4 ]
|
||||
reg byte a [ main::sb#0 ]
|
||||
reg byte a [ main::$8 ]
|
||||
|
||||
|
||||
FINAL ASSEMBLER
|
||||
Score: 571
|
||||
|
||||
//SEG0 File Comments
|
||||
// Check that multiplication by factors of 2 is converted to shifts
|
||||
//SEG1 Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
//SEG2 Global Constants & labels
|
||||
//SEG3 @begin
|
||||
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
//SEG5 @1
|
||||
//SEG6 [2] call main
|
||||
//SEG7 [4] phi from @1 to main [phi:@1->main]
|
||||
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
|
||||
//SEG9 @end
|
||||
//SEG10 main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
|
||||
//SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
|
||||
//SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
|
||||
//SEG15 main::@1
|
||||
b1:
|
||||
//SEG16 [6] (byte~) main::$0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuxx_rol_1
|
||||
txa
|
||||
asl
|
||||
//SEG17 [7] *((const byte*) main::SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN,x
|
||||
//SEG18 [8] (byte~) main::$2 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuaa=vbuxx_rol_2
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
//SEG19 [9] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $28 + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$28,x
|
||||
//SEG20 [10] (byte~) main::$4 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 3 -- vbuaa=vbuxx_rol_3
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
asl
|
||||
//SEG21 [11] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) $50 + (byte) main::i#2) ← (byte~) main::$4 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$50,x
|
||||
//SEG22 [12] (signed byte) main::sb#0 ← - (signed byte)(byte) main::i#2 -- vbsaa=_neg_vbsxx
|
||||
txa
|
||||
eor #$ff
|
||||
clc
|
||||
adc #1
|
||||
//SEG23 [13] (signed byte~) main::$8 ← (signed byte) main::sb#0 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbsaa=vbsaa_rol_1
|
||||
asl
|
||||
//SEG24 [14] *((const byte*) main::SCREEN#0+(byte/word/signed word/dword/signed dword) $a0 + (byte) main::i#2) ← (byte)(signed byte~) main::$8 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN+$a0,x
|
||||
//SEG25 [15] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
//SEG26 [16] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) $b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #$b
|
||||
bne b1
|
||||
//SEG27 main::@return
|
||||
//SEG28 [17] return
|
||||
rts
|
||||
}
|
||||
|
24
src/test/ref/multiply-2s.sym
Normal file
24
src/test/ref/multiply-2s.sym
Normal file
@ -0,0 +1,24 @@
|
||||
(label) @1
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(void()) main()
|
||||
(byte~) main::$0 reg byte a 22.0
|
||||
(byte~) main::$2 reg byte a 22.0
|
||||
(byte~) main::$4 reg byte a 22.0
|
||||
(signed byte~) main::$8 reg byte a 11.0
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(const byte*) main::SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) $400
|
||||
(byte) main::i
|
||||
(byte) main::i#1 reg byte x 16.5
|
||||
(byte) main::i#2 reg byte x 9.899999999999999
|
||||
(signed byte) main::sb
|
||||
(signed byte) main::sb#0 reg byte a 22.0
|
||||
|
||||
reg byte x [ main::i#2 main::i#1 ]
|
||||
reg byte a [ main::$0 ]
|
||||
reg byte a [ main::$2 ]
|
||||
reg byte a [ main::$4 ]
|
||||
reg byte a [ main::sb#0 ]
|
||||
reg byte a [ main::$8 ]
|
Loading…
Reference in New Issue
Block a user