1 #define xFN(TYPE,NAME) TYPE ## _ ## NAME
2 #define FN(TYPE,NAME) xFN(TYPE,NAME)
3 #define xS(TYPE,NAME) struct TYPE ## _ ## NAME
4 #define S(TYPE,NAME) xS(TYPE,NAME)
6 static __isl_give PW *FN(PW,alloc_)(__isl_take isl_dim *dim, int n)
12 isl_assert(dim->ctx, n >= 0, goto error);
13 pw = isl_alloc(dim->ctx, struct PW,
14 sizeof(struct PW) + (n - 1) * sizeof(S(PW,piece)));
28 __isl_give PW *FN(PW,zero)(__isl_take isl_dim *dim)
30 return FN(PW,alloc_)(dim, 0);
33 __isl_give PW *FN(PW,add_piece)(__isl_take PW *pw,
34 __isl_take isl_set *set, __isl_take EL *el)
36 if (!pw || !set || !el)
39 if (isl_set_fast_is_empty(set) || FN(EL,IS_ZERO)(el)) {
45 isl_assert(set->ctx, isl_dim_equal(pw->dim, el->dim), goto error);
46 isl_assert(set->ctx, pw->n < pw->size, goto error);
48 pw->p[pw->n].set = set;
49 pw->p[pw->n].FIELD = el;
60 __isl_give PW *FN(PW,alloc)(__isl_take isl_set *set, __isl_take EL *el)
67 pw = FN(PW,alloc_)(isl_set_get_dim(set), 1);
69 return FN(PW,add_piece)(pw, set, el);
76 __isl_give PW *FN(PW,dup)(__isl_keep PW *pw)
84 dup = FN(PW,alloc_)(isl_dim_copy(pw->dim), pw->n);
88 for (i = 0; i < pw->n; ++i)
89 dup = FN(PW,add_piece)(dup, isl_set_copy(pw->p[i].set),
90 FN(EL,copy)(pw->p[i].FIELD));
98 __isl_give PW *FN(PW,copy)(__isl_keep PW *pw)
107 void FN(PW,free)(__isl_take PW *pw)
116 for (i = 0; i < pw->n; ++i) {
117 isl_set_free(pw->p[i].set);
118 FN(EL,free)(pw->p[i].FIELD);
120 isl_dim_free(pw->dim);
124 int FN(PW,is_zero)(__isl_keep PW *pw)
132 __isl_give PW *FN(PW,add)(__isl_take PW *pw1, __isl_take PW *pw2)
141 isl_assert(pw1->dim->ctx, isl_dim_equal(pw1->dim, pw2->dim), goto error);
143 if (FN(PW,is_zero)(pw1)) {
148 if (FN(PW,is_zero)(pw2)) {
153 n = (pw1->n + 1) * (pw2->n + 1);
154 res = FN(PW,alloc_)(isl_dim_copy(pw1->dim), n);
156 for (i = 0; i < pw1->n; ++i) {
157 set = isl_set_copy(pw1->p[i].set);
158 for (j = 0; j < pw2->n; ++j) {
159 struct isl_set *common;
161 set = isl_set_subtract(set,
162 isl_set_copy(pw2->p[j].set));
163 common = isl_set_intersect(isl_set_copy(pw1->p[i].set),
164 isl_set_copy(pw2->p[j].set));
165 if (isl_set_fast_is_empty(common)) {
166 isl_set_free(common);
170 sum = FN(EL,ADD)(FN(EL,copy)(pw1->p[i].FIELD),
171 FN(EL,copy)(pw2->p[j].FIELD));
173 res = FN(PW,add_piece)(res, common, sum);
175 res = FN(PW,add_piece)(res, set, FN(EL,copy)(pw1->p[i].FIELD));
178 for (j = 0; j < pw2->n; ++j) {
179 set = isl_set_copy(pw2->p[j].set);
180 for (i = 0; i < pw1->n; ++i)
181 set = isl_set_subtract(set,
182 isl_set_copy(pw1->p[i].set));
183 res = FN(PW,add_piece)(res, set, FN(EL,copy)(pw2->p[j].FIELD));
196 __isl_give PW *FN(PW,add_disjoint)(__isl_take PW *pw1, __isl_take PW *pw2)
204 isl_assert(pw1->dim->ctx, isl_dim_equal(pw1->dim, pw2->dim), goto error);
206 if (FN(PW,is_zero)(pw1)) {
211 if (FN(PW,is_zero)(pw2)) {
216 res = FN(PW,alloc_)(isl_dim_copy(pw1->dim), pw1->n + pw2->n);
218 for (i = 0; i < pw1->n; ++i)
219 res = FN(PW,add_piece)(res,
220 isl_set_copy(pw1->p[i].set),
221 FN(EL,copy)(pw1->p[i].FIELD));
223 for (i = 0; i < pw2->n; ++i)
224 res = FN(PW,add_piece)(res,
225 isl_set_copy(pw2->p[i].set),
226 FN(EL,copy)(pw2->p[i].FIELD));