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
33 void anv_printflike(3, 4)
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
);
46 void anv_noreturn
anv_printflike(1, 2)
47 anv_abortf(const char *format
, ...)
52 anv_abortfv(format
, va
);
57 anv_abortfv(const char *format
, va_list va
)
59 fprintf(stderr
, "vk: error: ");
60 vfprintf(stderr
, format
, va
);
61 fprintf(stderr
, "\n");
66 anv_vector_init(struct anv_vector
*vector
, uint32_t element_size
, uint32_t size
)
68 assert(is_power_of_two(size
));
69 assert(element_size
< size
&& is_power_of_two(element_size
));
73 vector
->element_size
= element_size
;
75 vector
->data
= malloc(size
);
77 return vector
->data
!= NULL
;
81 anv_vector_add(struct anv_vector
*vector
)
83 uint32_t offset
, size
, split
, tail
;
86 if (vector
->head
- vector
->tail
== vector
->size
) {
87 size
= vector
->size
* 2;
91 split
= ALIGN_U32(vector
->tail
, vector
->size
);
92 tail
= vector
->tail
& (vector
->size
- 1);
93 if (vector
->head
- split
< vector
->size
) {
96 split
- vector
->tail
);
97 memcpy(data
+ vector
->size
,
98 vector
->data
, vector
->head
- split
);
102 vector
->head
- vector
->tail
);
109 assert(vector
->head
- vector
->tail
< vector
->size
);
111 offset
= vector
->head
& (vector
->size
- 1);
112 vector
->head
+= vector
->element_size
;
114 return vector
->data
+ offset
;
118 anv_vector_remove(struct anv_vector
*vector
)
122 if (vector
->head
== vector
->tail
)
125 assert(vector
->head
- vector
->tail
<= vector
->size
);
127 offset
= vector
->tail
& (vector
->size
- 1);
128 vector
->tail
+= vector
->element_size
;
130 return vector
->data
+ offset
;