X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_point.c;h=a86dd67d29d02aff41dee5f2e2c5675d05d347df;hb=63fb8a7f484648c3caa25351c8c94ac2395ec563;hp=152e9b0db6c2338211f8c7b08cd9767e7ea46e6f;hpb=f3c292bf31fbb13ce50a8877ee71910897276a24;p=platform%2Fupstream%2Fisl.git diff --git a/isl_point.c b/isl_point.c index 152e9b0..a86dd67 100644 --- a/isl_point.c +++ b/isl_point.c @@ -1,12 +1,23 @@ +#include #include #include -#include #include #include #include -#include +#include +#include -__isl_give isl_point *isl_point_alloc(__isl_take isl_dim *dim, +isl_ctx *isl_point_get_ctx(__isl_keep isl_point *pnt) +{ + return pnt ? isl_space_get_ctx(pnt->dim) : NULL; +} + +__isl_give isl_space *isl_point_get_space(__isl_keep isl_point *pnt) +{ + return pnt ? isl_space_copy(pnt->dim) : NULL; +} + +__isl_give isl_point *isl_point_alloc(__isl_take isl_space *dim, __isl_take isl_vec *vec) { struct isl_point *pnt; @@ -14,11 +25,11 @@ __isl_give isl_point *isl_point_alloc(__isl_take isl_dim *dim, if (!dim || !vec) goto error; - if (vec->size > 1 + isl_dim_total(dim)) { + if (vec->size > 1 + isl_space_dim(dim, isl_dim_all)) { vec = isl_vec_cow(vec); if (!vec) goto error; - vec->size = 1 + isl_dim_total(dim); + vec->size = 1 + isl_space_dim(dim, isl_dim_all); } pnt = isl_alloc_type(dim->ctx, struct isl_point); @@ -31,25 +42,25 @@ __isl_give isl_point *isl_point_alloc(__isl_take isl_dim *dim, return pnt; error: - isl_dim_free(dim); + isl_space_free(dim); isl_vec_free(vec); return NULL; } -__isl_give isl_point *isl_point_zero(__isl_take isl_dim *dim) +__isl_give isl_point *isl_point_zero(__isl_take isl_space *dim) { isl_vec *vec; if (!dim) return NULL; - vec = isl_vec_alloc(dim->ctx, 1 + isl_dim_total(dim)); + vec = isl_vec_alloc(dim->ctx, 1 + isl_space_dim(dim, isl_dim_all)); if (!vec) goto error; isl_int_set_si(vec->el[0], 1); isl_seq_clr(vec->el + 1, vec->size - 1); return isl_point_alloc(dim, vec); error: - isl_dim_free(dim); + isl_space_free(dim); return NULL; } @@ -59,7 +70,7 @@ __isl_give isl_point *isl_point_dup(__isl_keep isl_point *pnt) if (!pnt) return NULL; - pnt2 = isl_point_alloc(isl_dim_copy(pnt->dim), isl_vec_copy(pnt->vec)); + pnt2 = isl_point_alloc(isl_space_copy(pnt->dim), isl_vec_copy(pnt->vec)); return pnt2; } @@ -94,12 +105,12 @@ void isl_point_free(__isl_take isl_point *pnt) if (--pnt->ref > 0) return; - isl_dim_free(pnt->dim); + isl_space_free(pnt->dim); isl_vec_free(pnt->vec); free(pnt); } -__isl_give isl_point *isl_point_void(__isl_take isl_dim *dim) +__isl_give isl_point *isl_point_void(__isl_take isl_space *dim) { if (!dim) return NULL; @@ -115,14 +126,48 @@ int isl_point_is_void(__isl_keep isl_point *pnt) return pnt->vec->size == 0; } -void isl_point_get_coordinate(__isl_keep isl_point *pnt, +int isl_point_get_coordinate(__isl_keep isl_point *pnt, enum isl_dim_type type, int pos, isl_int *v) { if (!pnt || isl_point_is_void(pnt)) - return; + return -1; + + if (pos < 0 || pos >= isl_space_dim(pnt->dim, type)) + isl_die(isl_point_get_ctx(pnt), isl_error_invalid, + "position out of bounds", return -1); + if (type == isl_dim_set) - pos += isl_dim_size(pnt->dim, isl_dim_param); + pos += isl_space_dim(pnt->dim, isl_dim_param); isl_int_set(*v, pnt->vec->el[1 + pos]); + + return 0; +} + +/* Return the value of coordinate "pos" of type "type" of "pnt". + */ +__isl_give isl_val *isl_point_get_coordinate_val(__isl_keep isl_point *pnt, + enum isl_dim_type type, int pos) +{ + isl_ctx *ctx; + isl_val *v; + + if (!pnt) + return NULL; + + ctx = isl_point_get_ctx(pnt); + if (isl_point_is_void(pnt)) + isl_die(ctx, isl_error_invalid, + "void point does not have coordinates", return NULL); + if (pos < 0 || pos >= isl_space_dim(pnt->dim, type)) + isl_die(ctx, isl_error_invalid, + "position out of bounds", return NULL); + + if (type == isl_dim_set) + pos += isl_space_dim(pnt->dim, isl_dim_param); + + v = isl_val_rat_from_isl_int(ctx, pnt->vec->el[1 + pos], + pnt->vec->el[0]); + return isl_val_normalize(v); } __isl_give isl_point *isl_point_set_coordinate(__isl_take isl_point *pnt, @@ -139,7 +184,7 @@ __isl_give isl_point *isl_point_set_coordinate(__isl_take isl_point *pnt, goto error; if (type == isl_dim_set) - pos += isl_dim_size(pnt->dim, isl_dim_param); + pos += isl_space_dim(pnt->dim, isl_dim_param); isl_int_set(pnt->vec->el[1 + pos], v); @@ -149,6 +194,58 @@ error: return NULL; } +/* Replace coordinate "pos" of type "type" of "pnt" by "v". + */ +__isl_give isl_point *isl_point_set_coordinate_val(__isl_take isl_point *pnt, + enum isl_dim_type type, int pos, __isl_take isl_val *v) +{ + if (!pnt || !v) + goto error; + if (isl_point_is_void(pnt)) + isl_die(isl_point_get_ctx(pnt), isl_error_invalid, + "void point does not have coordinates", goto error); + if (pos < 0 || pos >= isl_space_dim(pnt->dim, type)) + isl_die(isl_point_get_ctx(pnt), isl_error_invalid, + "position out of bounds", goto error); + if (!isl_val_is_rat(v)) + isl_die(isl_point_get_ctx(pnt), isl_error_invalid, + "expecting rational value", goto error); + + if (isl_int_eq(pnt->vec->el[1 + pos], v->n) && + isl_int_eq(pnt->vec->el[0], v->d)) { + isl_val_free(v); + return pnt; + } + + pnt = isl_point_cow(pnt); + if (!pnt) + goto error; + pnt->vec = isl_vec_cow(pnt->vec); + if (!pnt->vec) + goto error; + + if (isl_int_eq(pnt->vec->el[0], v->d)) { + isl_int_set(pnt->vec->el[1 + pos], v->n); + } else if (isl_int_is_one(v->d)) { + isl_int_mul(pnt->vec->el[1 + pos], pnt->vec->el[0], v->n); + } else { + isl_seq_scale(pnt->vec->el + 1, + pnt->vec->el + 1, v->d, pnt->vec->size - 1); + isl_int_mul(pnt->vec->el[1 + pos], pnt->vec->el[0], v->n); + isl_int_mul(pnt->vec->el[0], pnt->vec->el[0], v->d); + pnt->vec = isl_vec_normalize(pnt->vec); + if (!pnt->vec) + goto error; + } + + isl_val_free(v); + return pnt; +error: + isl_val_free(v); + isl_point_free(pnt); + return NULL; +} + __isl_give isl_point *isl_point_add_ui(__isl_take isl_point *pnt, enum isl_dim_type type, int pos, unsigned val) { @@ -163,7 +260,7 @@ __isl_give isl_point *isl_point_add_ui(__isl_take isl_point *pnt, goto error; if (type == isl_dim_set) - pos += isl_dim_size(pnt->dim, isl_dim_param); + pos += isl_space_dim(pnt->dim, isl_dim_param); isl_int_add_ui(pnt->vec->el[1 + pos], pnt->vec->el[1 + pos], val); @@ -187,7 +284,7 @@ __isl_give isl_point *isl_point_sub_ui(__isl_take isl_point *pnt, goto error; if (type == isl_dim_set) - pos += isl_dim_size(pnt->dim, isl_dim_param); + pos += isl_space_dim(pnt->dim, isl_dim_param); isl_int_sub_ui(pnt->vec->el[1 + pos], pnt->vec->el[1 + pos], val); @@ -201,7 +298,7 @@ struct isl_foreach_point { struct isl_scan_callback callback; int (*fn)(__isl_take isl_point *pnt, void *user); void *user; - isl_dim *dim; + isl_space *dim; }; static int foreach_point(struct isl_scan_callback *cb, __isl_take isl_vec *sample) @@ -209,7 +306,7 @@ static int foreach_point(struct isl_scan_callback *cb, __isl_take isl_vec *sampl struct isl_foreach_point *fp = (struct isl_foreach_point *)cb; isl_point *pnt; - pnt = isl_point_alloc(isl_dim_copy(fp->dim), sample); + pnt = isl_point_alloc(isl_space_copy(fp->dim), sample); return fp->fn(pnt, fp->user); } @@ -223,7 +320,7 @@ int isl_set_foreach_point(__isl_keep isl_set *set, if (!set) return -1; - fp.dim = isl_set_get_dim(set); + fp.dim = isl_set_get_space(set); if (!fp.dim) return -1; @@ -240,12 +337,12 @@ int isl_set_foreach_point(__isl_keep isl_set *set, goto error; isl_set_free(set); - isl_dim_free(fp.dim); + isl_space_free(fp.dim); return 0; error: isl_set_free(set); - isl_dim_free(fp.dim); + isl_space_free(fp.dim); return -1; } @@ -264,7 +361,7 @@ int isl_basic_map_contains_point(__isl_keep isl_basic_map *bmap, if (!bmap || !point) return -1; - isl_assert(bmap->ctx, isl_dim_equal(bmap->dim, point->dim), return -1); + isl_assert(bmap->ctx, isl_space_is_equal(bmap->dim, point->dim), return -1); if (bmap->n_div == 0) return isl_basic_map_contains(bmap, point->vec); @@ -325,7 +422,7 @@ __isl_give isl_basic_set *isl_basic_set_from_point(__isl_take isl_point *pnt) isl_basic_set *bset; isl_basic_set *model; - model = isl_basic_set_empty(isl_dim_copy(pnt->dim)); + model = isl_basic_set_empty(isl_space_copy(pnt->dim)); bset = isl_basic_set_from_vec(isl_vec_copy(pnt->vec)); bset = isl_basic_set_from_underlying_set(bset, model); isl_point_free(pnt); @@ -355,10 +452,10 @@ __isl_give isl_basic_set *isl_basic_set_box_from_points( goto error; isl_assert(pnt1->dim->ctx, - isl_dim_equal(pnt1->dim, pnt2->dim), goto error); + isl_space_is_equal(pnt1->dim, pnt2->dim), goto error); if (isl_point_is_void(pnt1) && isl_point_is_void(pnt2)) { - isl_dim *dim = isl_dim_copy(pnt1->dim); + isl_space *dim = isl_space_copy(pnt1->dim); isl_point_free(pnt1); isl_point_free(pnt2); isl_int_clear(t); @@ -375,8 +472,8 @@ __isl_give isl_basic_set *isl_basic_set_box_from_points( return isl_basic_set_from_point(pnt1); } - total = isl_dim_total(pnt1->dim); - bset = isl_basic_set_alloc_dim(isl_dim_copy(pnt1->dim), 0, 0, 2 * total); + total = isl_space_dim(pnt1->dim, isl_dim_all); + bset = isl_basic_set_alloc_space(isl_space_copy(pnt1->dim), 0, 0, 2 * total); for (i = 0; i < total; ++i) { isl_int_mul(t, pnt1->vec->el[1 + i], pnt2->vec->el[0]); @@ -432,47 +529,52 @@ __isl_give isl_set *isl_set_box_from_points(__isl_take isl_point *pnt1, return isl_set_from_basic_set(bset); } -void isl_point_print(__isl_keep isl_point *pnt, FILE *out) +__isl_give isl_printer *isl_printer_print_point( + __isl_take isl_printer *p, __isl_keep isl_point *pnt) { int i; unsigned nparam; unsigned dim; if (!pnt) - return; + return p; if (isl_point_is_void(pnt)) { - fprintf(out, "void\n"); - return; + p = isl_printer_print_str(p, "void"); + return p; } - nparam = isl_dim_size(pnt->dim, isl_dim_param); - dim = isl_dim_size(pnt->dim, isl_dim_set); + nparam = isl_space_dim(pnt->dim, isl_dim_param); + dim = isl_space_dim(pnt->dim, isl_dim_set); if (nparam > 0) { - fprintf(out, "["); + p = isl_printer_print_str(p, "["); for (i = 0; i < nparam; ++i) { const char *name; if (i) - fprintf(out, ", "); - name = isl_dim_get_name(pnt->dim, isl_dim_param, i); - if (name) - fprintf(out, "%s = ", name); - isl_int_print(out, pnt->vec->el[1 + i], 0); + p = isl_printer_print_str(p, ", "); + name = isl_space_get_dim_name(pnt->dim, isl_dim_param, i); + if (name) { + p = isl_printer_print_str(p, name); + p = isl_printer_print_str(p, " = "); + } + p = isl_printer_print_isl_int(p, pnt->vec->el[1 + i]); if (!isl_int_is_one(pnt->vec->el[0])) { - fprintf(out, "/"); - isl_int_print(out, pnt->vec->el[0], 0); + p = isl_printer_print_str(p, "/"); + p = isl_printer_print_isl_int(p, pnt->vec->el[0]); } } - fprintf(out, "] -> "); + p = isl_printer_print_str(p, "]"); + p = isl_printer_print_str(p, " -> "); } - fprintf(out, "["); + p = isl_printer_print_str(p, "["); for (i = 0; i < dim; ++i) { if (i) - fprintf(out, ", "); - isl_int_print(out, pnt->vec->el[1 + nparam + i], 0); + p = isl_printer_print_str(p, ", "); + p = isl_printer_print_isl_int(p, pnt->vec->el[1 + nparam + i]); if (!isl_int_is_one(pnt->vec->el[0])) { - fprintf(out, "/"); - isl_int_print(out, pnt->vec->el[0], 0); + p = isl_printer_print_str(p, "/"); + p = isl_printer_print_isl_int(p, pnt->vec->el[0]); } } - fprintf(out, "]\n"); + p = isl_printer_print_str(p, "]"); + return p; }