1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-12-23 08:29:35 +00:00

Fix the sieve benchmark

This commit is contained in:
Karol Stasiak 2019-10-23 11:52:42 +02:00
parent 9beac45e99
commit 010647682a
5 changed files with 32 additions and 3 deletions

View File

@ -22,6 +22,10 @@
* Fixed a bug with variable overlapping (#11).
* 6502: Fixed a bug with flow analysis during optimizations.
* 6502: Fixed a bug with certain 16-bit additions.
* 8080: Fixed and optimized 16-bit comparisons.
* 8080: Optimized some library functions.

View File

@ -214,6 +214,8 @@ object CpuStatus {
v = AnyStatus,
z = AnyStatus,
n = AnyStatus,
a0 = AnyStatus,
a7 = AnyStatus,
d = SingleStatus(false),
m = SingleStatus(true),
w = SingleStatus(true),
@ -231,6 +233,8 @@ object CpuStatus {
v = AnyStatus,
z = AnyStatus,
n = AnyStatus,
a0 = AnyStatus,
a7 = AnyStatus,
d = SingleStatus(false),
m = SingleStatus(true),
w = SingleStatus(true),
@ -249,6 +253,8 @@ object CpuStatus {
v = AnyStatus,
z = AnyStatus,
n = AnyStatus,
a0 = AnyStatus,
a7 = AnyStatus,
d = AnyStatus,
m = AnyStatus,
w = AnyStatus,
@ -266,6 +272,8 @@ object CpuStatus {
v = AnyStatus,
z = AnyStatus,
n = AnyStatus,
a0 = AnyStatus,
a7 = AnyStatus,
d = SingleStatus(false),
m = AnyStatus,
w = AnyStatus,
@ -283,6 +291,8 @@ object CpuStatus {
v = AnyStatus,
z = AnyStatus,
n = AnyStatus,
a0 = AnyStatus,
a7 = AnyStatus,
d = SingleStatus(false),
m = AnyStatus,
w = AnyStatus,

View File

@ -45,7 +45,7 @@ object PseudoregisterBuiltIns {
case List(AssemblyLine0(LDA, Immediate, l), AssemblyLine0(LDX, Immediate, h)) =>
if (subtract) constant -= h.asl(8).+(l).quickSimplify
else constant += h.asl(8).+(l).quickSimplify
case List(l@AssemblyLine0(LDA, Absolute | ZeroPage | Immediate, _), h@AssemblyLine0(LDX, Absolute | ZeroPage | Immediate, _)) =>
case List(l@AssemblyLine0(LDA, Absolute | ZeroPage | Immediate | LongAbsolute, _), h@AssemblyLine0(LDX, Absolute | ZeroPage | Immediate | LongAbsolute, _)) =>
if (subtract) niceReads.+=(List(AssemblyLine.implied(SEC), l.copy(opcode = SBC)) -> List(h.copy(opcode = SBC)))
else niceReads += (List(AssemblyLine.implied(CLC), l.copy(opcode = ADC)) -> List(h.copy(opcode = ADC)))
counter += 1
@ -68,7 +68,7 @@ object PseudoregisterBuiltIns {
if (constant.isQuiteNegative) {
niceReads += List(AssemblyLine.implied(CLC), AssemblyLine.immediate(ADC, constant.loByte)) -> List(AssemblyLine.immediate(ADC, constant.hiByte))
} else {
val negC = Constant.Zero.-(constant).quickSimplify.quickSimplify
val negC = Constant.WordZero.-(constant).quickSimplify.quickSimplify
niceReads += List(AssemblyLine.implied(SEC), AssemblyLine.immediate(SBC, negC.loByte)) -> List(AssemblyLine.immediate(SBC, negC.hiByte))
}
}

View File

@ -40,7 +40,7 @@ sealed trait Constant {
case _ => CompoundConstant(MathOperator.Shl, this, i)
}
def asl(i: Int): Constant = CompoundConstant(MathOperator.Shl, this, NumericConstant(i, 1))
def asl(i: Int): Constant = CompoundConstant(MathOperator.Shl, this, NumericConstant(i, requiredSize + i/8))
def requiredSize: Int

View File

@ -20,6 +20,21 @@ class WordMathSuite extends FunSuite with Matchers with AppendedClues {
""".stripMargin)(_.readWord(0xc000) should equal(1280))
}
test("Addition that was buggy") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)("""
| word output @$c000
| array X [$1000] align($100)
| void main () {
| output = f(1)
| }
| noinline word f(byte I) {
| word S
| S = X + nonet(I << 1)
| return S
| }
""".stripMargin)(_.readWord(0xc000) should equal(0x302))
}
test("Cast word addition") {
EmuCrossPlatformBenchmarkRun(Cpu.Sixteen, Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Intel8085, Cpu.Sharp, Cpu.Intel8086, Cpu.Motorola6809)("""
| byte output @$c000