|
Packit |
fb9d21 |
#include <isl_val_private.h>
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define xFN(TYPE,NAME) TYPE ## _ ## NAME
|
|
Packit |
fb9d21 |
#define FN(TYPE,NAME) xFN(TYPE,NAME)
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
/* Compute the given non-zero power of "map" and return the result.
|
|
Packit |
fb9d21 |
* If the exponent "exp" is negative, then the -exp th power of the inverse
|
|
Packit |
fb9d21 |
* relation is computed.
|
|
Packit |
fb9d21 |
*/
|
|
Packit |
fb9d21 |
__isl_give TYPE *FN(TYPE,fixed_power)(__isl_take TYPE *map, isl_int exp)
|
|
Packit |
fb9d21 |
{
|
|
Packit |
fb9d21 |
isl_ctx *ctx;
|
|
Packit |
fb9d21 |
TYPE *res = NULL;
|
|
Packit |
fb9d21 |
isl_int r;
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
if (!map)
|
|
Packit |
fb9d21 |
return NULL;
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
ctx = FN(TYPE,get_ctx)(map);
|
|
Packit |
fb9d21 |
if (isl_int_is_zero(exp))
|
|
Packit |
fb9d21 |
isl_die(ctx, isl_error_invalid,
|
|
Packit |
fb9d21 |
"expecting non-zero exponent", goto error);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
if (isl_int_is_neg(exp)) {
|
|
Packit |
fb9d21 |
isl_int_neg(exp, exp);
|
|
Packit |
fb9d21 |
map = FN(TYPE,reverse)(map);
|
|
Packit |
fb9d21 |
return FN(TYPE,fixed_power)(map, exp);
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
isl_int_init(r);
|
|
Packit |
fb9d21 |
for (;;) {
|
|
Packit |
fb9d21 |
isl_int_fdiv_r(r, exp, ctx->two);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
if (!isl_int_is_zero(r)) {
|
|
Packit |
fb9d21 |
if (!res)
|
|
Packit |
fb9d21 |
res = FN(TYPE,copy)(map);
|
|
Packit |
fb9d21 |
else {
|
|
Packit |
fb9d21 |
res = FN(TYPE,apply_range)(res,
|
|
Packit |
fb9d21 |
FN(TYPE,copy)(map));
|
|
Packit |
fb9d21 |
res = FN(TYPE,coalesce)(res);
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
if (!res)
|
|
Packit |
fb9d21 |
break;
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
isl_int_fdiv_q(exp, exp, ctx->two);
|
|
Packit |
fb9d21 |
if (isl_int_is_zero(exp))
|
|
Packit |
fb9d21 |
break;
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
map = FN(TYPE,apply_range)(map, FN(TYPE,copy)(map));
|
|
Packit |
fb9d21 |
map = FN(TYPE,coalesce)(map);
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
isl_int_clear(r);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
FN(TYPE,free)(map);
|
|
Packit |
fb9d21 |
return res;
|
|
Packit |
fb9d21 |
error:
|
|
Packit |
fb9d21 |
FN(TYPE,free)(map);
|
|
Packit |
fb9d21 |
return NULL;
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
/* Compute the given non-zero power of "map" and return the result.
|
|
Packit |
fb9d21 |
* If the exponent "exp" is negative, then the -exp th power of the inverse
|
|
Packit |
fb9d21 |
* relation is computed.
|
|
Packit |
fb9d21 |
*/
|
|
Packit |
fb9d21 |
__isl_give TYPE *FN(TYPE,fixed_power_val)(__isl_take TYPE *map,
|
|
Packit |
fb9d21 |
__isl_take isl_val *exp)
|
|
Packit |
fb9d21 |
{
|
|
Packit |
fb9d21 |
if (!map || !exp)
|
|
Packit |
fb9d21 |
goto error;
|
|
Packit |
fb9d21 |
if (!isl_val_is_int(exp))
|
|
Packit |
fb9d21 |
isl_die(FN(TYPE,get_ctx)(map), isl_error_invalid,
|
|
Packit |
fb9d21 |
"expecting integer exponent", goto error);
|
|
Packit |
fb9d21 |
map = FN(TYPE,fixed_power)(map, exp->n);
|
|
Packit |
fb9d21 |
isl_val_free(exp);
|
|
Packit |
fb9d21 |
return map;
|
|
Packit |
fb9d21 |
error:
|
|
Packit |
fb9d21 |
FN(TYPE,free)(map);
|
|
Packit |
fb9d21 |
isl_val_free(exp);
|
|
Packit |
fb9d21 |
return NULL;
|
|
Packit |
fb9d21 |
}
|