Coverage Report

Created: 2017-08-18 19:41

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/lib/External/isl/isl_int_sioimath.c
Line
Count
Source (jump to first uncovered line)
1
#include <stdlib.h>
2
#include <string.h>
3
4
#include <isl_int.h>
5
6
extern int isl_sioimath_decode(isl_sioimath val, int32_t *small, mp_int *big);
7
extern int isl_sioimath_decode_big(isl_sioimath val, mp_int *big);
8
extern int isl_sioimath_decode_small(isl_sioimath val, int32_t *small);
9
10
extern isl_sioimath isl_sioimath_encode_small(int32_t val);
11
extern isl_sioimath isl_sioimath_encode_big(mp_int val);
12
extern int isl_sioimath_is_small(isl_sioimath val);
13
extern int isl_sioimath_is_big(isl_sioimath val);
14
extern int32_t isl_sioimath_get_small(isl_sioimath val);
15
extern mp_int isl_sioimath_get_big(isl_sioimath val);
16
17
extern void isl_siomath_uint32_to_digits(uint32_t num, mp_digit *digits,
18
  mp_size *used);
19
extern void isl_siomath_ulong_to_digits(unsigned long num, mp_digit *digits,
20
  mp_size *used);
21
extern void isl_siomath_uint64_to_digits(uint64_t num, mp_digit *digits,
22
  mp_size *used);
23
24
extern mp_int isl_sioimath_bigarg_src(isl_sioimath arg,
25
  isl_sioimath_scratchspace_t *scratch);
26
extern mp_int isl_sioimath_siarg_src(signed long arg,
27
  isl_sioimath_scratchspace_t *scratch);
28
extern mp_int isl_sioimath_si64arg_src(int64_t arg,
29
  isl_sioimath_scratchspace_t *scratch);
30
extern mp_int isl_sioimath_uiarg_src(unsigned long arg,
31
  isl_sioimath_scratchspace_t *scratch);
32
extern mp_int isl_sioimath_reinit_big(isl_sioimath_ptr ptr);
33
extern void isl_sioimath_set_small(isl_sioimath_ptr ptr, int32_t val);
34
extern void isl_sioimath_set_int32(isl_sioimath_ptr ptr, int32_t val);
35
extern void isl_sioimath_set_int64(isl_sioimath_ptr ptr, int64_t val);
36
extern void isl_sioimath_promote(isl_sioimath_ptr dst);
37
extern void isl_sioimath_try_demote(isl_sioimath_ptr dst);
38
39
extern void isl_sioimath_init(isl_sioimath_ptr dst);
40
extern void isl_sioimath_clear(isl_sioimath_ptr dst);
41
extern void isl_sioimath_set(isl_sioimath_ptr dst, isl_sioimath_src val);
42
extern void isl_sioimath_set_si(isl_sioimath_ptr dst, long val);
43
extern void isl_sioimath_set_ui(isl_sioimath_ptr dst, unsigned long val);
44
extern int isl_sioimath_fits_slong(isl_sioimath_src val);
45
extern long isl_sioimath_get_si(isl_sioimath_src val);
46
extern int isl_sioimath_fits_ulong(isl_sioimath_src val);
47
extern unsigned long isl_sioimath_get_ui(isl_sioimath_src val);
48
extern double isl_sioimath_get_d(isl_sioimath_src val);
49
extern char *isl_sioimath_get_str(isl_sioimath_src val);
50
extern void isl_sioimath_abs(isl_sioimath_ptr dst, isl_sioimath_src arg);
51
extern void isl_sioimath_neg(isl_sioimath_ptr dst, isl_sioimath_src arg);
52
extern void isl_sioimath_swap(isl_sioimath_ptr lhs, isl_sioimath_ptr rhs);
53
extern void isl_sioimath_add_ui(isl_sioimath_ptr dst, isl_sioimath lhs,
54
  unsigned long rhs);
55
extern void isl_sioimath_sub_ui(isl_sioimath_ptr dst, isl_sioimath lhs,
56
  unsigned long rhs);
57
58
extern void isl_sioimath_add(isl_sioimath_ptr dst, isl_sioimath_src lhs,
59
  isl_sioimath_src rhs);
60
extern void isl_sioimath_sub(isl_sioimath_ptr dst, isl_sioimath_src lhs,
61
  isl_sioimath_src rhs);
62
extern void isl_sioimath_mul(isl_sioimath_ptr dst, isl_sioimath_src lhs,
63
  isl_sioimath_src rhs);
64
extern void isl_sioimath_mul_2exp(isl_sioimath_ptr dst, isl_sioimath lhs,
65
  unsigned long rhs);
66
extern void isl_sioimath_mul_si(isl_sioimath_ptr dst, isl_sioimath lhs,
67
  signed long rhs);
68
extern void isl_sioimath_mul_ui(isl_sioimath_ptr dst, isl_sioimath lhs,
69
  unsigned long rhs);
70
extern void isl_sioimath_pow_ui(isl_sioimath_ptr dst, isl_sioimath_src lhs,
71
  unsigned long rhs);
72
extern void isl_sioimath_addmul(isl_sioimath_ptr dst, isl_sioimath_src lhs,
73
  isl_sioimath_src rhs);
74
extern void isl_sioimath_addmul_ui(isl_sioimath_ptr dst, isl_sioimath_src lhs,
75
  unsigned long rhs);
76
extern void isl_sioimath_submul(isl_sioimath_ptr dst, isl_sioimath_src lhs,
77
  isl_sioimath_src rhs);
78
extern void isl_sioimath_submul_ui(isl_sioimath_ptr dst, isl_sioimath_src lhs,
79
  unsigned long rhs);
80
81
/* Implements the Euclidean algorithm to compute the greatest common divisor of
82
 * two values in small representation.
83
 */
84
static uint32_t isl_sioimath_smallgcd(int32_t lhs, int32_t rhs)
85
18.6M
{
86
18.6M
  uint32_t dividend, divisor, remainder;
87
18.6M
88
18.6M
  dividend = labs(lhs);
89
18.6M
  divisor = labs(rhs);
90
50.9M
  while (
divisor50.9M
)
{32.2M
91
32.2M
    remainder = dividend % divisor;
92
32.2M
    dividend = divisor;
93
32.2M
    divisor = remainder;
94
32.2M
  }
95
18.6M
96
18.6M
  return dividend;
97
18.6M
}
98
99
/* Compute the greatest common divisor.
100
 *
101
 * Per GMP convention, gcd(0,0)==0 and otherwise always positive.
102
 */
103
void isl_sioimath_gcd(isl_sioimath_ptr dst, isl_sioimath_src lhs,
104
  isl_sioimath_src rhs)
105
14.9M
{
106
14.9M
  int32_t lhssmall, rhssmall;
107
14.9M
  uint32_t smallgcd;
108
14.9M
  isl_sioimath_scratchspace_t scratchlhs, scratchrhs;
109
14.9M
110
14.9M
  if (isl_sioimath_decode_small(lhs, &lhssmall) &&
111
14.9M
      
isl_sioimath_decode_small(rhs, &rhssmall)14.0M
)
{12.7M
112
12.7M
    smallgcd = isl_sioimath_smallgcd(lhssmall, rhssmall);
113
12.7M
    isl_sioimath_set_small(dst, smallgcd);
114
12.7M
    return;
115
14.9M
  }
116
14.9M
117
14.9M
  impz_gcd(isl_sioimath_reinit_big(dst),
118
2.20M
      isl_sioimath_bigarg_src(lhs, &scratchlhs),
119
2.20M
      isl_sioimath_bigarg_src(rhs, &scratchrhs));
120
2.20M
  isl_sioimath_try_demote(dst);
121
14.9M
}
122
123
/* Compute the lowest common multiple of two numbers.
124
 */
125
void isl_sioimath_lcm(isl_sioimath_ptr dst, isl_sioimath_src lhs,
126
  isl_sioimath_src rhs)
127
6.10M
{
128
6.10M
  int32_t lhssmall, rhssmall;
129
6.10M
  uint32_t smallgcd;
130
6.10M
  uint64_t multiple;
131
6.10M
  isl_sioimath_scratchspace_t scratchlhs, scratchrhs;
132
6.10M
133
6.10M
  if (isl_sioimath_decode_small(lhs, &lhssmall) &&
134
6.10M
      
isl_sioimath_decode_small(rhs, &rhssmall)5.94M
)
{5.83M
135
5.83M
    if (
lhssmall == 0 || 5.83M
rhssmall == 05.83M
)
{0
136
0
      isl_sioimath_set_small(dst, 0);
137
0
      return;
138
5.83M
    }
139
5.83M
    smallgcd = isl_sioimath_smallgcd(lhssmall, rhssmall);
140
5.83M
    multiple = (uint64_t) abs(lhssmall) * (uint64_t) abs(rhssmall);
141
5.83M
    isl_sioimath_set_int64(dst, multiple / smallgcd);
142
5.83M
    return;
143
6.10M
  }
144
6.10M
145
6.10M
  impz_lcm(isl_sioimath_reinit_big(dst),
146
270k
      isl_sioimath_bigarg_src(lhs, &scratchlhs),
147
270k
      isl_sioimath_bigarg_src(rhs, &scratchrhs));
148
270k
  isl_sioimath_try_demote(dst);
149
6.10M
}
150
151
extern void isl_sioimath_tdiv_q(isl_sioimath_ptr dst, isl_sioimath_src lhs,
152
  isl_sioimath_src rhs);
153
extern void isl_sioimath_tdiv_q_ui(isl_sioimath_ptr dst, isl_sioimath_src lhs,
154
  unsigned long rhs);
155
extern void isl_sioimath_cdiv_q(isl_sioimath_ptr dst, isl_sioimath_src lhs,
156
  isl_sioimath_src rhs);
157
extern void isl_sioimath_cdiv_q_ui(isl_sioimath_ptr dst, isl_sioimath_src lhs,
158
  unsigned long rhs);
159
extern void isl_sioimath_fdiv_q(isl_sioimath_ptr dst, isl_sioimath_src lhs,
160
  isl_sioimath_src rhs);
161
extern void isl_sioimath_fdiv_q_ui(isl_sioimath_ptr dst, isl_sioimath_src lhs,
162
  unsigned long rhs);
163
extern void isl_sioimath_fdiv_r(isl_sioimath_ptr dst, isl_sioimath_src lhs,
164
  isl_sioimath_src rhs);
165
166
/* Parse a number from a string.
167
 * If it has less than 10 characters then it will fit into the small
168
 * representation (i.e. strlen("2147483647")). Otherwise, let IMath parse it.
169
 */
170
void isl_sioimath_read(isl_sioimath_ptr dst, const char *str)
171
9.88k
{
172
9.88k
  int32_t small;
173
9.88k
174
9.88k
  if (
strlen(str) < 109.88k
)
{9.73k
175
9.73k
    small = strtol(str, NULL, 10);
176
9.73k
    isl_sioimath_set_small(dst, small);
177
9.73k
    return;
178
9.88k
  }
179
9.88k
180
9.88k
  mp_int_read_string(isl_sioimath_reinit_big(dst), 10, str);
181
148
  isl_sioimath_try_demote(dst);
182
9.88k
}
183
184
extern int isl_sioimath_sgn(isl_sioimath_src arg);
185
extern int isl_sioimath_cmp(isl_sioimath_src lhs, isl_sioimath_src rhs);
186
extern int isl_sioimath_cmp_si(isl_sioimath_src lhs, signed long rhs);
187
extern int isl_sioimath_abs_cmp(isl_sioimath_src lhs, isl_sioimath_src rhs);
188
extern int isl_sioimath_is_divisible_by(isl_sioimath_src lhs,
189
  isl_sioimath_src rhs);
190
191
extern uint32_t isl_sioimath_hash(isl_sioimath_src arg, uint32_t hash);
192
extern size_t isl_sioimath_sizeinbase(isl_sioimath_src arg, int base);
193
extern void isl_sioimath_print(FILE *out, isl_sioimath_src i, int width);
194
195
/* Print an isl_int to FILE*. Adds space padding to the left until at least
196
 * width characters are printed.
197
 */
198
void isl_sioimath_print(FILE *out, isl_sioimath_src i, int width)
199
0
{
200
0
  size_t len;
201
0
  int32_t small;
202
0
  mp_int big;
203
0
  char *buf;
204
0
205
0
  if (
isl_sioimath_decode_small(i, &small)0
)
{0
206
0
    fprintf(out, "%*" PRIi32, width, small);
207
0
    return;
208
0
  }
209
0
210
0
  big = isl_sioimath_get_big(i);
211
0
  len = mp_int_string_len(big, 10);
212
0
  buf = malloc(len);
213
0
  mp_int_to_string(big, 10, buf, len);
214
0
  fprintf(out, "%*s", width, buf);
215
0
  free(buf);
216
0
}
217
218
/* Print a number to stdout. Meant for debugging.
219
 */
220
void isl_sioimath_dump(isl_sioimath_src arg)
221
0
{
222
0
  isl_sioimath_print(stdout, arg, 0);
223
0
}