1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-06-25 19:29:49 +00:00

6502: Allow comparing words on stack

This commit is contained in:
Karol Stasiak 2019-07-31 22:32:41 +02:00
parent a3a168b90b
commit 5c5bfa3f00
2 changed files with 50 additions and 3 deletions

View File

@ -661,15 +661,15 @@ object BuiltIns {
case (_, Some(lc), rv: VariableExpression, None) =>
return compileWordComparison(ctx, ComparisonType.flip(compType), rhs, lhs, branches)
case (v: VariableExpression, None, _, Some(rc)) =>
val lva = env.get[VariableInMemory](v.name)
val lva = env.get[Variable](v.name)
(Nil,
AssemblyLine.variable(ctx, CMP, lva, 1),
AssemblyLine.variable(ctx, CMP, lva, 0),
List(AssemblyLine.immediate(CMP, rc.hiByte.quickSimplify)),
List(AssemblyLine.immediate(CMP, rc.loByte.quickSimplify)))
case (lv: VariableExpression, None, rv: VariableExpression, None) =>
val lva = env.get[VariableInMemory](lv.name)
val rva = env.get[VariableInMemory](rv.name)
val lva = env.get[Variable](lv.name)
val rva = env.get[Variable](rv.name)
(Nil,
AssemblyLine.variable(ctx, CMP, lva, 1),
AssemblyLine.variable(ctx, CMP, lva, 0),

View File

@ -493,4 +493,51 @@ class ComparisonSuite extends FunSuite with Matchers {
m.readByte(0xc000) should equal(11)
}
}
test("Various word comparisons") {
val code =
"""
| byte output @$c000
| void main() {
| word small1,medium1,big1
| stack word small2,medium2,big2
| small1 = id(1)
| small2 = id(1)
| medium1 = id(256)
| medium2 = id(256)
| big1 = id(5423)
| big2 = id(5423)
| output = 0
| if small1 == small2 { output += 1 } //
| if medium1 == medium2 { output += 1 } //
| if big1 == big2 { output += 1 } //
| if big2 > small2 { output += 1 } //
| if big2 > small1 { output += 1 } //
| if big1 > small2 { output += 1 } //
| if big1 > small1 { output += 1 } //
| if big2 >= small2 { output += 1 } //
| if big2 >= small1 { output += 1 } //
| if big1 >= small2 { output += 1 } //
| if big1 >= small1 { output += 1 } //
| if small1 == 1 { output += 1 } //
| if small2 == 1 { output += 1 } //
| if 1 == small1 { output += 1 } //
| if 1 == small2 { output += 1 } //
| if big1 == 5423 { output += 1 } //
| if big2 == 5423 { output += 1 } //
| if 5423 == big1 { output += 1 } //
| if 5423 == big2 { output += 1 } //
| if big1 != 6523 { output += 1 } //
| if big2 != 6523 { output += 1 } //
| if 6523 != big1 { output += 1 } //
| if 6523 != big2 { output += 1 } //
| if small2 != medium2 { output += 1 } //
| if small2 != medium1 { output += 1 } //
| if small1 != medium2 { output += 1 } //
| if small1 != medium1 { output += 1 } //
| }
| noinline word id(word x) = x
|""".stripMargin
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Sixteen, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(code) {m => m.readByte(0xc000) should equal (code.count(_ == '↑'))}
}
}