mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-01 06:29:53 +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)
|
||||
case _ => ()
|
||||
}
|
||||
val prepareAE = Z80ExpressionCompiler.compileToA(ctx, r) ++
|
||||
List(ZLine.ld8(ZRegister.E, ZRegister.A)) ++
|
||||
Z80ExpressionCompiler.stashDEIfChanged(ctx, Z80ExpressionCompiler.compileToA(ctx, l))
|
||||
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)) ++
|
||||
Z80ExpressionCompiler.stashDEIfChanged(ctx, Z80ExpressionCompiler.compileToA(ctx, l))
|
||||
}
|
||||
val calculateFlags = if (ComparisonType.isSigned(compType) && ctx.options.flag(CompilationFlag.EmitZ80Opcodes)) {
|
||||
val fixup = ctx.nextLabel("co")
|
||||
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