Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/lib/External/isl/isl_seq.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2008-2009 Katholieke Universiteit Leuven
3
 * Copyright 2011      INRIA Saclay
4
 *
5
 * Use of this software is governed by the MIT license
6
 *
7
 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8
 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9
 */
10
11
#include <isl_ctx_private.h>
12
#include <isl_seq.h>
13
14
void isl_seq_clr(isl_int *p, unsigned len)
15
76.5M
{
16
76.5M
  int i;
17
207M
  for (i = 0; 
i < len207M
;
++i131M
)
18
131M
    isl_int_set_si(p[i], 0);
19
76.5M
}
20
21
void isl_seq_set_si(isl_int *p, int v, unsigned len)
22
1.63k
{
23
1.63k
  int i;
24
2.50k
  for (i = 0; 
i < len2.50k
;
++i866
)
25
866
    isl_int_set_si(p[i], v);
26
1.63k
}
27
28
void isl_seq_set(isl_int *p, isl_int v, unsigned len)
29
10
{
30
10
  int i;
31
22
  for (i = 0; 
i < len22
;
++i12
)
32
12
    isl_int_set(p[i], v);
33
10
}
34
35
void isl_seq_neg(isl_int *dst, isl_int *src, unsigned len)
36
19.5M
{
37
19.5M
  int i;
38
203M
  for (i = 0; 
i < len203M
;
++i184M
)
39
184M
    isl_int_neg(dst[i], src[i]);
40
19.5M
}
41
42
void isl_seq_cpy(isl_int *dst, isl_int *src, unsigned len)
43
62.3M
{
44
62.3M
  int i;
45
594M
  for (i = 0; 
i < len594M
;
++i531M
)
46
531M
    isl_int_set(dst[i], src[i]);
47
62.3M
}
48
49
void isl_seq_submul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
50
5.36k
{
51
5.36k
  int i;
52
43.7k
  for (i = 0; 
i < len43.7k
;
++i38.4k
)
53
38.4k
    isl_int_submul(dst[i], f, src[i]);
54
5.36k
}
55
56
void isl_seq_addmul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
57
61.5k
{
58
61.5k
  int i;
59
329k
  for (i = 0; 
i < len329k
;
++i267k
)
60
267k
    isl_int_addmul(dst[i], f, src[i]);
61
61.5k
}
62
63
void isl_seq_swp_or_cpy(isl_int *dst, isl_int *src, unsigned len)
64
3.07M
{
65
3.07M
  int i;
66
28.4M
  for (i = 0; 
i < len28.4M
;
++i25.4M
)
67
25.4M
    isl_int_swap_or_set(dst[i], src[i]);
68
3.07M
}
69
70
void isl_seq_scale(isl_int *dst, isl_int *src, isl_int m, unsigned len)
71
4.55M
{
72
4.55M
  int i;
73
15.0M
  for (i = 0; 
i < len15.0M
;
++i10.4M
)
74
10.4M
    isl_int_mul(dst[i], src[i], m);
75
4.55M
}
76
77
void isl_seq_scale_down(isl_int *dst, isl_int *src, isl_int m, unsigned len)
78
3.35M
{
79
3.35M
  int i;
80
41.2M
  for (i = 0; 
i < len41.2M
;
++i37.9M
)
81
37.9M
    isl_int_divexact(dst[i], src[i], m);
82
3.35M
}
83
84
void isl_seq_cdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len)
85
3.23k
{
86
3.23k
  int i;
87
11.6k
  for (i = 0; 
i < len11.6k
;
++i8.43k
)
88
8.43k
    isl_int_cdiv_q(dst[i], src[i], m);
89
3.23k
}
90
91
void isl_seq_fdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len)
92
88
{
93
88
  int i;
94
605
  for (i = 0; 
i < len605
;
++i517
)
95
517
    isl_int_fdiv_q(dst[i], src[i], m);
96
88
}
97
98
void isl_seq_fdiv_r(isl_int *dst, isl_int *src, isl_int m, unsigned len)
99
592
{
100
592
  int i;
101
3.48k
  for (i = 0; 
i < len3.48k
;
++i2.89k
)
102
2.89k
    isl_int_fdiv_r(dst[i], src[i], m);
103
592
}
104
105
void isl_seq_combine(isl_int *dst, isl_int m1, isl_int *src1,
106
      isl_int m2, isl_int *src2, unsigned len)
107
12.9M
{
108
12.9M
  int i;
109
12.9M
  isl_int tmp;
110
12.9M
111
12.9M
  if (
dst == src1 && 12.9M
isl_int_is_one12.8M
(m1)) {
112
11.5M
    if (isl_int_is_zero(m2))
113
6.28M
      return;
114
42.0M
    
for (i = 0; 5.31M
i < len42.0M
;
++i36.7M
)
115
36.7M
      isl_int_addmul(src1[i], m2, src2[i]);
116
11.5M
    return;
117
11.5M
  }
118
1.32M
119
1.32M
  
isl_int_init1.32M
(tmp);
120
10.8M
  for (i = 0; 
i < len10.8M
;
++i9.57M
) {
121
9.57M
    isl_int_mul(tmp, m1, src1[i]);
122
9.57M
    isl_int_addmul(tmp, m2, src2[i]);
123
9.57M
    isl_int_set(dst[i], tmp);
124
9.57M
  }
125
1.32M
  isl_int_clear(tmp);
126
12.9M
}
127
128
/*
129
 * Let d = dst[pos] and s = src[pos]
130
 * dst is replaced by |s| dst - sgn(s)d src
131
 */
132
void isl_seq_elim(isl_int *dst, isl_int *src, unsigned pos, unsigned len,
133
      isl_int *m)
134
2.32M
{
135
2.32M
  isl_int a;
136
2.32M
  isl_int b;
137
2.32M
138
2.32M
  if (isl_int_is_zero(dst[pos]))
139
2.70k
    return;
140
2.32M
141
2.32M
  
isl_int_init2.32M
(a);
142
2.32M
  isl_int_init(b);
143
2.32M
144
2.32M
  isl_int_gcd(a, src[pos], dst[pos]);
145
2.32M
  isl_int_divexact(b, dst[pos], a);
146
2.32M
  if (isl_int_is_pos(src[pos]))
147
2.16M
    isl_int_neg(b, b);
148
2.32M
  isl_int_divexact(a, src[pos], a);
149
2.32M
  isl_int_abs(a, a);
150
2.32M
  isl_seq_combine(dst, a, dst, b, src, len);
151
2.32M
152
2.32M
  if (m)
153
10.7k
    isl_int_mul(*m, *m, a);
154
2.32M
155
2.32M
  isl_int_clear(a);
156
2.32M
  isl_int_clear(b);
157
2.32M
}
158
159
int isl_seq_eq(isl_int *p1, isl_int *p2, unsigned len)
160
14.8M
{
161
14.8M
  int i;
162
112M
  for (i = 0; 
i < len112M
;
++i97.2M
)
163
103M
    
if (103M
isl_int_ne103M
(p1[i], p2[i]))
164
6.75M
      return 0;
165
8.11M
  return 1;
166
14.8M
}
167
168
int isl_seq_cmp(isl_int *p1, isl_int *p2, unsigned len)
169
3.04M
{
170
3.04M
  int i;
171
3.04M
  int cmp;
172
24.0M
  for (i = 0; 
i < len24.0M
;
++i21.0M
)
173
22.6M
    
if (22.6M
(cmp = 22.6M
isl_int_cmp22.6M
(p1[i], p2[i])) != 0)
174
1.60M
      return cmp;
175
1.43M
  return 0;
176
3.04M
}
177
178
int isl_seq_is_neg(isl_int *p1, isl_int *p2, unsigned len)
179
136k
{
180
136k
  int i;
181
136k
182
732k
  for (i = 0; 
i < len732k
;
++i595k
) {
183
699k
    if (isl_int_abs_ne(p1[i], p2[i]))
184
24.8k
      return 0;
185
674k
    
if (674k
isl_int_is_zero674k
(p1[i]))
186
535k
      continue;
187
138k
    
if (138k
isl_int_eq138k
(p1[i], p2[i]))
188
78.7k
      return 0;
189
699k
  }
190
32.7k
  return 1;
191
136k
}
192
193
int isl_seq_first_non_zero(isl_int *p, unsigned len)
194
47.2M
{
195
47.2M
  int i;
196
47.2M
197
264M
  for (i = 0; 
i < len264M
;
++i217M
)
198
253M
    
if (253M
!253M
isl_int_is_zero253M
(p[i]))
199
35.8M
      return i;
200
11.3M
  return -1;
201
47.2M
}
202
203
int isl_seq_last_non_zero(isl_int *p, unsigned len)
204
10.0M
{
205
10.0M
  int i;
206
10.0M
207
53.8M
  for (i = len - 1; 
i >= 053.8M
;
--i43.7M
)
208
49.6M
    
if (49.6M
!49.6M
isl_int_is_zero49.6M
(p[i]))
209
5.97M
      return i;
210
4.12M
  return -1;
211
10.0M
}
212
213
void isl_seq_abs_max(isl_int *p, unsigned len, isl_int *max)
214
18.5k
{
215
18.5k
  int i;
216
18.5k
217
18.5k
  isl_int_set_si(*max, 0);
218
18.5k
219
128k
  for (i = 0; 
i < len128k
;
++i109k
)
220
109k
    
if (109k
isl_int_abs_gt109k
(p[i], *max))
221
18.8k
      isl_int_abs(*max, p[i]);
222
18.5k
}
223
224
int isl_seq_abs_min_non_zero(isl_int *p, unsigned len)
225
30.7M
{
226
30.7M
  int i, min = isl_seq_first_non_zero(p, len);
227
30.7M
  if (min < 0)
228
2.16M
    return -1;
229
210M
  
for (i = min + 1; 28.5M
i < len210M
;
++i182M
) {
230
182M
    if (isl_int_is_zero(p[i]))
231
145M
      continue;
232
36.7M
    
if (36.7M
isl_int_abs_lt36.7M
(p[i], p[min]))
233
6.93M
      min = i;
234
182M
  }
235
30.7M
  return min;
236
30.7M
}
237
238
void isl_seq_gcd(isl_int *p, unsigned len, isl_int *gcd)
239
28.7M
{
240
28.7M
  int i, min = isl_seq_abs_min_non_zero(p, len);
241
28.7M
242
28.7M
  if (
min < 028.7M
) {
243
1.60M
    isl_int_set_si(*gcd, 0);
244
1.60M
    return;
245
1.60M
  }
246
27.1M
  
isl_int_abs27.1M
(*gcd, p[min]);
247
67.8M
  for (i = 0; 
isl_int_cmp_si67.8M
(*gcd, 1) > 0 && 67.8M
i < len44.2M
;
++i40.6M
) {
248
40.6M
    if (i == min)
249
3.95M
      continue;
250
36.7M
    
if (36.7M
isl_int_is_zero36.7M
(p[i]))
251
23.6M
      continue;
252
13.0M
    
isl_int_gcd13.0M
(*gcd, *gcd, p[i]);
253
13.0M
  }
254
28.7M
}
255
256
void isl_seq_normalize(struct isl_ctx *ctx, isl_int *p, unsigned len)
257
12.3M
{
258
12.3M
  if (len == 0)
259
0
    return;
260
12.3M
  isl_seq_gcd(p, len, &ctx->normalize_gcd);
261
12.3M
  if (
!12.3M
isl_int_is_zero12.3M
(ctx->normalize_gcd) &&
262
11.6M
      
!11.6M
isl_int_is_one11.6M
(ctx->normalize_gcd))
263
3.19M
    isl_seq_scale_down(p, p, ctx->normalize_gcd, len);
264
12.3M
}
265
266
void isl_seq_lcm(isl_int *p, unsigned len, isl_int *lcm)
267
2.46k
{
268
2.46k
  int i;
269
2.46k
270
2.46k
  if (
len == 02.46k
) {
271
0
    isl_int_set_si(*lcm, 1);
272
0
    return;
273
0
  }
274
2.46k
  
isl_int_set2.46k
(*lcm, p[0]);
275
5.23k
  for (i = 1; 
i < len5.23k
;
++i2.76k
)
276
2.76k
    isl_int_lcm(*lcm, *lcm, p[i]);
277
2.46k
}
278
279
void isl_seq_inner_product(isl_int *p1, isl_int *p2, unsigned len,
280
         isl_int *prod)
281
9.87M
{
282
9.87M
  int i;
283
9.87M
  if (
len == 09.87M
) {
284
0
    isl_int_set_si(*prod, 0);
285
0
    return;
286
0
  }
287
9.87M
  
isl_int_mul9.87M
(*prod, p1[0], p2[0]);
288
84.2M
  for (i = 1; 
i < len84.2M
;
++i74.3M
)
289
74.3M
    isl_int_addmul(*prod, p1[i], p2[i]);
290
9.87M
}
291
292
uint32_t isl_seq_hash(isl_int *p, unsigned len, uint32_t hash)
293
21.3M
{
294
21.3M
  int i;
295
216M
  for (i = 0; 
i < len216M
;
++i195M
) {
296
195M
    if (isl_int_is_zero(p[i]))
297
167M
      continue;
298
27.9M
    hash *= 16777619;
299
27.9M
    hash ^= (i & 0xFF);
300
27.9M
    hash = isl_int_hash(p[i], hash);
301
195M
  }
302
21.3M
  return hash;
303
21.3M
}
304
305
/* Given two affine expressions "p" of length p_len (including the
306
 * denominator and the constant term) and "subs" of length subs_len,
307
 * plug in "subs" for the variable at position "pos".
308
 * The variables of "subs" and "p" are assumed to match up to subs_len,
309
 * but "p" may have additional variables.
310
 * "v" is an initialized isl_int that can be used internally.
311
 *
312
 * In particular, if "p" represents the expression
313
 *
314
 *  (a i + g)/m
315
 *
316
 * with i the variable at position "pos" and "subs" represents the expression
317
 *
318
 *  f/d
319
 *
320
 * then the result represents the expression
321
 *
322
 *  (a f + d g)/(m d)
323
 *
324
 */
325
void isl_seq_substitute(isl_int *p, int pos, isl_int *subs,
326
  int p_len, int subs_len, isl_int v)
327
1.15k
{
328
1.15k
  isl_int_set(v, p[1 + pos]);
329
1.15k
  isl_int_set_si(p[1 + pos], 0);
330
1.15k
  isl_seq_combine(p + 1, subs[0], p + 1, v, subs + 1, subs_len - 1);
331
1.15k
  isl_seq_scale(p + subs_len, p + subs_len, subs[0], p_len - subs_len);
332
1.15k
  isl_int_mul(p[0], p[0], subs[0]);
333
1.15k
}
334
335
uint32_t isl_seq_get_hash(isl_int *p, unsigned len)
336
21.3M
{
337
21.3M
  uint32_t hash = isl_hash_init();
338
21.3M
339
21.3M
  return isl_seq_hash(p, len, hash);
340
21.3M
}
341
342
uint32_t isl_seq_get_hash_bits(isl_int *p, unsigned len, unsigned bits)
343
21.1M
{
344
21.1M
  uint32_t hash;
345
21.1M
346
21.1M
  hash = isl_seq_get_hash(p, len);
347
21.1M
  return isl_hash_bits(hash, bits);
348
21.1M
}
349
350
void isl_seq_dump(isl_int *p, unsigned len)
351
0
{
352
0
  int i;
353
0
354
0
  for (i = 0; 
i < len0
;
++i0
) {
355
0
    if (i)
356
0
      fprintf(stderr, " ");
357
0
    isl_int_print(stderr, p[i], 0);
358
0
  }
359
0
  fprintf(stderr, "\n");
360
0
}