1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-05-31 18:41:30 +00:00

65816: Various codegen bugfixes

This commit is contained in:
Karol Stasiak 2020-09-22 17:59:14 +02:00
parent c9f602b049
commit 1decf2f087
4 changed files with 24 additions and 7 deletions

View File

@ -31,6 +31,12 @@ object SixteenOptimizations {
(Elidable & HasOpcode(XBA) & DoesntMatterWhatItDoesWith(State.A, State.AH, State.N, State.Z)) ~~> { code =>
Nil
},
(Elidable & HasOpcode(XBA) & DoesntMatterWhatItDoesWith(State.N, State.Z) & HasAccu8 & HasIndex8) ~
(Elidable & HasOpcode(TAX)) ~
(Elidable & HasOpcode(XBA)) ~
(Elidable & HasOpcode(TXA) & DoesntMatterWhatItDoesWith(State.X, State.AH)) ~~> { code =>
List(code.head)
},
)
val RepSepWeakening = new RuleBasedAssemblyOptimization("REP/SEP weakening",

View File

@ -788,7 +788,7 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] {
if (exprType.size > target.typ.size) {
ctx.log.error(s"Variable `$target.name` is too small", expr.position)
Nil
} else if (exprType.size == 2 && target.typ.size == 2 && ctx.options.flag(CompilationFlag.EmitNative65816Opcodes)) {
} else if (exprType.size == 2 && AbstractExpressionCompiler.getExpressionType(ctx, expr).size == 2 && target.typ.size == 2 && ctx.options.flag(CompilationFlag.EmitNative65816Opcodes)) {
AssemblyLine.accu16 :: (AssemblyLine.variable(ctx, LDA_W, source) ++ AssemblyLine.variable(ctx, STA_W, target) :+ AssemblyLine.accu8)
} else {
val copyFromLo = List.tabulate(exprType.size)(i => AssemblyLine.variable(ctx, LDA, source, i) ++ AssemblyLine.variable(ctx, STA, target, i))

View File

@ -785,12 +785,18 @@ object MosAssembler {
na(LDA, LongIndexedY, 0xB7)
na(LDA, LongAbsolute, 0xAF)
na(LDA, LongAbsoluteX, 0xBF)
em(CMP, Stack, 0xA3)
em(CMP, IndexedSY, 0xB3)
na(CMP, LongIndexedZ, 0xA7)
na(CMP, LongIndexedY, 0xB7)
na(CMP, LongAbsolute, 0xAF)
na(CMP, LongAbsoluteX, 0xBF)
em(CMP, Stack, 0xC3)
em(CMP, IndexedSY, 0xD3)
na(CMP, LongIndexedZ, 0xC7)
na(CMP, LongIndexedY, 0xD7)
na(CMP, LongAbsolute, 0xCF)
na(CMP, LongAbsoluteX, 0xDF)
em(SBC, Stack, 0xE3)
em(SBC, IndexedSY, 0xF3)
na(SBC, LongIndexedZ, 0xE7)
na(SBC, LongIndexedY, 0xF7)
na(SBC, LongAbsolute, 0xEF)
na(SBC, LongAbsoluteX, 0xFF)
em(COP, Immediate, 0x02)
em(XBA, Implied, 0xEB)

View File

@ -10,6 +10,7 @@ object EmuUnoptimizedCrossPlatformRun {
def apply(platforms: Cpu.Value*)(source: String)(verifier: MemoryBank => Unit): Unit = {
val (_, mm) = if (platforms.contains(Cpu.Mos) || platforms.contains(Cpu.StrictMos)) EmuUnoptimizedRun.apply2(source) else Timings(-1, -1) -> null
val (_, mc) = if (platforms.contains(Cpu.Cmos)) EmuUnoptimizedCmosRun.apply2(source) else Timings(-1, -1) -> null
val (_, ma) = if (platforms.contains(Cpu.Sixteen)) EmuUnoptimizedNative65816Run.apply2(source) else Timings(-1, -1) -> null
val (_, mn) = if (platforms.contains(Cpu.Ricoh)) EmuUnoptimizedRicohRun.apply2(source) else Timings(-1, -1) -> null
val (_, mz) = if (platforms.contains(Cpu.Z80)) EmuUnoptimizedZ80Run.apply2(source) else Timings(-1, -1) -> null
val (_, mi) = if (platforms.contains(Cpu.Intel8080)) EmuUnoptimizedIntel8080Run.apply2(source) else Timings(-1, -1) -> null
@ -24,6 +25,10 @@ object EmuUnoptimizedCrossPlatformRun {
println(f"Running Ricoh")
verifier(mn)
}
if (Settings.enableWdc85816Tests && platforms.contains(Cpu.Sixteen)) {
println(f"Running 65816")
verifier(ma)
}
if (Settings.enable65C02Tests && platforms.contains(Cpu.Cmos)) {
println(f"Running 65C02")
verifier(mc)