1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-11-03 18:04:46 +00:00

6502: Crank up the optimizations

This commit is contained in:
Karol Stasiak 2018-08-07 21:37:25 +02:00
parent 8dd8415432
commit 02d6b5b71c
5 changed files with 40 additions and 4 deletions

View File

@ -186,7 +186,8 @@ object Main {
if (options.flag(CompilationFlag.DangerousOptimizations)) DangerousOptimizations.All else Nil if (options.flag(CompilationFlag.DangerousOptimizations)) DangerousOptimizations.All else Nil
).flatten ).flatten
val goodCycle = List.fill(optLevel - 2)(OptimizationPresets.Good ++ goodExtras).flatten val goodCycle = List.fill(optLevel - 2)(OptimizationPresets.Good ++ goodExtras).flatten
goodCycle ++ OptimizationPresets.AssOpt ++ extras ++ goodCycle val mainCycle = List.fill(optLevel - 1)(OptimizationPresets.AssOpt ++ extras).flatten
goodCycle ++ mainCycle ++ goodCycle
} }
// compile // compile

View File

@ -114,6 +114,9 @@ object OptimizationPresets {
AlwaysGoodOptimizations.PoinlessStoreBeforeStore, AlwaysGoodOptimizations.PoinlessStoreBeforeStore,
LaterOptimizations.PointlessLoadAfterStore, LaterOptimizations.PointlessLoadAfterStore,
AlwaysGoodOptimizations.PoinlessLoadBeforeAnotherLoad, AlwaysGoodOptimizations.PoinlessLoadBeforeAnotherLoad,
AlwaysGoodOptimizations.UnconditionalJumpRemoval,
AlwaysGoodOptimizations.AlwaysTakenJumpRemoval,
AlwaysGoodOptimizations.UnusedLabelRemoval,
LaterOptimizations.LoadingAfterShifting, LaterOptimizations.LoadingAfterShifting,
AlwaysGoodOptimizations.PointlessAccumulatorShifting, AlwaysGoodOptimizations.PointlessAccumulatorShifting,
@ -147,6 +150,9 @@ object OptimizationPresets {
AlwaysGoodOptimizations.IncrementingIndexRegistersAfterTransfer, AlwaysGoodOptimizations.IncrementingIndexRegistersAfterTransfer,
AlwaysGoodOptimizations.MathOperationOnTwoIdenticalMemoryOperands, AlwaysGoodOptimizations.MathOperationOnTwoIdenticalMemoryOperands,
LaterOptimizations.UseZeropageAddressingMode, LaterOptimizations.UseZeropageAddressingMode,
AlwaysGoodOptimizations.UnconditionalJumpRemoval,
AlwaysGoodOptimizations.AlwaysTakenJumpRemoval,
AlwaysGoodOptimizations.UnusedLabelRemoval,
LaterOptimizations.UseXInsteadOfStack, LaterOptimizations.UseXInsteadOfStack,
LaterOptimizations.UseYInsteadOfStack, LaterOptimizations.UseYInsteadOfStack,

View File

@ -680,7 +680,7 @@ object AlwaysGoodOptimizations {
val UnconditionalJumpRemoval = new RuleBasedAssemblyOptimization("Unconditional jump removal", val UnconditionalJumpRemoval = new RuleBasedAssemblyOptimization("Unconditional jump removal",
needsFlowInfo = FlowInfoRequirement.NoRequirement, needsFlowInfo = FlowInfoRequirement.NoRequirement,
(Elidable & HasOpcode(JMP) & HasAddrMode(Absolute) & MatchParameter(0)) ~ (Elidable & HasOpcode(JMP) & HasAddrModeIn(Absolute, Relative, LongAbsolute, LongRelative) & MatchParameter(0)) ~
(Elidable & LinearOrBranch).* ~ (Elidable & LinearOrBranch).* ~
(HasOpcode(LABEL) & MatchParameter(0)) ~~> (code => List(code.last)), (HasOpcode(LABEL) & MatchParameter(0)) ~~> (code => List(code.last)),
(Elidable & HasOpcode(BRA) & MatchParameter(0)) ~ (Elidable & HasOpcode(BRA) & MatchParameter(0)) ~

View File

@ -102,9 +102,11 @@ class WordMathSuite extends FunSuite with Matchers {
test("nesdev.com example") { test("nesdev.com example") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(""" EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)("""
| byte output @$c000 | byte output @$c000
| byte tile @$C3A6
| array map [256] @$c300 | array map [256] @$c300
| array b[2] | array b[2]
| void main () { | void main () {
| tile = 77
| output = get(5, 6) | output = get(5, 6)
| } | }
| byte get(byte mx, byte my) { | byte get(byte mx, byte my) {
@ -114,7 +116,27 @@ class WordMathSuite extends FunSuite with Matchers {
| p += map | p += map
| return p[my] | return p[my]
| } | }
""".stripMargin)(m => ()) """.stripMargin) { m =>
m.readByte(0xc3a6) should equal(77)
}
}
test("nesdev.com example 2") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)("""
| byte output @$c000
| byte tile @$C3A6
| array map [256] @$c300
| array b[2]
| void main () {
| tile = 77
| output = get(5, 6)
| }
| byte get(byte mx, byte my) {
| return map[((mx + 00000) << 5) + my]
| }
""".stripMargin){ m =>
m.readByte(0xc3a6) should equal(77)
}
} }
test("hi()/lo()") { test("hi()/lo()") {

View File

@ -14,13 +14,20 @@ object EmuOptimizedInlinedRun extends EmuRun(
ZeropageRegisterOptimizations.All ++ ZeropageRegisterOptimizations.All ++
OptimizationPresets.Good ++ OptimizationPresets.Good ++
OptimizationPresets.Good ++ OptimizationPresets.Good ++
OptimizationPresets.AssOpt ++
OptimizationPresets.Good ++ LaterOptimizations.Nmos ++ OptimizationPresets.Good ++ LaterOptimizations.Nmos ++
ZeropageRegisterOptimizations.All ++ ZeropageRegisterOptimizations.All ++
OptimizationPresets.AssOpt ++
OptimizationPresets.Good ++ LaterOptimizations.Nmos ++ OptimizationPresets.Good ++ LaterOptimizations.Nmos ++
ZeropageRegisterOptimizations.All ++ ZeropageRegisterOptimizations.All ++
OptimizationPresets.AssOpt ++
OptimizationPresets.AssOpt ++
OptimizationPresets.AssOpt ++
OptimizationPresets.Good ++
ZeropageRegisterOptimizations.All ++
OptimizationPresets.Good ++ OptimizationPresets.Good ++
ZeropageRegisterOptimizations.All ++ ZeropageRegisterOptimizations.All ++
OptimizationPresets.Good) { OptimizationPresets.AssOpt) {
override def inline: Boolean = true override def inline: Boolean = true
override def blastProcessing: Boolean = true override def blastProcessing: Boolean = true
} }