mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-10 20:29:35 +00:00
Interrupt handler optimization
This commit is contained in:
parent
341466b198
commit
9410b8f9e3
@ -32,6 +32,7 @@ object OptimizationPresets {
|
|||||||
VariableToRegisterOptimization,
|
VariableToRegisterOptimization,
|
||||||
AlwaysGoodOptimizations.PoinlessLoadBeforeAnotherLoad,
|
AlwaysGoodOptimizations.PoinlessLoadBeforeAnotherLoad,
|
||||||
AlwaysGoodOptimizations.PointlessOperationPairRemoval,
|
AlwaysGoodOptimizations.PointlessOperationPairRemoval,
|
||||||
|
AlwaysGoodOptimizations.PointlessOperationPairRemoval2,
|
||||||
AlwaysGoodOptimizations.PoinlessLoadBeforeAnotherLoad,
|
AlwaysGoodOptimizations.PoinlessLoadBeforeAnotherLoad,
|
||||||
LaterOptimizations.PointlessLoadAfterStore,
|
LaterOptimizations.PointlessLoadAfterStore,
|
||||||
AlwaysGoodOptimizations.PointlessOperationAfterLoad,
|
AlwaysGoodOptimizations.PointlessOperationAfterLoad,
|
||||||
@ -146,6 +147,7 @@ object OptimizationPresets {
|
|||||||
AlwaysGoodOptimizations.PointlessMathFromFlow,
|
AlwaysGoodOptimizations.PointlessMathFromFlow,
|
||||||
AlwaysGoodOptimizations.PointlessOperationAfterLoad,
|
AlwaysGoodOptimizations.PointlessOperationAfterLoad,
|
||||||
AlwaysGoodOptimizations.PointlessOperationPairRemoval,
|
AlwaysGoodOptimizations.PointlessOperationPairRemoval,
|
||||||
|
AlwaysGoodOptimizations.PointlessOperationPairRemoval2,
|
||||||
AlwaysGoodOptimizations.PointlessRegisterTransfers,
|
AlwaysGoodOptimizations.PointlessRegisterTransfers,
|
||||||
AlwaysGoodOptimizations.PointlessRegisterTransfersBeforeCompare,
|
AlwaysGoodOptimizations.PointlessRegisterTransfersBeforeCompare,
|
||||||
AlwaysGoodOptimizations.PointlessRegisterTransfersBeforeReturn,
|
AlwaysGoodOptimizations.PointlessRegisterTransfersBeforeReturn,
|
||||||
|
@ -194,6 +194,47 @@ object AlwaysGoodOptimizations {
|
|||||||
operationPairBuilder(DEY, INY, Not(ConcernsX) & Not(ReadsNOrZ)),
|
operationPairBuilder(DEY, INY, Not(ConcernsX) & Not(ReadsNOrZ)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
private def operationPairBuilder2(op1: Opcode.Value, op1extra: AssemblyLinePattern, middle: AssemblyLinePattern,op2: Opcode.Value, op2extra: AssemblyLinePattern) = {
|
||||||
|
(HasOpcode(op1) & Elidable & op1extra) ~
|
||||||
|
(Linear & middle).*.capture(1) ~
|
||||||
|
(HasOpcode(op2) & Elidable & op2extra) ~~> { (_, ctx) =>
|
||||||
|
ctx.get[List[AssemblyLine]](1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val PointlessOperationPairRemoval2 = new RuleBasedAssemblyOptimization("Pointless operation pair 2",
|
||||||
|
needsFlowInfo = FlowInfoRequirement.BackwardFlow,
|
||||||
|
operationPairBuilder2(
|
||||||
|
PHA, Anything,
|
||||||
|
Not(ConcernsStack),
|
||||||
|
PLA, DoesntMatterWhatItDoesWith(State.A, State.N, State.Z)),
|
||||||
|
operationPairBuilder2(
|
||||||
|
PHX, Anything,
|
||||||
|
Not(ConcernsStack),
|
||||||
|
PLX, DoesntMatterWhatItDoesWith(State.X, State.N, State.Z)),
|
||||||
|
operationPairBuilder2(
|
||||||
|
PHY, Anything,
|
||||||
|
Not(ConcernsStack),
|
||||||
|
PLY, DoesntMatterWhatItDoesWith(State.Y, State.N, State.Z)),
|
||||||
|
operationPairBuilder2(
|
||||||
|
INX, DoesntMatterWhatItDoesWith(State.X, State.N, State.Z),
|
||||||
|
Anything,
|
||||||
|
DEX, DoesntMatterWhatItDoesWith(State.X, State.N, State.Z)),
|
||||||
|
operationPairBuilder2(
|
||||||
|
DEX, DoesntMatterWhatItDoesWith(State.X, State.N, State.Z),
|
||||||
|
Anything,
|
||||||
|
INX, DoesntMatterWhatItDoesWith(State.X, State.N, State.Z)),
|
||||||
|
operationPairBuilder2(
|
||||||
|
INY, DoesntMatterWhatItDoesWith(State.Y, State.N, State.Z),
|
||||||
|
Anything,
|
||||||
|
DEY, DoesntMatterWhatItDoesWith(State.Y, State.N, State.Z)),
|
||||||
|
operationPairBuilder2(
|
||||||
|
DEY, DoesntMatterWhatItDoesWith(State.Y, State.N, State.Z),
|
||||||
|
Anything,
|
||||||
|
INY, DoesntMatterWhatItDoesWith(State.Y, State.N, State.Z)),
|
||||||
|
)
|
||||||
|
|
||||||
val PointlessStackStashing = new RuleBasedAssemblyOptimization("Pointless stack stashing",
|
val PointlessStackStashing = new RuleBasedAssemblyOptimization("Pointless stack stashing",
|
||||||
needsFlowInfo = FlowInfoRequirement.NoRequirement,
|
needsFlowInfo = FlowInfoRequirement.NoRequirement,
|
||||||
(Elidable & HasOpcode(LDA) & MatchAddrMode(0) & MatchParameter(1)) ~
|
(Elidable & HasOpcode(LDA) & MatchAddrMode(0) & MatchParameter(1)) ~
|
||||||
|
@ -145,8 +145,10 @@ object ReverseFlowAnalyzer {
|
|||||||
currentImportance = currentImportance.copy(n = Important)
|
currentImportance = currentImportance.copy(n = Important)
|
||||||
case AssemblyLine(SED | CLD, _, _, _) =>
|
case AssemblyLine(SED | CLD, _, _, _) =>
|
||||||
currentImportance = currentImportance.copy(d = Unimportant)
|
currentImportance = currentImportance.copy(d = Unimportant)
|
||||||
case AssemblyLine(RTS | RTI, _, _, _) =>
|
case AssemblyLine(RTS, _, _, _) =>
|
||||||
currentImportance = finalImportance
|
currentImportance = finalImportance
|
||||||
|
case AssemblyLine(RTI, _, _, _) =>
|
||||||
|
currentImportance = new CpuImportance(a = Unimportant, x = Unimportant, y = Unimportant, z = Unimportant, n = Unimportant, c = Unimportant, v = Unimportant, d = Unimportant)
|
||||||
case AssemblyLine(DISCARD_XF, _, _, _) =>
|
case AssemblyLine(DISCARD_XF, _, _, _) =>
|
||||||
currentImportance = currentImportance.copy(x = Unimportant, n = Unimportant, z = Unimportant, c = Unimportant, v = Unimportant)
|
currentImportance = currentImportance.copy(x = Unimportant, n = Unimportant, z = Unimportant, c = Unimportant, v = Unimportant)
|
||||||
case AssemblyLine(DISCARD_YF, _, _, _) =>
|
case AssemblyLine(DISCARD_YF, _, _, _) =>
|
||||||
|
@ -2,7 +2,7 @@ package millfork.test
|
|||||||
|
|
||||||
import millfork.{Cpu, OptimizationPresets}
|
import millfork.{Cpu, OptimizationPresets}
|
||||||
import millfork.assembly.opt.{AlwaysGoodOptimizations, LaterOptimizations, VariableToRegisterOptimization}
|
import millfork.assembly.opt.{AlwaysGoodOptimizations, LaterOptimizations, VariableToRegisterOptimization}
|
||||||
import millfork.test.emu.{EmuBenchmarkRun, EmuUltraBenchmarkRun, EmuRun}
|
import millfork.test.emu.{EmuBenchmarkRun, EmuRun, EmuSuperOptimizedRun, EmuUltraBenchmarkRun}
|
||||||
import org.scalatest.{FunSuite, Matchers}
|
import org.scalatest.{FunSuite, Matchers}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -292,4 +292,14 @@ class AssemblyOptimizationSuite extends FunSuite with Matchers {
|
|||||||
m.readWord(0xc00c) should equal(0x201)
|
m.readWord(0xc00c) should equal(0x201)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("Empty interrupt"){
|
||||||
|
EmuSuperOptimizedRun(
|
||||||
|
"""
|
||||||
|
| void main () {
|
||||||
|
| }
|
||||||
|
| interrupt void i (){}
|
||||||
|
|
|
||||||
|
""".stripMargin)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user