2022-07-31 09:58:27 +00:00
|
|
|
%import textio
|
|
|
|
%import floats
|
|
|
|
|
|
|
|
; The "Byte Sieve" test. https://en.wikipedia.org/wiki/Byte_Sieve
|
2023-06-03 17:14:45 +00:00
|
|
|
; Note: this program can be compiled for multiple target systems.
|
2022-07-31 09:58:27 +00:00
|
|
|
|
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
|
|
|
|
|
|
|
|
const ubyte ITERS = 10
|
|
|
|
uword count
|
|
|
|
uword i
|
|
|
|
uword prime
|
|
|
|
uword k
|
|
|
|
const uword SIZEPL = 8191
|
2022-08-12 22:14:19 +00:00
|
|
|
uword @zp flags_ptr = memory("flags", SIZEPL, $100)
|
2022-07-31 09:58:27 +00:00
|
|
|
|
2022-09-27 20:36:10 +00:00
|
|
|
txt.print_ub(ITERS)
|
|
|
|
txt.print(" iterations, calculating...\n")
|
2022-07-31 09:58:27 +00:00
|
|
|
|
2023-09-05 20:59:36 +00:00
|
|
|
cbm.SETTIM(0, 0, 0)
|
|
|
|
|
2022-07-31 09:58:27 +00:00
|
|
|
repeat ITERS {
|
|
|
|
sys.memset(flags_ptr, SIZEPL, 1)
|
|
|
|
count = 0
|
|
|
|
for i in 0 to SIZEPL-1 {
|
2023-09-05 20:59:36 +00:00
|
|
|
if flags_ptr[i] {
|
|
|
|
prime = i*2 + 3
|
2022-07-31 09:58:27 +00:00
|
|
|
k = i + prime
|
2023-09-05 20:59:36 +00:00
|
|
|
while k < SIZEPL {
|
|
|
|
flags_ptr[k] = false
|
2022-07-31 09:58:27 +00:00
|
|
|
k += prime
|
|
|
|
}
|
|
|
|
; txt.print_uw(prime)
|
|
|
|
; txt.spc()
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
txt.print_uw(count)
|
|
|
|
txt.print(" primes\n")
|
|
|
|
|
2023-04-28 21:13:03 +00:00
|
|
|
float time = cbm.RDTIM16() as float / 60.0
|
2022-07-31 09:58:27 +00:00
|
|
|
floats.print_f(time)
|
|
|
|
txt.print(" sec total = ")
|
|
|
|
floats.print_f(time/ITERS)
|
|
|
|
txt.print(" sec per iteration\n")
|
2023-09-05 20:59:36 +00:00
|
|
|
sys.wait(9999)
|
2022-07-31 09:58:27 +00:00
|
|
|
}
|
|
|
|
}
|