aboutsummaryrefslogtreecommitdiff
path: root/gcc/lambda.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/lambda.h')
-rw-r--r--gcc/lambda.h40
1 files changed, 39 insertions, 1 deletions
diff --git a/gcc/lambda.h b/gcc/lambda.h
index 817f084..7a43be2 100644
--- a/gcc/lambda.h
+++ b/gcc/lambda.h
@@ -1,5 +1,5 @@
/* Lambda matrix and vector interface.
- Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
Contributed by Daniel Berlin <dberlin@dberlin.org>
This file is part of GCC.
@@ -380,6 +380,44 @@ print_lambda_vector (FILE * outfile, lambda_vector vector, int n)
fprintf (outfile, "\n");
}
+/* Compute the greatest common divisor of two numbers using
+ Euclid's algorithm. */
+
+static inline int
+gcd (int a, int b)
+{
+ int x, y, z;
+
+ x = abs (a);
+ y = abs (b);
+
+ while (x > 0)
+ {
+ z = y % x;
+ y = x;
+ x = z;
+ }
+
+ return y;
+}
+
+/* Compute the greatest common divisor of a VECTOR of SIZE numbers. */
+
+static inline int
+lambda_vector_gcd (lambda_vector vector, int size)
+{
+ int i;
+ int gcd1 = 0;
+
+ if (size > 0)
+ {
+ gcd1 = vector[0];
+ for (i = 1; i < size; i++)
+ gcd1 = gcd (gcd1, vector[i]);
+ }
+ return gcd1;
+}
+
/* Returns true when the vector V is lexicographically positive, in
other words, when the first nonzero element is positive. */