1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-06-12 06:29:34 +00:00

6502: Optimize ROL/ROR before AND

This commit is contained in:
Karol Stasiak 2019-09-16 21:31:12 +02:00
parent 635870585e
commit fa7844e0b8
2 changed files with 14 additions and 0 deletions

View File

@ -26,6 +26,8 @@
* Fixed several serious bugs related to cartridge-based targets.
* 6502: Few minor optimization improvements.
## 0.3.6
* **Breaking change!**

View File

@ -1583,6 +1583,18 @@ object AlwaysGoodOptimizations {
(Elidable & HasOpcode(ANC) & MatchImmediate(1)) ~~> { (lines, ctx) =>
lines.init.tail :+ AssemblyLine.immediate(ANC, CompoundConstant(MathOperator.And, ctx.get[Constant](0), ctx.get[Constant](1)))
},
(Elidable & HasOpcode(ROR) & HasAddrMode(Implied)) ~
(Linear & Not(ChangesA) & Not(ReadsNOrZ) & Not(ReadsC) & Not(ReadsA)).* ~
(HasOpcodeIn(AND, ANC) & MatchNumericImmediate(1)) ~
Where(ctx => ctx.get[Int](1).&(0x80) == 0)~~> { (lines, ctx) =>
lines.head.copy(opcode = LSR) :: lines.tail
},
(Elidable & HasOpcode(ROL) & HasAddrMode(Implied)) ~
(Linear & Not(ChangesA) & Not(ReadsNOrZ) & Not(ReadsC) & Not(ReadsA)).* ~
(HasOpcodeIn(AND, ANC) & MatchNumericImmediate(1)) ~
Where(ctx => ctx.get[Int](1).&(1) == 0)~~> { (lines, ctx) =>
lines.head.copy(opcode = ASL) :: lines.tail
},
)
val SimplifiableIndexChanging = new RuleBasedAssemblyOptimization("Simplifiable index changing",