Coverage Report

Created: 2017-08-21 19:50

/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
61.2M
{
16
61.2M
  int i;
17
162M
  for (i = 0; 
i < len162M
;
++i100M
)
18
100M
    isl_int_set_si(p[i], 0);
19
61.2M
}
20
21
void isl_seq_set_si(isl_int *p, int v, unsigned len)
22
1.61k
{
23
1.61k
  int i;
24
2.46k
  for (i = 0; 
i < len2.46k
;
++i854
)
25
854
    isl_int_set_si(p[i], v);
26
1.61k
}
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
14.0M
{
37
14.0M
  int i;
38
153M
  for (i = 0; 
i < len153M
;
++i139M
)
39
139M
    isl_int_neg(dst[i], src[i]);
40
14.0M
}
41
42
void isl_seq_cpy(isl_int *dst, isl_int *src, unsigned len)
43
50.9M
{
44
50.9M
  int i;
45
533M
  for (i = 0; 
i < len533M
;
++i483M
)
46
483M
    isl_int_set(dst[i], src[i]);
47
50.9M
}
48
49
void isl_seq_submul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
50
4.75k
{
51
4.75k
  int i;
52
34.6k
  for (i = 0; 
i < len34.6k
;
++i29.9k
)
53
29.9k
    isl_int_submul(dst[i], f, src[i]);
54
4.75k
}
55
56
void isl_seq_addmul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
57
60.6k
{
58
60.6k
  int i;
59
323k
  for (i = 0; 
i < len323k
;
++i263k
)
60
263k
    isl_int_addmul(dst[i], f, src[i]);
61
60.6k
}
62
63
void isl_seq_swp_or_cpy(isl_int *dst, isl_int *src, unsigned len)
64
2.16M
{
65
2.16M
  int i;
66
20.0M
  for (i = 0; 
i < len20.0M
;
++i17.9M
)
67
17.9M
    isl_int_swap_or_set(dst[i], src[i]);
68
2.16M
}
69
70
void isl_seq_scale(isl_int *dst, isl_int *src, isl_int m, unsigned len)
71
3.18M
{
72
3.18M
  int i;
73
10.6M
  for (i = 0; 
i < len10.6M
;
++i7.46M
)
74
7.46M
    isl_int_mul(dst[i], src[i], m);
75
3.18M
}
76
77
void isl_seq_scale_down(isl_int *dst, isl_int *src, isl_int m, unsigned len)
78
2.73M
{
79
2.73M
  int i;
80
34.0M
  for (i = 0; 
i < len34.0M
;
++i31.3M
)
81
31.3M
    isl_int_divexact(dst[i], src[i], m);
82
2.73M
}
83
84
void isl_seq_cdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len)
85
3.20k
{
86
3.20k
  int i;
87
11.4k
  for (i = 0; 
i < len11.4k
;
++i8.27k
)
88
8.27k
    isl_int_cdiv_q(dst[i], src[i], m);
89
3.20k
}
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
598
{
100
598
  int i;
101
3.53k
  for (i = 0; 
i < len3.53k
;
++i2.93k
)
102
2.93k
    isl_int_fdiv_r(dst[i], src[i], m);
103
598
}
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
8.76M
{
108
8.76M
  int i;
109
8.76M
  isl_int tmp;
110
8.76M
111
8.76M
  if (
dst == src1 && 8.76M
isl_int_is_one8.73M
(m1))
{7.78M
112
7.78M
    if (isl_int_is_zero(m2))
113
3.98M
      return;
114
30.2M
    
for (i = 0; 3.79M
i < len30.2M
;
++i26.4M
)
115
26.4M
      isl_int_addmul(src1[i], m2, src2[i]);
116
7.78M
    return;
117
8.76M
  }
118
8.76M
119
988k
  
isl_int_init988k
(tmp);988k
120
6.55M
  for (i = 0; 
i < len6.55M
;
++i5.56M
)
{5.56M
121
5.56M
    isl_int_mul(tmp, m1, src1[i]);
122
5.56M
    isl_int_addmul(tmp, m2, src2[i]);
123
5.56M
    isl_int_set(dst[i], tmp);
124
5.56M
  }
125
988k
  isl_int_clear(tmp);
126
8.76M
}
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
1.76M
{
135
1.76M
  isl_int a;
136
1.76M
  isl_int b;
137
1.76M
138
1.76M
  if (isl_int_is_zero(dst[pos]))
139
1.02k
    return;
140
1.76M
141
1.75M
  
isl_int_init1.75M
(a);1.75M
142
1.75M
  isl_int_init(b);
143
1.75M
144
1.75M
  isl_int_gcd(a, src[pos], dst[pos]);
145
1.75M
  isl_int_divexact(b, dst[pos], a);
146
1.75M
  if (isl_int_is_pos(src[pos]))
147
1.63M
    isl_int_neg(b, b);
148
1.75M
  isl_int_divexact(a, src[pos], a);
149
1.75M
  isl_int_abs(a, a);
150
1.75M
  isl_seq_combine(dst, a, dst, b, src, len);
151
1.75M
152
1.75M
  if (m)
153
10.7k
    isl_int_mul(*m, *m, a);
154
1.75M
155
1.75M
  isl_int_clear(a);
156
1.75M
  isl_int_clear(b);
157
1.76M
}
158
159
int isl_seq_eq(isl_int *p1, isl_int *p2, unsigned len)
160
10.3M
{
161
10.3M
  int i;
162
85.3M
  for (i = 0; 
i < len85.3M
;
++i75.0M
)
163
79.6M
    
if (79.6M
isl_int_ne79.6M
(p1[i], p2[i]))
164
4.64M
      return 0;
165
5.71M
  return 1;
166
10.3M
}
167
168
int isl_seq_cmp(isl_int *p1, isl_int *p2, unsigned len)
169
2.62M
{
170
2.62M
  int i;
171
2.62M
  int cmp;
172
21.6M
  for (i = 0; 
i < len21.6M
;
++i19.0M
)
173
20.4M
    
if (20.4M
(cmp = 20.4M
isl_int_cmp20.4M
(p1[i], p2[i])) != 0)
174
1.42M
      return cmp;
175
1.19M
  return 0;
176
2.62M
}
177
178
int isl_seq_is_neg(isl_int *p1, isl_int *p2, unsigned len)
179
85.4k
{
180
85.4k
  int i;
181
85.4k
182
465k
  for (i = 0; 
i < len465k
;
++i379k
)
{443k
183
443k
    if (isl_int_abs_ne(p1[i], p2[i]))
184
19.2k
      return 0;
185
424k
    
if (424k
isl_int_is_zero424k
(p1[i]))
186
337k
      continue;
187
86.5k
    
if (86.5k
isl_int_eq86.5k
(p1[i], p2[i]))
188
44.4k
      return 0;
189
86.5k
  }
190
21.7k
  return 1;
191
85.4k
}
192
193
int isl_seq_first_non_zero(isl_int *p, unsigned len)
194
37.5M
{
195
37.5M
  int i;
196
37.5M
197
234M
  for (i = 0; 
i < len234M
;
++i196M
)
198
225M
    
if (225M
!225M
isl_int_is_zero225M
(p[i]))
199
28.4M
      return i;
200
9.06M
  return -1;
201
37.5M
}
202
203
int isl_seq_last_non_zero(isl_int *p, unsigned len)
204
8.30M
{
205
8.30M
  int i;
206
8.30M
207
47.6M
  for (i = len - 1; 
i >= 047.6M
;
--i39.3M
)
208
44.3M
    
if (44.3M
!44.3M
isl_int_is_zero44.3M
(p[i]))
209
5.01M
      return i;
210
3.28M
  return -1;
211
8.30M
}
212
213
void isl_seq_abs_max(isl_int *p, unsigned len, isl_int *max)
214
8.12k
{
215
8.12k
  int i;
216
8.12k
217
8.12k
  isl_int_set_si(*max, 0);
218
8.12k
219
49.9k
  for (i = 0; 
i < len49.9k
;
++i41.8k
)
220
41.8k
    
if (41.8k
isl_int_abs_gt41.8k
(p[i], *max))
221
8.34k
      isl_int_abs(*max, p[i]);
222
8.12k
}
223
224
int isl_seq_abs_min_non_zero(isl_int *p, unsigned len)
225
23.2M
{
226
23.2M
  int i, min = isl_seq_first_non_zero(p, len);
227
23.2M
  if (min < 0)
228
1.54M
    return -1;
229
162M
  
for (i = min + 1; 21.7M
i < len162M
;
++i141M
)
{141M
230
141M
    if (isl_int_is_zero(p[i]))
231
111M
      continue;
232
29.7M
    
if (29.7M
isl_int_abs_lt29.7M
(p[i], p[min]))
233
5.48M
      min = i;
234
29.7M
  }
235
23.2M
  return min;
236
23.2M
}
237
238
void isl_seq_gcd(isl_int *p, unsigned len, isl_int *gcd)
239
21.9M
{
240
21.9M
  int i, min = isl_seq_abs_min_non_zero(p, len);
241
21.9M
242
21.9M
  if (
min < 021.9M
)
{1.17M
243
1.17M
    isl_int_set_si(*gcd, 0);
244
1.17M
    return;
245
21.9M
  }
246
20.7M
  
isl_int_abs20.7M
(*gcd, p[min]);20.7M
247
54.4M
  for (i = 0; 
isl_int_cmp_si54.4M
(*gcd, 1) > 0 && 54.4M
i < len36.6M
;
++i33.7M
)
{33.7M
248
33.7M
    if (i == min)
249
3.25M
      continue;
250
30.4M
    
if (30.4M
isl_int_is_zero30.4M
(p[i]))
251
18.7M
      continue;
252
11.6M
    
isl_int_gcd11.6M
(*gcd, *gcd, p[i]);11.6M
253
20.7M
  }
254
21.9M
}
255
256
void isl_seq_normalize(struct isl_ctx *ctx, isl_int *p, unsigned len)
257
9.51M
{
258
9.51M
  if (len == 0)
259
0
    return;
260
9.51M
  isl_seq_gcd(p, len, &ctx->normalize_gcd);
261
9.51M
  if (
!9.51M
isl_int_is_zero9.51M
(ctx->normalize_gcd) &&
262
8.98M
      
!8.98M
isl_int_is_one8.98M
(ctx->normalize_gcd))
263
2.58M
    isl_seq_scale_down(p, p, ctx->normalize_gcd, len);
264
9.51M
}
265
266
void isl_seq_lcm(isl_int *p, unsigned len, isl_int *lcm)
267
2.42k
{
268
2.42k
  int i;
269
2.42k
270
2.42k
  if (
len == 02.42k
)
{0
271
0
    isl_int_set_si(*lcm, 1);
272
0
    return;
273
2.42k
  }
274
2.42k
  
isl_int_set2.42k
(*lcm, p[0]);2.42k
275
5.16k
  for (i = 1; 
i < len5.16k
;
++i2.73k
)
276
2.73k
    isl_int_lcm(*lcm, *lcm, p[i]);
277
2.42k
}
278
279
void isl_seq_inner_product(isl_int *p1, isl_int *p2, unsigned len,
280
         isl_int *prod)
281
6.92M
{
282
6.92M
  int i;
283
6.92M
  if (
len == 06.92M
)
{0
284
0
    isl_int_set_si(*prod, 0);
285
0
    return;
286
6.92M
  }
287
6.92M
  
isl_int_mul6.92M
(*prod, p1[0], p2[0]);6.92M
288
60.2M
  for (i = 1; 
i < len60.2M
;
++i53.3M
)
289
53.3M
    isl_int_addmul(*prod, p1[i], p2[i]);
290
6.92M
}
291
292
uint32_t isl_seq_hash(isl_int *p, unsigned len, uint32_t hash)
293
15.7M
{
294
15.7M
  int i;
295
165M
  for (i = 0; 
i < len165M
;
++i149M
)
{149M
296
149M
    if (isl_int_is_zero(p[i]))
297
129M
      continue;
298
149M
    hash *= 16777619;
299
20.3M
    hash ^= (i & 0xFF);
300
20.3M
    hash = isl_int_hash(p[i], hash);
301
20.3M
  }
302
15.7M
  return hash;
303
15.7M
}
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
784
{
328
784
  isl_int_set(v, p[1 + pos]);
329
784
  isl_int_set_si(p[1 + pos], 0);
330
784
  isl_seq_combine(p + 1, subs[0], p + 1, v, subs + 1, subs_len - 1);
331
784
  isl_seq_scale(p + subs_len, p + subs_len, subs[0], p_len - subs_len);
332
784
  isl_int_mul(p[0], p[0], subs[0]);
333
784
}
334
335
uint32_t isl_seq_get_hash(isl_int *p, unsigned len)
336
15.7M
{
337
15.7M
  uint32_t hash = isl_hash_init();
338
15.7M
339
15.7M
  return isl_seq_hash(p, len, hash);
340
15.7M
}
341
342
uint32_t isl_seq_get_hash_bits(isl_int *p, unsigned len, unsigned bits)
343
15.5M
{
344
15.5M
  uint32_t hash;
345
15.5M
346
15.5M
  hash = isl_seq_get_hash(p, len);
347
15.5M
  return isl_hash_bits(hash, bits);
348
15.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 < len0
;
++i0
)
{0
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
}