aboutsummaryrefslogtreecommitdiff
path: root/forth/forth/sieve.fs
blob: c5e3cd530e6f854b65eaa31171867d04d1b53470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
\ *******************************************************************
\                                                                   *
\    Filename:      sieve.txt                                       *
\    Date:          31.12.2013                                      *
\    FF Version:    5.0                                             *
\    MCU:           PIC 18 24 30 33 Atmega                          *
\    Copyright:     Mikael Nordman                                  *
\    Author:        Mikael Nordman                                  *
\ *******************************************************************
\ FlashForth is licensed according to the GNU General Public License*
\ *******************************************************************
\ This normal sieve requires 8 KBytes of RAM.
\ It will not run on most PICs due to lack of memory.
\ sieve2 requires 1 Kbyte of RAM.

-sieve
marker -sieve
decimal ram
8191 constant size inlined
ram align here size allot constant flags inlined
: sieve
  flags size 1 fill
  0 1 !p>r size 1-
  for
    flags @p + c@
    if                              
        @p dup + 3 + 
        dup @p +
        begin
           dup size  <
        while
           0 over flags + c!
           over +
        repeat
        drop drop 1+ 
     then
     p+
  next
  r>p
  . ." primes " cr ;

: bench ticks sieve ticks swap - u. ." milliseconds" cr ;