1#include <isl_val_private.h>
2
3/* Return a reference to an isl_val representing the unsigned
4 * integer value stored in the "n" chunks of size "size" at "chunks".
5 * The least significant chunk is assumed to be stored first.
6 */
7__isl_give isl_val *isl_val_int_from_chunks(isl_ctx *ctx, size_t n,
8 size_t size, const void *chunks)
9{
10 isl_val *v;
11
12 v = isl_val_alloc(ctx);
13 if (!v)
14 return NULL;
15
16 impz_import(rop: isl_sioimath_reinit_big(ptr: v->n), count: n, order: -1, size, endian: 0, nails: 0, op: chunks);
17 isl_sioimath_try_demote(dst: v->n);
18 isl_int_set_si(v->d, 1);
19
20 return v;
21}
22
23/* Store a representation of the absolute value of the numerator of "v"
24 * in terms of chunks of size "size" at "chunks".
25 * The least significant chunk is stored first.
26 * The number of chunks in the result can be obtained by calling
27 * isl_val_n_abs_num_chunks. The user is responsible for allocating
28 * enough memory to store the results.
29 *
30 * In the special case of a zero value, isl_val_n_abs_num_chunks will
31 * return one, while impz_export will not fill in any chunks. We therefore
32 * do it ourselves.
33 */
34isl_stat isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size,
35 void *chunks)
36{
37 isl_sioimath_scratchspace_t scratch;
38
39 if (!v || !chunks)
40 return isl_stat_error;
41
42 if (!isl_val_is_rat(v))
43 isl_die(isl_val_get_ctx(v), isl_error_invalid,
44 "expecting rational value", return isl_stat_error);
45
46 impz_export(rop: chunks, NULL, order: -1, size, endian: 0, nails: 0,
47 op: isl_sioimath_bigarg_src(arg: *v->n, scratch: &scratch));
48 if (isl_val_is_zero(v))
49 memset(s: chunks, c: 0, n: size);
50
51 return isl_stat_ok;
52}
53
54/* Return the number of chunks of size "size" required to
55 * store the absolute value of the numerator of "v".
56 */
57isl_size isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size)
58{
59 if (!v)
60 return isl_size_error;
61
62 if (!isl_val_is_rat(v))
63 isl_die(isl_val_get_ctx(v), isl_error_invalid,
64 "expecting rational value", return isl_size_error);
65
66 size *= 8;
67 return (isl_sioimath_sizeinbase(arg: *v->n, base: 2) + size - 1) / size;
68}
69

source code of polly/lib/External/isl/isl_val_sioimath.c