PR c++/6749
[official-gcc.git] / gcc / lambda.h
blob998e3f18c62c08b6c36aef96f1b024fb346c32c3
1 /* Lambda matrix and vector interface.
2 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Daniel Berlin <dberlin@dberlin.org>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #ifndef LAMBDA_H
23 #define LAMBDA_H
25 /* An integer vector. A vector formally consists of an element of a vector
26 space. A vector space is a set that is closed under vector addition
27 and scalar multiplication. In this vector space, an element is a list of
28 integers. */
29 typedef int *lambda_vector;
30 /* An integer matrix. A matrix consists of m vectors of length n (IE
31 all vectors are the same length). */
32 typedef lambda_vector *lambda_matrix;
34 lambda_matrix lambda_matrix_new (int, int);
36 void lambda_matrix_id (lambda_matrix, int);
37 void lambda_matrix_copy (lambda_matrix, lambda_matrix, int, int);
38 void lambda_matrix_negate (lambda_matrix, lambda_matrix, int, int);
39 void lambda_matrix_transpose (lambda_matrix, lambda_matrix, int, int);
40 void lambda_matrix_add (lambda_matrix, lambda_matrix, lambda_matrix, int,
41 int);
42 void lambda_matrix_add_mc (lambda_matrix, int, lambda_matrix, int,
43 lambda_matrix, int, int);
44 void lambda_matrix_mult (lambda_matrix, lambda_matrix, lambda_matrix,
45 int, int, int);
46 void lambda_matrix_delete_rows (lambda_matrix, int, int, int);
47 void lambda_matrix_row_exchange (lambda_matrix, int, int);
48 void lambda_matrix_row_add (lambda_matrix, int, int, int, int);
49 void lambda_matrix_row_negate (lambda_matrix mat, int, int);
50 void lambda_matrix_row_mc (lambda_matrix, int, int, int);
51 void lambda_matrix_col_exchange (lambda_matrix, int, int, int);
52 void lambda_matrix_col_add (lambda_matrix, int, int, int, int);
53 void lambda_matrix_col_negate (lambda_matrix, int, int);
54 void lambda_matrix_col_mc (lambda_matrix, int, int, int);
55 int lambda_matrix_inverse (lambda_matrix, lambda_matrix, int);
56 void lambda_matrix_hermite (lambda_matrix, int, lambda_matrix, lambda_matrix);
57 void lambda_matrix_left_hermite (lambda_matrix, int, int, lambda_matrix, lambda_matrix);
58 void lambda_matrix_right_hermite (lambda_matrix, int, int, lambda_matrix, lambda_matrix);
59 int lambda_matrix_first_nz_vec (lambda_matrix, int, int, int);
60 void lambda_matrix_project_to_null (lambda_matrix, int, int, int,
61 lambda_vector);
62 void print_lambda_matrix (FILE *, lambda_matrix, int, int);
64 void lambda_matrix_vector_mult (lambda_matrix, int, int, lambda_vector,
65 lambda_vector);
67 static inline void lambda_vector_negate (lambda_vector, lambda_vector, int);
68 static inline void lambda_vector_mult_const (lambda_vector, lambda_vector, int, int);
69 static inline void lambda_vector_add (lambda_vector, lambda_vector,
70 lambda_vector, int);
71 static inline void lambda_vector_add_mc (lambda_vector, int, lambda_vector, int,
72 lambda_vector, int);
73 static inline void lambda_vector_copy (lambda_vector, lambda_vector, int);
74 static inline bool lambda_vector_zerop (lambda_vector, int);
75 static inline void lambda_vector_clear (lambda_vector, int);
76 static inline bool lambda_vector_equal (lambda_vector, lambda_vector, int);
77 static inline int lambda_vector_min_nz (lambda_vector, int, int);
78 static inline int lambda_vector_first_nz (lambda_vector, int, int);
79 static inline void print_lambda_vector (FILE *, lambda_vector, int);
81 /* Allocate a new vector of given SIZE. */
83 static inline lambda_vector
84 lambda_vector_new (int size)
86 return ggc_alloc_cleared (size * sizeof(int));
91 /* Multiply vector VEC1 of length SIZE by a constant CONST1,
92 and store the result in VEC2. */
94 static inline void
95 lambda_vector_mult_const (lambda_vector vec1, lambda_vector vec2,
96 int size, int const1)
98 int i;
100 if (const1 == 0)
101 lambda_vector_clear (vec2, size);
102 else
103 for (i = 0; i < size; i++)
104 vec2[i] = const1 * vec1[i];
107 /* Negate vector VEC1 with length SIZE and store it in VEC2. */
109 static inline void
110 lambda_vector_negate (lambda_vector vec1, lambda_vector vec2,
111 int size)
113 lambda_vector_mult_const (vec1, vec2, size, -1);
116 /* VEC3 = VEC1+VEC2, where all three the vectors are of length SIZE. */
118 static inline void
119 lambda_vector_add (lambda_vector vec1, lambda_vector vec2,
120 lambda_vector vec3, int size)
122 int i;
123 for (i = 0; i < size; i++)
124 vec3[i] = vec1[i] + vec2[i];
127 /* VEC3 = CONSTANT1*VEC1 + CONSTANT2*VEC2. All vectors have length SIZE. */
129 static inline void
130 lambda_vector_add_mc (lambda_vector vec1, int const1,
131 lambda_vector vec2, int const2,
132 lambda_vector vec3, int size)
134 int i;
135 for (i = 0; i < size; i++)
136 vec3[i] = const1 * vec1[i] + const2 * vec2[i];
139 /* Copy the elements of vector VEC1 with length SIZE to VEC2. */
141 static inline void
142 lambda_vector_copy (lambda_vector vec1, lambda_vector vec2,
143 int size)
145 memcpy (vec2, vec1, size * sizeof (*vec1));
148 /* Return true if vector VEC1 of length SIZE is the zero vector. */
150 static inline bool
151 lambda_vector_zerop (lambda_vector vec1, int size)
153 int i;
154 for (i = 0; i < size; i++)
155 if (vec1[i] != 0)
156 return false;
157 return true;
160 /* Clear out vector VEC1 of length SIZE. */
162 static inline void
163 lambda_vector_clear (lambda_vector vec1, int size)
165 memset (vec1, 0, size * sizeof (*vec1));
168 /* Return true if two vectors are equal. */
170 static inline bool
171 lambda_vector_equal (lambda_vector vec1, lambda_vector vec2, int size)
173 int i;
174 for (i = 0; i < size; i++)
175 if (vec1[i] != vec2[i])
176 return false;
177 return true;
180 /* Return the minimum non-zero element in vector VEC1 between START and N.
181 We must have START <= N. */
183 static inline int
184 lambda_vector_min_nz (lambda_vector vec1, int n, int start)
186 int j;
187 int min = -1;
188 #ifdef ENABLE_CHECKING
189 if (start > n)
190 abort ();
191 #endif
192 for (j = start; j < n; j++)
194 if (vec1[j])
195 if (min < 0 || vec1[j] < vec1[min])
196 min = j;
199 if (min < 0)
200 abort ();
202 return min;
205 /* Return the first nonzero element of vector VEC1 between START and N.
206 We must have START <= N. Returns N if VEC1 is the zero vector. */
208 static inline int
209 lambda_vector_first_nz (lambda_vector vec1, int n, int start)
211 int j = start;
212 while (j < n && vec1[j] == 0)
213 j++;
214 return j;
218 /* Multiply a vector by a matrix. */
220 static inline void
221 lambda_vector_matrix_mult (lambda_vector vect, int m, lambda_matrix mat,
222 int n, lambda_vector dest)
224 int i, j;
225 lambda_vector_clear (dest, n);
226 for (i = 0; i < n; i++)
227 for (j = 0; j < m; j++)
228 dest[i] += mat[j][i] * vect[j];
232 /* Print out a vector VEC of length N to OUTFILE. */
234 static inline void
235 print_lambda_vector (FILE * outfile, lambda_vector vector, int n)
237 int i;
239 for (i = 0; i < n; i++)
240 fprintf (outfile, "%3d ", vector[i]);
241 fprintf (outfile, "\n");
243 #endif /* LAMBDA_H */