Author: jisom
Date: Sun Jan 29 17:30:20 2006
New Revision: 11378

Modified:
   trunk/examples/shootout/fasta.pir
   trunk/examples/shootout/nsieve-bits-2.pir
   trunk/examples/shootout/nsieve-bits.pir
   trunk/examples/shootout/random.pir
Log:
Update some of the shootout examples.
random.pir now uses a coroutine and is considerably faster(2.5 times)


Modified: trunk/examples/shootout/fasta.pir
==============================================================================
--- trunk/examples/shootout/fasta.pir   (original)
+++ trunk/examples/shootout/fasta.pir   Sun Jan 29 17:30:20 2006
@@ -169,7 +169,6 @@ argsok:
        $S0 = argv[1]
        n = $S0
 argsdone:
-       load_bytecode "random_lib.pir"
 
        .local pmc iub
        iub = new .FixedPMCArray
@@ -213,3 +212,25 @@ argsdone:
        makeRandomFasta ("THREE", "Homo sapiens frequency", homosapiens, 4, $I0)
 .end
 
+.const float IM = 139968.0
+.const float IA = 3877.0
+.const float IC = 29573.0
+
+.sub gen_random
+       .param float max
+       .local float last
+       last = 42.0
+loop:
+       $N0 = last
+       $N0 *= IA
+       $N0 += IC
+       $N0 %= IM
+       $N1 = max
+       $N1 *= $N0
+       $N1 /= IM
+       last = $N0
+       .yield($N1)
+       get_params "(0)", max
+       goto loop
+.end
+

Modified: trunk/examples/shootout/nsieve-bits-2.pir
==============================================================================
--- trunk/examples/shootout/nsieve-bits-2.pir   (original)
+++ trunk/examples/shootout/nsieve-bits-2.pir   Sun Jan 29 17:30:20 2006
@@ -8,7 +8,7 @@
     .param int M
     .local pmc flags
     .local int i, count
-    flags = new FixedBooleanArray
+    flags = new .FixedBooleanArray
     flags = M
     i = 2
 lp0:

Modified: trunk/examples/shootout/nsieve-bits.pir
==============================================================================
--- trunk/examples/shootout/nsieve-bits.pir     (original)
+++ trunk/examples/shootout/nsieve-bits.pir     Sun Jan 29 17:30:20 2006
@@ -2,15 +2,14 @@
 #
 # nsieve-bits N  (N = 9 for shootout)
 # by Leopold Toetsch
+# modified by Joshua Isom
 
 # set bits - this might be cheating see nsieve-bits-2 for resetting bits
 
 .sub primes_in_range
     .param int M
-    .local pmc flags
-    .local int i, prim, count
-    flags = new FixedBooleanArray
-    flags = M
+    .param pmc flags
+    .local int i, count
     i = 2
     count = 0
 lp1:
@@ -34,15 +33,20 @@ not_p:
     .param pmc argv
     $S0 = argv[1]
     .local int i, j, N, M, count
+       .local pmc flags
+    flags = new .FixedBooleanArray
     N = $S0
-    null i
+       M = 1 << N
+       M *= 10000
+       flags = M
+       null i
     null j
 loop:
     $I0 = N - j
     inc j
     $I1 = 1 << $I0
     M = $I1 * 10000
-    count = primes_in_range(M)
+    count = primes_in_range(M, flags)
     $P0 = new .FixedIntegerArray
     $P0 = 2
     $P0[0] = M

Modified: trunk/examples/shootout/random.pir
==============================================================================
--- trunk/examples/shootout/random.pir  (original)
+++ trunk/examples/shootout/random.pir  Sun Jan 29 17:30:20 2006
@@ -3,26 +3,42 @@
 # random.pir N         (N = 900000 for shootout)
 # by Joshua Isom
 
-# this needs random_lib.pir either in the parrot directory
-# or in $prefix.../library
-
 .sub main :main
        .param pmc argv
        $S0 = argv[1]
        $I0 = $S0
-       load_bytecode "random_lib.pir"
-       $P0 = global "gen_random"
-        .local float max, r
-        max = 100.0
 while_1:
-       r = $P0(max)
+       gen_random(100.0)
        dec $I0
-       if $I0 goto while_1
+       if $I0 > 1 goto while_1
+       $N0 = gen_random(100.0)
        $P0 = new .FixedFloatArray
        $P0 = 1
-       $P0[0] = r
+       $P0[0] = $N0
        $S0 = sprintf "%.9f\n", $P0
        print $S0
        .return(0)
 .end
 
+.const float IM = 139968.0
+.const float IA = 3877.0
+.const float IC = 29573.0
+
+.sub gen_random
+       .param float max
+       .local float last
+       last = 42.0
+loop:
+       $N0 = last
+       $N0 *= IA
+       $N0 += IC
+       $N0 %= IM
+       $N1 = max
+       $N1 *= $N0
+       $N1 /= IM
+       last = $N0
+       .yield($N1)
+       get_params "(0)", max
+       goto loop
+.end
+

Reply via email to