Lines Matching +full:v +full:- +full:bit
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2019 Intel Corporation
11 * Generic, commonly-used macro and inline function definitions
107 * Check format string and its arguments at compile-time.
109 * GCC on Windows assumes MS-specific format string by default,
110 * even if the underlying stdio implementation is ANSI-compliant,
207 * add a byte-value offset to a pointer
212 * subtract a byte-value offset from a pointer
214 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x)))
221 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
224 * Workaround to cast a const field of a structure to non-const type.
233 * Macro to align a pointer to a given power-of-two. The resultant
236 * must be a power-of-two value.
242 * Macro to align a value to a given power-of-two. The resultant value
245 * power-of-two value.
248 (typeof(val))((val) & (~((typeof(val))((align) - 1))))
251 * Macro to align a pointer to a given power-of-two. The resultant
254 * must be a power-of-two value.
257 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
260 * Macro to align a value to a given power-of-two. The resultant value
262 * than the first parameter. Second parameter must be a power-of-two
266 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
269 * Macro to align a pointer to a given power-of-two. The resultant
272 * must be a power-of-two value.
278 * Macro to align a value to a given power-of-two. The resultant
281 * must be a power-of-two value.
291 #define RTE_ALIGN_MUL_CEIL(v, mul) \ argument
292 (((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
299 #define RTE_ALIGN_MUL_FLOOR(v, mul) \ argument
300 ((v / ((typeof(v))(mul))) * (typeof(v))(mul))
307 #define RTE_ALIGN_MUL_NEAR(v, mul) \ argument
309 typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); \
310 typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); \
311 (ceil - v) > (v - floor) ? floor : ceil; \
315 * Checks if a pointer is aligned to a given power-of-two value
320 * The power-of-two value to which the ptr should be aligned
336 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
341 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1)
343 /** Return the first cache-aligned value greater or equal to size. */
345 (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / \
370 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1)
380 #define RTE_BAD_IOVA ((rte_iova_t)-1)
422 * @param v
428 rte_combine64ms1b(register uint64_t v) in rte_combine64ms1b() argument
430 v |= v >> 1; in rte_combine64ms1b()
431 v |= v >> 2; in rte_combine64ms1b()
432 v |= v >> 4; in rte_combine64ms1b()
433 v |= v >> 8; in rte_combine64ms1b()
434 v |= v >> 16; in rte_combine64ms1b()
435 v |= v >> 32; in rte_combine64ms1b()
437 return v; in rte_combine64ms1b()
445 #define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
456 return n && !(n & (n - 1)); in rte_is_power_of_2()
471 x--; in rte_align32pow2()
491 return x - (x >> 1); in rte_align32prevpow2()
497 * @param v
504 rte_align64pow2(uint64_t v) in rte_align64pow2() argument
506 v--; in rte_align64pow2()
507 v = rte_combine64ms1b(v); in rte_align64pow2()
509 return v + 1; in rte_align64pow2()
515 * @param v
522 rte_align64prevpow2(uint64_t v) in rte_align64prevpow2() argument
524 v = rte_combine64ms1b(v); in rte_align64prevpow2()
526 return v - (v >> 1); in rte_align64prevpow2()
554 * Searches the input parameter for the least significant set bit
556 * If a least significant 1 bit is found, its bit index is returned.
559 * @param v
562 * least significant set bit in the input parameter.
565 rte_bsf32(uint32_t v) in rte_bsf32() argument
567 return (uint32_t)__builtin_ctz(v); in rte_bsf32()
571 * Searches the input parameter for the least significant set bit
576 * @param v
579 * If ``v`` was not 0, this value will contain position of least significant
580 * bit within the input parameter.
582 * Returns 0 if ``v`` was 0, otherwise returns 1.
585 rte_bsf32_safe(uint64_t v, uint32_t *pos) in rte_bsf32_safe() argument
587 if (v == 0) in rte_bsf32_safe()
590 *pos = rte_bsf32(v); in rte_bsf32_safe()
595 * Return the rounded-up log2 of a integer.
598 * rte_log2_u32(0) == 0 and not -inf.
600 * @param v
603 * The rounded-up log2 of the input, or 0 if the input is 0.
606 rte_log2_u32(uint32_t v) in rte_log2_u32() argument
608 if (v == 0) in rte_log2_u32()
610 v = rte_align32pow2(v); in rte_log2_u32()
611 return rte_bsf32(v); in rte_log2_u32()
616 * Return the last (most-significant) bit set.
618 * @note The last (most significant) bit is at position 32.
624 * The last (most-significant) bit set, or 0 if the input is 0.
629 return (x == 0) ? 0 : 32 - __builtin_clz(x); in rte_fls_u32()
633 * Searches the input parameter for the least significant set bit
635 * If a least significant 1 bit is found, its bit index is returned.
638 * @param v
641 * least significant set bit in the input parameter.
644 rte_bsf64(uint64_t v) in rte_bsf64() argument
646 return (uint32_t)__builtin_ctzll(v); in rte_bsf64()
650 * Searches the input parameter for the least significant set bit
655 * @param v
658 * If ``v`` was not 0, this value will contain position of least significant
659 * bit within the input parameter.
661 * Returns 0 if ``v`` was 0, otherwise returns 1.
664 rte_bsf64_safe(uint64_t v, uint32_t *pos) in rte_bsf64_safe() argument
666 if (v == 0) in rte_bsf64_safe()
669 *pos = rte_bsf64(v); in rte_bsf64_safe()
674 * Return the last (most-significant) bit set.
676 * @note The last (most significant) bit is at position 64.
683 * The last (most-significant) bit set, or 0 if the input is 0.
688 return (x == 0) ? 0 : 64 - __builtin_clzll(x); in rte_fls_u64()
692 * Return the rounded-up log2 of a 64-bit integer.
695 * rte_log2_u64(0) == 0 and not -inf.
697 * @param v
700 * The rounded-up log2 of the input, or 0 if the input is 0.
703 rte_log2_u64(uint64_t v) in rte_log2_u64() argument
705 if (v == 0) in rte_log2_u64()
707 v = rte_align64pow2(v); in rte_log2_u64()
708 /* we checked for v being 0 already, so no undefined behavior */ in rte_log2_u64()
709 return rte_bsf64(v); in rte_log2_u64()
733 const typeof(((type *)0)->member) *_ptr = (ptr); \
736 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
750 #define RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field))
765 /** Mask value of type "tp" for the first "ln" bit set. */
767 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
777 * If a negative number is passed in i.e. a string with the first non-black
778 * character being "-", zero is returned. Zero is also returned in the case of
795 if (*str == '-')
807 case 'G': case 'g': size *= 1024; /* fall-through */
808 case 'M': case 'm': size *= 1024; /* fall-through */
809 case 'K': case 'k': size *= 1024; /* fall-through */