mirror of
https://github.com/KarolS/millfork.git
synced 2024-08-27 14:29:40 +00:00
8080: improve comparisons against constants
This commit is contained in:
parent
51a6ec9d73
commit
2a233930e8
@ -26,9 +26,13 @@ object Z80Comparisons {
|
|||||||
return compile8BitComparison(ctx, ComparisonType.flip(compType), r, l, branches)
|
return compile8BitComparison(ctx, ComparisonType.flip(compType), r, l, branches)
|
||||||
case _ => ()
|
case _ => ()
|
||||||
}
|
}
|
||||||
val prepareAE = Z80ExpressionCompiler.compileToA(ctx, r) ++
|
val prepareAE = Z80ExpressionCompiler.compileToA(ctx, r) match {
|
||||||
|
case List(ZLine0(ZOpcode.LD, TwoRegisters(ZRegister.A, ZRegister.IMM_8), param)) =>
|
||||||
|
Z80ExpressionCompiler.compileToA(ctx, l) :+ ZLine.ldImm8(ZRegister.E, param)
|
||||||
|
case compiledR => compiledR ++
|
||||||
List(ZLine.ld8(ZRegister.E, ZRegister.A)) ++
|
List(ZLine.ld8(ZRegister.E, ZRegister.A)) ++
|
||||||
Z80ExpressionCompiler.stashDEIfChanged(ctx, Z80ExpressionCompiler.compileToA(ctx, l))
|
Z80ExpressionCompiler.stashDEIfChanged(ctx, Z80ExpressionCompiler.compileToA(ctx, l))
|
||||||
|
}
|
||||||
val calculateFlags = if (ComparisonType.isSigned(compType) && ctx.options.flag(CompilationFlag.EmitZ80Opcodes)) {
|
val calculateFlags = if (ComparisonType.isSigned(compType) && ctx.options.flag(CompilationFlag.EmitZ80Opcodes)) {
|
||||||
val fixup = ctx.nextLabel("co")
|
val fixup = ctx.nextLabel("co")
|
||||||
List(
|
List(
|
||||||
|
@ -691,4 +691,21 @@ class AssemblyOptimizationSuite extends FunSuite with Matchers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("Simple flags") {
|
||||||
|
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Intel8080)(
|
||||||
|
"""
|
||||||
|
| byte output @ $c000
|
||||||
|
| void main() {
|
||||||
|
| output = 0
|
||||||
|
| if f() & 1 != 0 {
|
||||||
|
| output += 1
|
||||||
|
| }
|
||||||
|
| }
|
||||||
|
| noinline byte f() = 1
|
||||||
|
""".stripMargin
|
||||||
|
) { m =>
|
||||||
|
m.readByte(0xc000) should equal(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user