Coverage Report

Created: 2018-10-23 15:26

/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
77.6M
{
16
77.6M
  int i;
17
221M
  for (i = 0; i < len; 
++i143M
)
18
143M
    isl_int_set_si(p[i], 0);
19
77.6M
}
20
21
void isl_seq_set_si(isl_int *p, int v, unsigned len)
22
1.71k
{
23
1.71k
  int i;
24
2.63k
  for (i = 0; i < len; 
++i918
)
25
1.71k
    
isl_int_set_si918
(p[i], v);
26
1.71k
}
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
18.5M
{
37
18.5M
  int i;
38
201M
  for (i = 0; i < len; 
++i183M
)
39
183M
    isl_int_neg(dst[i], src[i]);
40
18.5M
}
41
42
void isl_seq_cpy(isl_int *dst, isl_int *src, unsigned len)
43
63.0M
{
44
63.0M
  int i;
45
642M
  for (i = 0; i < len; 
++i579M
)
46
579M
    isl_int_set(dst[i], src[i]);
47
63.0M
}
48
49
void isl_seq_submul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
50
9.79k
{
51
9.79k
  int i;
52
98.2k
  for (i = 0; i < len; 
++i88.4k
)
53
88.4k
    isl_int_submul(dst[i], f, src[i]);
54
9.79k
}
55
56
void isl_seq_addmul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
57
65.7k
{
58
65.7k
  int i;
59
348k
  for (i = 0; i < len; 
++i282k
)
60
282k
    isl_int_addmul(dst[i], f, src[i]);
61
65.7k
}
62
63
void isl_seq_swp_or_cpy(isl_int *dst, isl_int *src, unsigned len)
64
2.91M
{
65
2.91M
  int i;
66
27.6M
  for (i = 0; i < len; 
++i24.7M
)
67
24.7M
    isl_int_swap_or_set(dst[i], src[i]);
68
2.91M
}
69
70
void isl_seq_scale(isl_int *dst, isl_int *src, isl_int m, unsigned len)
71
4.67M
{
72
4.67M
  int i;
73
15.8M
  for (i = 0; i < len; 
++i11.2M
)
74
11.2M
    isl_int_mul(dst[i], src[i], m);
75
4.67M
}
76
77
void isl_seq_scale_down(isl_int *dst, isl_int *src, isl_int m, unsigned len)
78
3.69M
{
79
3.69M
  int i;
80
45.8M
  for (i = 0; i < len; 
++i42.1M
)
81
42.1M
    isl_int_divexact(dst[i], src[i], m);
82
3.69M
}
83
84
void isl_seq_cdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len)
85
3.58k
{
86
3.58k
  int i;
87
13.9k
  for (i = 0; i < len; 
++i10.3k
)
88
10.3k
    isl_int_cdiv_q(dst[i], src[i], m);
89
3.58k
}
90
91
void isl_seq_fdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len)
92
117
{
93
117
  int i;
94
877
  for (i = 0; i < len; 
++i760
)
95
760
    isl_int_fdiv_q(dst[i], src[i], m);
96
117
}
97
98
void isl_seq_fdiv_r(isl_int *dst, isl_int *src, isl_int m, unsigned len)
99
689
{
100
689
  int i;
101
4.35k
  for (i = 0; i < len; 
++i3.66k
)
102
3.66k
    isl_int_fdiv_r(dst[i], src[i], m);
103
689
}
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
14.0M
{
108
14.0M
  int i;
109
14.0M
  isl_int tmp;
110
14.0M
111
14.0M
  if (dst == src1 && 
isl_int_is_one13.9M
(m1)) {
112
12.4M
    if (isl_int_is_zero(m2))
113
12.4M
      
return7.22M
;
114
43.6M
    
for (i = 0; 5.26M
i < len;
++i38.3M
)
115
38.3M
      isl_int_addmul(src1[i], m2, src2[i]);
116
5.26M
    return;
117
5.26M
  }
118
1.55M
119
1.55M
  isl_int_init(tmp);
120
13.4M
  for (i = 0; i < len; 
++i11.8M
) {
121
11.8M
    isl_int_mul(tmp, m1, src1[i]);
122
11.8M
    isl_int_addmul(tmp, m2, src2[i]);
123
11.8M
    isl_int_set(dst[i], tmp);
124
11.8M
  }
125
1.55M
  isl_int_clear(tmp);
126
1.55M
}
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.25M
{
135
2.25M
  isl_int a;
136
2.25M
  isl_int b;
137
2.25M
138
2.25M
  if (isl_int_is_zero(dst[pos]))
139
2.25M
    
return5.06k
;
140
2.25M
141
2.25M
  isl_int_init(a);
142
2.25M
  isl_int_init(b);
143
2.25M
144
2.25M
  isl_int_gcd(a, src[pos], dst[pos]);
145
2.25M
  isl_int_divexact(b, dst[pos], a);
146
2.25M
  if (isl_int_is_pos(src[pos]))
147
2.25M
    
isl_int_neg2.07M
(b, b);
148
2.25M
  isl_int_divexact(a, src[pos], a);
149
2.25M
  isl_int_abs(a, a);
150
2.25M
  isl_seq_combine(dst, a, dst, b, src, len);
151
2.25M
152
2.25M
  if (m)
153
2.25M
    
isl_int_mul20.9k
(*m, *m, a);
154
2.25M
155
2.25M
  isl_int_clear(a);
156
2.25M
  isl_int_clear(b);
157
2.25M
}
158
159
int isl_seq_eq(isl_int *p1, isl_int *p2, unsigned len)
160
14.3M
{
161
14.3M
  int i;
162
109M
  for (i = 0; i < len; 
++i94.8M
)
163
102M
    if (isl_int_ne(p1[i], p2[i]))
164
102M
      
return 07.23M
;
165
14.3M
  
return 17.11M
;
166
14.3M
}
167
168
int isl_seq_cmp(isl_int *p1, isl_int *p2, unsigned len)
169
3.01M
{
170
3.01M
  int i;
171
3.01M
  int cmp;
172
24.4M
  for (i = 0; i < len; 
++i21.3M
)
173
22.9M
    if ((cmp = isl_int_cmp(p1[i], p2[i])) != 0)
174
1.58M
      return cmp;
175
3.01M
  
return 01.42M
;
176
3.01M
}
177
178
int isl_seq_is_neg(isl_int *p1, isl_int *p2, unsigned len)
179
141k
{
180
141k
  int i;
181
141k
182
798k
  for (i = 0; i < len; 
++i657k
) {
183
759k
    if (isl_int_abs_ne(p1[i], p2[i]))
184
759k
      
return 028.5k
;
185
730k
    if (isl_int_is_zero(p1[i]))
186
730k
      
continue585k
;
187
145k
    if (isl_int_eq(p1[i], p2[i]))
188
145k
      
return 073.4k
;
189
145k
  }
190
141k
  
return 139.0k
;
191
141k
}
192
193
int isl_seq_first_non_zero(isl_int *p, unsigned len)
194
48.7M
{
195
48.7M
  int i;
196
48.7M
197
291M
  for (i = 0; i < len; 
++i243M
)
198
280M
    if (!isl_int_is_zero(p[i]))
199
280M
      
return i36.9M
;
200
48.7M
  
return -111.8M
;
201
48.7M
}
202
203
int isl_seq_last_non_zero(isl_int *p, unsigned len)
204
12.0M
{
205
12.0M
  int i;
206
12.0M
207
69.3M
  for (i = len - 1; i >= 0; 
--i57.3M
)
208
64.9M
    if (!isl_int_is_zero(p[i]))
209
64.9M
      
return i7.64M
;
210
12.0M
  
return -14.39M
;
211
12.0M
}
212
213
void isl_seq_abs_max(isl_int *p, unsigned len, isl_int *max)
214
18.1k
{
215
18.1k
  int i;
216
18.1k
217
18.1k
  isl_int_set_si(*max, 0);
218
18.1k
219
126k
  for (i = 0; i < len; 
++i108k
)
220
108k
    if (isl_int_abs_gt(p[i], *max))
221
108k
      
isl_int_abs18.7k
(*max, p[i]);
222
18.1k
}
223
224
int isl_seq_abs_min_non_zero(isl_int *p, unsigned len)
225
30.9M
{
226
30.9M
  int i, min = isl_seq_first_non_zero(p, len);
227
30.9M
  if (min < 0)
228
2.04M
    return -1;
229
223M
  
for (i = min + 1; 28.9M
i < len;
++i194M
) {
230
194M
    if (isl_int_is_zero(p[i]))
231
194M
      
continue154M
;
232
39.8M
    if (isl_int_abs_lt(p[i], p[min]))
233
39.8M
      
min = i7.54M
;
234
39.8M
  }
235
28.9M
  return min;
236
28.9M
}
237
238
void isl_seq_gcd(isl_int *p, unsigned len, isl_int *gcd)
239
29.0M
{
240
29.0M
  int i, min = isl_seq_abs_min_non_zero(p, len);
241
29.0M
242
29.0M
  if (min < 0) {
243
1.56M
    isl_int_set_si(*gcd, 0);
244
1.56M
    return;
245
1.56M
  }
246
27.4M
  isl_int_abs(*gcd, p[min]);
247
72.3M
  for (i = 0; isl_int_cmp_si(*gcd, 1) > 0 && 
i < len48.7M
;
++i44.8M
) {
248
44.8M
    if (i == min)
249
4.25M
      continue;
250
40.6M
    if (isl_int_is_zero(p[i]))
251
40.6M
      
continue26.2M
;
252
14.3M
    isl_int_gcd(*gcd, *gcd, p[i]);
253
14.3M
  }
254
27.4M
}
255
256
void isl_seq_normalize(struct isl_ctx *ctx, isl_int *p, unsigned len)
257
13.0M
{
258
13.0M
  if (len == 0)
259
0
    return;
260
13.0M
  isl_seq_gcd(p, len, &ctx->normalize_gcd);
261
13.0M
  if (!isl_int_is_zero(ctx->normalize_gcd) &&
262
13.0M
      
!12.3M
isl_int_is_one12.3M
(ctx->normalize_gcd))
263
13.0M
    
isl_seq_scale_down(p, p, ctx->normalize_gcd, len)3.52M
;
264
13.0M
}
265
266
void isl_seq_lcm(isl_int *p, unsigned len, isl_int *lcm)
267
3.32k
{
268
3.32k
  int i;
269
3.32k
270
3.32k
  if (len == 0) {
271
0
    isl_int_set_si(*lcm, 1);
272
0
    return;
273
0
  }
274
3.32k
  isl_int_set(*lcm, p[0]);
275
7.17k
  for (i = 1; i < len; 
++i3.84k
)
276
3.84k
    isl_int_lcm(*lcm, *lcm, p[i]);
277
3.32k
}
278
279
void isl_seq_inner_product(isl_int *p1, isl_int *p2, unsigned len,
280
         isl_int *prod)
281
9.84M
{
282
9.84M
  int i;
283
9.84M
  if (len == 0) {
284
0
    isl_int_set_si(*prod, 0);
285
0
    return;
286
0
  }
287
9.84M
  isl_int_mul(*prod, p1[0], p2[0]);
288
86.7M
  for (i = 1; i < len; 
++i76.9M
)
289
76.9M
    isl_int_addmul(*prod, p1[i], p2[i]);
290
9.84M
}
291
292
uint32_t isl_seq_hash(isl_int *p, unsigned len, uint32_t hash)
293
20.1M
{
294
20.1M
  int i;
295
214M
  for (i = 0; i < len; 
++i194M
) {
296
194M
    if (isl_int_is_zero(p[i]))
297
194M
      
continue168M
;
298
25.9M
    hash *= 16777619;
299
25.9M
    hash ^= (i & 0xFF);
300
25.9M
    hash = isl_int_hash(p[i], hash);
301
25.9M
  }
302
20.1M
  return hash;
303
20.1M
}
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.07k
{
328
2.07k
  isl_int_set(v, p[1 + pos]);
329
2.07k
  isl_int_set_si(p[1 + pos], 0);
330
2.07k
  isl_seq_combine(p + 1, subs[0], p + 1, v, subs + 1, subs_len - 1);
331
2.07k
  isl_seq_scale(p + subs_len, p + subs_len, subs[0], p_len - subs_len);
332
2.07k
  isl_int_mul(p[0], p[0], subs[0]);
333
2.07k
}
334
335
uint32_t isl_seq_get_hash(isl_int *p, unsigned len)
336
20.1M
{
337
20.1M
  uint32_t hash = isl_hash_init();
338
20.1M
339
20.1M
  return isl_seq_hash(p, len, hash);
340
20.1M
}
341
342
uint32_t isl_seq_get_hash_bits(isl_int *p, unsigned len, unsigned bits)
343
19.8M
{
344
19.8M
  uint32_t hash;
345
19.8M
346
19.8M
  hash = isl_seq_get_hash(p, len);
347
19.8M
  return isl_hash_bits(hash, bits);
348
19.8M
}
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
}