Coverage Report

Created: 2017-04-29 12:21

/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
41.9M
{
16
41.9M
  int i;
17
110M
  for (i = 0; 
i < len110M
;
++i68.7M
)
18
68.7M
    isl_int_set_si(p[i], 0);
19
41.9M
}
20
21
void isl_seq_set_si(isl_int *p, int v, unsigned len)
22
1.52k
{
23
1.52k
  int i;
24
2.29k
  for (i = 0; 
i < len2.29k
;
++i769
)
25
769
    isl_int_set_si(p[i], v);
26
1.52k
}
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
10.0M
{
37
10.0M
  int i;
38
92.6M
  for (i = 0; 
i < len92.6M
;
++i82.5M
)
39
82.5M
    isl_int_neg(dst[i], src[i]);
40
10.0M
}
41
42
void isl_seq_cpy(isl_int *dst, isl_int *src, unsigned len)
43
34.0M
{
44
34.0M
  int i;
45
235M
  for (i = 0; 
i < len235M
;
++i201M
)
46
201M
    isl_int_set(dst[i], src[i]);
47
34.0M
}
48
49
void isl_seq_submul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
50
3.60k
{
51
3.60k
  int i;
52
26.7k
  for (i = 0; 
i < len26.7k
;
++i23.1k
)
53
23.1k
    isl_int_submul(dst[i], f, src[i]);
54
3.60k
}
55
56
void isl_seq_addmul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
57
54.7k
{
58
54.7k
  int i;
59
298k
  for (i = 0; 
i < len298k
;
++i243k
)
60
243k
    isl_int_addmul(dst[i], f, src[i]);
61
54.7k
}
62
63
void isl_seq_swp_or_cpy(isl_int *dst, isl_int *src, unsigned len)
64
1.64M
{
65
1.64M
  int i;
66
13.6M
  for (i = 0; 
i < len13.6M
;
++i12.0M
)
67
12.0M
    isl_int_swap_or_set(dst[i], src[i]);
68
1.64M
}
69
70
void isl_seq_scale(isl_int *dst, isl_int *src, isl_int m, unsigned len)
71
2.24M
{
72
2.24M
  int i;
73
7.55M
  for (i = 0; 
i < len7.55M
;
++i5.31M
)
74
5.31M
    isl_int_mul(dst[i], src[i], m);
75
2.24M
}
76
77
void isl_seq_scale_down(isl_int *dst, isl_int *src, isl_int m, unsigned len)
78
2.50M
{
79
2.50M
  int i;
80
32.7M
  for (i = 0; 
i < len32.7M
;
++i30.2M
)
81
30.2M
    isl_int_divexact(dst[i], src[i], m);
82
2.50M
}
83
84
void isl_seq_cdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len)
85
2.01k
{
86
2.01k
  int i;
87
8.04k
  for (i = 0; 
i < len8.04k
;
++i6.03k
)
88
6.03k
    isl_int_cdiv_q(dst[i], src[i], m);
89
2.01k
}
90
91
void isl_seq_fdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len)
92
76
{
93
76
  int i;
94
533
  for (i = 0; 
i < len533
;
++i457
)
95
457
    isl_int_fdiv_q(dst[i], src[i], m);
96
76
}
97
98
void isl_seq_fdiv_r(isl_int *dst, isl_int *src, isl_int m, unsigned len)
99
448
{
100
448
  int i;
101
3.18k
  for (i = 0; 
i < len3.18k
;
++i2.74k
)
102
2.74k
    isl_int_fdiv_r(dst[i], src[i], m);
103
448
}
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
7.04M
{
108
7.04M
  int i;
109
7.04M
  isl_int tmp;
110
7.04M
111
7.04M
  if (
dst == src1 && 7.04M
isl_int_is_one7.01M
(m1))
{6.15M
112
6.15M
    if (isl_int_is_zero(m2))
113
3.22M
      return;
114
23.0M
    
for (i = 0; 2.93M
i < len23.0M
;
++i20.1M
)
115
20.1M
      isl_int_addmul(src1[i], m2, src2[i]);
116
2.93M
    return;
117
6.15M
  }
118
7.04M
119
884k
  
isl_int_init884k
(tmp);884k
120
5.97M
  for (i = 0; 
i < len5.97M
;
++i5.09M
)
{5.09M
121
5.09M
    isl_int_mul(tmp, m1, src1[i]);
122
5.09M
    isl_int_addmul(tmp, m2, src2[i]);
123
5.09M
    isl_int_set(dst[i], tmp);
124
5.09M
  }
125
884k
  isl_int_clear(tmp);
126
884k
}
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.39M
{
135
1.39M
  isl_int a;
136
1.39M
  isl_int b;
137
1.39M
138
1.39M
  if (isl_int_is_zero(dst[pos]))
139
626
    return;
140
1.39M
141
1.39M
  
isl_int_init1.39M
(a);1.39M
142
1.39M
  isl_int_init(b);
143
1.39M
144
1.39M
  isl_int_gcd(a, src[pos], dst[pos]);
145
1.39M
  isl_int_divexact(b, dst[pos], a);
146
1.39M
  if (isl_int_is_pos(src[pos]))
147
1.30M
    isl_int_neg(b, b);
148
1.39M
  isl_int_divexact(a, src[pos], a);
149
1.39M
  isl_int_abs(a, a);
150
1.39M
  isl_seq_combine(dst, a, dst, b, src, len);
151
1.39M
152
1.39M
  if (m)
153
7.86k
    isl_int_mul(*m, *m, a);
154
1.39M
155
1.39M
  isl_int_clear(a);
156
1.39M
  isl_int_clear(b);
157
1.39M
}
158
159
int isl_seq_eq(isl_int *p1, isl_int *p2, unsigned len)
160
7.21M
{
161
7.21M
  int i;
162
48.4M
  for (i = 0; 
i < len48.4M
;
++i41.2M
)
163
44.5M
    
if (44.5M
isl_int_ne44.5M
(p1[i], p2[i]))
164
3.30M
      return 0;
165
3.90M
  return 1;
166
7.21M
}
167
168
int isl_seq_cmp(isl_int *p1, isl_int *p2, unsigned len)
169
2.64M
{
170
2.64M
  int i;
171
2.64M
  int cmp;
172
21.3M
  for (i = 0; 
i < len21.3M
;
++i18.6M
)
173
20.1M
    
if (20.1M
(cmp = 20.1M
isl_int_cmp20.1M
(p1[i], p2[i])) != 0)
174
1.44M
      return cmp;
175
1.19M
  return 0;
176
2.64M
}
177
178
int isl_seq_is_neg(isl_int *p1, isl_int *p2, unsigned len)
179
69.3k
{
180
69.3k
  int i;
181
69.3k
182
414k
  for (i = 0; 
i < len414k
;
++i345k
)
{397k
183
397k
    if (isl_int_abs_ne(p1[i], p2[i]))
184
12.0k
      return 0;
185
385k
    
if (385k
isl_int_is_zero385k
(p1[i]))
186
310k
      continue;
187
74.2k
    
if (74.2k
isl_int_eq74.2k
(p1[i], p2[i]))
188
40.1k
      return 0;
189
74.2k
  }
190
17.1k
  return 1;
191
69.3k
}
192
193
int isl_seq_first_non_zero(isl_int *p, unsigned len)
194
25.7M
{
195
25.7M
  int i;
196
25.7M
197
107M
  for (i = 0; 
i < len107M
;
++i82.1M
)
198
102M
    
if (102M
!102M
isl_int_is_zero102M
(p[i]))
199
20.3M
      return i;
200
5.41M
  return -1;
201
25.7M
}
202
203
int isl_seq_last_non_zero(isl_int *p, unsigned len)
204
5.84M
{
205
5.84M
  int i;
206
5.84M
207
24.2M
  for (i = len - 1; 
i >= 024.2M
;
--i18.3M
)
208
21.6M
    
if (21.6M
!21.6M
isl_int_is_zero21.6M
(p[i]))
209
3.30M
      return i;
210
2.54M
  return -1;
211
5.84M
}
212
213
void isl_seq_abs_max(isl_int *p, unsigned len, isl_int *max)
214
4.12k
{
215
4.12k
  int i;
216
4.12k
217
4.12k
  isl_int_set_si(*max, 0);
218
4.12k
219
26.2k
  for (i = 0; 
i < len26.2k
;
++i22.1k
)
220
22.1k
    
if (22.1k
isl_int_abs_gt22.1k
(p[i], *max))
221
4.32k
      isl_int_abs(*max, p[i]);
222
4.12k
}
223
224
int isl_seq_abs_min_non_zero(isl_int *p, unsigned len)
225
18.0M
{
226
18.0M
  int i, min = isl_seq_first_non_zero(p, len);
227
18.0M
  if (min < 0)
228
1.12M
    return -1;
229
122M
  
for (i = min + 1; 16.9M
i < len122M
;
++i105M
)
{105M
230
105M
    if (isl_int_is_zero(p[i]))
231
79.6M
      continue;
232
26.3M
    
if (26.3M
isl_int_abs_lt26.3M
(p[i], p[min]))
233
4.60M
      min = i;
234
26.3M
  }
235
16.9M
  return min;
236
18.0M
}
237
238
void isl_seq_gcd(isl_int *p, unsigned len, isl_int *gcd)
239
17.0M
{
240
17.0M
  int i, min = isl_seq_abs_min_non_zero(p, len);
241
17.0M
242
17.0M
  if (
min < 017.0M
)
{876k
243
876k
    isl_int_set_si(*gcd, 0);
244
876k
    return;
245
876k
  }
246
16.1M
  
isl_int_abs16.1M
(*gcd, p[min]);16.1M
247
48.6M
  for (i = 0; 
isl_int_cmp_si48.6M
(*gcd, 1) > 0 && 48.6M
i < len35.1M
;
++i32.4M
)
{32.4M
248
32.4M
    if (i == min)
249
2.98M
      continue;
250
29.4M
    
if (29.4M
isl_int_is_zero29.4M
(p[i]))
251
17.9M
      continue;
252
11.4M
    
isl_int_gcd11.4M
(*gcd, *gcd, p[i]);11.4M
253
11.4M
  }
254
16.1M
}
255
256
void isl_seq_normalize(struct isl_ctx *ctx, isl_int *p, unsigned len)
257
7.78M
{
258
7.78M
  if (len == 0)
259
0
    return;
260
7.78M
  isl_seq_gcd(p, len, &ctx->normalize_gcd);
261
7.78M
  if (
!7.78M
isl_int_is_zero7.78M
(ctx->normalize_gcd) &&
262
7.38M
      
!7.38M
isl_int_is_one7.38M
(ctx->normalize_gcd))
263
2.36M
    isl_seq_scale_down(p, p, ctx->normalize_gcd, len);
264
7.78M
}
265
266
void isl_seq_lcm(isl_int *p, unsigned len, isl_int *lcm)
267
1.72k
{
268
1.72k
  int i;
269
1.72k
270
1.72k
  if (
len == 01.72k
)
{0
271
0
    isl_int_set_si(*lcm, 1);
272
0
    return;
273
0
  }
274
1.72k
  
isl_int_set1.72k
(*lcm, p[0]);1.72k
275
3.88k
  for (i = 1; 
i < len3.88k
;
++i2.15k
)
276
2.15k
    isl_int_lcm(*lcm, *lcm, p[i]);
277
1.72k
}
278
279
void isl_seq_inner_product(isl_int *p1, isl_int *p2, unsigned len,
280
         isl_int *prod)
281
5.25M
{
282
5.25M
  int i;
283
5.25M
  if (
len == 05.25M
)
{0
284
0
    isl_int_set_si(*prod, 0);
285
0
    return;
286
0
  }
287
5.25M
  
isl_int_mul5.25M
(*prod, p1[0], p2[0]);5.25M
288
42.7M
  for (i = 1; 
i < len42.7M
;
++i37.5M
)
289
37.5M
    isl_int_addmul(*prod, p1[i], p2[i]);
290
5.25M
}
291
292
uint32_t isl_seq_hash(isl_int *p, unsigned len, uint32_t hash)
293
11.4M
{
294
11.4M
  int i;
295
102M
  for (i = 0; 
i < len102M
;
++i90.7M
)
{90.7M
296
90.7M
    if (isl_int_is_zero(p[i]))
297
75.5M
      continue;
298
15.1M
    hash *= 16777619;
299
15.1M
    hash ^= (i & 0xFF);
300
15.1M
    hash = isl_int_hash(p[i], hash);
301
15.1M
  }
302
11.4M
  return hash;
303
11.4M
}
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
428
{
328
428
  isl_int_set(v, p[1 + pos]);
329
428
  isl_int_set_si(p[1 + pos], 0);
330
428
  isl_seq_combine(p + 1, subs[0], p + 1, v, subs + 1, subs_len - 1);
331
428
  isl_seq_scale(p + subs_len, p + subs_len, subs[0], p_len - subs_len);
332
428
  isl_int_mul(p[0], p[0], subs[0]);
333
428
}
334
335
uint32_t isl_seq_get_hash(isl_int *p, unsigned len)
336
11.4M
{
337
11.4M
  uint32_t hash = isl_hash_init();
338
11.4M
339
11.4M
  return isl_seq_hash(p, len, hash);
340
11.4M
}
341
342
uint32_t isl_seq_get_hash_bits(isl_int *p, unsigned len, unsigned bits)
343
11.3M
{
344
11.3M
  uint32_t hash;
345
11.3M
346
11.3M
  hash = isl_seq_get_hash(p, len);
347
11.3M
  return isl_hash_bits(hash, bits);
348
11.3M
}
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
}