declare isl_union_pw_multi_aff_intersect_params
[isl.git] / isl_val_imath.c
blob8f91700a895db9dd3f7190a162feea71e1146063
1 #include <isl_val_private.h>
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)
10 isl_val *v;
12 v = isl_val_alloc(ctx);
13 if (!v)
14 return NULL;
16 impz_import(v->n, n, -1, size, 0, 0, chunks);
17 isl_int_set_si(v->d, 1);
19 return v;
22 /* Store a representation of the absolute value of the numerator of "v"
23 * in terms of chunks of size "size" at "chunks".
24 * The least significant chunk is stored first.
25 * The number of chunks in the result can be obtained by calling
26 * isl_val_n_abs_num_chunks. The user is responsible for allocating
27 * enough memory to store the results.
29 * In the special case of a zero value, isl_val_n_abs_num_chunks will
30 * return one, while impz_export will not fill in any chunks. We therefore
31 * do it ourselves.
33 int isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size,
34 void *chunks)
36 if (!v || !chunks)
37 return -1;
39 if (!isl_val_is_rat(v))
40 isl_die(isl_val_get_ctx(v), isl_error_invalid,
41 "expecting rational value", return -1);
43 impz_export(chunks, NULL, -1, size, 0, 0, v->n);
44 if (isl_val_is_zero(v))
45 memset(chunks, 0, size);
47 return 0;
50 /* Return the number of chunks of size "size" required to
51 * store the absolute value of the numerator of "v".
53 size_t isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size)
55 if (!v)
56 return 0;
58 if (!isl_val_is_rat(v))
59 isl_die(isl_val_get_ctx(v), isl_error_invalid,
60 "expecting rational value", return 0);
62 size *= 8;
63 return (impz_sizeinbase(v->n, 2) + size - 1) / size;