mirror of
https://github.com/KarolS/millfork.git
synced 2024-10-31 14:04:58 +00:00
Optimize some bitmask operations
This commit is contained in:
parent
c51c08ad56
commit
ffb46c4250
@ -152,6 +152,15 @@ object AlwaysGoodMOptimizations {
|
||||
(_.map(_.copy(opcode = LDD))),
|
||||
(Elidable & HasImmediate(0) & HasOpcodeIn(ORB, EORB, ADDB, ORA, EORA, ADDA, ADDD) & DoesntMatterWhatItDoesWith(MState.VF, MState.ZF, MState.NF, MState.CF, MState.HF)) ~~>
|
||||
(_ => Nil),
|
||||
(HasOpcode(LDB)) ~
|
||||
(Elidable & HasOpcode(ANDB) & HasAddrMode(Immediate) & MatchParameter(0)) ~
|
||||
(Elidable & HasOpcode(BNE) & MatchParameter(1)) ~
|
||||
(Elidable & HasOpcode(LDB)) ~
|
||||
(HasOpcode(ANDB) & HasAddrMode(Immediate) & MatchParameter(0)) ~
|
||||
(HasOpcode(BEQ)) ~
|
||||
(HasOpcode(LABEL) & MatchParameter(1)) ~~> { code =>
|
||||
List(code.head, code(3).copy(opcode = ORB)) ++ code.drop(4)
|
||||
},
|
||||
|
||||
)
|
||||
|
||||
|
@ -1605,6 +1605,15 @@ object AlwaysGoodOptimizations {
|
||||
Where(ctx => ctx.get[Int](1).&(1) == 0)~~> { (lines, ctx) =>
|
||||
lines.head.copy(opcode = ASL) :: lines.tail
|
||||
},
|
||||
(Elidable & HasOpcode(LDA)) ~
|
||||
(Elidable & HasOpcode(AND) & HasAddrMode(Immediate) & MatchParameter(0)) ~
|
||||
(Elidable & HasOpcode(BNE) & MatchParameter(1)) ~
|
||||
(Elidable & HasOpcode(LDA)) ~
|
||||
(Elidable & HasOpcode(AND) & HasAddrMode(Immediate) & MatchParameter(0)) ~
|
||||
(Elidable & HasOpcode(BEQ)) ~
|
||||
(Elidable & HasOpcode(LABEL) & MatchParameter(1)) ~~> { (code, ctx) =>
|
||||
List(code.head, code(3).copy(opcode = ORA)) ++ code.drop(4)
|
||||
},
|
||||
)
|
||||
|
||||
val SimplifiableIndexChanging = new RuleBasedAssemblyOptimization("Simplifiable index changing",
|
||||
|
@ -962,4 +962,28 @@ class AssemblyOptimizationSuite extends FunSuite with Matchers {
|
||||
m.readWord(0xc008) should equal(10)
|
||||
}
|
||||
}
|
||||
|
||||
test("Optimize certain bitmasking operations") {
|
||||
val code =
|
||||
"""
|
||||
|byte output @$c000
|
||||
|const byte c = 4
|
||||
|
|
||||
|noinline void inc(byte x, byte y) {
|
||||
| if x & c != 0 || y & c != 0 { output += 1 }
|
||||
|}
|
||||
|
|
||||
|void main() {
|
||||
| output = 0
|
||||
| inc(0, 0)
|
||||
| inc(4, 0) // ↑
|
||||
| inc(4, 4) // ↑
|
||||
| inc(0, 4) // ↑
|
||||
|}
|
||||
|""".stripMargin
|
||||
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Motorola6809)(
|
||||
code) { m =>
|
||||
m.readByte(0xc000) should equal(code.count(_ == '↑'))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user