X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_val.c;h=dca322898e060fb609ddff05859046f868e6d0ea;hb=19596bc4e5cd282b2e75d17077b1aaaeacbfd6f9;hp=fb4b85749636c7f7205798d441eb19fd906a8ad7;hpb=4fb89cf309098bf62a6de2e60dde256d01566f52;p=platform%2Fupstream%2Fisl.git diff --git a/isl_val.c b/isl_val.c index fb4b857..dca3228 100644 --- a/isl_val.c +++ b/isl_val.c @@ -284,6 +284,21 @@ long isl_val_get_num_si(__isl_keep isl_val *v) return isl_int_get_si(v->n); } +/* Extract the numerator of a rational value "v" as an isl_int. + * + * If "v" is not a rational value, then the result is undefined. + */ +int isl_val_get_num_isl_int(__isl_keep isl_val *v, isl_int *n) +{ + if (!v) + return -1; + if (!isl_val_is_rat(v)) + isl_die(isl_val_get_ctx(v), isl_error_invalid, + "expecting rational value", return -1); + isl_int_set(*n, v->n); + return 0; +} + /* Extract the denominator of a rational value "v" as an integer. * * If "v" is not a rational value, then the result is undefined. @@ -749,6 +764,17 @@ error: } /* Return the product of "v1" and "v2". + * + * This is a private copy of isl_val_mul for use in the generic + * isl_multi_*_scale_val instantiated for isl_val. + */ +__isl_give isl_val *isl_val_scale_val(__isl_take isl_val *v1, + __isl_take isl_val *v2) +{ + return isl_val_mul(v1, v2); +} + +/* Return the product of "v1" and "v2". */ __isl_give isl_val *isl_val_mul_ui(__isl_take isl_val *v1, unsigned long v2) { @@ -1254,3 +1280,168 @@ __isl_give isl_printer *isl_printer_print_val(__isl_take isl_printer *p, return p; } + +/* Insert "n" dimensions of type "type" at position "first". + * + * This function is only meant to be used in the generic isl_multi_* + * functions which have to deal with base objects that have an associated + * space. Since an isl_val does not have an associated space, this function + * does not do anything. + */ +__isl_give isl_val *isl_val_insert_dims(__isl_take isl_val *v, + enum isl_dim_type type, unsigned first, unsigned n) +{ + return v; +} + +/* Drop the the "n" first dimensions of type "type" at position "first". + * + * This function is only meant to be used in the generic isl_multi_* + * functions which have to deal with base objects that have an associated + * space. Since an isl_val does not have an associated space, this function + * does not do anything. + */ +__isl_give isl_val *isl_val_drop_dims(__isl_take isl_val *v, + enum isl_dim_type type, unsigned first, unsigned n) +{ + return v; +} + +/* Change the name of the dimension of type "type" at position "pos" to "s". + * + * This function is only meant to be used in the generic isl_multi_* + * functions which have to deal with base objects that have an associated + * space. Since an isl_val does not have an associated space, this function + * does not do anything. + */ +__isl_give isl_val *isl_val_set_dim_name(__isl_take isl_val *v, + enum isl_dim_type type, unsigned pos, const char *s) +{ + return v; +} + +/* Reset the domain space of "v" to "space". + * + * This function is only meant to be used in the generic isl_multi_* + * functions which have to deal with base objects that have an associated + * space. Since an isl_val does not have an associated space, this function + * does not do anything, apart from error handling and cleaning up memory. + */ +__isl_give isl_val *isl_val_reset_domain_space(__isl_take isl_val *v, + __isl_take isl_space *space) +{ + if (!space) + return isl_val_free(v); + isl_space_free(space); + return v; +} + +/* Reorder the dimensions of the domain of "v" according + * to the given reordering. + * + * This function is only meant to be used in the generic isl_multi_* + * functions which have to deal with base objects that have an associated + * space. Since an isl_val does not have an associated space, this function + * does not do anything, apart from error handling and cleaning up memory. + */ +__isl_give isl_val *isl_val_realign_domain(__isl_take isl_val *v, + __isl_take isl_reordering *r) +{ + if (!r) + return isl_val_free(v); + isl_reordering_free(r); + return v; +} + +/* Return an isl_val that is zero on "ls". + * + * This function is only meant to be used in the generic isl_multi_* + * functions which have to deal with base objects that have an associated + * space. Since an isl_val does not have an associated space, this function + * simply returns a zero isl_val in the same context as "ls". + */ +__isl_give isl_val *isl_val_zero_on_domain(__isl_take isl_local_space *ls) +{ + isl_ctx *ctx; + + if (!ls) + return NULL; + ctx = isl_local_space_get_ctx(ls); + isl_local_space_free(ls); + return isl_val_zero(ctx); +} + +/* Check that the domain space of "v" matches "space". + * + * Return 0 on success and -1 on error. + * + * This function is only meant to be used in the generic isl_multi_* + * functions which have to deal with base objects that have an associated + * space. Since an isl_val does not have an associated space, this function + * simply returns 0, except if "v" or "space" are NULL. + */ +int isl_val_check_match_domain_space(__isl_keep isl_val *v, + __isl_keep isl_space *space) +{ + if (!v || !space) + return -1; + return 0; +} + +#undef BASE +#define BASE val + +#define NO_GIST +#define NO_IDENTITY +#define NO_FROM_BASE +#include + +/* Apply "fn" to each of the elements of "mv" with as second argument "v". + */ +static __isl_give isl_multi_val *isl_multi_val_fn_val( + __isl_take isl_multi_val *mv, + __isl_give isl_val *(*fn)(__isl_take isl_val *v1, + __isl_take isl_val *v2), + __isl_take isl_val *v) +{ + int i; + + mv = isl_multi_val_cow(mv); + if (!mv || !v) + goto error; + + for (i = 0; i < mv->n; ++i) { + mv->p[i] = fn(mv->p[i], isl_val_copy(v)); + if (!mv->p[i]) + goto error; + } + + isl_val_free(v); + return mv; +error: + isl_val_free(v); + isl_multi_val_free(mv); + return NULL; +} + +/* Add "v" to each of the elements of "mv". + */ +__isl_give isl_multi_val *isl_multi_val_add_val(__isl_take isl_multi_val *mv, + __isl_take isl_val *v) +{ + if (!v) + return isl_multi_val_free(mv); + if (isl_val_is_zero(v)) { + isl_val_free(v); + return mv; + } + return isl_multi_val_fn_val(mv, &isl_val_add, v); +} + +/* Reduce the elements of "mv" modulo "v". + */ +__isl_give isl_multi_val *isl_multi_val_mod_val(__isl_take isl_multi_val *mv, + __isl_take isl_val *v) +{ + return isl_multi_val_fn_val(mv, &isl_val_mod, v); +}