change calling conventions of isl_basic_set_has_defining_{,in}equalit{y,ies}
[platform/upstream/isl.git] / isl_div.c
1 #include <isl_div.h>
2 #include <isl_map.h>
3
4 static unsigned n(struct isl_div *d, enum isl_dim_type type)
5 {
6         struct isl_dim *dim = d->bmap->dim;
7         switch (type) {
8         case isl_dim_param:     return dim->nparam;
9         case isl_dim_in:        return dim->n_in;
10         case isl_dim_out:       return dim->n_out;
11         case isl_dim_div:       return d->bmap->n_div;
12         }
13 }
14
15 static unsigned offset(struct isl_div *d, enum isl_dim_type type)
16 {
17         struct isl_dim *dim = d->bmap->dim;
18         switch (type) {
19         case isl_dim_param: return 1 + 1;
20         case isl_dim_in:    return 1 + 1 + dim->nparam;
21         case isl_dim_out:   return 1 + 1 + dim->nparam + dim->n_in;
22         case isl_dim_div:   return 1 + 1 + dim->nparam + dim->n_in + dim->n_out;
23         }
24 }
25
26 struct isl_div *isl_basic_map_div(struct isl_basic_map *bmap, isl_int **line)
27 {
28         struct isl_div *div;
29
30         if (!bmap || !line)
31                 goto error;
32         
33         div = isl_alloc_type(bmap->ctx, struct isl_div);
34         if (!div)
35                 goto error;
36
37         div->ctx = bmap->ctx;
38         isl_ctx_ref(div->ctx);
39         div->ref = 1;
40         div->bmap = bmap;
41         div->line = line;
42
43         return div;
44 error:
45         isl_basic_map_free(bmap);
46         return NULL;
47 }
48
49 struct isl_div *isl_div_free(struct isl_div *c)
50 {
51         if (!c)
52                 return;
53
54         if (--c->ref > 0)
55                 return;
56
57         isl_basic_map_free(c->bmap);
58         isl_ctx_deref(c->ctx);
59         free(c);
60 }
61
62 void isl_div_get_constant(struct isl_div *div, isl_int *v)
63 {
64         if (!div)
65                 return;
66         isl_int_set(*v, div->line[0][1]);
67 }
68
69 void isl_div_get_denominator(struct isl_div *div, isl_int *v)
70 {
71         if (!div)
72                 return;
73         isl_int_set(*v, div->line[0][0]);
74 }
75
76 void isl_div_get_coefficient(struct isl_div *div,
77         enum isl_dim_type type, int pos, isl_int *v)
78 {
79         if (!div)
80                 return;
81
82         isl_assert(div->ctx, pos < n(div, type), return);
83         isl_int_set(*v, div->line[0][offset(div, type) + pos]);
84 }