Line data Source code
1 : #include <isl_val_private.h>
2 :
3 : #define xFN(TYPE,NAME) TYPE ## _ ## NAME
4 : #define FN(TYPE,NAME) xFN(TYPE,NAME)
5 :
6 : /* Compute the given non-zero power of "map" and return the result.
7 : * If the exponent "exp" is negative, then the -exp th power of the inverse
8 : * relation is computed.
9 : */
10 0 : __isl_give TYPE *FN(TYPE,fixed_power)(__isl_take TYPE *map, isl_int exp)
11 : {
12 : isl_ctx *ctx;
13 0 : TYPE *res = NULL;
14 : isl_int r;
15 :
16 0 : if (!map)
17 0 : return NULL;
18 :
19 0 : ctx = FN(TYPE,get_ctx)(map);
20 0 : if (isl_int_is_zero(exp))
21 0 : isl_die(ctx, isl_error_invalid,
22 : "expecting non-zero exponent", goto error);
23 :
24 0 : if (isl_int_is_neg(exp)) {
25 0 : isl_int_neg(exp, exp);
26 0 : map = FN(TYPE,reverse)(map);
27 0 : return FN(TYPE,fixed_power)(map, exp);
28 : }
29 :
30 0 : isl_int_init(r);
31 : for (;;) {
32 0 : isl_int_fdiv_r(r, exp, ctx->two);
33 :
34 0 : if (!isl_int_is_zero(r)) {
35 0 : if (!res)
36 0 : res = FN(TYPE,copy)(map);
37 : else {
38 0 : res = FN(TYPE,apply_range)(res,
39 : FN(TYPE,copy)(map));
40 0 : res = FN(TYPE,coalesce)(res);
41 : }
42 0 : if (!res)
43 0 : break;
44 : }
45 :
46 0 : isl_int_fdiv_q(exp, exp, ctx->two);
47 0 : if (isl_int_is_zero(exp))
48 0 : break;
49 :
50 0 : map = FN(TYPE,apply_range)(map, FN(TYPE,copy)(map));
51 0 : map = FN(TYPE,coalesce)(map);
52 0 : }
53 0 : isl_int_clear(r);
54 :
55 0 : FN(TYPE,free)(map);
56 0 : return res;
57 : error:
58 0 : FN(TYPE,free)(map);
59 0 : return NULL;
60 : }
61 :
62 : /* Compute the given non-zero power of "map" and return the result.
63 : * If the exponent "exp" is negative, then the -exp th power of the inverse
64 : * relation is computed.
65 : */
66 0 : __isl_give TYPE *FN(TYPE,fixed_power_val)(__isl_take TYPE *map,
67 : __isl_take isl_val *exp)
68 : {
69 0 : if (!map || !exp)
70 : goto error;
71 0 : if (!isl_val_is_int(exp))
72 0 : isl_die(FN(TYPE,get_ctx)(map), isl_error_invalid,
73 : "expecting integer exponent", goto error);
74 0 : map = FN(TYPE,fixed_power)(map, exp->n);
75 0 : isl_val_free(exp);
76 0 : return map;
77 : error:
78 0 : FN(TYPE,free)(map);
79 0 : isl_val_free(exp);
80 0 : return NULL;
81 : }
|