From b6eef3612f57a188d941d002e64dd395efbf3367 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 12 Aug 2022 22:02:44 +0200 Subject: [PATCH] added some ported bench8 test programs --- compiler/res/version.txt | 2 +- compiler/test/ZeropageTests.kt | 4 ++-- docs/source/todo.rst | 1 - examples/bench8/crc16.p8 | 30 ++++++++++++++++++++++++ examples/bench8/crc32.p8 | 42 ++++++++++++++++++++++++++++++++++ examples/bench8/crc8.p8 | 30 ++++++++++++++++++++++++ examples/bench8/pow.p8 | 42 ++++++++++++++++++++++++++++++++++ examples/bench8/readme.txt | 1 + 8 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 examples/bench8/crc16.p8 create mode 100644 examples/bench8/crc32.p8 create mode 100644 examples/bench8/crc8.p8 create mode 100644 examples/bench8/pow.p8 create mode 100644 examples/bench8/readme.txt diff --git a/compiler/res/version.txt b/compiler/res/version.txt index 47ea0f6ff..c9dc04908 100644 --- a/compiler/res/version.txt +++ b/compiler/res/version.txt @@ -1 +1 @@ -8.4-dev +8.4 diff --git a/compiler/test/ZeropageTests.kt b/compiler/test/ZeropageTests.kt index bdb9fecc7..ea8fd3e2d 100644 --- a/compiler/test/ZeropageTests.kt +++ b/compiler/test/ZeropageTests.kt @@ -120,9 +120,9 @@ class TestC64Zeropage: FunSpec({ val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, c64target, 999u)) zp1.availableBytes() shouldBe 18 val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false, false, c64target, 999u)) - zp2.availableBytes() shouldBe 92 + zp2.availableBytes() shouldBe 88 val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, false, c64target, 999u)) - zp3.availableBytes() shouldBe 102 + zp3.availableBytes() shouldBe 97 val zp4 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, c64target, 999u)) zp4.availableBytes() shouldBe 207 zp4.allocate(listOf("test"), DataType.UBYTE, null, null, errors) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index c50f8af7c..066ca40b7 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,6 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- try more benchmarks from https://gglabs.us/node/2293 - check that all examples still function correctly ... diff --git a/examples/bench8/crc16.p8 b/examples/bench8/crc16.p8 new file mode 100644 index 000000000..42662e808 --- /dev/null +++ b/examples/bench8/crc16.p8 @@ -0,0 +1,30 @@ +%import textio + +main { + + sub crc16(uword data, uword length) -> uword { + uword crc = 0 + repeat length { + crc ^= @(data) << $0008 + repeat 8 { + if crc & $8000 + crc = (crc<<1)^$1021 + else + crc<<=1 + } + data++ + } + return crc + } + + sub start() { + txt.print("calculating...") + c64.SETTIM(0,0,0) + uword crc = crc16($e000, $2000) + txt.print_uwhex(crc, true) ; should be $ffd0 + txt.nl() + txt.print_uw(c64.RDTIM16()) + txt.print(" jiffies") + sys.wait(100) + } +} diff --git a/examples/bench8/crc32.p8 b/examples/bench8/crc32.p8 new file mode 100644 index 000000000..070ffe5f5 --- /dev/null +++ b/examples/bench8/crc32.p8 @@ -0,0 +1,42 @@ +%import textio + +main { + sub crc32(uword data, uword length) { + ; because prog8 doesn't have 32 bits integers, we have to split up the calucation over 2 words. + ; result in cx16.r0 (high word) and cx1.r1 (low word). + cx16.r0 = 0 + cx16.r1 = 0 + repeat length { + cx16.r0 ^= @(data) << $0008 + repeat 8 { + if cx16.r0 & $8000 { + sys.clear_carry() + rol(cx16.r1) + rol(cx16.r0) + cx16.r0 ^= $04c1 + cx16.r1 ^= $1db7 + } + else { + sys.clear_carry() + rol(cx16.r1) + rol(cx16.r0) + } + } + data++ + } + cx16.r0 ^= $ffff + cx16.r1 ^= $ffff + } + + sub start() { + txt.print("calculating...") + c64.SETTIM(0,0,0) + crc32($e000, $2000) + txt.print_uwhex(cx16.r0, true) + txt.print_uwhex(cx16.r1, false) + txt.nl() + txt.print_uw(c64.RDTIM16()) + txt.print(" jiffies") + sys.wait(100) + } +} diff --git a/examples/bench8/crc8.p8 b/examples/bench8/crc8.p8 new file mode 100644 index 000000000..04f6e2bff --- /dev/null +++ b/examples/bench8/crc8.p8 @@ -0,0 +1,30 @@ +%import textio + +main { + + sub crc8(uword data, uword length) -> ubyte { + ubyte crc = 0 + repeat length { + crc ^= @(data) + repeat 8 { + if crc & $80 + crc = (crc<<1)^$1d + else + crc<<=1 + } + data++ + } + return crc + } + + sub start() { + txt.print("calculating...") + c64.SETTIM(0,0,0) + ubyte crc = crc8($e000, $2000) + txt.print_ubhex(crc, true) ; should be $a2 + txt.nl() + txt.print_uw(c64.RDTIM16()) + txt.print(" jiffies") + sys.wait(100) + } +} diff --git a/examples/bench8/pow.p8 b/examples/bench8/pow.p8 new file mode 100644 index 000000000..9e9cc7f38 --- /dev/null +++ b/examples/bench8/pow.p8 @@ -0,0 +1,42 @@ +%import textio +%import floats + +main { + const ubyte N_ITER = 10 + const ubyte SIZE = 32 + + float[SIZE] array = 0.0 + + sub testpow(float x, uword y) -> float { + float tmp = x + if y==0 + return 1 + repeat y-1 { + tmp *= x + } + return tmp + } + + sub start() { + txt.print("calculating...") + c64.SETTIM(0,0,0) + + float res + uword i + ubyte j + for i in 0 to N_ITER-1 { + for j in 0 to SIZE-1 { + array[j] += testpow(2.5/(i+1.0), j) + } + } + for j in 0 to SIZE-1 { + res += array[j] + } + + floats.print_f(res) + txt.nl() + txt.print_uw(c64.RDTIM16()) + txt.print(" jiffies") + sys.wait(100) + } +} diff --git a/examples/bench8/readme.txt b/examples/bench8/readme.txt new file mode 100644 index 000000000..a0d5f746f --- /dev/null +++ b/examples/bench8/readme.txt @@ -0,0 +1 @@ +Contains several benchmarks from https://gglabs.us/node/2293 ported to prog8.