2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
34 __anv_finishme(const char *file
, int line
, const char *format
, ...)
40 vsnprintf(buffer
, sizeof(buffer
), format
, ap
);
43 fprintf(stderr
, "%s:%d: FINISHME: %s\n", file
, line
, buffer
);
47 anv_vector_init(struct anv_vector
*vector
, uint32_t element_size
, uint32_t size
)
49 assert(is_power_of_two(size
));
50 assert(element_size
< size
&& is_power_of_two(element_size
));
54 vector
->element_size
= element_size
;
56 vector
->data
= malloc(size
);
58 return vector
->data
!= NULL
;
62 anv_vector_add(struct anv_vector
*vector
)
64 uint32_t offset
, size
, split
, tail
;
67 if (vector
->head
- vector
->tail
== vector
->size
) {
68 size
= vector
->size
* 2;
72 split
= ALIGN_U32(vector
->tail
, vector
->size
);
73 tail
= vector
->tail
& (vector
->size
- 1);
74 if (vector
->head
- split
< vector
->size
) {
77 split
- vector
->tail
);
78 memcpy(data
+ vector
->size
,
79 vector
->data
, vector
->head
- split
);
83 vector
->head
- vector
->tail
);
90 assert(vector
->head
- vector
->tail
< vector
->size
);
92 offset
= vector
->head
& (vector
->size
- 1);
93 vector
->head
+= vector
->element_size
;
95 return vector
->data
+ offset
;
99 anv_vector_remove(struct anv_vector
*vector
)
103 if (vector
->head
== vector
->tail
)
106 assert(vector
->head
- vector
->tail
<= vector
->size
);
108 offset
= vector
->tail
& (vector
->size
- 1);
109 vector
->tail
+= vector
->element_size
;
111 return vector
->data
+ offset
;