mirror of
https://github.com/KarolS/millfork.git
synced 2025-08-10 01:25:31 +00:00
6502: Correctly inlie variables that happen to be returned (fixes #32)
This commit is contained in:
@@ -858,6 +858,7 @@ object VariableToRegisterOptimization extends AssemblyOptimization[AssemblyLine]
|
|||||||
aCandidate: Option[String],
|
aCandidate: Option[String],
|
||||||
features: FeaturesForIndexRegisters,
|
features: FeaturesForIndexRegisters,
|
||||||
lines: List[(AssemblyLine, CpuImportance)]): TailRec[List[AssemblyLine]] = {
|
lines: List[(AssemblyLine, CpuImportance)]): TailRec[List[AssemblyLine]] = {
|
||||||
|
// only one of these will be defined:
|
||||||
val vx = xCandidate.getOrElse("-")
|
val vx = xCandidate.getOrElse("-")
|
||||||
val vy = yCandidate.getOrElse("-")
|
val vy = yCandidate.getOrElse("-")
|
||||||
val vz = zCandidate.getOrElse("-")
|
val vz = zCandidate.getOrElse("-")
|
||||||
@@ -911,7 +912,7 @@ object VariableToRegisterOptimization extends AssemblyOptimization[AssemblyLine]
|
|||||||
if opcodesIdentityTable(op) && th.name == vy =>
|
if opcodesIdentityTable(op) && th.name == vy =>
|
||||||
tailcall(inlineVars(xCandidate, yCandidate, zCandidate, aCandidate, features, xs)).map(l.copy(addrMode = AbsoluteY, parameter = features.identityArray) :: _)
|
tailcall(inlineVars(xCandidate, yCandidate, zCandidate, aCandidate, features, xs)).map(l.copy(addrMode = AbsoluteY, parameter = features.identityArray) :: _)
|
||||||
|
|
||||||
case (l@AssemblyLine0(LDA | TYA | TXA | TZA | CLA, _, _), _) :: xs if va != "" && isReturn(xs) =>
|
case (l@AssemblyLine0(LDA | TYA | TXA | TZA | CLA, _, _), _) :: xs if aCandidate.isDefined && isReturn(xs) =>
|
||||||
tailcall(inlineVars(xCandidate, yCandidate, zCandidate, aCandidate, features, xs)).map(l :: _)
|
tailcall(inlineVars(xCandidate, yCandidate, zCandidate, aCandidate, features, xs)).map(l :: _)
|
||||||
|
|
||||||
case (l@AssemblyLine0(LDA, _, _), _) :: (AssemblyLine0(op, Absolute | ZeroPage, MemoryAddressConstant(th)), _) :: xs
|
case (l@AssemblyLine0(LDA, _, _), _) :: (AssemblyLine0(op, Absolute | ZeroPage, MemoryAddressConstant(th)), _) :: xs
|
||||||
|
@@ -768,4 +768,26 @@ class AssemblyOptimizationSuite extends FunSuite with Matchers {
|
|||||||
m.readByte(0xc000) should equal(2)
|
m.readByte(0xc000) should equal(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("Inline variables correctly") {
|
||||||
|
EmuBenchmarkRun("""
|
||||||
|
|array arr = [2,2,2,1,1,2,2]
|
||||||
|
|noinline byte f() {
|
||||||
|
| byte i
|
||||||
|
| i = 0
|
||||||
|
| while true {
|
||||||
|
| if arr[i] == 1 { return i }
|
||||||
|
| i += 1
|
||||||
|
| }
|
||||||
|
| return $ff
|
||||||
|
|}
|
||||||
|
|volatile byte output @$c000
|
||||||
|
|void main() {
|
||||||
|
| output = f()
|
||||||
|
|}
|
||||||
|
|""".stripMargin
|
||||||
|
) { m =>
|
||||||
|
m.readByte(0xc000) should equal(3)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user