mirror of
https://github.com/irmen/prog8.git
synced 2024-10-19 07:23:56 +00:00
some more obvious optimizations for X+X and X-X
This commit is contained in:
parent
267adb4612
commit
b73da4ed02
@ -1772,7 +1772,6 @@ _loop_hi ldy _index_first
|
|||||||
|
|
||||||
ror2_mem_ub .proc
|
ror2_mem_ub .proc
|
||||||
; -- in-place 8-bit ror of byte at memory location on stack
|
; -- in-place 8-bit ror of byte at memory location on stack
|
||||||
; TODO use self modifying code here
|
|
||||||
inx
|
inx
|
||||||
lda c64.ESTACK_LO,x
|
lda c64.ESTACK_LO,x
|
||||||
sta c64.SCRATCH_ZPWORD1
|
sta c64.SCRATCH_ZPWORD1
|
||||||
@ -1789,7 +1788,6 @@ ror2_mem_ub .proc
|
|||||||
|
|
||||||
rol2_mem_ub .proc
|
rol2_mem_ub .proc
|
||||||
; -- in-place 8-bit rol of byte at memory location on stack
|
; -- in-place 8-bit rol of byte at memory location on stack
|
||||||
; TODO use self modifying code here
|
|
||||||
inx
|
inx
|
||||||
lda c64.ESTACK_LO,x
|
lda c64.ESTACK_LO,x
|
||||||
sta c64.SCRATCH_ZPWORD1
|
sta c64.SCRATCH_ZPWORD1
|
||||||
|
@ -165,6 +165,9 @@ private fun optimizeAst(programAst: Program, errors: ErrorReporter) {
|
|||||||
if (optsDone1 + optsDone2 == 0)
|
if (optsDone1 + optsDone2 == 0)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
// because simplified statements and expressions could give rise to more constants that can be folded away:
|
||||||
|
programAst.constantFold(errors)
|
||||||
|
errors.handle()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun postprocessAst(programAst: Program, errors: ErrorReporter, compilerOptions: CompilationOptions) {
|
private fun postprocessAst(programAst: Program, errors: ErrorReporter, compilerOptions: CompilationOptions) {
|
||||||
|
@ -258,6 +258,14 @@ internal class ExpressionSimplifier(private val program: Program) : AstWalker()
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun optimizeAdd(expr: BinaryExpression, leftVal: NumericLiteralValue?, rightVal: NumericLiteralValue?): Expression? {
|
private fun optimizeAdd(expr: BinaryExpression, leftVal: NumericLiteralValue?, rightVal: NumericLiteralValue?): Expression? {
|
||||||
|
if(expr.left.isSameAs(expr.right)) {
|
||||||
|
// optimize X+X into X *2
|
||||||
|
expr.operator = "*"
|
||||||
|
expr.right = NumericLiteralValue.optimalInteger(2, expr.right.position)
|
||||||
|
expr.right.linkParents(expr)
|
||||||
|
return expr
|
||||||
|
}
|
||||||
|
|
||||||
if (leftVal == null && rightVal == null)
|
if (leftVal == null && rightVal == null)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
@ -278,6 +286,11 @@ internal class ExpressionSimplifier(private val program: Program) : AstWalker()
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun optimizeSub(expr: BinaryExpression, leftVal: NumericLiteralValue?, rightVal: NumericLiteralValue?): Expression? {
|
private fun optimizeSub(expr: BinaryExpression, leftVal: NumericLiteralValue?, rightVal: NumericLiteralValue?): Expression? {
|
||||||
|
if(expr.left.isSameAs(expr.right)) {
|
||||||
|
// optimize X-X into 0
|
||||||
|
return NumericLiteralValue.optimalInteger(0, expr.position)
|
||||||
|
}
|
||||||
|
|
||||||
if (leftVal == null && rightVal == null)
|
if (leftVal == null && rightVal == null)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
@ -1,33 +1,9 @@
|
|||||||
%import c64lib
|
%import c64lib
|
||||||
%import c64utils
|
%import c64utils
|
||||||
%zeropage dontuse
|
|
||||||
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
ubyte ub
|
|
||||||
byte bb
|
|
||||||
word ww
|
|
||||||
uword uw
|
|
||||||
uword auw
|
|
||||||
word aww
|
|
||||||
byte ab
|
|
||||||
ubyte aub
|
|
||||||
|
|
||||||
; TODO optimize all of these:
|
|
||||||
ab = bb+bb ; TODO bb * 2? (bb<<1)
|
|
||||||
ab = bb+bb+bb
|
|
||||||
aww = ww+ww
|
|
||||||
aww = ww+ww+ww
|
|
||||||
|
|
||||||
aub = ub+ub
|
|
||||||
aub = ub+ub+ub
|
|
||||||
auw = uw+uw
|
|
||||||
auw = uw+uw+uw
|
|
||||||
|
|
||||||
|
|
||||||
A = A+A
|
|
||||||
Y=Y+Y+Y
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user