isl_basic_map_sort_constraints: change comparison routine
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 18 Feb 2011 12:09:02 +0000 (13:09 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Sun, 20 Feb 2011 09:03:57 +0000 (10:03 +0100)
In particular, before we would simply sort the constraints lexicographically.
Now, we first check for the last non-zero coefficients and only when those
positions are the same do we continue with the lexicographical order.
The new ordering is the same as that used to order divs in isl_polynomial.c

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_map.c

index 48e3663..5173369 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -6739,7 +6739,15 @@ static int qsort_constraint_cmp(const void *p1, const void *p2)
 {
        const struct constraint *c1 = (const struct constraint *)p1;
        const struct constraint *c2 = (const struct constraint *)p2;
+       int l1, l2;
        unsigned size = isl_min(c1->size, c2->size);
+
+       l1 = isl_seq_last_non_zero(c1->c, size);
+       l2 = isl_seq_last_non_zero(c2->c, size);
+
+       if (l1 != l2)
+               return l1 - l2;
+
        return isl_seq_cmp(c1->c, c2->c, size);
 }