mirror of
https://github.com/irmen/prog8.git
synced 2024-10-18 01:24:51 +00:00
40 lines
940 B
Plaintext
40 lines
940 B
Plaintext
|
%import textio
|
||
|
|
||
|
; The "Byte Sieve" test. https://en.wikipedia.org/wiki/Byte_Sieve
|
||
|
|
||
|
main {
|
||
|
sub start() {
|
||
|
|
||
|
const ubyte ITERS = 10
|
||
|
uword count
|
||
|
uword i
|
||
|
uword prime
|
||
|
uword k
|
||
|
const uword SIZEPL = 8191
|
||
|
uword @zp flags_ptr = memory("flags", SIZEPL, $100)
|
||
|
|
||
|
txt.print("calculating...\n")
|
||
|
|
||
|
repeat ITERS {
|
||
|
sys.memset(flags_ptr, SIZEPL, 1)
|
||
|
count = 0
|
||
|
for i in 0 to SIZEPL-1 {
|
||
|
if @(flags_ptr+i) {
|
||
|
prime = i + i + 3
|
||
|
k = i + prime
|
||
|
while k <= SIZEPL-1 {
|
||
|
@(flags_ptr + k) = false
|
||
|
k += prime
|
||
|
}
|
||
|
; txt.print_uw(prime)
|
||
|
; txt.spc()
|
||
|
count++
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
txt.print_uw(count)
|
||
|
txt.print(" primes\n")
|
||
|
}
|
||
|
}
|