added sieve
authorChristian Würdig <chriswue@ipd.info.uni-karlsruhe.de>
Fri, 16 Mar 2007 12:38:51 +0000 (12:38 +0000)
committerChristian Würdig <chriswue@ipd.info.uni-karlsruhe.de>
Fri, 16 Mar 2007 12:38:51 +0000 (12:38 +0000)
ir/be/test/sieve.c [new file with mode: 0644]

diff --git a/ir/be/test/sieve.c b/ir/be/test/sieve.c
new file mode 100644 (file)
index 0000000..0cf4fb5
--- /dev/null
@@ -0,0 +1,72 @@
+/* Hey Emacs, this is a -*- C -*- file */
+/*
+ * Project:     STAC
+ * File name:   test/stantard/sieve.c
+ * Purpose:     test case:  Eratostenes sieve
+ * Author:      Eratostenes
+ * Modified by: Boris Boesler
+ * Created:     17.7.2006
+ * Copyright:   (c) 2006 Dresden Silicon GmbH
+ * Licence:
+ * CVS-ID:      $Id$
+ */
+
+/* switch to STA code generation */
+#pragma codegenerator STA
+
+/* Eratostenes Sieve Prime Number Program in C */
+#define TRUE 1
+#define FALSE 0
+//#define SIZE 8190
+#define SIZE   100
+#define ITERATIONS     1
+
+/* result as local variable to check */
+/*
+ * sieve(10) = 0x08
+ * sieve(20) = 0x0d
+ * sieve(100) = 0x2d
+ */
+short res;
+
+/* the sieve */
+short flags[SIZE + 1];
+
+void task_start()
+{
+  register short i, prime, k, count, iter;
+  count = 0;
+
+  for (iter = 1; iter <= ITERATIONS; iter++) {
+    count = 0;
+
+    /* init solid sieve */
+    for(i = 0; i <= SIZE; i++) {
+      flags[i] = TRUE;
+    }
+
+    /* make holes in sieve */
+    for(i = 0; i <= SIZE; i++) {
+      if(flags[i]) {
+       prime = i + i + 3;
+       for (k = i + prime; k <= SIZE; k += prime) {
+         flags[k] = FALSE;
+       }
+       count++;
+      }
+    }
+  }
+  res = count ;
+}
+
+/* switch back to Control Flow Processor code generation */
+#pragma codegenerator CFP
+
+
+#ifdef REFERENCE_TESTS
+int main(int argc, char **argv)
+{
+  task_start();
+  printf("sieve(%d) = 0x%x\n", SIZE, res);
+}
+#endif