rte_ptr_compress.h(3)
๐ rte_ptr_compress.h โ the rte_ptr_compress.h(3) glow-up ๐
okay bestie, sit down, hydrate, because today we're talking about the Library Functions Manual entry for rte_ptr_compress.h and it is genuinely one of the most lowkey iconic headers in DPDK. no cap.
โจ NAME โจ
rte_ptr_compress.h โ it's giving "pointer compression and decompression functions" and it's serving exactly that ๐
๐ SYNOPSIS ๐
first of all, the includes. she needs her little friends:
#include <stdint.h>
#include <inttypes.h>
#include <rte_bitops.h>
#include <rte_branch_prediction.h>
#include <rte_common.h>
#include <rte_debug.h>
#include <rte_vect.h>
๐ง Macros
#define
RTE_PTR_COMPRESS_BITS_NEEDED_FOR_POINTER_WITHIN_RANGE(mem_length)
#define RTE_PTR_COMPRESS_BIT_SHIFT_FROM_ALIGNMENT(alignment)
#define RTE_PTR_COMPRESS_CAN_COMPRESS_16_SHIFT(mem_length,
obj_alignment)
#define RTE_PTR_COMPRESS_CAN_COMPRESS_32_SHIFT(mem_length,
obj_alignment)
๐ฆ Functions
static __rte_always_inline void rte_ptr_compress_32_shift (void
*ptr_base, void *const *src_table, uint32_t *dest_table, size_t n,
uint8_t bit_shift)
static __rte_always_inline void rte_ptr_decompress_32_shift (void
*ptr_base, uint32_t const *src_table, void **dest_table, size_t n,
uint8_t bit_shift)
static __rte_always_inline void rte_ptr_compress_16_shift (void
*ptr_base, void *const *src_table, uint16_t *dest_table, size_t n,
uint8_t bit_shift)
static __rte_always_inline void rte_ptr_decompress_16_shift (void
*ptr_base, uint16_t const *src_table, void **dest_table, size_t n,
uint8_t bit_shift)
๐ Detailed Description ๐
bestie. pointer compression and decompression functions. that's the whole vibe. ๐
so here's the tea: when you're passing arrays full of pointers between threads, that memory containing the pointers gets copied multiple times, and that is especially costly between cores. it's giving "why are we like this". ao these functions let us compress the pointers instead. obsessed.
compression takes advantage of the fact that pointers are usually located in a limited memory region. so we compress them by converting them to offsets from a base memory address. and offsets? offsets can be stored in fewer bytes. ate. ๐
the compression functions come in two varieties: 32-bit and 16-bit.
to determine how many bits are needed to compress the pointer, you calculate the biggest offset possible (highest value pointer - base pointer) and shift the value right according to alignment โ shift by the exponent of the power of 2 of alignment: aligned by 4 โ shift by 2, aligned by 8 โ shift by 3, etc. the resulting value must fit in either 32 or 16 bits. and you may use the macros provided in this file to do it programmatically, which is the slay part. โจ
for a usage example and further explanation, please see this library's documentation in the programming guide. iykyk.
๐ Definition in file rte_ptr_compress.h.
๐ Macro Definition Documentation ๐
๐ #define RTE_PTR_COMPRESS_BITS_NEEDED_FOR_POINTER_WITHIN_RANGE( mem_length)
Value:
(((uint64_t)mem_length) < 2 ? 1 : \
(sizeof(uint64_t) * CHAR_BIT - \
rte_clz64((uint64_t)mem_length - 1)))
calculate how many bits are required to store pointers within a given memory region as offsets. this can help you decide which pointer compression functions can be used. very "let me do the math so you don't have to" of her. ๐งฎ
Parameters
mem_lengthโ length of the memory region the pointers are constrained to.
Returns
- number of bits required to store a value.
Definition at line 56 of file rte_ptr_compress.h.
๐ #define RTE_PTR_COMPRESS_BIT_SHIFT_FROM_ALIGNMENT( alignment)
Value:
((alignment) == 0 ? 0 : rte_ctz64((uint64_t)alignment))
calculate how many bits in the address can be dropped without losing any information, thanks to the alignment of the address. no information lost?? that's the standard. ๐
Parameters
alignmentโ memory alignment.
Returns
- size of shift allowed without dropping any information from the pointer.
Definition at line 70 of file rte_ptr_compress.h.
๐ #define RTE_PTR_COMPRESS_CAN_COMPRESS_16_SHIFT( mem_length, obj_alignment)
Value:
((RTE_PTR_COMPRESS_BITS_NEEDED_FOR_POINTER_WITHIN_RANGE(mem_length) - \
RTE_PTR_COMPRESS_BIT_SHIFT_FROM_ALIGNMENT(obj_alignment)) <= 16 ? 1 : 0)
determine if rte_ptr_compress_16_shift can be used to compress pointers that contain addresses of memory objects whose memory is aligned by a given amount and contained in a given memory region. it's a yes/no girlie and honestly? same.
Parameters
mem_lengthโ the length of the memory region that contains the objects pointed to.obj_alignmentโ the alignment of objects pointed to.
Returns
1if the function can be used,0otherwise.
Definition at line 85 of file rte_ptr_compress.h.
๐ #define RTE_PTR_COMPRESS_CAN_COMPRESS_32_SHIFT( mem_length, obj_alignment)
Value:
((RTE_PTR_COMPRESS_BITS_NEEDED_FOR_POINTER_WITHIN_RANGE(mem_length) - \
RTE_PTR_COMPRESS_BIT_SHIFT_FROM_ALIGNMENT(obj_alignment)) <= 32 ? 1 : 0)
determine if rte_ptr_compress_32_shift can be used to compress pointers that contain addresses of memory objects whose memory is aligned by a given amount and contained in a given memory region. literally the same energy as the 16 one but with bigger numbers โจ
Parameters
mem_lengthโ the length of the memory region that contains the objects pointed to.obj_alignmentโ the alignment of objects pointed to.
Returns
1if the function can be used,0otherwise.
Definition at line 101 of file rte_ptr_compress.h.
๐ซถ Function Documentation ๐ซถ
๐ธ __rte_always_inline void rte_ptr_compress_32_shift (void * ptr_base, void *const * src_table, uint32_t * dest_table, size_t n, uint8_t bit_shift) [static]
compress pointers into 32-bit offsets from a base pointer. ๐
โ ๏ธ Note โ it is the programmer's responsibility to ensure the resulting offsets fit into 32 bits. alignment of the structures pointed to by the pointers allows us to drop bits from the offsets, and that's controlled by the bit_shift parameter. what this means, bestie: if structures are aligned by 8 bytes they must be within 32GB of the base pointer. if there is no such alignment guarantee, they must be within 4GB. that's the whole thing, don't be messy about it. ๐ญ
Parameters
ptr_baseโ a pointer used to calculate offsets of pointers insrc_table.src_tableโ a pointer to an array of pointers.dest_tableโ a pointer to an array of compressed pointers returned by this function.nโ the number of objects to compress, must be strictly positive.bit_shiftโ byte alignment of memory pointed to by the pointers allows for bits to be dropped from the offset and hence widen the memory region that can be covered. this controls how many bits are right shifted.
Definition at line 129 of file rte_ptr_compress.h.
๐ธ __rte_always_inline void rte_ptr_decompress_32_shift (void * ptr_base, uint32_t const * src_table, void ** dest_table, size_t n, uint8_t bit_shift) [static]
decompress pointers from 32-bit offsets from a base pointer. the un-girlbossing of the compression, we love to see it. ๐
Parameters
ptr_baseโ a pointer which was used to calculate offsets insrc_table.src_tableโ a pointer to an array to compressed pointers.dest_tableโ a pointer to an array of decompressed pointers returned by this function.nโ the number of objects to decompress, must be strictly positive.bit_shiftโ byte alignment of memory pointed to by the pointers allows for bits to be dropped from the offset and hence widen the memory region that can be covered. this controls how many bits are left shifted when pointers are recovered from the offsets.
Definition at line 190 of file rte_ptr_compress.h.
๐ธ __rte_always_inline void rte_ptr_compress_16_shift (void * ptr_base, void *const * src_table, uint16_t * dest_table, size_t n, uint8_t bit_shift) [static]
compress pointers into 16-bit offsets from a base pointer. tiny offsets, big energy. ๐ฆ
โ ๏ธ Note โ again, it is the programmer's responsibility to ensure the resulting offsets fit into 16 bits. alignment of the structures pointed to by the pointers allows us to drop bits from the offsets, and that's controlled by the bit_shift parameter. so: if structures are aligned by 8 bytes they must be within 256KB of the base pointer. if there is no such alignment guarantee, they must be within 64KB. 256KB!! she's compact!! ๐
Parameters
ptr_baseโ a pointer used to calculate offsets of pointers insrc_table.src_tableโ a pointer to an array of pointers.dest_tableโ a pointer to an array of compressed pointers returned by this function.nโ the number of objects to compress, must be strictly positive.bit_shiftโ byte alignment of memory pointed to by the pointers allows for bits to be dropped from the offset and hence widen the memory region that can be covered. this controls how many bits are right shifted.
Definition at line 254 of file rte_ptr_compress.h.
๐ธ __rte_always_inline void rte_ptr_decompress_16_shift (void * ptr_base, uint16_t const * src_table, void ** dest_table, size_t n, uint8_t bit_shift) [static]
decompress pointers from 16-bit offsets from a base pointer. the reverse card, played flawlessly. ๐
Parameters
ptr_baseโ a pointer which was used to calculate offsets insrc_table.src_tableโ a pointer to an array to compressed pointers.dest_tableโ a pointer to an array of decompressed pointers returned by this function.nโ the number of objects to decompress, must be strictly positive.bit_shiftโ byte alignment of memory pointed to by the pointers allows for bits to be dropped from the offset and hence widen the memory region that can be covered. this controls how many bits are left shifted when pointers are recovered from the offsets.
Definition at line 298 of file rte_ptr_compress.h.
๐ Author ๐
generated automatically by Doxygen for DPDK from the source code. not a human, just a little documentation robot doing her thing. no thoughts, just docs. ๐ค๐
anyway bestie, that's the whole page โ pointer compression, offsets, alignment shifts, and every single macro and function exactly where you left them. go compress something responsibly. remember: programmer's responsibility to check those offsets fit, i am not your size_t. ๐ญ
mwah ๐ โ this was DPDK, Version 25.11.3, and we're out ๐ซถโจ
๐ฆ where this page comes from
- ubuntu resolute: dpdk-doc 25.11.3-0ubuntu0.26.04.1 ยท BSD-3-Clause
- ubuntu stonking: dpdk-doc 25.11.3-1 ยท BSD-3-Clause
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms