From 4e7769ec99a5db90d8832c5d76cb28f89bf25cef Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 23 Jan 2014 14:45:51 +0100 Subject: [PATCH] add isl_pw_aff_plain_cmp We make this function public since we want to use it from the AST generator, which should only use public fucntions. Signed-off-by: Sven Verdoolaege --- doc/user.pod | 7 ++++++ include/isl/aff.h | 2 ++ isl_aff.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index 1d371c53..378cbcf0 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -4046,6 +4046,13 @@ or (obviously) equal to some other affine expression, use __isl_keep isl_pw_aff *pwaff2); int isl_pw_aff_is_equal(__isl_keep isl_pw_aff *pa1, __isl_keep isl_pw_aff *pa2); + int isl_pw_aff_plain_cmp(__isl_keep isl_pw_aff *pa1, + __isl_keep isl_pw_aff *pa2); + +The function C can be used to sort +Cs. The order is not strictly defined. +The current order sorts expressions that only involve +earlier dimensions before those that involve later dimensions. Operations include diff --git a/include/isl/aff.h b/include/isl/aff.h index 51d6b0e8..2ef4cd5b 100644 --- a/include/isl/aff.h +++ b/include/isl/aff.h @@ -154,6 +154,8 @@ __isl_give isl_pw_aff *isl_pw_aff_set_dim_id(__isl_take isl_pw_aff *pma, enum isl_dim_type type, unsigned pos, __isl_take isl_id *id); int isl_pw_aff_is_empty(__isl_keep isl_pw_aff *pwaff); +int isl_pw_aff_plain_cmp(__isl_keep isl_pw_aff *pa1, + __isl_keep isl_pw_aff *pa2); int isl_pw_aff_plain_is_equal(__isl_keep isl_pw_aff *pwaff1, __isl_keep isl_pw_aff *pwaff2); int isl_pw_aff_is_equal(__isl_keep isl_pw_aff *pa1, __isl_keep isl_pw_aff *pa2); diff --git a/isl_aff.c b/isl_aff.c index 2fe80c09..17e8aa65 100644 --- a/isl_aff.c +++ b/isl_aff.c @@ -6273,3 +6273,77 @@ __isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_multi_pw_aff( return isl_multi_pw_aff_align_params_multi_multi_and(mpa1, mpa2, &isl_multi_pw_aff_pullback_multi_pw_aff_aligned); } + +/* Compare two isl_affs. + * + * Return -1 if "aff1" is "smaller" than "aff2", 1 if "aff1" is "greater" + * than "aff2" and 0 if they are equal. + * + * The order is fairly arbitrary. We do consider expressions that only involve + * earlier dimensions as "smaller". + */ +int isl_aff_plain_cmp(__isl_keep isl_aff *aff1, __isl_keep isl_aff *aff2) +{ + int cmp; + int last1, last2; + + if (aff1 == aff2) + return 0; + + if (!aff1) + return -1; + if (!aff2) + return 1; + + cmp = isl_local_space_cmp(aff1->ls, aff2->ls); + if (cmp != 0) + return cmp; + + last1 = isl_seq_last_non_zero(aff1->v->el + 1, aff1->v->size - 1); + last2 = isl_seq_last_non_zero(aff2->v->el + 1, aff1->v->size - 1); + if (last1 != last2) + return last1 - last2; + + return isl_seq_cmp(aff1->v->el, aff2->v->el, aff1->v->size); +} + +/* Compare two isl_pw_affs. + * + * Return -1 if "pa1" is "smaller" than "pa2", 1 if "pa1" is "greater" + * than "pa2" and 0 if they are equal. + * + * The order is fairly arbitrary. We do consider expressions that only involve + * earlier dimensions as "smaller". + */ +int isl_pw_aff_plain_cmp(__isl_keep isl_pw_aff *pa1, + __isl_keep isl_pw_aff *pa2) +{ + int i; + int cmp; + + if (pa1 == pa2) + return 0; + + if (!pa1) + return -1; + if (!pa2) + return 1; + + cmp = isl_space_cmp(pa1->dim, pa2->dim); + if (cmp != 0) + return cmp; + + if (pa1->n != pa2->n) + return pa1->n - pa2->n; + + for (i = 0; i < pa1->n; ++i) { + cmp = isl_set_plain_cmp(pa1->p[i].set, pa2->p[i].set); + if (cmp != 0) + return cmp; + cmp = isl_aff_plain_cmp(pa1->p[i].aff, pa2->p[i].aff); + if (cmp != 0) + return cmp; + } + + return 0; +} -- 2.11.4.GIT