31#define INIT_MINMAX(min, max) \
33 (min)[0] = (min)[1] = (min)[2] = 1.0e30f; \
34 (max)[0] = (max)[1] = (max)[2] = -1.0e30f; \
37#define INIT_MINMAX2(min, max) \
39 (min)[0] = (min)[1] = 1.0e30f; \
40 (max)[0] = (max)[1] = -1.0e30f; \
50#define SWAP(type, a, b) \
53 CHECK_TYPE(a, type); \
54 CHECK_TYPE(b, type); \
62#define SHIFT3(type, a, b, c) \
65 CHECK_TYPE(a, type); \
66 CHECK_TYPE(b, type); \
67 CHECK_TYPE(c, type); \
75#define SHIFT4(type, a, b, c, d) \
78 CHECK_TYPE(a, type); \
79 CHECK_TYPE(b, type); \
80 CHECK_TYPE(c, type); \
81 CHECK_TYPE(d, type); \
101#define _VA_ELEM2(v, a) ((v) == (a))
102#define _VA_ELEM3(v, a, b) \
103 (_VA_ELEM2(v, a) || _VA_ELEM2(v, b))
104#define _VA_ELEM4(v, a, b, c) \
105 (_VA_ELEM3(v, a, b) || _VA_ELEM2(v, c))
106#define _VA_ELEM5(v, a, b, c, d) \
107 (_VA_ELEM4(v, a, b, c) || _VA_ELEM2(v, d))
108#define _VA_ELEM6(v, a, b, c, d, e) \
109 (_VA_ELEM5(v, a, b, c, d) || _VA_ELEM2(v, e))
110#define _VA_ELEM7(v, a, b, c, d, e, f) \
111 (_VA_ELEM6(v, a, b, c, d, e) || _VA_ELEM2(v, f))
112#define _VA_ELEM8(v, a, b, c, d, e, f, g) \
113 (_VA_ELEM7(v, a, b, c, d, e, f) || _VA_ELEM2(v, g))
114#define _VA_ELEM9(v, a, b, c, d, e, f, g, h) \
115 (_VA_ELEM8(v, a, b, c, d, e, f, g) || _VA_ELEM2(v, h))
116#define _VA_ELEM10(v, a, b, c, d, e, f, g, h, i) \
117 (_VA_ELEM9(v, a, b, c, d, e, f, g, h) || _VA_ELEM2(v, i))
118#define _VA_ELEM11(v, a, b, c, d, e, f, g, h, i, j) \
119 (_VA_ELEM10(v, a, b, c, d, e, f, g, h, i) || _VA_ELEM2(v, j))
120#define _VA_ELEM12(v, a, b, c, d, e, f, g, h, i, j, k) \
121 (_VA_ELEM11(v, a, b, c, d, e, f, g, h, i, j) || _VA_ELEM2(v, k))
122#define _VA_ELEM13(v, a, b, c, d, e, f, g, h, i, j, k, l) \
123 (_VA_ELEM12(v, a, b, c, d, e, f, g, h, i, j, k) || _VA_ELEM2(v, l))
124#define _VA_ELEM14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) \
125 (_VA_ELEM13(v, a, b, c, d, e, f, g, h, i, j, k, l) || _VA_ELEM2(v, m))
126#define _VA_ELEM15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
127 (_VA_ELEM14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) || _VA_ELEM2(v, n))
128#define _VA_ELEM16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
129 (_VA_ELEM15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) || _VA_ELEM2(v, o))
130#define _VA_ELEM17(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
131 (_VA_ELEM16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) || _VA_ELEM2(v, p))
135#define ELEM(...) VA_NARGS_CALL_OVERLOAD(_VA_ELEM, __VA_ARGS__)
146 (CHECK_TYPE_INLINE_NONCONST(a, double), \
147 CHECK_TYPE_INLINE_NONCONST(b, double), \
148 ((fabs((double)((a) - (b))) >= (double)FLT_EPSILON) ? false : true))
150#define IS_EQF(a, b) \
151 (CHECK_TYPE_INLINE_NONCONST(a, float), \
152 CHECK_TYPE_INLINE_NONCONST(b, float), \
153 ((fabsf((float)((a) - (b))) >= (float)FLT_EPSILON) ? false : true))
155#define IS_EQT(a, b, c) (((a) > (b)) ? ((((a) - (b)) <= (c))) : (((((b) - (a)) <= (c)))))
156#define IN_RANGE(a, b, c) (((b) < (c)) ? (((b) < (a) && (a) < (c))) : (((c) < (a) && (a) < (b))))
157#define IN_RANGE_INCL(a, b, c) \
158 (((b) < (c)) ? (((b) <= (a) && (a) <= (c))) : (((c) <= (a) && (a) <= (b))))
168#define DECIMAL_DIGITS_BOUND(t) (241 * sizeof(t) / 100 + 1)
173 return (
x & (
x - 1)) == 0;
200#define CLAMP(a, b, c) \
205 else if ((a) > (c)) { \
211#define CLAMP_MAX(a, c) \
219#define CLAMP_MIN(a, b) \
234#define UNPACK2(a) ((a)[0]), ((a)[1])
235#define UNPACK3(a) UNPACK2(a), ((a)[2])
236#define UNPACK4(a) UNPACK3(a), ((a)[3])
238#define UNPACK2_EX(pre, a, post) (pre((a)[0]) post), (pre((a)[1]) post)
239#define UNPACK3_EX(pre, a, post) UNPACK2_EX(pre, a, post), (pre((a)[2]) post)
240#define UNPACK4_EX(pre, a, post) UNPACK3_EX(pre, a, post), (pre((a)[3]) post)
248#define ARRAY_HAS_ITEM(arr_item, arr_start, arr_len) \
249 (CHECK_TYPE_PAIR_INLINE(arr_start, arr_item), \
250 ((size_t)((arr_item) - (arr_start)) < (size_t)(arr_len)))
256#define _VA_ARRAY_SET_ITEMS2(v, a) ((v)[0] = (a))
257#define _VA_ARRAY_SET_ITEMS3(v, a, b) \
258 _VA_ARRAY_SET_ITEMS2(v, a); \
260#define _VA_ARRAY_SET_ITEMS4(v, a, b, c) \
261 _VA_ARRAY_SET_ITEMS3(v, a, b); \
263#define _VA_ARRAY_SET_ITEMS5(v, a, b, c, d) \
264 _VA_ARRAY_SET_ITEMS4(v, a, b, c); \
266#define _VA_ARRAY_SET_ITEMS6(v, a, b, c, d, e) \
267 _VA_ARRAY_SET_ITEMS5(v, a, b, c, d); \
269#define _VA_ARRAY_SET_ITEMS7(v, a, b, c, d, e, f) \
270 _VA_ARRAY_SET_ITEMS6(v, a, b, c, d, e); \
272#define _VA_ARRAY_SET_ITEMS8(v, a, b, c, d, e, f, g) \
273 _VA_ARRAY_SET_ITEMS7(v, a, b, c, d, e, f); \
275#define _VA_ARRAY_SET_ITEMS9(v, a, b, c, d, e, f, g, h) \
276 _VA_ARRAY_SET_ITEMS8(v, a, b, c, d, e, f, g); \
278#define _VA_ARRAY_SET_ITEMS10(v, a, b, c, d, e, f, g, h, i) \
279 _VA_ARRAY_SET_ITEMS9(v, a, b, c, d, e, f, g, h); \
281#define _VA_ARRAY_SET_ITEMS11(v, a, b, c, d, e, f, g, h, i, j) \
282 _VA_ARRAY_SET_ITEMS10(v, a, b, c, d, e, f, g, h, i); \
284#define _VA_ARRAY_SET_ITEMS12(v, a, b, c, d, e, f, g, h, i, j, k) \
285 _VA_ARRAY_SET_ITEMS11(v, a, b, c, d, e, f, g, h, i, j); \
287#define _VA_ARRAY_SET_ITEMS13(v, a, b, c, d, e, f, g, h, i, j, k, l) \
288 _VA_ARRAY_SET_ITEMS12(v, a, b, c, d, e, f, g, h, i, j, k); \
290#define _VA_ARRAY_SET_ITEMS14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) \
291 _VA_ARRAY_SET_ITEMS13(v, a, b, c, d, e, f, g, h, i, j, k, l); \
293#define _VA_ARRAY_SET_ITEMS15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
294 _VA_ARRAY_SET_ITEMS14(v, a, b, c, d, e, f, g, h, i, j, k, l, m); \
296#define _VA_ARRAY_SET_ITEMS16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
297 _VA_ARRAY_SET_ITEMS15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n); \
299#define _VA_ARRAY_SET_ITEMS17(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
300 _VA_ARRAY_SET_ITEMS16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o); \
304#define ARRAY_SET_ITEMS(...) \
306 VA_NARGS_CALL_OVERLOAD(_VA_ARRAY_SET_ITEMS, __VA_ARGS__); \
316#define POINTER_OFFSET(v, ofs) \
317 (reinterpret_cast<std::remove_reference_t<decltype(v)>>((char *)(v) + (ofs)))
321#define POINTER_FROM_INT(i) ((void *)(intptr_t)(i))
322#define POINTER_AS_INT(i) ((void)0, ((int)(intptr_t)(i)))
324#define POINTER_FROM_UINT(i) ((void *)(uintptr_t)(i))
325#define POINTER_AS_UINT(i) ((void)0, ((unsigned int)(uintptr_t)(i)))
338#define OFFSETOF_STRUCT_AFTER(_struct, _member) \
339 ((size_t)(((const char *)&((_struct)->_member)) - ((const char *)(_struct))) + \
340 sizeof((_struct)->_member))
347#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member) \
349 CHECK_TYPE_NONCONST(struct_dst); \
350 ((void)(struct_dst == struct_src), \
351 memcpy((char *)(struct_dst) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
352 (const char *)(struct_src) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
353 sizeof(*(struct_dst)) - OFFSETOF_STRUCT_AFTER(struct_dst, member))); \
357#define MEMSET_STRUCT_AFTER(struct_var, value, member) \
359 CHECK_TYPE_NONCONST(struct_var); \
360 memset((char *)(struct_var) + OFFSETOF_STRUCT_AFTER(struct_var, member), \
362 sizeof(*(struct_var)) - OFFSETOF_STRUCT_AFTER(struct_var, member)); \
377 const char *arr_byte =
static_cast<const char *
>(
data);
378 const char *arr_end =
static_cast<const char *
>(
data) + size;
380 while ((arr_byte != arr_end) && (*arr_byte == 0)) {
384 return (arr_byte == arr_end);
396 if constexpr (std::is_pointer_v<T>) {
397 return value ==
nullptr;
399 else if constexpr (std::is_integral_v<T>) {
402 else if constexpr (std::is_floating_point_v<T>) {
403 return value == 0.0f;
405 else if constexpr (std::has_unique_object_representations_v<T>) {
415#define MEMCMP_STRUCT_AFTER_IS_ZERO_OR_EQUAL(struct_dst, struct_src, member) \
416 (memory_is_zero((const char *)(struct_dst) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
417 sizeof(*(struct_dst)) - OFFSETOF_STRUCT_AFTER(struct_dst, member)) || \
418 (memcmp((const char *)(struct_dst) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
419 (const char *)(struct_src) + OFFSETOF_STRUCT_AFTER(struct_src, member), \
420 sizeof(*(struct_dst)) - OFFSETOF_STRUCT_AFTER(struct_dst, member)) == 0))
422#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member) \
424 const typename std::remove_reference<decltype(*(struct_dst))>::type struct_src; \
425 BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO_OR_EQUAL(struct_dst, &struct_src, member)); \
426 MEMCPY_STRUCT_AFTER(struct_dst, &struct_src, member); \
441#define STRINGIFY_ARG(x) "" #x
442#define STRINGIFY_APPEND(a, b) "" a #b
443#define STRINGIFY(x) STRINGIFY_APPEND("", x)
447# define strcasecmp _stricmp
448# define strncasecmp _strnicmp
451#define STREQ(a, b) (strcmp(a, b) == 0)
452#define STRCASEEQ(a, b) (strcasecmp(a, b) == 0)
453#define STREQLEN(a, b, n) (strncmp(a, b, n) == 0)
454#define STRCASEEQLEN(a, b, n) (strncasecmp(a, b, n) == 0)
456#define STRPREFIX(a, b) (strncmp((a), (b), strlen(b)) == 0)
468#if defined(__GNUC__) || defined(__clang__)
469# define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_##x
471# define UNUSED_FUNCTION(x) UNUSED_##x
474#if defined(__GNUC__) || defined(__clang__)
475# define UNUSED_FUNCTION_WITH_RETURN_TYPE(rtype, x) __attribute__((__unused__)) rtype UNUSED_##x
477# define UNUSED_FUNCTION_WITH_RETURN_TYPE(rtype, x) rtype UNUSED_##x
493#define _VA_UNUSED_VARS_1(a0) ((void)(a0))
494#define _VA_UNUSED_VARS_2(a0, b0) ((void)(a0), _VA_UNUSED_VARS_1(b0))
495#define _VA_UNUSED_VARS_3(a0, b0, c0) ((void)(a0), _VA_UNUSED_VARS_2(b0, c0))
496#define _VA_UNUSED_VARS_4(a0, b0, c0, d0) ((void)(a0), _VA_UNUSED_VARS_3(b0, c0, d0))
497#define _VA_UNUSED_VARS_5(a0, b0, c0, d0, e0) ((void)(a0), _VA_UNUSED_VARS_4(b0, c0, d0, e0))
498#define _VA_UNUSED_VARS_6(a0, b0, c0, d0, e0, f0) \
499 ((void)(a0), _VA_UNUSED_VARS_5(b0, c0, d0, e0, f0))
500#define _VA_UNUSED_VARS_7(a0, b0, c0, d0, e0, f0, g0) \
501 ((void)(a0), _VA_UNUSED_VARS_6(b0, c0, d0, e0, f0, g0))
502#define _VA_UNUSED_VARS_8(a0, b0, c0, d0, e0, f0, g0, h0) \
503 ((void)(a0), _VA_UNUSED_VARS_7(b0, c0, d0, e0, f0, g0, h0))
504#define _VA_UNUSED_VARS_9(a0, b0, c0, d0, e0, f0, g0, h0, i0) \
505 ((void)(a0), _VA_UNUSED_VARS_8(b0, c0, d0, e0, f0, g0, h0, i0))
506#define _VA_UNUSED_VARS_10(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0) \
507 ((void)(a0), _VA_UNUSED_VARS_9(b0, c0, d0, e0, f0, g0, h0, i0, j0))
508#define _VA_UNUSED_VARS_11(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0) \
509 ((void)(a0), _VA_UNUSED_VARS_10(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0))
510#define _VA_UNUSED_VARS_12(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0) \
511 ((void)(a0), _VA_UNUSED_VARS_11(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0))
512#define _VA_UNUSED_VARS_13(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0) \
513 ((void)(a0), _VA_UNUSED_VARS_12(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0))
514#define _VA_UNUSED_VARS_14(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0) \
515 ((void)(a0), _VA_UNUSED_VARS_13(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0))
516#define _VA_UNUSED_VARS_15(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0) \
517 ((void)(a0), _VA_UNUSED_VARS_14(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0))
518#define _VA_UNUSED_VARS_16(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0, p0) \
519 ((void)(a0), _VA_UNUSED_VARS_15(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0, p0))
522#define UNUSED_VARS(...) VA_NARGS_CALL_OVERLOAD(_VA_UNUSED_VARS_, __VA_ARGS__)
526# define UNUSED_VARS_NDEBUG(...)
528# define UNUSED_VARS_NDEBUG UNUSED_VARS
543# define LIKELY(x) __builtin_expect(!!(x), 1)
544# define UNLIKELY(x) __builtin_expect(!!(x), 0)
546# define LIKELY(x) (x)
547# define UNLIKELY(x) (x)
557#define SET_FLAG_FROM_TEST(value, test, flag) \
563 (value) &= ~(flag); \
575#define AT __FILE__ ":" STRINGIFY(__LINE__)
578#define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0)
580#if defined(_MSC_VER) && !defined(__clang__)
581# define BLI_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
582#elif defined(__has_cpp_attribute)
583# if __has_cpp_attribute(no_unique_address)
584# define BLI_NO_UNIQUE_ADDRESS [[no_unique_address]]
586# define BLI_NO_UNIQUE_ADDRESS
589# define BLI_NO_UNIQUE_ADDRESS [[no_unique_address]]
608template<
class T,
size_t N>
constexpr size_t ARRAY_SIZE(
const T (&arg)[
N])
noexcept
625constexpr std::enable_if_t<blenlib_internal::IsBoundedArray<T>::value,
size_t>
628 return sizeof(std::declval<T>()) /
sizeof(std::declval<T>()[0]);
constexpr int64_t log2_floor(const int64_t x)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
constexpr int64_t power_of_2_max(const int64_t x)
constexpr bool value_is_zero_memory(const VecBase< T, Size > &v)
constexpr bool memory_is_zero(const void *data, const size_t size)
constexpr std::enable_if_t< blenlib_internal::IsBoundedArray< T >::value, size_t > BOUNDED_ARRAY_TYPE_SIZE() noexcept
constexpr int64_t log2_ceil(const int64_t x)
BMesh const char void * data
constexpr int64_t is_power_of_2(const int64_t x)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept