Coverage Report

Created: 2017-03-27 23:01

/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
 *
4
 * Use of this software is governed by the MIT license
5
 *
6
 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7
 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8
 */
9
10
#include <isl_ctx_private.h>
11
#include <isl_seq.h>
12
13
void isl_seq_clr(isl_int *p, unsigned len)
14
38.1M
{
15
38.1M
  int i;
16
102M
  for (i = 0; 
i < len102M
;
++i64.5M
)
17
64.5M
    isl_int_set_si(p[i], 0);
18
38.1M
}
19
20
void isl_seq_set_si(isl_int *p, int v, unsigned len)
21
1.51k
{
22
1.51k
  int i;
23
2.26k
  for (i = 0; 
i < len2.26k
;
++i756
)
24
756
    isl_int_set_si(p[i], v);
25
1.51k
}
26
27
void isl_seq_set(isl_int *p, isl_int v, unsigned len)
28
10
{
29
10
  int i;
30
22
  for (i = 0; 
i < len22
;
++i12
)
31
12
    isl_int_set(p[i], v);
32
10
}
33
34
void isl_seq_neg(isl_int *dst, isl_int *src, unsigned len)
35
9.17M
{
36
9.17M
  int i;
37
86.6M
  for (i = 0; 
i < len86.6M
;
++i77.4M
)
38
77.4M
    isl_int_neg(dst[i], src[i]);
39
9.17M
}
40
41
void isl_seq_cpy(isl_int *dst, isl_int *src, unsigned len)
42
30.7M
{
43
30.7M
  int i;
44
222M
  for (i = 0; 
i < len222M
;
++i192M
)
45
192M
    isl_int_set(dst[i], src[i]);
46
30.7M
}
47
48
void isl_seq_submul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
49
2.74k
{
50
2.74k
  int i;
51
20.6k
  for (i = 0; 
i < len20.6k
;
++i17.9k
)
52
17.9k
    isl_int_submul(dst[i], f, src[i]);
53
2.74k
}
54
55
void isl_seq_addmul(isl_int *dst, isl_int f, isl_int *src, unsigned len)
56
54.1k
{
57
54.1k
  int i;
58
285k
  for (i = 0; 
i < len285k
;
++i231k
)
59
231k
    isl_int_addmul(dst[i], f, src[i]);
60
54.1k
}
61
62
void isl_seq_swp_or_cpy(isl_int *dst, isl_int *src, unsigned len)
63
1.52M
{
64
1.52M
  int i;
65
13.0M
  for (i = 0; 
i < len13.0M
;
++i11.4M
)
66
11.4M
    isl_int_swap_or_set(dst[i], src[i]);
67
1.52M
}
68
69
void isl_seq_scale(isl_int *dst, isl_int *src, isl_int m, unsigned len)
70
2.02M
{
71
2.02M
  int i;
72
7.03M
  for (i = 0; 
i < len7.03M
;
++i5.00M
)
73
5.00M
    isl_int_mul(dst[i], src[i], m);
74
2.02M
}
75
76
void isl_seq_scale_down(isl_int *dst, isl_int *src, isl_int m, unsigned len)
77
2.46M
{
78
2.46M
  int i;
79
32.4M
  for (i = 0; 
i < len32.4M
;
++i29.9M
)
80
29.9M
    isl_int_divexact(dst[i], src[i], m);
81
2.46M
}
82
83
void isl_seq_cdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len)
84
1.74k
{
85
1.74k
  int i;
86
7.17k
  for (i = 0; 
i < len7.17k
;
++i5.43k
)
87
5.43k
    isl_int_cdiv_q(dst[i], src[i], m);
88
1.74k
}
89
90
void isl_seq_fdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len)
91
36
{
92
36
  int i;
93
253
  for (i = 0; 
i < len253
;
++i217
)
94
217
    isl_int_fdiv_q(dst[i], src[i], m);
95
36
}
96
97
void isl_seq_fdiv_r(isl_int *dst, isl_int *src, isl_int m, unsigned len)
98
401
{
99
401
  int i;
100
2.86k
  for (i = 0; 
i < len2.86k
;
++i2.46k
)
101
2.46k
    isl_int_fdiv_r(dst[i], src[i], m);
102
401
}
103
104
void isl_seq_combine(isl_int *dst, isl_int m1, isl_int *src1,
105
      isl_int m2, isl_int *src2, unsigned len)
106
6.41M
{
107
6.41M
  int i;
108
6.41M
  isl_int tmp;
109
6.41M
110
6.41M
  if (
dst == src1 && 6.41M
isl_int_is_one6.38M
(m1))
{5.54M
111
5.54M
    if (isl_int_is_zero(m2))
112
2.97M
      return;
113
20.3M
    
for (i = 0; 2.57M
i < len20.3M
;
++i17.7M
)
114
17.7M
      isl_int_addmul(src1[i], m2, src2[i]);
115
2.57M
    return;
116
5.54M
  }
117
6.41M
118
861k
  
isl_int_init861k
(tmp);861k
119
5.83M
  for (i = 0; 
i < len5.83M
;
++i4.97M
)
{4.97M
120
4.97M
    isl_int_mul(tmp, m1, src1[i]);
121
4.97M
    isl_int_addmul(tmp, m2, src2[i]);
122
4.97M
    isl_int_set(dst[i], tmp);
123
4.97M
  }
124
861k
  isl_int_clear(tmp);
125
861k
}
126
127
/*
128
 * Let d = dst[pos] and s = src[pos]
129
 * dst is replaced by |s| dst - sgn(s)d src
130
 */
131
void isl_seq_elim(isl_int *dst, isl_int *src, unsigned pos, unsigned len,
132
      isl_int *m)
133
1.13M
{
134
1.13M
  isl_int a;
135
1.13M
  isl_int b;
136
1.13M
137
1.13M
  if (isl_int_is_zero(dst[pos]))
138
616
    return;
139
1.13M
140
1.13M
  
isl_int_init1.13M
(a);1.13M
141
1.13M
  isl_int_init(b);
142
1.13M
143
1.13M
  isl_int_gcd(a, src[pos], dst[pos]);
144
1.13M
  isl_int_divexact(b, dst[pos], a);
145
1.13M
  if (isl_int_is_pos(src[pos]))
146
1.07M
    isl_int_neg(b, b);
147
1.13M
  isl_int_divexact(a, src[pos], a);
148
1.13M
  isl_int_abs(a, a);
149
1.13M
  isl_seq_combine(dst, a, dst, b, src, len);
150
1.13M
151
1.13M
  if (m)
152
5.64k
    isl_int_mul(*m, *m, a);
153
1.13M
154
1.13M
  isl_int_clear(a);
155
1.13M
  isl_int_clear(b);
156
1.13M
}
157
158
int isl_seq_eq(isl_int *p1, isl_int *p2, unsigned len)
159
6.68M
{
160
6.68M
  int i;
161
45.6M
  for (i = 0; 
i < len45.6M
;
++i38.9M
)
162
42.0M
    
if (42.0M
isl_int_ne42.0M
(p1[i], p2[i]))
163
3.13M
      return 0;
164
3.55M
  return 1;
165
6.68M
}
166
167
int isl_seq_cmp(isl_int *p1, isl_int *p2, unsigned len)
168
2.62M
{
169
2.62M
  int i;
170
2.62M
  int cmp;
171
21.2M
  for (i = 0; 
i < len21.2M
;
++i18.6M
)
172
20.0M
    
if (20.0M
(cmp = 20.0M
isl_int_cmp20.0M
(p1[i], p2[i])) != 0)
173
1.44M
      return cmp;
174
1.18M
  return 0;
175
2.62M
}
176
177
int isl_seq_is_neg(isl_int *p1, isl_int *p2, unsigned len)
178
67.7k
{
179
67.7k
  int i;
180
67.7k
181
406k
  for (i = 0; 
i < len406k
;
++i338k
)
{390k
182
390k
    if (isl_int_abs_ne(p1[i], p2[i]))
183
11.5k
      return 0;
184
378k
    
if (378k
isl_int_is_zero378k
(p1[i]))
185
306k
      continue;
186
71.9k
    
if (71.9k
isl_int_eq71.9k
(p1[i], p2[i]))
187
40.1k
      return 0;
188
71.9k
  }
189
16.0k
  return 1;
190
67.7k
}
191
192
int isl_seq_first_non_zero(isl_int *p, unsigned len)
193
23.7M
{
194
23.7M
  int i;
195
23.7M
196
102M
  for (i = 0; 
i < len102M
;
++i78.9M
)
197
97.6M
    
if (97.6M
!97.6M
isl_int_is_zero97.6M
(p[i]))
198
18.6M
      return i;
199
5.08M
  return -1;
200
23.7M
}
201
202
int isl_seq_last_non_zero(isl_int *p, unsigned len)
203
5.11M
{
204
5.11M
  int i;
205
5.11M
206
23.0M
  for (i = len - 1; 
i >= 023.0M
;
--i17.8M
)
207
21.0M
    
if (21.0M
!21.0M
isl_int_is_zero21.0M
(p[i]))
208
3.12M
      return i;
209
1.99M
  return -1;
210
5.11M
}
211
212
void isl_seq_abs_max(isl_int *p, unsigned len, isl_int *max)
213
4.29k
{
214
4.29k
  int i;
215
4.29k
216
4.29k
  isl_int_set_si(*max, 0);
217
4.29k
218
27.3k
  for (i = 0; 
i < len27.3k
;
++i23.0k
)
219
23.0k
    
if (23.0k
isl_int_abs_gt23.0k
(p[i], *max))
220
4.49k
      isl_int_abs(*max, p[i]);
221
4.29k
}
222
223
int isl_seq_abs_min_non_zero(isl_int *p, unsigned len)
224
16.3M
{
225
16.3M
  int i, min = isl_seq_first_non_zero(p, len);
226
16.3M
  if (min < 0)
227
1.01M
    return -1;
228
114M
  
for (i = min + 1; 15.3M
i < len114M
;
++i98.7M
)
{98.7M
229
98.7M
    if (isl_int_is_zero(p[i]))
230
73.5M
      continue;
231
25.2M
    
if (25.2M
isl_int_abs_lt25.2M
(p[i], p[min]))
232
4.46M
      min = i;
233
25.2M
  }
234
15.3M
  return min;
235
16.3M
}
236
237
void isl_seq_gcd(isl_int *p, unsigned len, isl_int *gcd)
238
15.4M
{
239
15.4M
  int i, min = isl_seq_abs_min_non_zero(p, len);
240
15.4M
241
15.4M
  if (
min < 015.4M
)
{773k
242
773k
    isl_int_set_si(*gcd, 0);
243
773k
    return;
244
773k
  }
245
14.6M
  
isl_int_abs14.6M
(*gcd, p[min]);14.6M
246
46.7M
  for (i = 0; 
isl_int_cmp_si46.7M
(*gcd, 1) > 0 && 46.7M
i < len34.8M
;
++i32.1M
)
{32.1M
247
32.1M
    if (i == min)
248
2.94M
      continue;
249
29.2M
    
if (29.2M
isl_int_is_zero29.2M
(p[i]))
250
17.7M
      continue;
251
11.4M
    
isl_int_gcd11.4M
(*gcd, *gcd, p[i]);11.4M
252
11.4M
  }
253
14.6M
}
254
255
void isl_seq_normalize(struct isl_ctx *ctx, isl_int *p, unsigned len)
256
7.30M
{
257
7.30M
  if (len == 0)
258
0
    return;
259
7.30M
  isl_seq_gcd(p, len, &ctx->normalize_gcd);
260
7.30M
  if (
!7.30M
isl_int_is_zero7.30M
(ctx->normalize_gcd) &&
261
6.96M
      
!6.96M
isl_int_is_one6.96M
(ctx->normalize_gcd))
262
2.33M
    isl_seq_scale_down(p, p, ctx->normalize_gcd, len);
263
7.30M
}
264
265
void isl_seq_lcm(isl_int *p, unsigned len, isl_int *lcm)
266
1.43k
{
267
1.43k
  int i;
268
1.43k
269
1.43k
  if (
len == 01.43k
)
{0
270
0
    isl_int_set_si(*lcm, 1);
271
0
    return;
272
0
  }
273
1.43k
  
isl_int_set1.43k
(*lcm, p[0]);1.43k
274
3.26k
  for (i = 1; 
i < len3.26k
;
++i1.83k
)
275
1.83k
    isl_int_lcm(*lcm, *lcm, p[i]);
276
1.43k
}
277
278
void isl_seq_inner_product(isl_int *p1, isl_int *p2, unsigned len,
279
         isl_int *prod)
280
4.82M
{
281
4.82M
  int i;
282
4.82M
  if (
len == 04.82M
)
{0
283
0
    isl_int_set_si(*prod, 0);
284
0
    return;
285
0
  }
286
4.82M
  
isl_int_mul4.82M
(*prod, p1[0], p2[0]);4.82M
287
40.4M
  for (i = 1; 
i < len40.4M
;
++i35.6M
)
288
35.6M
    isl_int_addmul(*prod, p1[i], p2[i]);
289
4.82M
}
290
291
uint32_t isl_seq_hash(isl_int *p, unsigned len, uint32_t hash)
292
10.4M
{
293
10.4M
  int i;
294
95.3M
  for (i = 0; 
i < len95.3M
;
++i84.8M
)
{84.8M
295
84.8M
    if (isl_int_is_zero(p[i]))
296
70.8M
      continue;
297
14.0M
    hash *= 16777619;
298
14.0M
    hash ^= (i & 0xFF);
299
14.0M
    hash = isl_int_hash(p[i], hash);
300
14.0M
  }
301
10.4M
  return hash;
302
10.4M
}
303
304
uint32_t isl_seq_get_hash(isl_int *p, unsigned len)
305
10.4M
{
306
10.4M
  uint32_t hash = isl_hash_init();
307
10.4M
308
10.4M
  return isl_seq_hash(p, len, hash);
309
10.4M
}
310
311
uint32_t isl_seq_get_hash_bits(isl_int *p, unsigned len, unsigned bits)
312
10.3M
{
313
10.3M
  uint32_t hash;
314
10.3M
315
10.3M
  hash = isl_seq_get_hash(p, len);
316
10.3M
  return isl_hash_bits(hash, bits);
317
10.3M
}
318
319
void isl_seq_dump(isl_int *p, unsigned len)
320
0
{
321
0
  int i;
322
0
323
0
  for (i = 0; 
i < len0
;
++i0
)
{0
324
0
    if (i)
325
0
      fprintf(stderr, " ");
326
0
    isl_int_print(stderr, p[i], 0);
327
0
  }
328
0
  fprintf(stderr, "\n");
329
0
}