1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-07-05 09:28:54 +00:00

More aggressive constant simplification

This commit is contained in:
Karol Stasiak 2018-04-15 02:21:51 +02:00
parent a2171aeef0
commit 60b9378554
2 changed files with 17 additions and 1 deletions

View File

@ -745,7 +745,7 @@ object ExpressionCompiler {
if (neg) MathOperator.DecimalMinus else MathOperator.DecimalPlus
} else {
if (neg) MathOperator.Minus else MathOperator.Plus
}, c, v)
}, c, v).quickSimplify
}
exprTypeAndVariable.map(x => compileConstant(ctx, value.quickSimplify, x._2)).getOrElse(Nil)
} else {

View File

@ -170,6 +170,22 @@ case class CompoundConstant(operator: MathOperator.Value, lhs: Constant, rhs: Co
val l = lhs.quickSimplify
val r = rhs.quickSimplify
(l, r) match {
case (CompoundConstant(MathOperator.Plus, a, ll@NumericConstant(lv, _)), rr@NumericConstant(rv,_)) if operator == MathOperator.Plus =>
CompoundConstant(MathOperator.Plus, a, ll + rr).quickSimplify
case (CompoundConstant(MathOperator.Minus, a, ll@NumericConstant(lv, _)), rr@NumericConstant(rv,_)) if operator == MathOperator.Minus =>
CompoundConstant(MathOperator.Minus, a, ll + rr).quickSimplify
case (CompoundConstant(MathOperator.Plus, a, ll@NumericConstant(lv, _)), rr@NumericConstant(rv,_)) if operator == MathOperator.Minus =>
if (lv >= rv) {
CompoundConstant(MathOperator.Plus, a, ll - rr).quickSimplify
} else {
CompoundConstant(MathOperator.Minus, a, rr - ll).quickSimplify
}
case (CompoundConstant(MathOperator.Minus, a, ll@NumericConstant(lv, _)), rr@NumericConstant(rv,_)) if operator == MathOperator.Plus =>
if (lv >= rv) {
CompoundConstant(MathOperator.Minus, a, ll - rr).quickSimplify
} else {
CompoundConstant(MathOperator.Plus, a, rr - ll).quickSimplify
}
case (CompoundConstant(MathOperator.Shl, HalfWordConstant(c1, true), NumericConstant(8, _)), HalfWordConstant(c2, false)) if operator == MathOperator.Or && c1 == c2 => c1
case (NumericConstant(lv, ls), NumericConstant(rv, rs)) =>
var size = ls max rs