Polly 19.0.0git
isl_val_imath.c
Go to the documentation of this file.
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 */
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(v->n, n, -1, size, 0, 0, chunks);
17 isl_int_set_si(v->d, 1);
18
19 return v;
20}
21
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.
28 *
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.
32 */
34 void *chunks)
35{
36 if (!v || !chunks)
37 return isl_stat_error;
38
39 if (!isl_val_is_rat(v))
41 "expecting rational value", return isl_stat_error);
42
43 impz_export(chunks, NULL, -1, size, 0, 0, v->n);
44 if (isl_val_is_zero(v))
45 memset(chunks, 0, size);
46
47 return isl_stat_ok;
48}
49
50/* Return the number of chunks of size "size" required to
51 * store the absolute value of the numerator of "v".
52 */
54{
55 if (!v)
56 return isl_size_error;
57
58 if (!isl_val_is_rat(v))
60 "expecting rational value", return isl_size_error);
61
62 size *= 8;
63 return (impz_sizeinbase(v->n, 2) + size - 1) / size;
64}
isl_stat
Definition: ctx.h:84
@ isl_stat_error
Definition: ctx.h:85
@ isl_stat_ok
Definition: ctx.h:86
#define __isl_give
Definition: ctx.h:19
#define isl_size_error
Definition: ctx.h:97
#define isl_die(ctx, errno, msg, code)
Definition: ctx.h:137
@ isl_error_invalid
Definition: ctx.h:80
#define __isl_keep
Definition: ctx.h:25
int isl_size
Definition: ctx.h:96
#define isl_int_set_si(r, i)
Definition: isl_int_gmp.h:15
const char * size
Definition: isl_test.c:1570
__isl_give isl_val * isl_val_alloc(isl_ctx *ctx)
Definition: isl_val.c:22
__isl_give isl_val * isl_val_int_from_chunks(isl_ctx *ctx, size_t n, size_t size, const void *chunks)
Definition: isl_val_imath.c:7
isl_size isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size)
Definition: isl_val_imath.c:53
isl_stat isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size, void *chunks)
Definition: isl_val_imath.c:33
isl_int d
isl_int n
isl_ctx * isl_val_get_ctx(__isl_keep isl_val *val)
Definition: isl_val.c:355
__isl_export isl_bool isl_val_is_zero(__isl_keep isl_val *v)
Definition: isl_val.c:1191
__isl_export isl_bool isl_val_is_rat(__isl_keep isl_val *v)
Definition: isl_val.c:1151
#define impz_export
Definition: wrap.h:40
#define impz_import
Definition: wrap.h:47
#define impz_sizeinbase
Definition: wrap.h:60
n
Definition: youcefn.c:8