From d23f6e4248ce39d119a63c0ca471bf073bf35127 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Wed, 29 May 2019 14:09:21 +0200 Subject: [PATCH] 6502: improve optimizations using undocumented instructions --- .../assembly/mos/opt/UndocumentedOptimizations.scala | 5 +++++ src/test/scala/millfork/test/IllegalSuite.scala | 12 ++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/scala/millfork/assembly/mos/opt/UndocumentedOptimizations.scala b/src/main/scala/millfork/assembly/mos/opt/UndocumentedOptimizations.scala index f52a5f4c..291a2576 100644 --- a/src/main/scala/millfork/assembly/mos/opt/UndocumentedOptimizations.scala +++ b/src/main/scala/millfork/assembly/mos/opt/UndocumentedOptimizations.scala @@ -89,6 +89,11 @@ object UndocumentedOptimizations { val fragment2 = sax :: ctx.get[List[AssemblyLine]](12) List(fragment0, fragment1, fragment2).flatten }, + (Elidable & HasOpcode(TXA)) ~ + (Elidable & HasOpcode(AND)) ~ + (Elidable & HasOpcode(STA) & HasAddrModeIn(SaxModes) & DoesntMatterWhatItDoesWith(State.A, State.Z, State.N)) ~~> { code => + code(1).copy(opcode = LDA) :: code(2).copy(opcode = SAX) :: code.drop(3) + }, ) def andConstant(const: Constant, mask: Int): Option[Long] = const match { diff --git a/src/test/scala/millfork/test/IllegalSuite.scala b/src/test/scala/millfork/test/IllegalSuite.scala index b84a267e..d39ea709 100644 --- a/src/test/scala/millfork/test/IllegalSuite.scala +++ b/src/test/scala/millfork/test/IllegalSuite.scala @@ -140,6 +140,10 @@ class IllegalSuite extends FunSuite with Matchers { | byte c | b = five(a) | c = five(a) + | asm { + | iny + | inx + | } | a = c | five(a) | c = a & b @@ -156,9 +160,9 @@ class IllegalSuite extends FunSuite with Matchers { val m = EmuUndocumentedRun(""" | word output @$c000 | void main () { - | output = five(5) + | output = five(0, 5) | } - | word five (byte a) { + | word five (byte dummy, byte a) { | return a:a | } """.stripMargin) @@ -169,9 +173,9 @@ class IllegalSuite extends FunSuite with Matchers { val m = EmuUndocumentedRun(""" | byte output @$c000 | void main () { - | output = five(1) + | output = five(0, 1) | } - | byte five (byte a) { + | byte five (byte dummy, byte a) { | byte b | b = a | a += 4