[llvm-commits] CVS: llvm-java/test/Programs/SingleSource/UnitTests/ackermann.java ary.java fibo.java heapsort.java methcall.java nestedloop.java objinst.java random.java sieve.java takfp.java Makefile

Alkis Evlogimenos alkis at cs.uiuc.edu
Fri Dec 10 15:50:33 PST 2004



Changes in directory llvm-java/test/Programs/SingleSource/UnitTests:

ackermann.java added (r1.1)
ary.java added (r1.1)
fibo.java added (r1.1)
heapsort.java added (r1.1)
methcall.java added (r1.1)
nestedloop.java added (r1.1)
objinst.java added (r1.1)
random.java added (r1.1)
sieve.java added (r1.1)
takfp.java added (r1.1)
Makefile updated: 1.27 -> 1.28
---
Log message:

Add some testcases from The Great Language Shootout

---
Diffs of the changes:  (+271 -0)

Index: llvm-java/test/Programs/SingleSource/UnitTests/ackermann.java
diff -c /dev/null llvm-java/test/Programs/SingleSource/UnitTests/ackermann.java:1.1
*** /dev/null	Fri Dec 10 17:50:32 2004
--- llvm-java/test/Programs/SingleSource/UnitTests/ackermann.java	Fri Dec 10 17:50:22 2004
***************
*** 0 ****
--- 1,9 ----
+ public class ackermann {
+     public static void main(String[] args) {
+         Test.print_int_ln(Ack(3, 10));
+     }
+     public static int Ack(int m, int n) {
+         return (m == 0) ? (n + 1) : ((n == 0) ? Ack(m-1, 1) :
+                                      Ack(m-1, Ack(m, n - 1)));
+     }
+ }


Index: llvm-java/test/Programs/SingleSource/UnitTests/ary.java
diff -c /dev/null llvm-java/test/Programs/SingleSource/UnitTests/ary.java:1.1
*** /dev/null	Fri Dec 10 17:50:33 2004
--- llvm-java/test/Programs/SingleSource/UnitTests/ary.java	Fri Dec 10 17:50:22 2004
***************
*** 0 ****
--- 1,16 ----
+ public class ary {
+     public static void main(String args[]) {
+         int i, j, k, n = 9000;
+         int x[] = new int[n];
+         int y[] = new int[n];
+ 
+         for (i = 0; i < n; i++)
+             x[i] = i + 1;
+         for (k = 0; k < 1000; k++ )
+             for (j = n-1; j >= 0; j--)
+                 y[j] += x[j];
+ 
+         Test.print_int_ln(y[0]);
+         Test.print_int_ln(y[n-1]);
+     }
+ }
\ No newline at end of file


Index: llvm-java/test/Programs/SingleSource/UnitTests/fibo.java
diff -c /dev/null llvm-java/test/Programs/SingleSource/UnitTests/fibo.java:1.1
*** /dev/null	Fri Dec 10 17:50:33 2004
--- llvm-java/test/Programs/SingleSource/UnitTests/fibo.java	Fri Dec 10 17:50:22 2004
***************
*** 0 ****
--- 1,10 ----
+ public class fibo {
+     public static void main(String args[]) {
+         int N = 32;
+         Test.print_int_ln(fib(N));
+     }
+     public static int fib(int n) {
+         if (n < 2) return(1);
+         return( fib(n-2) + fib(n-1) );
+     }
+ }
\ No newline at end of file


Index: llvm-java/test/Programs/SingleSource/UnitTests/heapsort.java
diff -c /dev/null llvm-java/test/Programs/SingleSource/UnitTests/heapsort.java:1.1
*** /dev/null	Fri Dec 10 17:50:33 2004
--- llvm-java/test/Programs/SingleSource/UnitTests/heapsort.java	Fri Dec 10 17:50:22 2004
***************
*** 0 ****
--- 1,53 ----
+ public class heapsort {
+ 
+     public static final long IM = 139968;
+     public static final long IA =   3877;
+     public static final long IC =  29573;
+ 
+     public static void main(String args[]) {
+         int N = 100000;
+         double []ary = new double[N+1];
+         for (int i=1; i<=N; i++) {
+             ary[i] = gen_random(1);
+         }
+         heapsort(N, ary);
+         Test.print_double_ln(ary[N]);
+     }
+ 
+     public static long last = 42;
+     public static double gen_random(double max) {
+         return( max * (last = (last * IA + IC) % IM) / IM );
+     }
+ 
+     public static void heapsort(int n, double ra[]) {
+         int l, j, ir, i;
+         double rra;
+ 
+         l = (n >> 1) + 1;
+         ir = n;
+         for (;;) {
+             if (l > 1) {
+                 rra = ra[--l];
+             } else {
+                 rra = ra[ir];
+                 ra[ir] = ra[1];
+                 if (--ir == 1) {
+                     ra[1] = rra;
+                     return;
+                 }
+             }
+             i = l;
+             j = l << 1;
+             while (j <= ir) {
+                 if (j < ir && ra[j] < ra[j+1]) { ++j; }
+                 if (rra < ra[j]) {
+                     ra[i] = ra[j];
+                     j += (i = j);
+                 } else {
+                     j = ir + 1;
+                 }
+             }
+             ra[i] = rra;
+         }
+     }
+ }
\ No newline at end of file


Index: llvm-java/test/Programs/SingleSource/UnitTests/methcall.java
diff -c /dev/null llvm-java/test/Programs/SingleSource/UnitTests/methcall.java:1.1
*** /dev/null	Fri Dec 10 17:50:33 2004
--- llvm-java/test/Programs/SingleSource/UnitTests/methcall.java	Fri Dec 10 17:50:22 2004
***************
*** 0 ****
--- 1,52 ----
+ public class methcall {
+     private static class Toggle {
+         boolean state = true;
+         public Toggle(boolean start_state) {
+             this.state = start_state;
+         }
+         public boolean value() {
+             return(this.state);
+         }
+         public Toggle activate() {
+             this.state = !this.state;
+             return(this);
+         }
+     }
+ 
+     private static class NthToggle extends Toggle {
+         int count_max = 0;
+         int counter = 0;
+ 
+         public NthToggle(boolean start_state, int max_counter) {
+             super(start_state);
+             this.count_max = max_counter;
+             this.counter = 0;
+         }
+         public Toggle activate() {
+             this.counter += 1;
+             if (this.counter >= this.count_max) {
+                 this.state = !this.state;
+                 this.counter = 0;
+             }
+             return(this);
+         }
+     }
+ 
+     public static void main(String args[]) {
+         int n = 1000000;
+ 
+         boolean val = true;
+         Toggle toggle = new Toggle(val);
+         for (int i=0; i<n; i++) {
+             val = toggle.activate().value();
+         }
+         Test.print_boolean_ln(val);
+ 
+         val = true;
+         NthToggle ntoggle = new NthToggle(true, 3);
+         for (int i=0; i<n; i++) {
+             val = ntoggle.activate().value();
+         }
+         Test.print_boolean_ln(val);
+     }
+ }
\ No newline at end of file


Index: llvm-java/test/Programs/SingleSource/UnitTests/nestedloop.java
diff -c /dev/null llvm-java/test/Programs/SingleSource/UnitTests/nestedloop.java:1.1
*** /dev/null	Fri Dec 10 17:50:33 2004
--- llvm-java/test/Programs/SingleSource/UnitTests/nestedloop.java	Fri Dec 10 17:50:22 2004
***************
*** 0 ****
--- 1,14 ----
+ public class nestedloop {
+     public static void main(String args[]) {
+         int n = 18;
+         int x = 0;
+         for (int a=0; a<n; a++)
+             for (int b=0; b<n; b++)
+                 for (int c=0; c<n; c++)
+                     for (int d=0; d<n; d++)
+                         for (int e=0; e<n; e++)
+                             for (int f=0; f<n; f++)
+                                 x++;
+         Test.print_int_ln(x);
+     }
+ }
\ No newline at end of file


Index: llvm-java/test/Programs/SingleSource/UnitTests/objinst.java
diff -c /dev/null llvm-java/test/Programs/SingleSource/UnitTests/objinst.java:1.1
*** /dev/null	Fri Dec 10 17:50:33 2004
--- llvm-java/test/Programs/SingleSource/UnitTests/objinst.java	Fri Dec 10 17:50:22 2004
***************
*** 0 ****
--- 1,53 ----
+ public class objinst {
+     private static class Toggle {
+         boolean state = true;
+         public Toggle(boolean start_state) {
+             this.state = start_state;
+         }
+         public boolean value() {
+             return(this.state);
+         }
+         public Toggle activate() {
+             this.state = !this.state;
+             return(this);
+         }
+     }
+ 
+     private static class NthToggle extends Toggle {
+         int count_max = 0;
+         int counter = 0;
+ 
+         public NthToggle(boolean start_state, int max_counter) {
+             super(start_state);
+             this.count_max = max_counter;
+             this.counter = 0;
+         }
+         public Toggle activate() {
+             this.counter += 1;
+             if (this.counter >= this.count_max) {
+                 this.state = !this.state;
+                 this.counter = 0;
+             }
+             return(this);
+         }
+     }
+ 
+     public static void main(String args[]) {
+         int n = 1500000;
+         Toggle toggle1 = new Toggle(true);
+         for (int i=0; i<5; i++) {
+             Test.print_boolean_ln(toggle1.activate().value());
+         }
+         for (int i=0; i<n; i++) {
+             Toggle toggle = new Toggle(true);
+         }
+ 
+         NthToggle ntoggle1 = new NthToggle(true, 3);
+         for (int i=0; i<8; i++) {
+             Test.print_boolean_ln(ntoggle1.activate().value());
+         }
+         for (int i=0; i<n; i++) {
+             NthToggle toggle = new NthToggle(true, 3);
+         }
+     }
+ }
\ No newline at end of file


Index: llvm-java/test/Programs/SingleSource/UnitTests/random.java
diff -c /dev/null llvm-java/test/Programs/SingleSource/UnitTests/random.java:1.1
*** /dev/null	Fri Dec 10 17:50:33 2004
--- llvm-java/test/Programs/SingleSource/UnitTests/random.java	Fri Dec 10 17:50:22 2004
***************
*** 0 ****
--- 1,20 ----
+ public class random {
+ 
+     public static final int IM = 139968;
+     public static final int IA = 3877;
+     public static final int IC = 29573;
+ 
+     public static void main(String args[]) {
+         int N = 900000;
+ 
+         while (--N > 0) {
+             gen_random(100);
+         }
+         Test.print_double_ln(gen_random(100));
+     }
+ 
+     public static int last = 42;
+     public static double gen_random(double max) {
+         return( max * (last = (last * IA + IC) % IM) / IM );
+     }
+ }
\ No newline at end of file


Index: llvm-java/test/Programs/SingleSource/UnitTests/sieve.java
diff -c /dev/null llvm-java/test/Programs/SingleSource/UnitTests/sieve.java:1.1
*** /dev/null	Fri Dec 10 17:50:33 2004
--- llvm-java/test/Programs/SingleSource/UnitTests/sieve.java	Fri Dec 10 17:50:22 2004
***************
*** 0 ****
--- 1,23 ----
+ public class sieve {
+     public static void main(String args[]) {
+         int NUM = 1200;
+         boolean [] flags = new boolean[8192 + 1];
+         int count = 0;
+         while (NUM-- > 0) {
+             count = 0;
+             for (int i=2; i <= 8192; i++) {
+                 flags[i] = true;
+             }
+             for (int i=2; i <= 8192; i++) {
+                 if (flags[i]) {
+                     // remove all multiples of prime: i
+                     for (int k=i+i; k <= 8192; k+=i) {
+                         flags[k] = false;
+                     }
+                     count++;
+                 }
+             }
+         }
+         Test.print_int_ln(count);
+     }
+ }
\ No newline at end of file


Index: llvm-java/test/Programs/SingleSource/UnitTests/takfp.java
diff -c /dev/null llvm-java/test/Programs/SingleSource/UnitTests/takfp.java:1.1
*** /dev/null	Fri Dec 10 17:50:33 2004
--- llvm-java/test/Programs/SingleSource/UnitTests/takfp.java	Fri Dec 10 17:50:22 2004
***************
*** 0 ****
--- 1,11 ----
+ public class takfp {
+     public static void main(String args[]) {
+         int n = 10;
+         Test.print_double_ln( Tak(n*3.0f, n*2.0f, n*1.0f) );
+     }
+ 
+   public static float Tak (float x, float y, float z) {
+     if (y >= x) return z;
+     else return Tak(Tak(x-1.0f,y,z), Tak(y-1.0f,z,x), Tak(z-1.0f,x,y));
+   }
+ }
\ No newline at end of file


Index: llvm-java/test/Programs/SingleSource/UnitTests/Makefile
diff -u llvm-java/test/Programs/SingleSource/UnitTests/Makefile:1.27 llvm-java/test/Programs/SingleSource/UnitTests/Makefile:1.28
--- llvm-java/test/Programs/SingleSource/UnitTests/Makefile:1.27	Fri Dec 10 14:59:24 2004
+++ llvm-java/test/Programs/SingleSource/UnitTests/Makefile	Fri Dec 10 17:50:22 2004
@@ -29,6 +29,16 @@
 	Test \
 	VirtualCall \
 	VTable \
+	ackermann \
+	ary \
+	fibo \
+	heapsort \
+	methcall \
+	nestedloop \
+	objinst \
+	sieve \
+	random \
+	takfp \
 #	Lists1 \
 #	Strings \
 #	MultipleInterfaces \






More information about the llvm-commits mailing list