Coverage Report

Created: 2018-06-24 14:39

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/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
80.3M
{
16
80.3M
  int i;
17
223M
  for (i = 0; i < len; 
++i142M
)
18
142M
    isl_int_set_si(p[i], 0);
19
80.3M
}
20
21
void isl_seq_set_si(isl_int *p, int v, unsigned len)
22
1.65k
{
23
1.65k
  int i;
24
2.53k
  for (i = 0; i < len; 
++i875
)
25
1.65k
    
isl_int_set_si875
(p[i], v);
26
1.65k
}
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 < len; 
++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.9M
{
37
19.9M
  int i;
38
212M
  for (i = 0; i < len; 
++i192M
)
39
192M
    isl_int_neg(dst[i], src[i]);
40
19.9M
}
41
42
void isl_seq_cpy(isl_int *dst, isl_int *src, unsigned len)
43
65.6M
{
44
65.6M
  int i;
45
652M
  for (i = 0; i < len; 
++i586M
)
46
586M
    isl_int_set(dst[i], src[i]);
47
65.6M
}
48
49
void isl_seq_submul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
50
9.69k
{
51
9.69k
  int i;
52
96.3k
  for (i = 0; i < len; 
++i86.6k
)
53
86.6k
    isl_int_submul(dst[i], f, src[i]);
54
9.69k
}
55
56
void isl_seq_addmul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
57
67.3k
{
58
67.3k
  int i;
59
353k
  for (i = 0; i < len; 
++i286k
)
60
286k
    isl_int_addmul(dst[i], f, src[i]);
61
67.3k
}
62
63
void isl_seq_swp_or_cpy(isl_int *dst, isl_int *src, unsigned len)
64
3.16M
{
65
3.16M
  int i;
66
29.7M
  for (i = 0; i < len; 
++i26.5M
)
67
26.5M
    isl_int_swap_or_set(dst[i], src[i]);
68
3.16M
}
69
70
void isl_seq_scale(isl_int *dst, isl_int *src, isl_int m, unsigned len)
71
4.78M
{
72
4.78M
  int i;
73
15.8M
  for (i = 0; i < len; 
++i11.0M
)
74
11.0M
    isl_int_mul(dst[i], src[i], m);
75
4.78M
}
76
77
void isl_seq_scale_down(isl_int *dst, isl_int *src, isl_int m, unsigned len)
78
3.51M
{
79
3.51M
  int i;
80
42.9M
  for (i = 0; i < len; 
++i39.4M
)
81
39.4M
    isl_int_divexact(dst[i], src[i], m);
82
3.51M
}
83
84
void isl_seq_cdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len)
85
3.44k
{
86
3.44k
  int i;
87
12.7k
  for (i = 0; i < len; 
++i9.31k
)
88
9.31k
    isl_int_cdiv_q(dst[i], src[i], m);
89
3.44k
}
90
91
void isl_seq_fdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len)
92
118
{
93
118
  int i;
94
891
  for (i = 0; i < len; 
++i773
)
95
773
    isl_int_fdiv_q(dst[i], src[i], m);
96
118
}
97
98
void isl_seq_fdiv_r(isl_int *dst, isl_int *src, isl_int m, unsigned len)
99
691
{
100
691
  int i;
101
4.37k
  for (i = 0; i < len; 
++i3.68k
)
102
3.68k
    isl_int_fdiv_r(dst[i], src[i], m);
103
691
}
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.6M
{
108
12.6M
  int i;
109
12.6M
  isl_int tmp;
110
12.6M
111
12.6M
  if (dst == src1 && 
isl_int_is_one12.5M
(m1)) {
112
11.2M
    if (isl_int_is_zero(m2))
113
11.2M
      
return5.94M
;
114
42.9M
    
for (i = 0; 5.26M
i < len;
++i37.7M
)
115
37.7M
      isl_int_addmul(src1[i], m2, src2[i]);
116
5.26M
    return;
117
5.26M
  }
118
1.40M
119
1.40M
  isl_int_init(tmp);
120
11.6M
  for (i = 0; i < len; 
++i10.2M
) {
121
10.2M
    isl_int_mul(tmp, m1, src1[i]);
122
10.2M
    isl_int_addmul(tmp, m2, src2[i]);
123
10.2M
    isl_int_set(dst[i], tmp);
124
10.2M
  }
125
1.40M
  isl_int_clear(tmp);
126
1.40M
}
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.39M
{
135
2.39M
  isl_int a;
136
2.39M
  isl_int b;
137
2.39M
138
2.39M
  if (isl_int_is_zero(dst[pos]))
139
2.39M
    
return4.88k
;
140
2.38M
141
2.38M
  isl_int_init(a);
142
2.38M
  isl_int_init(b);
143
2.38M
144
2.38M
  isl_int_gcd(a, src[pos], dst[pos]);
145
2.38M
  isl_int_divexact(b, dst[pos], a);
146
2.38M
  if (isl_int_is_pos(src[pos]))
147
2.38M
    
isl_int_neg2.20M
(b, b);
148
2.38M
  isl_int_divexact(a, src[pos], a);
149
2.38M
  isl_int_abs(a, a);
150
2.38M
  isl_seq_combine(dst, a, dst, b, src, len);
151
2.38M
152
2.38M
  if (m)
153
2.38M
    
isl_int_mul20.9k
(*m, *m, a);
154
2.38M
155
2.38M
  isl_int_clear(a);
156
2.38M
  isl_int_clear(b);
157
2.38M
}
158
159
int isl_seq_eq(isl_int *p1, isl_int *p2, unsigned len)
160
15.2M
{
161
15.2M
  int i;
162
117M
  for (i = 0; i < len; 
++i102M
)
163
109M
    if (isl_int_ne(p1[i], p2[i]))
164
109M
      
return 06.88M
;
165
15.2M
  
return 18.32M
;
166
15.2M
}
167
168
int isl_seq_cmp(isl_int *p1, isl_int *p2, unsigned len)
169
2.75M
{
170
2.75M
  int i;
171
2.75M
  int cmp;
172
22.4M
  for (i = 0; i < len; 
++i19.6M
)
173
21.1M
    if ((cmp = isl_int_cmp(p1[i], p2[i])) != 0)
174
1.49M
      return cmp;
175
2.75M
  
return 01.25M
;
176
2.75M
}
177
178
int isl_seq_is_neg(isl_int *p1, isl_int *p2, unsigned len)
179
142k
{
180
142k
  int i;
181
142k
182
756k
  for (i = 0; i < len; 
++i614k
) {
183
721k
    if (isl_int_abs_ne(p1[i], p2[i]))
184
721k
      
return 027.7k
;
185
693k
    if (isl_int_is_zero(p1[i]))
186
693k
      
continue548k
;
187
144k
    if (isl_int_eq(p1[i], p2[i]))
188
144k
      
return 079.6k
;
189
144k
  }
190
142k
  
return 135.4k
;
191
142k
}
192
193
int isl_seq_first_non_zero(isl_int *p, unsigned len)
194
49.8M
{
195
49.8M
  int i;
196
49.8M
197
295M
  for (i = 0; i < len; 
++i245M
)
198
283M
    if (!isl_int_is_zero(p[i]))
199
283M
      
return i37.5M
;
200
49.8M
  
return -112.3M
;
201
49.8M
}
202
203
int isl_seq_last_non_zero(isl_int *p, unsigned len)
204
10.7M
{
205
10.7M
  int i;
206
10.7M
207
62.0M
  for (i = len - 1; i >= 0; 
--i51.3M
)
208
57.7M
    if (!isl_int_is_zero(p[i]))
209
57.7M
      
return i6.39M
;
210
10.7M
  
return -14.31M
;
211
10.7M
}
212
213
void isl_seq_abs_max(isl_int *p, unsigned len, isl_int *max)
214
18.2k
{
215
18.2k
  int i;
216
18.2k
217
18.2k
  isl_int_set_si(*max, 0);
218
18.2k
219
123k
  for (i = 0; i < len; 
++i104k
)
220
104k
    if (isl_int_abs_gt(p[i], *max))
221
104k
      
isl_int_abs18.8k
(*max, p[i]);
222
18.2k
}
223
224
int isl_seq_abs_min_non_zero(isl_int *p, unsigned len)
225
31.7M
{
226
31.7M
  int i, min = isl_seq_first_non_zero(p, len);
227
31.7M
  if (min < 0)
228
2.24M
    return -1;
229
221M
  
for (i = min + 1; 29.4M
i < len;
++i191M
) {
230
191M
    if (isl_int_is_zero(p[i]))
231
191M
      
continue153M
;
232
38.1M
    if (isl_int_abs_lt(p[i], p[min]))
233
38.1M
      
min = i7.22M
;
234
38.1M
  }
235
29.4M
  return min;
236
29.4M
}
237
238
void isl_seq_gcd(isl_int *p, unsigned len, isl_int *gcd)
239
29.6M
{
240
29.6M
  int i, min = isl_seq_abs_min_non_zero(p, len);
241
29.6M
242
29.6M
  if (min < 0) {
243
1.67M
    isl_int_set_si(*gcd, 0);
244
1.67M
    return;
245
1.67M
  }
246
27.9M
  isl_int_abs(*gcd, p[min]);
247
70.1M
  for (i = 0; isl_int_cmp_si(*gcd, 1) > 0 && 
i < len45.8M
;
++i42.2M
) {
248
42.2M
    if (i == min)
249
4.11M
      continue;
250
38.0M
    if (isl_int_is_zero(p[i]))
251
38.0M
      
continue24.5M
;
252
13.5M
    isl_int_gcd(*gcd, *gcd, p[i]);
253
13.5M
  }
254
27.9M
}
255
256
void isl_seq_normalize(struct isl_ctx *ctx, isl_int *p, unsigned len)
257
12.6M
{
258
12.6M
  if (len == 0)
259
0
    return;
260
12.6M
  isl_seq_gcd(p, len, &ctx->normalize_gcd);
261
12.6M
  if (!isl_int_is_zero(ctx->normalize_gcd) &&
262
12.6M
      
!11.9M
isl_int_is_one11.9M
(ctx->normalize_gcd))
263
12.6M
    
isl_seq_scale_down(p, p, ctx->normalize_gcd, len)3.33M
;
264
12.6M
}
265
266
void isl_seq_lcm(isl_int *p, unsigned len, isl_int *lcm)
267
3.28k
{
268
3.28k
  int i;
269
3.28k
270
3.28k
  if (len == 0) {
271
0
    isl_int_set_si(*lcm, 1);
272
0
    return;
273
0
  }
274
3.28k
  isl_int_set(*lcm, p[0]);
275
7.08k
  for (i = 1; i < len; 
++i3.80k
)
276
3.80k
    isl_int_lcm(*lcm, *lcm, p[i]);
277
3.28k
}
278
279
void isl_seq_inner_product(isl_int *p1, isl_int *p2, unsigned len,
280
         isl_int *prod)
281
10.0M
{
282
10.0M
  int i;
283
10.0M
  if (len == 0) {
284
0
    isl_int_set_si(*prod, 0);
285
0
    return;
286
0
  }
287
10.0M
  isl_int_mul(*prod, p1[0], p2[0]);
288
87.1M
  for (i = 1; i < len; 
++i77.1M
)
289
77.1M
    isl_int_addmul(*prod, p1[i], p2[i]);
290
10.0M
}
291
292
uint32_t isl_seq_hash(isl_int *p, unsigned len, uint32_t hash)
293
21.8M
{
294
21.8M
  int i;
295
227M
  for (i = 0; i < len; 
++i205M
) {
296
205M
    if (isl_int_is_zero(p[i]))
297
205M
      
continue177M
;
298
28.7M
    hash *= 16777619;
299
28.7M
    hash ^= (i & 0xFF);
300
28.7M
    hash = isl_int_hash(p[i], hash);
301
28.7M
  }
302
21.8M
  return hash;
303
21.8M
}
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
2.20k
{
328
2.20k
  isl_int_set(v, p[1 + pos]);
329
2.20k
  isl_int_set_si(p[1 + pos], 0);
330
2.20k
  isl_seq_combine(p + 1, subs[0], p + 1, v, subs + 1, subs_len - 1);
331
2.20k
  isl_seq_scale(p + subs_len, p + subs_len, subs[0], p_len - subs_len);
332
2.20k
  isl_int_mul(p[0], p[0], subs[0]);
333
2.20k
}
334
335
uint32_t isl_seq_get_hash(isl_int *p, unsigned len)
336
21.8M
{
337
21.8M
  uint32_t hash = isl_hash_init();
338
21.8M
339
21.8M
  return isl_seq_hash(p, len, hash);
340
21.8M
}
341
342
uint32_t isl_seq_get_hash_bits(isl_int *p, unsigned len, unsigned bits)
343
21.5M
{
344
21.5M
  uint32_t hash;
345
21.5M
346
21.5M
  hash = isl_seq_get_hash(p, len);
347
21.5M
  return isl_hash_bits(hash, bits);
348
21.5M
}
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 < len; ++i) {
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
}