5 #ifndef __BLI_UTILDEFINES_H__
6 #define __BLI_UTILDEFINES_H__
34 # define _TYPECHECK(a, b) ((void)(((typeof(a) *)0) == ((typeof(b) *)0)))
35 # define MIN2(x, y) (_TYPECHECK(x, y), (((x) < (y) ? (x) : (y))))
36 # define MAX2(x, y) (_TYPECHECK(x, y), (((x) > (y) ? (x) : (y))))
40 #if defined(__GNUC__) || defined(__clang__)
46 ((a_) < (b_) ? (a_) : (b_)); \
53 ((a_) > (b_) ? (a_) : (b_)); \
56 # define MIN3(a, b, c) \
61 ((a_ < b_) ? ((a_ < c_) ? a_ : c_) : ((b_ < c_) ? b_ : c_)); \
64 # define MAX3(a, b, c) \
69 ((a_ > b_) ? ((a_ > c_) ? a_ : c_) : ((b_ > c_) ? b_ : c_)); \
72 # define MIN4(a, b, c, d) \
78 ((a_ < b_) ? ((a_ < c_) ? ((a_ < d_) ? a_ : d_) : ((c_ < d_) ? c_ : d_)) : \
79 ((b_ < c_) ? ((b_ < d_) ? b_ : d_) : ((c_ < d_) ? c_ : d_))); \
82 # define MAX4(a, b, c, d) \
88 ((a_ > b_) ? ((a_ > c_) ? ((a_ > d_) ? a_ : d_) : ((c_ > d_) ? c_ : d_)) : \
89 ((b_ > c_) ? ((b_ > d_) ? b_ : d_) : ((c_ > d_) ? c_ : d_))); \
93 # define MIN2(a, b) ((a) < (b) ? (a) : (b))
94 # define MAX2(a, b) ((a) > (b) ? (a) : (b))
96 # define MIN3(a, b, c) (MIN2(MIN2((a), (b)), (c)))
97 # define MIN4(a, b, c, d) (MIN2(MIN2((a), (b)), MIN2((c), (d))))
99 # define MAX3(a, b, c) (MAX2(MAX2((a), (b)), (c)))
100 # define MAX4(a, b, c, d) (MAX2(MAX2((a), (b)), MAX2((c), (d))))
104 #define MAX3_PAIR(cmp_a, cmp_b, cmp_c, ret_a, ret_b, ret_c) \
105 ((cmp_a > cmp_b) ? ((cmp_a > cmp_c) ? ret_a : ret_c) : ((cmp_b > cmp_c) ? ret_b : ret_c))
107 #define MIN3_PAIR(cmp_a, cmp_b, cmp_c, ret_a, ret_b, ret_c) \
108 ((cmp_a < cmp_b) ? ((cmp_a < cmp_c) ? ret_a : ret_c) : ((cmp_b < cmp_c) ? ret_b : ret_c))
110 #define INIT_MINMAX(min, max) \
112 (min)[0] = (min)[1] = (min)[2] = 1.0e30f; \
113 (max)[0] = (max)[1] = (max)[2] = -1.0e30f; \
116 #define INIT_MINMAX2(min, max) \
118 (min)[0] = (min)[1] = 1.0e30f; \
119 (max)[0] = (max)[1] = -1.0e30f; \
122 #define DO_MIN(vec, min) \
124 if ((min)[0] > (vec)[0]) { \
125 (min)[0] = (vec)[0]; \
127 if ((min)[1] > (vec)[1]) { \
128 (min)[1] = (vec)[1]; \
130 if ((min)[2] > (vec)[2]) { \
131 (min)[2] = (vec)[2]; \
135 #define DO_MAX(vec, max) \
137 if ((max)[0] < (vec)[0]) { \
138 (max)[0] = (vec)[0]; \
140 if ((max)[1] < (vec)[1]) { \
141 (max)[1] = (vec)[1]; \
143 if ((max)[2] < (vec)[2]) { \
144 (max)[2] = (vec)[2]; \
148 #define DO_MINMAX(vec, min, max) \
150 if ((min)[0] > (vec)[0]) { \
151 (min)[0] = (vec)[0]; \
153 if ((min)[1] > (vec)[1]) { \
154 (min)[1] = (vec)[1]; \
156 if ((min)[2] > (vec)[2]) { \
157 (min)[2] = (vec)[2]; \
159 if ((max)[0] < (vec)[0]) { \
160 (max)[0] = (vec)[0]; \
162 if ((max)[1] < (vec)[1]) { \
163 (max)[1] = (vec)[1]; \
165 if ((max)[2] < (vec)[2]) { \
166 (max)[2] = (vec)[2]; \
170 #define DO_MINMAX2(vec, min, max) \
172 if ((min)[0] > (vec)[0]) { \
173 (min)[0] = (vec)[0]; \
175 if ((min)[1] > (vec)[1]) { \
176 (min)[1] = (vec)[1]; \
178 if ((max)[0] < (vec)[0]) { \
179 (max)[0] = (vec)[0]; \
181 if ((max)[1] < (vec)[1]) { \
182 (max)[1] = (vec)[1]; \
193 #define SWAP(type, a, b) \
196 CHECK_TYPE(a, type); \
197 CHECK_TYPE(b, type); \
205 #define SWAP_TVAL(tval, a, b) \
207 CHECK_TYPE_PAIR(tval, a); \
208 CHECK_TYPE_PAIR(tval, b); \
216 #define SHIFT3(type, a, b, c) \
219 CHECK_TYPE(a, type); \
220 CHECK_TYPE(b, type); \
221 CHECK_TYPE(c, type); \
229 #define SHIFT4(type, a, b, c, d) \
232 CHECK_TYPE(a, type); \
233 CHECK_TYPE(b, type); \
234 CHECK_TYPE(c, type); \
235 CHECK_TYPE(d, type); \
255 #define _VA_ELEM2(v, a) ((v) == (a))
256 #define _VA_ELEM3(v, a, b) \
257 (_VA_ELEM2(v, a) || _VA_ELEM2(v, b))
258 #define _VA_ELEM4(v, a, b, c) \
259 (_VA_ELEM3(v, a, b) || _VA_ELEM2(v, c))
260 #define _VA_ELEM5(v, a, b, c, d) \
261 (_VA_ELEM4(v, a, b, c) || _VA_ELEM2(v, d))
262 #define _VA_ELEM6(v, a, b, c, d, e) \
263 (_VA_ELEM5(v, a, b, c, d) || _VA_ELEM2(v, e))
264 #define _VA_ELEM7(v, a, b, c, d, e, f) \
265 (_VA_ELEM6(v, a, b, c, d, e) || _VA_ELEM2(v, f))
266 #define _VA_ELEM8(v, a, b, c, d, e, f, g) \
267 (_VA_ELEM7(v, a, b, c, d, e, f) || _VA_ELEM2(v, g))
268 #define _VA_ELEM9(v, a, b, c, d, e, f, g, h) \
269 (_VA_ELEM8(v, a, b, c, d, e, f, g) || _VA_ELEM2(v, h))
270 #define _VA_ELEM10(v, a, b, c, d, e, f, g, h, i) \
271 (_VA_ELEM9(v, a, b, c, d, e, f, g, h) || _VA_ELEM2(v, i))
272 #define _VA_ELEM11(v, a, b, c, d, e, f, g, h, i, j) \
273 (_VA_ELEM10(v, a, b, c, d, e, f, g, h, i) || _VA_ELEM2(v, j))
274 #define _VA_ELEM12(v, a, b, c, d, e, f, g, h, i, j, k) \
275 (_VA_ELEM11(v, a, b, c, d, e, f, g, h, i, j) || _VA_ELEM2(v, k))
276 #define _VA_ELEM13(v, a, b, c, d, e, f, g, h, i, j, k, l) \
277 (_VA_ELEM12(v, a, b, c, d, e, f, g, h, i, j, k) || _VA_ELEM2(v, l))
278 #define _VA_ELEM14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) \
279 (_VA_ELEM13(v, a, b, c, d, e, f, g, h, i, j, k, l) || _VA_ELEM2(v, m))
280 #define _VA_ELEM15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
281 (_VA_ELEM14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) || _VA_ELEM2(v, n))
282 #define _VA_ELEM16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
283 (_VA_ELEM15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) || _VA_ELEM2(v, o))
284 #define _VA_ELEM17(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
285 (_VA_ELEM16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) || _VA_ELEM2(v, p))
289 #define ELEM(...) VA_NARGS_CALL_OVERLOAD(_VA_ELEM, __VA_ARGS__)
299 #define IS_EQ(a, b) \
300 (CHECK_TYPE_INLINE(a, double), \
301 CHECK_TYPE_INLINE(b, double), \
302 ((fabs((double)((a) - (b))) >= (double)FLT_EPSILON) ? false : true))
304 #define IS_EQF(a, b) \
305 (CHECK_TYPE_INLINE(a, float), \
306 CHECK_TYPE_INLINE(b, float), \
307 ((fabsf((float)((a) - (b))) >= (float)FLT_EPSILON) ? false : true))
309 #define IS_EQT(a, b, c) (((a) > (b)) ? ((((a) - (b)) <= (c))) : (((((b) - (a)) <= (c)))))
310 #define IN_RANGE(a, b, c) (((b) < (c)) ? (((b) < (a) && (a) < (c))) : (((c) < (a) && (a) < (b))))
311 #define IN_RANGE_INCL(a, b, c) \
312 (((b) < (c)) ? (((b) <= (a) && (a) <= (c))) : (((c) <= (a) && (a) <= (b))))
322 #define DECIMAL_DIGITS_BOUND(t) (241 * sizeof(t) / 100 + 1)
330 #define CLAMPIS(a, b, c) ((a) < (b) ? (b) : (a) > (c) ? (c) : (a))
332 #define CLAMP(a, b, c) \
337 else if ((a) > (c)) { \
343 #define CLAMP_MAX(a, c) \
351 #define CLAMP_MIN(a, b) \
359 #define CLAMP2(vec, b, c) \
361 CLAMP((vec)[0], b, c); \
362 CLAMP((vec)[1], b, c); \
366 #define CLAMP2_MIN(vec, b) \
368 CLAMP_MIN((vec)[0], b); \
369 CLAMP_MIN((vec)[1], b); \
373 #define CLAMP2_MAX(vec, b) \
375 CLAMP_MAX((vec)[0], b); \
376 CLAMP_MAX((vec)[1], b); \
380 #define CLAMP3(vec, b, c) \
382 CLAMP((vec)[0], b, c); \
383 CLAMP((vec)[1], b, c); \
384 CLAMP((vec)[2], b, c); \
388 #define CLAMP3_MIN(vec, b) \
390 CLAMP_MIN((vec)[0], b); \
391 CLAMP_MIN((vec)[1], b); \
392 CLAMP_MIN((vec)[2], b); \
396 #define CLAMP3_MAX(vec, b) \
398 CLAMP_MAX((vec)[0], b); \
399 CLAMP_MAX((vec)[1], b); \
400 CLAMP_MAX((vec)[2], b); \
404 #define CLAMP4(vec, b, c) \
406 CLAMP((vec)[0], b, c); \
407 CLAMP((vec)[1], b, c); \
408 CLAMP((vec)[2], b, c); \
409 CLAMP((vec)[3], b, c); \
413 #define CLAMP4_MIN(vec, b) \
415 CLAMP_MIN((vec)[0], b); \
416 CLAMP_MIN((vec)[1], b); \
417 CLAMP_MIN((vec)[2], b); \
418 CLAMP_MIN((vec)[3], b); \
422 #define CLAMP4_MAX(vec, b) \
424 CLAMP_MAX((vec)[0], b); \
425 CLAMP_MAX((vec)[1], b); \
426 CLAMP_MAX((vec)[2], b); \
427 CLAMP_MAX((vec)[3], b); \
438 #define UNPACK2(a) ((a)[0]), ((a)[1])
439 #define UNPACK3(a) UNPACK2(a), ((a)[2])
440 #define UNPACK4(a) UNPACK3(a), ((a)[3])
442 #define UNPACK2_EX(pre, a, post) (pre((a)[0]) post), (pre((a)[1]) post)
443 #define UNPACK3_EX(pre, a, post) UNPACK2_EX(pre, a, post), (pre((a)[2]) post)
444 #define UNPACK4_EX(pre, a, post) UNPACK3_EX(pre, a, post), (pre((a)[3]) post)
453 #define ARRAY_LAST_ITEM(arr_start, arr_dtype, arr_len) \
454 (arr_dtype *)((char *)(arr_start) + (sizeof(*((arr_dtype *)NULL)) * (size_t)(arr_len - 1)))
456 #define ARRAY_HAS_ITEM(arr_item, arr_start, arr_len) \
457 (CHECK_TYPE_PAIR_INLINE(arr_start, arr_item), \
458 ((unsigned int)((arr_item) - (arr_start)) < (unsigned int)(arr_len)))
463 #define ARRAY_DELETE(arr, index, delete_len, arr_len) \
465 BLI_assert((&arr[index] >= arr) && ((index) + delete_len <= arr_len)); \
466 memmove(&(arr)[index], \
467 &(arr)[(index) + (delete_len)], \
468 (((arr_len) - (index)) - (delete_len)) * sizeof(*(arr))); \
479 #define ARRAY_DELETE_REORDER_LAST(arr, index, delete_len, arr_len) \
481 BLI_assert((&arr[index] >= arr) && ((index) + delete_len <= arr_len)); \
482 if ((index) + (delete_len) != (arr_len)) { \
483 if (((delete_len) == 1) || ((delete_len) <= ((arr_len) - ((index) + (delete_len))))) { \
484 memcpy(&(arr)[index], &(arr)[(arr_len) - (delete_len)], (delete_len) * sizeof(*(arr))); \
487 memcpy(&(arr)[index], \
488 &(arr)[(arr_len) - ((arr_len) - ((index) + (delete_len)))], \
489 ((arr_len) - ((index) + (delete_len))) * sizeof(*(arr))); \
496 #if defined(__GNUC__) && !defined(__cplusplus) && !defined(__clang__) && !defined(__INTEL_COMPILER)
497 # define ARRAY_SIZE(arr) \
498 ((sizeof(struct { int isnt_array : ((const void *)&(arr) == &(arr)[0]); }) * 0) + \
499 (sizeof(arr) / sizeof(*(arr))))
501 # define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr)))
506 #define _VA_ARRAY_SET_ITEMS2(v, a) ((v)[0] = (a))
507 #define _VA_ARRAY_SET_ITEMS3(v, a, b) \
508 _VA_ARRAY_SET_ITEMS2(v, a); \
510 #define _VA_ARRAY_SET_ITEMS4(v, a, b, c) \
511 _VA_ARRAY_SET_ITEMS3(v, a, b); \
513 #define _VA_ARRAY_SET_ITEMS5(v, a, b, c, d) \
514 _VA_ARRAY_SET_ITEMS4(v, a, b, c); \
516 #define _VA_ARRAY_SET_ITEMS6(v, a, b, c, d, e) \
517 _VA_ARRAY_SET_ITEMS5(v, a, b, c, d); \
519 #define _VA_ARRAY_SET_ITEMS7(v, a, b, c, d, e, f) \
520 _VA_ARRAY_SET_ITEMS6(v, a, b, c, d, e); \
522 #define _VA_ARRAY_SET_ITEMS8(v, a, b, c, d, e, f, g) \
523 _VA_ARRAY_SET_ITEMS7(v, a, b, c, d, e, f); \
525 #define _VA_ARRAY_SET_ITEMS9(v, a, b, c, d, e, f, g, h) \
526 _VA_ARRAY_SET_ITEMS8(v, a, b, c, d, e, f, g); \
528 #define _VA_ARRAY_SET_ITEMS10(v, a, b, c, d, e, f, g, h, i) \
529 _VA_ARRAY_SET_ITEMS9(v, a, b, c, d, e, f, g, h); \
531 #define _VA_ARRAY_SET_ITEMS11(v, a, b, c, d, e, f, g, h, i, j) \
532 _VA_ARRAY_SET_ITEMS10(v, a, b, c, d, e, f, g, h, i); \
534 #define _VA_ARRAY_SET_ITEMS12(v, a, b, c, d, e, f, g, h, i, j, k) \
535 _VA_ARRAY_SET_ITEMS11(v, a, b, c, d, e, f, g, h, i, j); \
537 #define _VA_ARRAY_SET_ITEMS13(v, a, b, c, d, e, f, g, h, i, j, k, l) \
538 _VA_ARRAY_SET_ITEMS12(v, a, b, c, d, e, f, g, h, i, j, k); \
540 #define _VA_ARRAY_SET_ITEMS14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) \
541 _VA_ARRAY_SET_ITEMS13(v, a, b, c, d, e, f, g, h, i, j, k, l); \
543 #define _VA_ARRAY_SET_ITEMS15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
544 _VA_ARRAY_SET_ITEMS14(v, a, b, c, d, e, f, g, h, i, j, k, l, m); \
546 #define _VA_ARRAY_SET_ITEMS16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
547 _VA_ARRAY_SET_ITEMS15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n); \
549 #define _VA_ARRAY_SET_ITEMS17(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
550 _VA_ARRAY_SET_ITEMS16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o); \
554 #define ARRAY_SET_ITEMS(...) \
556 VA_NARGS_CALL_OVERLOAD(_VA_ARRAY_SET_ITEMS, __VA_ARGS__); \
566 #if defined(__GNUC__) || defined(__clang__)
567 # define POINTER_OFFSET(v, ofs) ((typeof(v))((char *)(v) + (ofs)))
569 # define POINTER_OFFSET(v, ofs) ((void *)((char *)(v) + (ofs)))
574 #define POINTER_FROM_INT(i) ((void *)(intptr_t)(i))
575 #define POINTER_AS_INT(i) ((void)0, ((int)(intptr_t)(i)))
577 #define POINTER_FROM_UINT(i) ((void *)(uintptr_t)(i))
578 #define POINTER_AS_UINT(i) ((void)0, ((unsigned int)(uintptr_t)(i)))
591 #define OFFSETOF_STRUCT_AFTER(_struct, _member) \
592 ((((const char *)&((_struct)->_member)) - ((const char *)(_struct))) + \
593 sizeof((_struct)->_member))
600 #define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member) \
602 CHECK_TYPE_NONCONST(struct_dst); \
603 ((void)(struct_dst == struct_src), \
604 memcpy((char *)(struct_dst) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
605 (const char *)(struct_src) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
606 sizeof(*(struct_dst)) - OFFSETOF_STRUCT_AFTER(struct_dst, member))); \
610 #define MEMSET_STRUCT_AFTER(struct_var, value, member) \
612 CHECK_TYPE_NONCONST(struct_var); \
613 memset((char *)(struct_var) + OFFSETOF_STRUCT_AFTER(struct_var, member), \
615 sizeof(*(struct_var)) - OFFSETOF_STRUCT_AFTER(struct_var, member)); \
621 #ifndef __BLI_MEMORY_UTILS_H__
628 #define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member) \
629 (BLI_memory_is_zero((const char *)(struct_var) + OFFSETOF_STRUCT_AFTER(struct_var, member), \
630 sizeof(*(struct_var)) - OFFSETOF_STRUCT_AFTER(struct_var, member)))
644 #define STRINGIFY_ARG(x) "" #x
645 #define STRINGIFY_APPEND(a, b) "" a #b
646 #define STRINGIFY(x) STRINGIFY_APPEND("", x)
649 #if defined(_MSC_VER)
650 # define strcasecmp _stricmp
651 # define strncasecmp _strnicmp
654 #define STREQ(a, b) (strcmp(a, b) == 0)
655 #define STRCASEEQ(a, b) (strcasecmp(a, b) == 0)
656 #define STREQLEN(a, b, n) (strncmp(a, b, n) == 0)
657 #define STRCASEEQLEN(a, b, n) (strncasecmp(a, b, n) == 0)
659 #define STRPREFIX(a, b) (strncmp((a), (b), strlen(b)) == 0)
668 #if defined(__GNUC__) || defined(__clang__)
669 # define UNUSED(x) UNUSED_##x __attribute__((__unused__))
671 # define UNUSED(x) UNUSED_##x
678 #if defined(__GNUC__) || defined(__clang__)
679 # define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_##x
681 # define UNUSED_FUNCTION(x) UNUSED_##x
684 #if defined(__GNUC__) || defined(__clang__)
685 # define UNUSED_FUNCTION_WITH_RETURN_TYPE(rtype, x) __attribute__((__unused__)) rtype UNUSED_##x
687 # define UNUSED_FUNCTION_WITH_RETURN_TYPE(rtype, x) rtype UNUSED_##x
703 #define _VA_UNUSED_VARS_1(a0) ((void)(a0))
704 #define _VA_UNUSED_VARS_2(a0, b0) ((void)(a0), _VA_UNUSED_VARS_1(b0))
705 #define _VA_UNUSED_VARS_3(a0, b0, c0) ((void)(a0), _VA_UNUSED_VARS_2(b0, c0))
706 #define _VA_UNUSED_VARS_4(a0, b0, c0, d0) ((void)(a0), _VA_UNUSED_VARS_3(b0, c0, d0))
707 #define _VA_UNUSED_VARS_5(a0, b0, c0, d0, e0) ((void)(a0), _VA_UNUSED_VARS_4(b0, c0, d0, e0))
708 #define _VA_UNUSED_VARS_6(a0, b0, c0, d0, e0, f0) \
709 ((void)(a0), _VA_UNUSED_VARS_5(b0, c0, d0, e0, f0))
710 #define _VA_UNUSED_VARS_7(a0, b0, c0, d0, e0, f0, g0) \
711 ((void)(a0), _VA_UNUSED_VARS_6(b0, c0, d0, e0, f0, g0))
712 #define _VA_UNUSED_VARS_8(a0, b0, c0, d0, e0, f0, g0, h0) \
713 ((void)(a0), _VA_UNUSED_VARS_7(b0, c0, d0, e0, f0, g0, h0))
714 #define _VA_UNUSED_VARS_9(a0, b0, c0, d0, e0, f0, g0, h0, i0) \
715 ((void)(a0), _VA_UNUSED_VARS_8(b0, c0, d0, e0, f0, g0, h0, i0))
716 #define _VA_UNUSED_VARS_10(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0) \
717 ((void)(a0), _VA_UNUSED_VARS_9(b0, c0, d0, e0, f0, g0, h0, i0, j0))
718 #define _VA_UNUSED_VARS_11(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0) \
719 ((void)(a0), _VA_UNUSED_VARS_10(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0))
720 #define _VA_UNUSED_VARS_12(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0) \
721 ((void)(a0), _VA_UNUSED_VARS_11(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0))
722 #define _VA_UNUSED_VARS_13(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0) \
723 ((void)(a0), _VA_UNUSED_VARS_12(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0))
724 #define _VA_UNUSED_VARS_14(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0) \
725 ((void)(a0), _VA_UNUSED_VARS_13(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0))
726 #define _VA_UNUSED_VARS_15(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0) \
727 ((void)(a0), _VA_UNUSED_VARS_14(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0))
728 #define _VA_UNUSED_VARS_16(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0, p0) \
729 ((void)(a0), _VA_UNUSED_VARS_15(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0, p0))
732 #define UNUSED_VARS(...) VA_NARGS_CALL_OVERLOAD(_VA_UNUSED_VARS_, __VA_ARGS__)
736 # define UNUSED_VARS_NDEBUG(...)
738 # define UNUSED_VARS_NDEBUG UNUSED_VARS
749 # define LIKELY(x) __builtin_expect(!!(x), 1)
750 # define UNLIKELY(x) __builtin_expect(!!(x), 0)
752 # define LIKELY(x) (x)
753 # define UNLIKELY(x) (x)
763 #define SET_FLAG_FROM_TEST(value, test, flag) \
769 (value) &= ~(flag); \
785 # define ENUM_OPERATORS(_enum_type, _max_enum_value) \
787 inline constexpr _enum_type operator|(_enum_type a, _enum_type b) \
789 return static_cast<_enum_type>(static_cast<uint64_t>(a) | static_cast<uint64_t>(b)); \
791 inline constexpr _enum_type operator&(_enum_type a, _enum_type b) \
793 return static_cast<_enum_type>(static_cast<uint64_t>(a) & static_cast<uint64_t>(b)); \
795 inline constexpr _enum_type operator~(_enum_type a) \
797 return static_cast<_enum_type>(~static_cast<uint64_t>(a) & \
798 (2 * static_cast<uint64_t>(_max_enum_value) - 1)); \
800 inline _enum_type &operator|=(_enum_type &a, _enum_type b) \
802 return a = static_cast<_enum_type>(static_cast<uint64_t>(a) | static_cast<uint64_t>(b)); \
804 inline _enum_type &operator&=(_enum_type &a, _enum_type b) \
806 return a = static_cast<_enum_type>(static_cast<uint64_t>(a) & static_cast<uint64_t>(b)); \
812 # define ENUM_OPERATORS(_type, _max)
820 # define CPP_ARG_DEFAULT(default_value) = default_value
822 # define CPP_ARG_DEFAULT(default_value)
832 #define AT __FILE__ ":" STRINGIFY(__LINE__)
835 #define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0)
844 #define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr
846 #if defined(_MSC_VER)
847 # define BLI_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
848 #elif defined(__has_cpp_attribute)
849 # if __has_cpp_attribute(no_unique_address)
850 # define BLI_NO_UNIQUE_ADDRESS [[no_unique_address]]
852 # define BLI_NO_UNIQUE_ADDRESS
855 # define BLI_NO_UNIQUE_ADDRESS [[no_unique_address]]
bool BLI_memory_is_zero(const void *arr, size_t arr_size)