isl_vec.c: remove unused variable
[platform/upstream/isl.git] / isl_vec.c
1 #include "isl_seq.h"
2 #include "isl_vec.h"
3
4 struct isl_vec *isl_vec_alloc(struct isl_ctx *ctx, unsigned size)
5 {
6         struct isl_vec *vec;
7
8         vec = isl_alloc_type(ctx, struct isl_vec);
9         if (!vec)
10                 return NULL;
11
12         vec->block = isl_blk_alloc(ctx, size);
13         if (isl_blk_is_error(vec->block))
14                 goto error;
15
16         vec->ctx = ctx;
17         isl_ctx_ref(ctx);
18         vec->ref = 1;
19         vec->size = size;
20         vec->el = vec->block.data;
21
22         return vec;
23 error:
24         isl_blk_free(ctx, vec->block);
25         return NULL;
26 }
27
28 struct isl_vec *isl_vec_copy(struct isl_vec *vec)
29 {
30         if (!vec)
31                 return NULL;
32
33         vec->ref++;
34         return vec;
35 }
36
37 struct isl_vec *isl_vec_dup(struct isl_vec *vec)
38 {
39         struct isl_vec *vec2;
40
41         if (!vec)
42                 return NULL;
43         vec2 = isl_vec_alloc(vec->ctx, vec->size);
44         isl_seq_cpy(vec2->el, vec->el, vec->size);
45         return vec2;
46 }
47
48 struct isl_vec *isl_vec_cow(struct isl_vec *vec)
49 {
50         struct isl_vec *vec2;
51         if (!vec)
52                 return NULL;
53
54         if (vec->ref == 1)
55                 return vec;
56
57         vec2 = isl_vec_dup(vec);
58         isl_vec_free( vec);
59         return vec2;
60 }
61
62 void isl_vec_free(struct isl_vec *vec)
63 {
64         if (!vec)
65                 return;
66
67         if (--vec->ref > 0)
68                 return;
69
70         isl_ctx_deref(vec->ctx);
71         isl_blk_free(vec->ctx, vec->block);
72         free(vec);
73 }
74
75 void isl_vec_dump(struct isl_vec *vec, FILE *out, int indent)
76 {
77         int i;
78
79         if (!vec) {
80                 fprintf(out, "%*snull vec\n", indent, "");
81                 return;
82         }
83
84         fprintf(out, "%*s[", indent, "");
85         for (i = 0; i < vec->size; ++i) {
86                 if (i)
87                     fprintf(out, ",");
88                 isl_int_print(out, vec->el[i], 0);
89         }
90         fprintf(out, "]\n");
91 }
92
93 void isl_vec_lcm(struct isl_vec *vec, isl_int *lcm)
94 {
95         isl_seq_lcm(vec->block.data, vec->size, lcm);
96 }
97
98 /* Given a rational vector, with the denominator in the first element
99  * of the vector, round up all coordinates.
100  */
101 struct isl_vec *isl_vec_ceil(struct isl_vec *vec)
102 {
103         vec = isl_vec_cow(vec);
104         if (!vec)
105                 return NULL;
106
107         isl_seq_cdiv_q(vec->el + 1, vec->el + 1, vec->el[0], vec->size - 1);
108
109         isl_int_set_si(vec->el[0], 1);
110
111         return vec;
112 }
113
114 struct isl_vec *isl_vec_normalize(struct isl_vec *vec)
115 {
116         if (!vec)
117                 return NULL;
118         isl_seq_normalize(vec->ctx, vec->el, vec->size);
119         return vec;
120 }