diff options
-rw-r--r-- | source/blender/blenlib/BLI_array_utils.h | 18 | ||||
-rw-r--r-- | source/blender/blenlib/intern/array_utils.c | 28 |
2 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_array_utils.h b/source/blender/blenlib/BLI_array_utils.h index ff7976dc701..c5359d56f9c 100644 --- a/source/blender/blenlib/BLI_array_utils.h +++ b/source/blender/blenlib/BLI_array_utils.h @@ -26,6 +26,8 @@ * \brief Generic array manipulation API. */ +#include "BLI_compiler_typecheck.h" + void _bli_array_reverse(void *arr, unsigned int arr_len, size_t arr_stride); #define BLI_array_reverse(arr, arr_len) \ _bli_array_reverse(arr, arr_len, sizeof(*(arr))) @@ -46,4 +48,20 @@ int _bli_array_findindex(const void *arr, unsigned int arr_len, size_t arr_strid #define BLI_array_findindex(arr, arr_len, p) \ _bli_array_findindex(arr, arr_len, sizeof(*(arr)), p) +void _bli_array_binary_and( + void *arr, const void *arr_a, const void *arr_b, + unsigned int arr_len, size_t arr_stride); +#define BLI_array_binary_and(arr, arr_a, arr_b, arr_len) \ + (CHECK_TYPE_PAIR_INLINE(*(arr), *(arr_a)), \ + CHECK_TYPE_PAIR_INLINE(*(arr), *(arr_b)), \ + _bli_array_binary_and(arr, arr_a, arr_b, arr_len, sizeof(*(arr)))) + +void _bli_array_binary_or( + void *arr, const void *arr_a, const void *arr_b, + unsigned int arr_len, size_t arr_stride); +#define BLI_array_binary_or(arr, arr_a, arr_b, arr_len) \ + (CHECK_TYPE_PAIR_INLINE(*(arr), *(arr_a)), \ + CHECK_TYPE_PAIR_INLINE(*(arr), *(arr_b)), \ + _bli_array_binary_or(arr, arr_a, arr_b, arr_len, sizeof(*(arr)))) + #endif /* __BLI_ARRAY_UTILS_H__ */ diff --git a/source/blender/blenlib/intern/array_utils.c b/source/blender/blenlib/intern/array_utils.c index cef912e42a3..52ca835876e 100644 --- a/source/blender/blenlib/intern/array_utils.c +++ b/source/blender/blenlib/intern/array_utils.c @@ -142,3 +142,31 @@ int _bli_array_findindex(const void *arr, unsigned int arr_len, size_t arr_strid } return -1; } + +void _bli_array_binary_and( + void *arr, const void *arr_a, const void *arr_b, + unsigned int arr_len, size_t arr_stride) +{ + char *dst = arr; + const char *src_a = arr_a; + const char *src_b = arr_b; + + size_t i = arr_stride * arr_len; + while (i--) { + *(dst++) = *(src_a++) & *(src_b++); + } +} + +void _bli_array_binary_or( + void *arr, const void *arr_a, const void *arr_b, + unsigned int arr_len, size_t arr_stride) +{ + char *dst = arr; + const char *src_a = arr_a; + const char *src_b = arr_b; + + size_t i = arr_stride * arr_len; + while (i--) { + *(dst++) = *(src_a++) | *(src_b++); + } +}
\ No newline at end of file |