Lines Matching +full:string +full:- +full:array

2  * Copyright (c) 2011-2014, Wind River Systems, Inc.
4 * SPDX-License-Identifier: Apache-2.0
40 * @defgroup sys-util Utility Functions
80 (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
83 * @brief Create a contiguous 64-bit bitmask starting at bit position @p l
87 (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
89 /** @brief 0 if @p cond is true-ish; causes a compile error otherwise. */
90 #define ZERO_OR_COMPILE_ERROR(cond) ((int) sizeof(char[1 - 2 * !(cond)]) - 1)
94 /* The built-in function used below for type checking in C is not
97 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) argument
102 * @brief Zero if @p array has an array type, a compile error otherwise
106 #define IS_ARRAY(array) \
108 !__builtin_types_compatible_p(__typeof__(array), \
109 __typeof__(&(array)[0])))
112 * @brief Number of elements in the given @p array
114 * In C++, due to language limitations, this will accept as @p array
118 * In C, passing a pointer as @p array causes a compile error.
120 #define ARRAY_SIZE(array) \
121 ((size_t) (IS_ARRAY(array) + (sizeof(array) / sizeof((array)[0]))))
126 * @brief Declare a flexible array member.
128 * This macro declares a flexible array member in a struct. The member
149 * @brief Whether @p ptr is an element of @p array
152 * in that it also ensures that @p ptr is aligned to an array-element boundary
153 * of @p array.
155 * In C, passing a pointer as @p array causes a compile error.
157 * @param array the array in question
160 * @return 1 if @p ptr is part of @p array, 0 otherwise
162 #define IS_ARRAY_ELEMENT(array, ptr) \ argument
163 ((ptr) && POINTER_TO_UINT(array) <= POINTER_TO_UINT(ptr) && \
164 POINTER_TO_UINT(ptr) < POINTER_TO_UINT(&(array)[ARRAY_SIZE(array)]) && \
165 (POINTER_TO_UINT(ptr) - POINTER_TO_UINT(array)) % sizeof((array)[0]) == 0)
168 * @brief Index of @p ptr within @p array
171 * when @p ptr does not fall into the range of @p array or when @p ptr
172 * is not aligned to an array-element boundary of @p array.
174 * In C, passing a pointer as @p array causes a compile error.
176 * @param array the array in question
177 * @param ptr pointer to an element of @p array
179 * @return the array index of @p ptr within @p array, on success
181 #define ARRAY_INDEX(array, ptr) \ argument
183 __ASSERT_NO_MSG(IS_ARRAY_ELEMENT(array, ptr)); \
184 (__typeof__((array)[0]) *)(ptr) - (array); \
188 * @brief Check if a pointer @p ptr lies within @p array.
190 * In C but not C++, this causes a compile error if @p array is not an array
191 * (e.g. if @p ptr and @p array are mixed up).
193 * @param array an array
195 * @return 1 if @p ptr is part of @p array, 0 otherwise
197 #define PART_OF_ARRAY(array, ptr) \ argument
198 ((ptr) && POINTER_TO_UINT(array) <= POINTER_TO_UINT(ptr) && \
199 POINTER_TO_UINT(ptr) < POINTER_TO_UINT(&(array)[ARRAY_SIZE(array)]))
202 * @brief Array-index of @p ptr within @p array, rounded down
205 * difference that it accepts any @p ptr in the range of @p array rather than
206 * exclusively a @p ptr aligned to an array-element boundary of @p array.
209 * when @p ptr does not fall into the range of @p array.
211 * In C, passing a pointer as @p array causes a compile error.
213 * @param array the array in question
214 * @param ptr pointer to an element of @p array
216 * @return the array index of @p ptr within @p array, on success
218 #define ARRAY_INDEX_FLOOR(array, ptr) \ argument
220 __ASSERT_NO_MSG(PART_OF_ARRAY(array, ptr)); \
221 (POINTER_TO_UINT(ptr) - POINTER_TO_UINT(array)) / sizeof((array)[0]); \
225 * @brief Iterate over members of an array using an index variable
227 * @param array the array in question
228 * @param idx name of array index variable
230 #define ARRAY_FOR_EACH(array, idx) for (size_t idx = 0; (idx) < ARRAY_SIZE(array); ++(idx)) argument
233 * @brief Iterate over members of an array using a pointer
235 * @param array the array in question
236 * @param ptr pointer to an element of @p array
238 #define ARRAY_FOR_EACH_PTR(array, ptr) \ argument
239 for (__typeof__(*(array)) *ptr = (array); (size_t)((ptr) - (array)) < ARRAY_SIZE(array); \
256 BUILD_ASSERT(SAME_TYPE(*(ptr), ((type *)0)->field) || \
287 ((type *)(((char *)(ptr)) - offsetof(type, field))); \
298 #define SIZEOF_FIELD(type, member) sizeof((((type *)0)->member))
323 ((((unsigned long)(x) + ((unsigned long)(align) - 1)) / \
352 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
360 * DIV_ROUND_CLOSEST(5, -2); // -3
370 (((((__typeof__(n))-1) < 0) && (((__typeof__(d))-1) < 0) && ((n) < 0) ^ ((d) < 0)) \
371 ? ((n) - ((d) / 2)) / (d) \
378 * @note Arguments are evaluated twice. Use Z_MAX for a GCC-only, single
393 * @note Arguments are evaluated twice. Use Z_MIN for a GCC-only, single
408 * @note Arguments are evaluated multiple times. Use Z_CLAMP for a GCC-only,
448 * multiple use-cases, but NULL checks can generate warnings if such a macro
454 * b) tracking of macro expansions are turned off (-ftrack-macro-expansion=0)
487 sign_ext = -sign_ext; in arithmetic_shift_right()
490 return (value >> shift) | (sign_ext << (64 - shift)); in arithmetic_shift_right()
527 for (; size > 0; --size) { in byteswp()
555 * @brief Convert a binary array into string representation.
557 * @param buf The binary array to convert
558 * @param buflen The length of the binary array to convert
559 * @param hex Address of where to store the string representation.
560 * @param hexlen Size of the storage area for string representation.
562 * @return The length of the converted string, or 0 if an error occurred.
567 * @brief Convert a hexadecimal string into a binary array.
569 * @param hex The hexadecimal string to convert
570 * @param hexlen The length of the hexadecimal string to convert.
574 * @return The length of the binary array, or 0 if an error occurred.
603 * @brief Convert a uint8_t into a decimal string representation.
605 * Convert a uint8_t value into its ASCII decimal string representation.
606 * The string is terminated if there is enough space in buf.
608 * @param buf Address of where to store the string representation.
609 * @param buflen Size of the storage area for string representation.
610 * @param value The value to convert to decimal string
612 * @return The length of the converted string (excluding terminator if
627 uint8_t shift = 31 - index; in sign_extend()
642 uint8_t shift = 63 - index; in sign_extend_64()
648 * @brief Properly truncate a NULL-terminated UTF-8 string
650 * Take a NULL-terminated UTF-8 string and ensure that if the string has been
652 * the string ends with a properly formatted UTF-8 character (1-4 bytes).
661 * trunc_utf8[sizeof(trunc_utf8) - 1] = '\0';
667 * @param utf8_str NULL-terminated string
674 * @brief Copies a UTF-8 encoded string from @p src to @p dst
677 * and the @p dst string will always be properly UTF-8 truncated.
679 * @param dst The destination of the UTF-8 string.
680 * @param src The source string
682 * is @p n - 1. If 0 nothing will be done, and the @p dst will not be
689 #define __z_log2d(x) (32 - __builtin_clz(x) - 1)
690 #define __z_log2q(x) (64 - __builtin_clzll(x) - 1)
701 * @return log2(x) when 1 <= x <= max(x), -1 when x < 1
703 #define LOG2(x) ((x) < 1 ? -1 : __z_log2(x))
715 #define LOG2CEIL(x) ((x) <= 1 ? 0 : __z_log2((x)-1) + 1)
727 * @return 2^ceil(log2(x)) or 0 if 2^ceil(log2(x)) would saturate 64-bits
745 ((UINTPTR_MAX - (uintptr_t)(addr)) <= ((uintptr_t)((buflen) - 1))))
757 while (len--) { in mem_xor_n()
816 * For other architectures this is a no-op.
851 while (!(expr) && (_wf_cycle_count > (k_cycle_get_32() - _wf_start))) { \