rte_bitops.h(3)

๐Ÿ“ฆ
version 25.11.3 ยท 5 versions
, in ubuntu resolute, ubuntu stonking

โœจ rte_bitops.h โœจ

okay bestie, welcome to the little header that runs the whole bit-twiddling universe ๐Ÿ’… this is rte_bitops.h, and it lives in the Library Functions Manual. it's from rte_bitops.h(3), and honestly? she's iconic.


๐ŸŒธ NAME ๐ŸŒธ

rte_bitops.h โ€” no notes, that's the whole name, she needs no introduction ๐Ÿ’–


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

first things first, you gotta include the girlies:

#include <stdint.h>
#include <rte_compat.h>
#include <rte_debug.h>
#include <rte_stdatomic.h>

then you've got two whole squadrons: Macros and Functions. buckle up ๐Ÿฆ‹

๐Ÿ’ซ Macros ๐Ÿ’ซ

#define RTE_BIT64(nr)
#define RTE_BIT32(nr)
#define RTE_SHIFT_VAL32(val,  nr)
#define RTE_SHIFT_VAL64(val,  nr)
#define RTE_GENMASK32(high,  low)
#define RTE_GENMASK64(high,  low)
#define RTE_FIELD_GET32(mask,  reg)
#define RTE_FIELD_GET64(mask,  reg)
#define rte_bit_test(addr,  nr)
#define rte_bit_set(addr,  nr)
#define rte_bit_clear(addr,  nr)
#define rte_bit_assign(addr,  nr,  value)
#define rte_bit_flip(addr,  nr)
#define rte_bit_atomic_test(addr,  nr,  memory_order)
#define rte_bit_atomic_set(addr,  nr,  memory_order)
#define rte_bit_atomic_clear(addr,  nr,  memory_order)
#define rte_bit_atomic_assign(addr,  nr,  value,  memory_order)
#define rte_bit_atomic_flip(addr,  nr,  memory_order)
#define rte_bit_atomic_test_and_set(addr,  nr,  memory_order)
#define rte_bit_atomic_test_and_clear(addr,  nr,  memory_order)
#define rte_bit_atomic_test_and_assign(addr,  nr,  value,  memory_order)
#define RTE_IS_POWER_OF_2(n)

๐Ÿ’ซ Functions ๐Ÿ’ซ

static uint32_t rte_bit_relaxed_get32 (unsigned int nr, volatile
    uint32_t *addr)
static void rte_bit_relaxed_set32 (unsigned int nr, volatile uint32_t
    *addr)
static void rte_bit_relaxed_clear32 (unsigned int nr, volatile uint32_t
    *addr)
static uint32_t rte_bit_relaxed_test_and_set32 (unsigned int nr,
    volatile uint32_t *addr)
static uint32_t rte_bit_relaxed_test_and_clear32 (unsigned int nr,
    volatile uint32_t *addr)
static uint64_t rte_bit_relaxed_get64 (unsigned int nr, volatile
    uint64_t *addr)
static void rte_bit_relaxed_set64 (unsigned int nr, volatile uint64_t
    *addr)
static void rte_bit_relaxed_clear64 (unsigned int nr, volatile uint64_t
    *addr)
static uint64_t rte_bit_relaxed_test_and_set64 (unsigned int nr,
    volatile uint64_t *addr)
static uint64_t rte_bit_relaxed_test_and_clear64 (unsigned int nr,
    volatile uint64_t *addr)
static unsigned int rte_clz32 (uint32_t v)
static unsigned int rte_clz64 (uint64_t v)
static unsigned int rte_ctz32 (uint32_t v)
static unsigned int rte_ctz64 (uint64_t v)
static unsigned int rte_popcount32 (uint32_t v)
static unsigned int rte_popcount64 (uint64_t v)
static __rte_experimental unsigned int rte_ffs32 (uint32_t v)
static __rte_experimental unsigned int rte_ffs64 (uint64_t v)
static uint32_t rte_combine32ms1b (uint32_t x)
static uint64_t rte_combine64ms1b (uint64_t v)
static uint32_t rte_bsf32 (uint32_t v)
static int rte_bsf32_safe (uint32_t v, uint32_t *pos)
static uint32_t rte_bsf64 (uint64_t v)
static int rte_bsf64_safe (uint64_t v, uint32_t *pos)
static uint32_t rte_fls_u32 (uint32_t x)
static uint32_t rte_fls_u64 (uint64_t x)
static int rte_is_power_of_2 (uint32_t n)
static uint32_t rte_align32pow2 (uint32_t x)
static uint32_t rte_align32prevpow2 (uint32_t x)
static uint64_t rte_align64pow2 (uint64_t v)
static uint64_t rte_align64prevpow2 (uint64_t v)
static uint32_t rte_log2_u32 (uint32_t v)
static uint32_t rte_log2_u64 (uint64_t v)

๐Ÿงš Detailed Description ๐Ÿงš

๐ŸŒˆ Bit Operations ๐ŸŒˆ

so like, what even is this file?? it's your go-to for low-level, single-word arithmetic and bit-level shenanigans โ€” the little things like counting bits or flipping individual bits on and off, one at a time, no drama. ๐Ÿ”ฅ

Definition in file rte_bitops.h.


๐Ÿ‘‘ Macro Definition Documentation ๐Ÿ‘‘

๐ŸŒŸ #define RTE_BIT64( nr) ๐ŸŒŸ

Value:

(UINT64_C(1) << (nr))

grabs you the uint64_t value with a specified bit set, bestie. one bit, one girl, iconic. โœจ

Parameters

  • nr โ€” the bit number, and she's gotta be in range 0 to 63. no rogue numbers allowed.

Definition at line 36 of file rte_bitops.h.


๐ŸŒŸ #define RTE_BIT32( nr) ๐ŸŒŸ

Value:

(UINT32_C(1) << (nr))

same vibe, but for uint32_t โ€” get that value for a specified bit set ๐Ÿ’œ

Parameters

  • nr โ€” the bit number, range 0 to 31. stay in your lane (affectionately).

Definition at line 44 of file rte_bitops.h.


๐ŸŒŸ #define RTE_SHIFT_VAL32( val, nr) ๐ŸŒŸ

Value:

((uint32_t)(val) << (nr))

shifting time!! get the uint32_t shifted value, slay. ๐Ÿ’ซ

Parameters

  • val โ€” the value to be shifted.
  • nr โ€” the shift number, range 0 to (32 - width of val). yes, that's the actual rule, don't fight it.

Definition at line 54 of file rte_bitops.h.


๐ŸŒŸ #define RTE_SHIFT_VAL64( val, nr) ๐ŸŒŸ

Value:

((uint64_t)(val) << (nr))

the 64-bit version of the shift moment, she's bigger and she knows it ๐ŸŽ€

Parameters

  • val โ€” the value to be shifted.
  • nr โ€” the shift number, range 0 to (64 - width of val).

Definition at line 64 of file rte_bitops.h.


๐ŸŒŸ #define RTE_GENMASK32( high, low) ๐ŸŒŸ

Value:

        (((~UINT32_C(0)) << (low)) & (~UINT32_C(0) >> (31u - (high))))

generate a contiguous 32-bit mask, starting at bit position low and ending at position high. it's giving "make me a fence and make it cute." ๐Ÿšง๐Ÿ’–

Parameters

  • high โ€” high bit position.
  • low โ€” low bit position.

Definition at line 75 of file rte_bitops.h.


๐ŸŒŸ #define RTE_GENMASK64( high, low) ๐ŸŒŸ

Value:

        (((~UINT64_C(0)) << (low)) & (~UINT64_C(0) >> (63u - (high))))

generate a contiguous 64-bit mask, from bit position low up to position high. the 64-bit glow-up of the mask above, no cap. ๐ŸŒˆ

Parameters

  • high โ€” high bit position.
  • low โ€” low bit position.

Definition at line 87 of file rte_bitops.h.


๐ŸŒŸ #define RTE_FIELD_GET32( mask, reg) ๐ŸŒŸ

Value:

        ((typeof(mask))(((reg) & (mask)) >> rte_ctz32(mask)))

extract a 32-bit field element, bestie. reach in, grab your lil field, pull it out. ๐Ÿ’…

Parameters

  • mask โ€” shifted mask.
  • reg โ€” value of entire bitfield.

Definition at line 98 of file rte_bitops.h.


๐ŸŒŸ #define RTE_FIELD_GET64( mask, reg) ๐ŸŒŸ

Value:

        ((typeof(mask))(((reg) & (mask)) >> rte_ctz64(mask)))

extract a 64-bit field element. same energy, double the bits. โœจ

Parameters

  • mask โ€” shifted mask.
  • reg โ€” value of entire bitfield.

Definition at line 109 of file rte_bitops.h.


๐ŸŒŸ #define rte_bit_test( addr, nr) ๐ŸŒŸ

Value:

    _Generic((addr), \
        uint32_t *: __rte_bit_test32, \
        const uint32_t *: __rte_bit_test32, \
        volatile uint32_t *: __rte_bit_v_test32, \
        const volatile uint32_t *: __rte_bit_v_test32, \
        uint64_t *: __rte_bit_test64, \
        const uint64_t *: __rte_bit_test64, \
        volatile uint64_t *: __rte_bit_v_test64, \
        const volatile uint64_t *: __rte_bit_v_test64) \
            (addr, nr)
Warning โ€” EXPERIMENTAL: this API may change without prior notice. okay so she's experimental, meaning she might switch up on us, no cap. proceed accordingly ๐Ÿ’€

test bit in word. it's a generic selection macro that tests the value of a bit inside a 32-bit or 64-bit word. which exact operation you get depends on the type of the addr parameter โ€” she reads the vibes and picks. ๐Ÿฆ‹

this macro does not give any guarantees in regards to memory ordering or atomicity โ€” just so we're clear, bestie.

Parameters

  • addr โ€” a pointer to the word to modify.
  • nr โ€” the index of the bit.

Definition at line 130 of file rte_bitops.h.


๐ŸŒŸ #define rte_bit_set( addr, nr) ๐ŸŒŸ

Value:

    _Generic((addr), \
        uint32_t *: __rte_bit_set32, \
        volatile uint32_t *: __rte_bit_v_set32, \
        uint64_t *: __rte_bit_set64, \
        volatile uint64_t *: __rte_bit_v_set64) \
            (addr, nr)
Warning โ€” EXPERIMENTAL: this API may change without prior notice. yeah she's experimental too ๐Ÿ™ˆ

set bit in word. generic selection macro that sets a bit in a 32-bit or 64-bit word, and the operation type depends on the type of addr.

this macro does not give any guarantees in regards to memory ordering or atomicity. periodt.

Parameters

  • addr โ€” a pointer to the word to modify.
  • nr โ€” the index of the bit.

Definition at line 160 of file rte_bitops.h.


๐ŸŒŸ #define rte_bit_clear( addr, nr) ๐ŸŒŸ

Value:

    _Generic((addr), \
        uint32_t *: __rte_bit_clear32, \
        volatile uint32_t *: __rte_bit_v_clear32, \
        uint64_t *: __rte_bit_clear64, \
        volatile uint64_t *: __rte_bit_v_clear64) \
            (addr, nr)
Warning โ€” EXPERIMENTAL: this API may change without prior notice. (she's in her experimental era, respect it)

clear bit in word. generic selection macro that clears a bit in a 32-bit or 64-bit word, and again the operation type depends on the type of addr.

this macro does not give any guarantees in regards to memory ordering or atomicity.

Parameters

  • addr โ€” a pointer to the word to modify.
  • nr โ€” the index of the bit.

Definition at line 186 of file rte_bitops.h.


๐ŸŒŸ #define rte_bit_assign( addr, nr, value) ๐ŸŒŸ

Value:

    _Generic((addr), \
        uint32_t *: __rte_bit_assign32, \
        volatile uint32_t *: __rte_bit_v_assign32, \
        uint64_t *: __rte_bit_assign64, \
        volatile uint64_t *: __rte_bit_v_assign64) \
            (addr, nr, value)
Warning โ€” EXPERIMENTAL: this API may change without prior notice. ๐Ÿ’€ (experimental, you've been warned)

assign a value to a bit in word. generic selection macro that assigns a value to a bit in a 32-bit or 64-bit word, depending on the type of addr.

this macro does not give any guarantees in regards to memory ordering or atomicity.

Parameters

  • addr โ€” a pointer to the word to modify.
  • nr โ€” the index of the bit.
  • value โ€” the new value of the bit โ€” true for '1', or false for '0'.

Definition at line 213 of file rte_bitops.h.


๐ŸŒŸ #define rte_bit_flip( addr, nr) ๐ŸŒŸ

Value:

    _Generic((addr), \
        uint32_t *: __rte_bit_flip32, \
        volatile uint32_t *: __rte_bit_v_flip32, \
        uint64_t *: __rte_bit_flip64, \
        volatile uint64_t *: __rte_bit_v_flip64) \
            (addr, nr)
Warning โ€” EXPERIMENTAL: this API may change without prior notice. โœจ

flip a bit in word. generic selection macro that changes the value of a bit to '0' if it was '1', or to '1' if it was '0', in a 32-bit or 64-bit word. operation type depends on the type of addr โ€” main character energy, she adapts. ๐Ÿ‘‘

this macro does not give any guarantees in regards to memory ordering or atomicity.

Parameters

  • addr โ€” a pointer to the word to modify.
  • nr โ€” the index of the bit.

Definition at line 239 of file rte_bitops.h.


๐ŸŒŸ #define rte_bit_atomic_test( addr, nr, memory_order) ๐ŸŒŸ

Value:

    _Generic((addr), \
        uint32_t *: __rte_bit_atomic_test32, \
        const uint32_t *: __rte_bit_atomic_test32, \
        volatile uint32_t *: __rte_bit_atomic_v_test32, \
        const volatile uint32_t *: __rte_bit_atomic_v_test32, \
        uint64_t *: __rte_bit_atomic_test64, \
        const uint64_t *: __rte_bit_atomic_test64, \
        volatile uint64_t *: __rte_bit_atomic_v_test64, \
        const volatile uint64_t *: __rte_bit_atomic_v_test64) \
            (addr, nr, memory_order)
Warning โ€” EXPERIMENTAL: this API may change without prior notice. ๐Ÿ”ฅ

test if a particular bit in a word is set with a particular memory order. it tests a bit with the resulting memory load ordered as per the specified memory order โ€” so like, the memory ordering is your choice, bestie, she's flexible. ๐ŸŒธ

Parameters

  • addr โ€” a pointer to the word to query.
  • nr โ€” the index of the bit.
  • memory_order โ€” the memory order to use.

  • Returns โ€” true if the bit is set, and false otherwise.
    • Defined at line 266 of file rte_bitops.h.

๐ŸŒธ #define rte_bit_atomic_set( addr, nr, memory_order)

โš ๏ธ EXPERIMENTAL: this API may change without prior notice. So likeโ€ฆ don't build your whole personality on it staying the same, bestie ๐Ÿ’€

Value:

_Generic((addr), \
    uint32_t *: __rte_bit_atomic_set32, \
    volatile uint32_t *: __rte_bit_atomic_v_set32, \
    uint64_t *: __rte_bit_atomic_set64, \
    volatile uint64_t *: __rte_bit_atomic_v_set64) \
        (addr, nr, memory_order)

Atomically set bit in word. โœจ

It's a generic selection macro that atomically sets the bit at index nr in the word that addr points to, flipping it to '1', using the memory ordering you picked out in memory_order. The way it just picks the right 32 or 64 helper for you based on the pointer type? Iconic. No cap. ๐Ÿ‘‘

Parameters

  • addr โ€” a pointer to the word you wanna modify.
  • nr โ€” the index of the bit.
  • memory_order โ€” the memory order to use.

Defined at line 295 of file rte_bitops.h.


๐Ÿฆ‹ #define rte_bit_atomic_clear( addr, nr, memory_order)

โš ๏ธ EXPERIMENTAL: this API may change without prior notice.

Value:

_Generic((addr), \
    uint32_t *: __rte_bit_atomic_clear32, \
    volatile uint32_t *: __rte_bit_atomic_v_clear32, \
    uint64_t *: __rte_bit_atomic_clear64, \
    volatile uint64_t *: __rte_bit_atomic_v_clear64) \
        (addr, nr, memory_order)

Atomically clear bit in word. ๐Ÿงผ

Generic selection macro that atomically sets the bit at index nr in the word pointed to by addr to '0' (yes, the original says "set" here too, and honestly bestie we are reporting it exactly as it's written, not fixing it ๐Ÿ’…), with the memory ordering as specified by memory_order.

Parameters

  • addr โ€” a pointer to the word to modify.
  • nr โ€” the index of the bit.
  • memory_order โ€” the memory order to use.

Defined at line 320 of file rte_bitops.h.


๐ŸŽ€ #define rte_bit_atomic_assign( addr, nr, value, memory_order)

โš ๏ธ EXPERIMENTAL: this API may change without prior notice.

Value:

_Generic((addr), \
    uint32_t *: __rte_bit_atomic_assign32, \
    volatile uint32_t *: __rte_bit_atomic_v_assign32, \
    uint64_t *: __rte_bit_atomic_assign64, \
    volatile uint64_t *: __rte_bit_atomic_v_assign64) \
        (addr, nr, value, memory_order)

Atomically assign a value to bit in word. ๐Ÿ’ซ

Generic selection macro that atomically sets the bit at index nr in the word pointed to by addr to whatever value says, using the memory ordering you specified with memory_order.

Parameters

  • addr โ€” a pointer to the word to modify.
  • nr โ€” the index of the bit.
  • value โ€” the new value of the bit โ€” true for '1', or false for '0'.
  • memory_order โ€” the memory order to use.

Defined at line 347 of file rte_bitops.h.


๐ŸŒˆ #define rte_bit_atomic_flip( addr, nr, memory_order)

โš ๏ธ EXPERIMENTAL: this API may change without prior notice.

Value:

_Generic((addr), \
    uint32_t *: __rte_bit_atomic_flip32, \
    volatile uint32_t *: __rte_bit_atomic_v_flip32, \
    uint64_t *: __rte_bit_atomic_flip64, \
    volatile uint64_t *: __rte_bit_atomic_v_flip64) \
        (addr, nr, memory_order)

Atomically flip bit in word. ๐Ÿ”„

Generic selection macro that atomically negates the value of the bit at index nr in the word pointed to by addr, to the value indicated by value (that's what it says, bestie โ€” we are not editorialising, just vibing โœจ), with the memory ordering as specified with memory_order.

Parameters

  • addr โ€” a pointer to the word to modify.
  • nr โ€” the index of the bit.
  • memory_order โ€” the memory order to use.

Defined at line 373 of file rte_bitops.h.


๐Ÿ’œ #define rte_bit_atomic_test_and_set( addr, nr, memory_order)

โš ๏ธ EXPERIMENTAL: this API may change without prior notice.

Value:

_Generic((addr), \
    uint32_t *: __rte_bit_atomic_test_and_set32, \
    volatile uint32_t *: __rte_bit_atomic_v_test_and_set32, \
    uint64_t *: __rte_bit_atomic_test_and_set64, \
    volatile uint64_t *: __rte_bit_atomic_v_test_and_set64) \
        (addr, nr, memory_order)

Atomically test and set a bit in word. ๐Ÿซถ

Generic selection macro that atomically tests and sets the bit at index nr in the word pointed to by addr to '1', with the memory ordering as specified with memory_order.

Parameters

  • addr โ€” a pointer to the word to modify.
  • nr โ€” the index of the bit.
  • memory_order โ€” the memory order to use.

Returns

true if the bit was set, and false otherwise.

Defined at line 400 of file rte_bitops.h.


๐Ÿ“ #define rte_bit_atomic_test_and_clear( addr, nr, memory_order)

โš ๏ธ EXPERIMENTAL: this API may change without prior notice.

Value:

_Generic((addr), \
    uint32_t *: __rte_bit_atomic_test_and_clear32, \
    volatile uint32_t *: __rte_bit_atomic_v_test_and_clear32, \
    uint64_t *: __rte_bit_atomic_test_and_clear64, \
    volatile uint64_t *: __rte_bit_atomic_v_test_and_clear64) \
        (addr, nr, memory_order)

Atomically test and clear a bit in word. ๐Ÿงš

Generic selection macro that atomically tests and clears the bit at index nr in the word pointed to by addr to '0', with the memory ordering as specified with memory_order.

Parameters

  • addr โ€” a pointer to the word to modify.
  • nr โ€” the index of the bit.
  • memory_order โ€” the memory order to use.

Returns

true if the bit was set, and false otherwise.

Defined at line 427 of file rte_bitops.h.


๐ŸŒŸ #define rte_bit_atomic_test_and_assign( addr, nr, value, memory_order)

โš ๏ธ EXPERIMENTAL: this API may change without prior notice.

Value:

_Generic((addr), \
    uint32_t *: __rte_bit_atomic_test_and_assign32, \
    volatile uint32_t *: __rte_bit_atomic_v_test_and_assign32, \
    uint64_t *: __rte_bit_atomic_test_and_assign64, \
    volatile uint64_t *: __rte_bit_atomic_v_test_and_assign64) \
        (addr, nr, value, memory_order)

Atomically test and assign a bit in word. ๐Ÿ’–

Generic selection macro that atomically tests and assigns the bit at index nr in the word pointed to by addr the value specified by value, with the memory ordering as specified with memory_order.

Parameters

  • addr โ€” a pointer to the word to modify.
  • nr โ€” the index of the bit.
  • value โ€” the new value of the bit โ€” true for '1', or false for '0'.
  • memory_order โ€” the memory order to use.

Returns

true if the bit was set, and false otherwise.

Defined at line 457 of file rte_bitops.h.


๐Ÿงฎ #define RTE_IS_POWER_OF_2( n)

Value:

((n) != 0 && (((n) - 1) & (n)) == 0)

Macro to return 1 if n is a power of 2, 0 otherwise. โญ

The way this one-liner just knows whether your number is a power of two? Ate. No crumbs. ๐Ÿ‘‘

Defined at line 1302 of file rte_bitops.h.


๐Ÿ”ง Function Documentation

uint32_t rte_bit_relaxed_get32 (unsigned int nr, volatile uint32_t * addr)

[inline], [static]

Get the target bit from a 32-bit value without memory ordering. ๐Ÿ‘€

Parameters

  • nr โ€” the target bit to get.
  • addr โ€” the address holding the bit.

Returns

The target bit.

Defined at line 674 of file rte_bitops.h.


void rte_bit_relaxed_set32 (unsigned int nr, volatile uint32_t * addr)

[inline], [static]

Set the target bit in a 32-bit value to 1 without memory ordering. โœ…

Parameters

  • nr โ€” the target bit to set.
  • addr โ€” the address holding the bit.

Defined at line 691 of file rte_bitops.h.


void rte_bit_relaxed_clear32 (unsigned int nr, volatile uint32_t * addr)

[inline], [static]

Clear the target bit in a 32-bit value to 0 without memory ordering. ๐Ÿงฝ

Parameters

  • nr โ€” the target bit to clear.
  • addr โ€” the address holding the bit.

Defined at line 708 of file rte_bitops.h.


uint32_t rte_bit_relaxed_test_and_set32 (unsigned int nr, volatile uint32_t * addr)

[inline], [static]

Return the original bit from a 32-bit value, then set it to 1 without memory ordering. ๐ŸŽ

Parameters

  • nr โ€” the target bit to get and set.
  • addr โ€” the address holding the bit.

Returns

The original bit.

Defined at line 728 of file rte_bitops.h.


uint32_t rte_bit_relaxed_test_and_clear32 (unsigned int nr, volatile uint32_t * addr)

[inline], [static]

Return the original bit from a 32-bit value, then clear it to 0 without memory ordering. ๐Ÿซง

Parameters

  • nr โ€” the target bit to get and clear.
  • addr โ€” the address holding the bit.

Returns

The original bit.

Defined at line 750 of file rte_bitops.h.


uint64_t rte_bit_relaxed_get64 (unsigned int nr, volatile uint64_t * addr)

[inline], [static]

Get the target bit from a 64-bit value without memory ordering. ๐Ÿ‘€โœจ

Parameters

  • nr โ€” the target bit to get.
  • addr โ€” the address holding the bit.

Returns

The target bit.

Defined at line 773 of file rte_bitops.h.


void rte_bit_relaxed_set64 (unsigned int nr, volatile uint64_t * addr)

[inline], [static]

Set the target bit in a 64-bit value to 1 without memory ordering. โœ…โœจ

Parameters

  • nr โ€” the target bit to set.
  • addr โ€” the address holding the bit.

Defined at line 790 of file rte_bitops.h.


void rte_bit_relaxed_clear64 (unsigned int nr, volatile uint64_t * addr)

[inline], [static]

Clear the target bit in a 64-bit value to 0 without memory ordering. ๐Ÿงฝโœจ

Parameters

  • nr โ€” the target bit to clear.
  • addr โ€” the address holding the bit.

Defined at line 807 of file rte_bitops.h.


uint64_t rte_bit_relaxed_test_and_set64 (unsigned int nr, volatile uint64_t * addr)

[inline], [static]

Return the original bit from a 64-bit value, then set it to 1 without memory ordering. ๐ŸŽโœจ

Parameters

  • nr โ€” the target bit to get and set.
  • addr โ€” the address holding the bit.

Returns

The original bit.

Defined at line 827 of file rte_bitops.h.


uint64_t rte_bit_relaxed_test_and_clear64 (unsigned int nr, volatile uint64_t * addr)

[inline], [static]

Return the original bit from a 64-bit value, then clear it to 0 without memory ordering. ๐Ÿซงโœจ

Parameters

  • nr โ€” the target bit to get and clear.
  • addr โ€” the address holding the bit.

Returns

The original bit.

Defined at line 849 of file rte_bitops.h.


unsigned int rte_clz32 (uint32_t v)

[inline], [static]

Get the count of leading 0-bits in v. ๐Ÿ”ข

Parameters

  • v โ€” the value.

Returns

The count of leading zero bits.

Defined at line 1020 of file rte_bitops.h.


unsigned int rte_clz64 (uint64_t v)

[inline], [static]

Get the count of leading 0-bits in v. ๐Ÿ”ขโœจ

Parameters

  • v โ€” the value.

Returns

The count of leading zero bits.

Defined at line 1034 of file rte_bitops.h.


unsigned int rte_ctz32 (uint32_t v)

[inline], [static]

Get the count of trailing 0-bits in v. ๐Ÿ”š

Parameters

  • v โ€” the value.

Returns

The count of trailing zero bits.

Defined at line 1048 of file rte_bitops.h.

๐Ÿ’ซ rte_ctz64 ๐Ÿ’ซ

unsigned int rte_ctz64 (uint64_t v) [inline],  [static]

okay bestie, this one counts your trailing 0-bits in v. like, how many zeros are chilling at the bottom before a 1 shows up. slay.

  • v โ€” the value, periodt.
  • Returns โ€” the count of trailing zero bits. ๐Ÿ’–

Definition at line 1062 of file rte_bitops.h.


โœจ rte_popcount32 โœจ

unsigned int rte_popcount32 (uint32_t v) [inline],  [static]

counting the 1-bits in v fr fr. the population count. it's giving census energy.

  • v โ€” the value.
  • Returns โ€” the count of 1-bits. ๐ŸŒธ

Definition at line 1076 of file rte_bitops.h.


๐ŸŽ€ rte_popcount64 ๐ŸŽ€

unsigned int rte_popcount64 (uint64_t v) [inline],  [static]

same vibe as the 32 version but for your 64-bit bestie. counting 1-bits in v, iconic.

  • v โ€” the value.
  • Returns โ€” the count of 1-bits. โœจ

Definition at line 1090 of file rte_bitops.h.


๐Ÿฆ‹ rte_ffs32 ๐Ÿฆ‹

__rte_experimental unsigned int rte_ffs32 (uint32_t v) [inline],  [static]
โš ๏ธ EXPERIMENTAL: this API may change without prior notice. like, it's still in its glow-up era, don't build your whole personality on it.

it searches v from the least significant bit (LSB) all the way up to the most significant bit (MSB) looking for a set bit (1). first one it finds? that's the moment.

  • v โ€” the value.
  • Returns โ€” bit index + 1 if a set bit is found, zero otherwise. ๐Ÿ’…

Definition at line 1109 of file rte_bitops.h.


๐ŸŒˆ rte_ffs64 ๐ŸŒˆ

__rte_experimental unsigned int rte_ffs64 (uint64_t v) [inline],  [static]
โš ๏ธ EXPERIMENTAL: this API may change without prior notice. same disclaimer, still experimental, still cute.

searches v from the least significant bit (LSB) to the most significant bit (MSB) hunting for a set bit (1).

  • v โ€” the value.
  • Returns โ€” bit index + 1 if a set bit is found, zero otherwise. โญ

Definition at line 1128 of file rte_bitops.h.


๐Ÿ’œ rte_combine32ms1b ๐Ÿ’œ

uint32_t rte_combine32ms1b (uint32_t x) [inline],  [static]

okay so this one combines 32b inputs' most significant set bits into the least significant bits to construct a value with the same MSBs as x but all 1's under it. it's giving "smear the vibe downward" and honestly? obsessed.

  • x โ€” the integer whose MSBs need to be combined with its LSBs.
  • Returns โ€” the combined value. ๐Ÿซถ

Definition at line 1146 of file rte_bitops.h.


๐Ÿ’ซ rte_combine64ms1b ๐Ÿ’ซ

uint64_t rte_combine64ms1b (uint64_t v) [inline],  [static]

the 64b glow-up of the one above, no cap: combines 64b inputs' most significant set bits into the least significant bits to construct a value with the same MSBs as x but all 1's under it.

  • v โ€” the integer whose MSBs need to be combined with its LSBs.
  • Returns โ€” the combined value. ๐ŸŽ€

Definition at line 1168 of file rte_bitops.h.


๐Ÿ”ฅ rte_bsf32 ๐Ÿ”ฅ

uint32_t rte_bsf32 (uint32_t v) [inline],  [static]

searches the input parameter for the least significant set bit (starting from zero). if a least significant 1 bit is found, its bit index is returned. but bestie, listen โ€” if the content of the input parameter is zero, then the content of the return value is undefined. ๐Ÿ˜ญ it's giving "don't do that".

  • v โ€” input parameter, should not be zero.
  • Returns โ€” least significant set bit in the input parameter.

Definition at line 1192 of file rte_bitops.h.


๐Ÿ˜ญ rte_bsf32_safe ๐Ÿ˜ญ

int rte_bsf32_safe (uint32_t v, uint32_t * pos) [inline],  [static]

searches the input parameter for the least significant set bit (starting from zero). this is the safe version โ€” it actually checks whether the input parameter is zero, so it won't leave you on read like the other one.

โš ๏ธ pos must be a valid pointer. It is not checked! like, it will simply not catch that for you. that's on you, bestie.
  • v โ€” the input parameter.
  • pos โ€” if v was not 0, this value will contain position of least significant bit within the input parameter.
  • Returns โ€” returns 0 if v was 0, otherwise returns 1. โœจ

Definition at line 1212 of file rte_bitops.h.


๐Ÿงš rte_bsf64 ๐Ÿงš

uint32_t rte_bsf64 (uint64_t v) [inline],  [static]

searches the input parameter for the least significant set bit (starting from zero). if a least significant 1 bit is found, its bit index is returned. and if the content of the input parameter is zero? the content of the return value is undefined. yeah. same energy as the 32 one, just taller. ๐Ÿ’€

  • v โ€” input parameter, should not be zero.
  • Returns โ€” least significant set bit in the input parameter.

Definition at line 1233 of file rte_bitops.h.


๐Ÿ’– rte_bsf64_safe ๐Ÿ’–

int rte_bsf64_safe (uint64_t v, uint32_t * pos) [inline],  [static]

searches the input parameter for the least significant set bit (starting from zero). safe version โ€” it checks for the input parameter being zero, so you get a real answer instead of chaos.

โš ๏ธ pos must be a valid pointer. It is not checked! once again, validating that pointer is a you problem.
  • v โ€” the input parameter.
  • pos โ€” if v was not 0, this value will contain position of least significant bit within the input parameter.
  • Returns โ€” returns 0 if v was 0, otherwise returns 1. ๐ŸŒธ

Definition at line 1253 of file rte_bitops.h.


๐Ÿ‘‘ rte_fls_u32 ๐Ÿ‘‘

uint32_t rte_fls_u32 (uint32_t x) [inline],  [static]

returns the last (most-significant) bit set. main character bit, fr.

๐Ÿ“ Note: the last (most significant) bit is at position 32. rte_fls_u32(0) = 0, rte_fls_u32(1) = 1, rte_fls_u32(0x80000000) = 32
  • x โ€” the input parameter.
  • Returns โ€” the last (most-significant) bit set, or 0 if the input is 0. โญ

Definition at line 1274 of file rte_bitops.h.


๐Ÿฆ‹ rte_fls_u64 ๐Ÿฆ‹

uint32_t rte_fls_u64 (uint64_t x) [inline],  [static]

returns the last (most-significant) bit set, but make it 64-bit.

๐Ÿ“ Note: the last (most significant) bit is at position 64. rte_fls_u64(0) = 0, rte_fls_u64(1) = 1, rte_fls_u64(0x8000000000000000) = 64
  • x โ€” the input parameter.
  • Returns โ€” the last (most-significant) bit set, or 0 if the input is 0. ๐Ÿ’œ

Definition at line 1292 of file rte_bitops.h.


โœจ rte_is_power_of_2 โœจ

int rte_is_power_of_2 (uint32_t n) [inline],  [static]

returns true if n is a power of 2. vibe check for powers of 2, basically.

  • n โ€” number to check.
  • Returns โ€” 1 if true, 0 otherwise. ๐ŸŽ€

Definition at line 1311 of file rte_bitops.h.


๐ŸŒˆ rte_align32pow2 ๐ŸŒˆ

uint32_t rte_align32pow2 (uint32_t x) [inline],  [static]

aligns the input parameter to the next power of 2. it's giving "round up to something tidy".

  • x โ€” the integer value to align.
  • Returns โ€” the smallest power of 2 which is greater than or equal to x. ๐Ÿ’…

Definition at line 1326 of file rte_bitops.h.


๐Ÿ“ rte_align32prevpow2 ๐Ÿ“

uint32_t rte_align32prevpow2 (uint32_t x) [inline],  [static]

aligns the input parameter to the previous power of 2. going down instead of up, and honestly? sometimes that's the move.

  • x โ€” the integer value to align.
  • Returns โ€” the greatest power of 2 which is smaller than or equal to x. ๐Ÿซถ

Definition at line 1344 of file rte_bitops.h.


๐Ÿ”ฅ rte_align64pow2 ๐Ÿ”ฅ

uint64_t rte_align64pow2 (uint64_t v) [inline],  [static]

aligns a 64b input parameter to the next power of 2.

  • v โ€” the 64b value to align.
  • Returns โ€” the smallest power of 2 which is greater than or equal to v. โœจ

Definition at line 1361 of file rte_bitops.h.


๐Ÿ’ซ rte_align64prevpow2 ๐Ÿ’ซ

uint64_t rte_align64prevpow2 (uint64_t v) [inline],  [static]

aligns a 64b input parameter to the previous power of 2.

  • v โ€” the 64b value to align.
  • Returns โ€” the greatest power of 2 which is smaller than or equal to v. ๐ŸŒธ

Definition at line 1379 of file rte_bitops.h.


๐Ÿงš rte_log2_u32 ๐Ÿงš

uint32_t rte_log2_u32 (uint32_t v) [inline],  [static]

returns the rounded-up log2 of an integer. math class but make it cute.

๐Ÿ“ Note: contrary to the logarithm mathematical operation, rte_log2_u32(0) == 0 and not -inf. like yeah, zero gets special treatment here, don't @ me.
  • v โ€” the input parameter.
  • Returns โ€” the rounded-up log2 of the input, or 0 if the input is 0. โญ

Definition at line 1398 of file rte_bitops.h.


๐ŸŒŸ rte_log2_u64 ๐ŸŒŸ

uint32_t rte_log2_u64 (uint64_t v) [inline],  [static]

returns the rounded-up log2 of a 64-bit integer. same math, bigger number, still adorable.

๐Ÿ“ Note: contrary to the logarithm mathematical operation, rte_log2_u64(0) == 0 and not -inf. bestie, zero is still built different.
  • v โ€” the input parameter.
  • Returns โ€” the rounded-up log2 of the input, or 0 if the input is 0. ๐Ÿ’–

Definition at line 1418 of file rte_bitops.h.


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Generated automatically by Doxygen for DPDK from the source code. ๐Ÿ”งโœจ


and that's the whole page, bestie! ๐ŸŽ‰ every single one of these little inline baddies lives in rte_bitops.h, and this documentation came to you straight from DPDK, Version 25.11.3, as the manual page rte_bitops.h(3). go forth and bit-twiddle responsibly, ily, mwah ๐Ÿ’…๐Ÿ’–

๐Ÿ“ฆ where this page comes from