---
name: "rte_bitops.h"
section: "3"
platform: "linux"
package: "dpdk-doc"
version: "24.11.4-0+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/rte_bitops.h"
---

# rte\_bitops.h(3)

## NAME

rte\_bitops.h

## SYNOPSIS

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

### Macros

\#define **RTE\_BIT64**(nr)   (UINT64\_C(1) \<\< (nr))\
 \#define **RTE\_BIT32**(nr)   (UINT32\_C(1) \<\< (nr))\
 \#define **RTE\_SHIFT\_VAL32**(val,  nr)   (UINT32\_C(val) \<\< (nr))\
 \#define **RTE\_SHIFT\_VAL64**(val,  nr)   (UINT64\_C(val) \<\< (nr))\
 \#define **RTE\_GENMASK32**(high,  low)   		(((~UINT32\_C(0)) \<\< (low)) & (~UINT32\_C(0) \>\> (31u - (high))))\
 \#define **RTE\_GENMASK64**(high,  low)   		(((~UINT64\_C(0)) \<\< (low)) & (~UINT64\_C(0) \>\> (63u - (high))))\
 \#define **RTE\_FIELD\_GET32**(mask,  reg)   		((typeof(mask))(((reg) & (mask)) \>\> **rte\_ctz32**(mask)))\
 \#define **RTE\_FIELD\_GET64**(mask,  reg)   		((typeof(mask))(((reg) & (mask)) \>\> **rte\_ctz64**(mask)))\
 \#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)   ((n) && !(((n) - 1) & (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 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

This file provides functionality for low-level, single-word arithmetic and bit-level operations, such as counting or setting individual bits.

Definition in file **rte\_bitops.h**.

## Macro Definition Documentation

### #define RTE\_BIT64(nr) (UINT64\_C(1) \<\< (nr))

Get the uint64\_t value for a specified bit set.

**Parameters**

*nr* The bit number in range of 0 to 63.

Definition at line **36** of file **rte\_bitops.h**.

### #define RTE\_BIT32(nr) (UINT32\_C(1) \<\< (nr))

Get the uint32\_t value for a specified bit set.

**Parameters**

*nr* The bit number in range of 0 to 31.

Definition at line **44** of file **rte\_bitops.h**.

### #define RTE\_SHIFT\_VAL32(val, nr) (UINT32\_C(val) \<\< (nr))

Get the uint32\_t shifted value.

**Parameters**

*val* The value to be shifted. \
 *nr* The shift number in range of 0 to (32 - width of val).

Definition at line **54** of file **rte\_bitops.h**.

### #define RTE\_SHIFT\_VAL64(val, nr) (UINT64\_C(val) \<\< (nr))

Get the uint64\_t shifted value.

**Parameters**

*val* The value to be shifted. \
 *nr* The shift number in range of 0 to (64 - width of val).

Definition at line **64** of file **rte\_bitops.h**.

### #define RTE\_GENMASK32(high, low) (((~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.

**Parameters**

*high* High bit position. \
 *low* Low bit position.

Definition at line **75** of file **rte\_bitops.h**.

### #define RTE\_GENMASK64(high, low) (((~UINT64\_C(0)) \<\< (low)) & (~UINT64\_C(0) \>\> (63u - (high))))

Generate a contiguous 64-bit mask starting at bit position low and ending at position high.

**Parameters**

*high* High bit position. \
 *low* Low bit position.

Definition at line **87** of file **rte\_bitops.h**.

### #define RTE\_FIELD\_GET32(mask, reg) ((typeof(mask))(((reg) & (mask)) \>\> rte\_ctz32(mask)))

Extract a 32-bit field element.

**Parameters**

*mask* Shifted mask. \
 *reg* Value of entire bitfield.

Definition at line **98** of file **rte\_bitops.h**.

### #define RTE\_FIELD\_GET64(mask, reg) ((typeof(mask))(((reg) & (mask)) \>\> rte\_ctz64(mask)))

Extract a 64-bit field element.

**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:**.PP

```
    _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.

Test bit in word.

Generic selection macro to test the value of a bit in a 32-bit or 64-bit word. The type of operation depends on the type of the `addr` parameter.

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 **130** of file **rte\_bitops.h**.

### #define rte\_bit\_set(addr, nr)

**Value:**.PP

```
    _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.

Set bit in word.

Generic selection macro to set a bit in a 32-bit or 64-bit word. The type of operation depends on the type of the `addr` parameter.

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 **160** of file **rte\_bitops.h**.

### #define rte\_bit\_clear(addr, nr)

**Value:**.PP

```
    _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.

Clear bit in word.

Generic selection macro to clear a bit in a 32-bit or 64-bit word. The type of operation depends on the type of the `addr` parameter.

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:**.PP

```
    _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.

Assign a value to a bit in word.

Generic selection macro to assign a value to a bit in a 32-bit or 64-bit word. The type of operation depends on the type of the `addr` parameter.

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:**.PP

```
    _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 to change the value of a bit to '0' if '1' or '1' if '0' in a 32-bit or 64-bit word. The type of operation depends on the type of the `addr` parameter.

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:**.PP

```
    _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.

Test a bit with the resulting memory load ordered as per the specified memory order.

**Parameters**

*addr* A pointer to the word to query. \
 *nr* The index of the bit. \
 *memory\_order* The memory order to use.

**Returns**

Returns true if the bit is set, and false otherwise.

Definition at line **266** of file **rte\_bitops.h**.

### #define rte\_bit\_atomic\_set(addr, nr, memory\_order)

**Value:**.PP

```
    _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)
```

**Warning**

**EXPERIMENTAL:** this API may change without prior notice.

Atomically set bit in word.

Generic selection macro to atomically set bit specified by `nr` in the word pointed to by `addr` to '1', 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.

Definition at line **295** of file **rte\_bitops.h**.

### #define rte\_bit\_atomic\_clear(addr, nr, memory\_order)

**Value:**.PP

```
    _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)
```

**Warning**

**EXPERIMENTAL:** this API may change without prior notice.

Atomically clear bit in word.

Generic selection macro to atomically set bit specified by `nr` in the word pointed to by `addr` to '0', 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.

Definition at line **320** of file **rte\_bitops.h**.

### #define rte\_bit\_atomic\_assign(addr, nr, value, memory\_order)

**Value:**.PP

```
    _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)
```

**Warning**

**EXPERIMENTAL:** this API may change without prior notice.

Atomically assign a value to bit in word.

Generic selection macro to atomically set bit specified by `nr` in the word pointed to by `addr` to the value indicated 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.

Definition at line **347** of file **rte\_bitops.h**.

### #define rte\_bit\_atomic\_flip(addr, nr, memory\_order)

**Value:**.PP

```
    _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)
```

**Warning**

**EXPERIMENTAL:** this API may change without prior notice.

Atomically flip bit in word.

Generic selection macro to atomically negate the value of the bit specified by `nr` in the word pointed to by `addr` to the value indicated 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. \
 *memory\_order* The memory order to use.

Definition at line **373** of file **rte\_bitops.h**.

### #define rte\_bit\_atomic\_test\_and\_set(addr, nr, memory\_order)

**Value:**.PP

```
    _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)
```

**Warning**

**EXPERIMENTAL:** this API may change without prior notice.

Atomically test and set a bit in word.

Generic selection macro to atomically test and set bit specified by `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**

Returns true if the bit was set, and false otherwise.

Definition at line **400** of file **rte\_bitops.h**.

### #define rte\_bit\_atomic\_test\_and\_clear(addr, nr, memory\_order)

**Value:**.PP

```
    _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)
```

**Warning**

**EXPERIMENTAL:** this API may change without prior notice.

Atomically test and clear a bit in word.

Generic selection macro to atomically test and clear bit specified by `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**

Returns true if the bit was set, and false otherwise.

Definition at line **427** of file **rte\_bitops.h**.

### #define rte\_bit\_atomic\_test\_and\_assign(addr, nr, value, memory\_order)

**Value:**.PP

```
    _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)
```

**Warning**

**EXPERIMENTAL:** this API may change without prior notice.

Atomically test and assign a bit in word.

Generic selection macro to atomically test and assign bit specified by `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**

Returns true if the bit was set, and false otherwise.

Definition at line **457** of file **rte\_bitops.h**.

### #define RTE\_IS\_POWER\_OF\_2(n) ((n) && !(((n) - 1) & (n)))

Macro to return 1 if n is a power of 2, 0 otherwise

Definition at line **1216** of file **rte\_bitops.h**.

## Function Documentation

### static 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.

Definition at line **674** of file **rte\_bitops.h**.

### static 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.

Definition at line **691** of file **rte\_bitops.h**.

### static 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.

Definition at line **708** of file **rte\_bitops.h**.

### static 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.

Definition at line **728** of file **rte\_bitops.h**.

### static 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.

Definition at line **750** of file **rte\_bitops.h**.

### static 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.

Definition at line **773** of file **rte\_bitops.h**.

### static 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.

Definition at line **790** of file **rte\_bitops.h**.

### static 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.

Definition at line **807** of file **rte\_bitops.h**.

### static 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.

Definition at line **827** of file **rte\_bitops.h**.

### static 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.

Definition at line **849** of file **rte\_bitops.h**.

### static 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.

Definition at line **972** of file **rte\_bitops.h**.

### static 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.

Definition at line **986** of file **rte\_bitops.h**.

### static 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.

Definition at line **1000** of file **rte\_bitops.h**.

### static unsigned int rte\_ctz64 (uint64\_t v)` [inline]`, ` [static]`

Get the count of trailing 0-bits in v.

**Parameters**

*v* The value.

**Returns**

The count of trailing zero bits.

Definition at line **1014** of file **rte\_bitops.h**.

### static unsigned int rte\_popcount32 (uint32\_t v)` [inline]`, ` [static]`

Get the count of 1-bits in v.

**Parameters**

*v* The value.

**Returns**

The count of 1-bits.

Definition at line **1028** of file **rte\_bitops.h**.

### static unsigned int rte\_popcount64 (uint64\_t v)` [inline]`, ` [static]`

Get the count of 1-bits in v.

**Parameters**

*v* The value.

**Returns**

The count of 1-bits.

Definition at line **1042** of file **rte\_bitops.h**.

### static uint32\_t rte\_combine32ms1b (uint32\_t x)` [inline]`, ` [static]`

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.

**Parameters**

*x* The integer whose MSBs need to be combined with its LSBs

**Returns**

The combined value.

Definition at line **1060** of file **rte\_bitops.h**.

### static uint64\_t rte\_combine64ms1b (uint64\_t v)` [inline]`, ` [static]`

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.

**Parameters**

*v* The integer whose MSBs need to be combined with its LSBs

**Returns**

The combined value.

Definition at line **1082** of file **rte\_bitops.h**.

### static 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. If the content of the input parameter is zero, then the content of the return value is undefined.

**Parameters**

*v* input parameter, should not be zero.

**Returns**

least significant set bit in the input parameter.

Definition at line **1106** of file **rte\_bitops.h**.

### static 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). Safe version (checks for input parameter being zero).

**Warning**

`pos` must be a valid pointer. It is not checked!

**Parameters**

*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 **1126** of file **rte\_bitops.h**.

### static 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. If the content of the input parameter is zero, then the content of the return value is undefined.

**Parameters**

*v* input parameter, should not be zero.

**Returns**

least significant set bit in the input parameter.

Definition at line **1147** of file **rte\_bitops.h**.

### static 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 (checks for input parameter being zero).

**Warning**

`pos` must be a valid pointer. It is not checked!

**Parameters**

*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 **1167** of file **rte\_bitops.h**.

### static uint32\_t rte\_fls\_u32 (uint32\_t x)` [inline]`, ` [static]`

Return the last (most-significant) bit set.

**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

**Parameters**

*x* The input parameter.

**Returns**

The last (most-significant) bit set, or 0 if the input is 0.

Definition at line **1188** of file **rte\_bitops.h**.

### static uint32\_t rte\_fls\_u64 (uint64\_t x)` [inline]`, ` [static]`

Return the last (most-significant) bit set.

**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

**Parameters**

*x* The input parameter.

**Returns**

The last (most-significant) bit set, or 0 if the input is 0.

Definition at line **1206** of file **rte\_bitops.h**.

### static int rte\_is\_power\_of\_2 (uint32\_t n)` [inline]`, ` [static]`

Returns true if n is a power of 2

**Parameters**

*n* Number to check

**Returns**

1 if true, 0 otherwise

Definition at line **1225** of file **rte\_bitops.h**.

### static uint32\_t rte\_align32pow2 (uint32\_t x)` [inline]`, ` [static]`

Aligns input parameter to the next power of 2

**Parameters**

*x* The integer value to align

**Returns**

The smallest power of 2 which is greater than or equal to `x`.

Definition at line **1240** of file **rte\_bitops.h**.

### static uint32\_t rte\_align32prevpow2 (uint32\_t x)` [inline]`, ` [static]`

Aligns input parameter to the previous power of 2

**Parameters**

*x* The integer value to align

**Returns**

The greatest power of 2 which is smaller than or equal to `x`.

Definition at line **1258** of file **rte\_bitops.h**.

### static uint64\_t rte\_align64pow2 (uint64\_t v)` [inline]`, ` [static]`

Aligns 64b input parameter to the next power of 2

**Parameters**

*v* The 64b value to align

**Returns**

The smallest power of 2 which is greater than or equal to `v`.

Definition at line **1275** of file **rte\_bitops.h**.

### static uint64\_t rte\_align64prevpow2 (uint64\_t v)` [inline]`, ` [static]`

Aligns 64b input parameter to the previous power of 2

**Parameters**

*v* The 64b value to align

**Returns**

The greatest power of 2 which is smaller than or equal to `v`.

Definition at line **1293** of file **rte\_bitops.h**.

### static uint32\_t rte\_log2\_u32 (uint32\_t v)` [inline]`, ` [static]`

Return the rounded-up log2 of a integer.

**Note**

Contrary to the logarithm mathematical operation, rte\_log2\_u32(0) == 0 and not -inf.

**Parameters**

*v* The input parameter.

**Returns**

The rounded-up log2 of the input, or 0 if the input is 0.

Definition at line **1312** of file **rte\_bitops.h**.

### static uint32\_t rte\_log2\_u64 (uint64\_t v)` [inline]`, ` [static]`

Return the rounded-up log2 of a 64-bit integer.

**Note**

Contrary to the logarithm mathematical operation, rte\_log2\_u64(0) == 0 and not -inf.

**Parameters**

*v* The input parameter.

**Returns**

The rounded-up log2 of the input, or 0 if the input is 0.

Definition at line **1332** of file **rte\_bitops.h**.

## Author

Generated automatically by Doxygen for DPDK from the source code.
