eal: RTE_PTR_ADD/SUB char* for compiler optimizations
v3 cover eal: RTE_PTR_ADD/SUB char* for compiler optimizations
From: Scott Mitchell <[email protected]>
This series optimizes RTE_PTR_ADD and RTE_PTR_SUB by using char* pointer arithmetic instead of uintptr_t casts when operating on pointer types. This enables better compiler optimization, particularly for Clang which can now recognize simple pointer patterns and apply vectorization, loop unrolling, and improved assembly.
The implementation uses C11 _Generic to dispatch based on input type, maintaining full API compatibility while enabling significant performance improvements in checksum operations (40% for small buffers, up to 8x for larger buffers).
The first patch contains the core optimization changes and unit tests. The second patch adds a .mailmap entry for consistent git attribution.
Note on checkpatch warnings: The patches generate checkpatch warnings due to C11 _Generic syntax not being fully recognized by checkpatch.pl (designed for kernel C). The warnings are false positives - the code is valid C11 and follows the same pattern as existing DPDK code (e.g., __rte_constant macro, rte_bitops.h). The COMPLEX_MACRO warning is explicitly acknowledged by checkpatch itself as expected for statement expression macros.
Changes in v3:
- Fixed CI build failures on GCC
- Simplified const pointer handling: GCC type-checks all _Generic branches including unselected ones, causing errors with the nested _Generic/ternary approach used in v2. Now uses simple char* cast for all pointer types, which compiles on both GCC and Clang while still achieving the optimization goal (char* arithmetic enables compiler optimizations vs uintptr_t).
- Removed Clang-specific pragma for -Wconditional-type-mismatch (no longer needed without the ternary operator)
Changes in v2:
- Fixed copyright in test file to Apple Inc. (was Intel Corporation)
- Added checkpatch warning explanation to cover letter
Scott Mitchell (2):
eal: RTE_PTR_ADD/SUB char* for compiler optimizations
mailmap: add Scott Mitchell
.mailmap | 1 + app/test/meson.build | 1 + app/test/test_ptr_add_sub.c | 190 +++++++++++++++++++++++++++++++++++ lib/eal/include/rte_common.h | 60 +++++++++++ 4 files changed, 252 insertions(+) create mode 100644 app/test/test_ptr_add_sub.c
--
2.39.5 (Apple Git-154)
PATCH v3 1/2 eal: RTE_PTR_ADD/SUB char* for compiler optimizations
From: Scott Mitchell <[email protected]>
Modify RTE_PTR_ADD and RTE_PTR_SUB to use char* pointer arithmetic instead of uintptr_t casts when operating on pointer types. This enables better compiler optimization, particularly for Clang which can now recognize simple pointer patterns and apply vectorization, loop unrolling, and improved assembly.
The implementation uses C11 _Generic to dispatch based on input type:
- Integer types (int, uint64_t, etc.) continue using uintptr_t arithmetic for API compatibility
- Pointer types use char* arithmetic, with const-qualified pointers using const char* internally to preserve optimization hints
Example use case which benefits is __rte_raw_cksum. Performance results from cksum_perf_autotest on Intel Xeon (Cascade Lake, AVX-512) built with Clang 18.1 (TSC cycles/byte):
Block size Before After Improvement
100 0.40 0.24 ~40%
1500 0.50 0.06 ~8x
9000 0.49 0.06 ~8x--- app/test/meson.build | 1 + app/test/test_ptr_add_sub.c | 190 +++++++++++++++++++++++++++++++++++ lib/eal/include/rte_common.h | 60 +++++++++++ 3 files changed, 251 insertions(+) create mode 100644 app/test/test_ptr_add_sub.c
app/test/meson.build +1 -0
@@ -152,6 +152,7 @@ source_file_deps = { 'test_power_intel_uncore.c': ['power', 'power_intel_uncore'], 'test_power_kvm_vm.c': ['power', 'power_kvm_vm'], 'test_prefetch.c': [], + 'test_ptr_add_sub.c': [], 'test_ptr_compress.c': ['ptr_compress'], 'test_rand_perf.c': [], 'test_rawdev.c': ['rawdev', 'bus_vdev', 'raw_skeleton'],
app/test/test_ptr_add_sub.c new file +190 -0
190 lines not on this page · raw message
lib/eal/include/rte_common.h +60 -0
72 lines not on this page · raw message
Signature · 1 line
2.39.5 (Apple Git-154)
lib/eal/include/rte_common.h static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) · line 564
Quoted 10 lines · On Sun, 11 Jan 2026 11:00:58 -0500 [email protected] wrote:
lib/eal/include/rte_common.h +10
-0+#define RTE_PTR_ADD(ptr, x) \ + (__extension__ ({ \ + /* Diagnostics suppressed for internal macro operations only. \ +* Compiler type-checks all _Generic branches even when unselected, \ +* triggering warnings with no external impact. */ \ + __rte_diagnostic_push \ + __rte_diagnostic_ignored_wcast_qual \ + /* Uses uintptr_t arithmetic for integer types (API compatibility), \ +* and char* arithmetic for pointer types (enables optimization). */ \ + __auto_type _ptr_result = _Generic((ptr), \
NAK
No ignoring cast qualifiers. Is this just to preserve const?
DPDK does not guarantee API compatibility across versions, only ABI.
Why not clarify the code by using inline?
static inline void *__rte_ptr_offset(void *ptr, long delta)
{
return (char *)ptr + delta;
}#define RTE_PTR_ADD(ptr, x) __rte_ptr_offset(ptr, (long)(x)) #define RTE_PTR_SUB(ptr, x) __rte_ptr_offset(ptr, -(long)(x))
What about RTE_PTR_SUB() and RTE_PTR_DIFF()?
PATCH v3 2/2 mailmap: add Scott Mitchell
In reply to [email protected]From: Scott Mitchell <[email protected]>
Add email mapping for consistent git attribution.
--- .mailmap | 1 + 1 file changed, 1 insertion(+)
.mailmap +1 -0
@@ -1437,6 +1437,7 @@ Saurabh Singhal <[email protected]> Savinay Dharmappa <[email protected]> Scott Branden <[email protected]> Scott Daniels <[email protected]> +Scott Mitchell <[email protected]> <[email protected]> Scott W Taylor <[email protected]> Scott Wasson <[email protected]> Seán Harte <[email protected]>
Signature · 1 line
2.39.5 (Apple Git-154)
RE: [PATCH v3 v3 2/2] mailmap: add Scott Mitchell
.mailmap Saurabh Singhal <[email protected]> · line 1440
Quoted 7 lines
.mailmap +1
-0@@ -1437,6 +1437,7 @@ Saurabh Singhal <[email protected]> Savinay Dharmappa <[email protected]> Scott Branden <[email protected]> Scott Daniels <[email protected]> +Scott Mitchell <[email protected]> <[email protected]>
The order of the email addresses in .mailmap matters.
The first email address is the official, and the following are aliases. Suggest adding as:
+Scott Mitchell <[email protected]> <[email protected]>
RE: [PATCH v3 v3 2/2] mailmap: add Scott Mitchell
In reply to [email protected]I have verified that Scott replies to the Apple email address.
Venlig hilsen / Kind regards,
-Morten Brørup
Quoted 30 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Sunday, 11 January 2026 17.01
To: [email protected]
Cc: Morten Brørup; [email protected]; Scott Mitchell
Subject: [PATCH v3 v3 2/2] mailmap: add Scott MitchellFrom: Scott Mitchell <[email protected]>
Add email mapping for consistent git attribution.
Signed-off-by Scott Mitchell <[email protected]>--- .mailmap | 1 + 1 file changed, 1 insertion(+).mailmap +1
-1@@ -1437,6 +1437,7 @@ Saurabh Singhal <[email protected]> Savinay Dharmappa <[email protected]> Scott Branden <[email protected]> Scott Daniels <[email protected]> +Scott Mitchell <[email protected]> <[email protected]> Scott W Taylor <[email protected]> Scott Wasson <[email protected]> Seán Harte <[email protected]> --2.39.5 (Apple Git-154)
Re: [PATCH v3 v3 2/2] mailmap: add Scott Mitchell
Thanks Morten!
Quoted 42 lines · Morten Brørup
I have verified that Scott replies to the Apple email address.
Tested-by Morten Brørup <[email protected]>Reviewed-by Morten Brørup <[email protected]>Venlig hilsen / Kind regards,
-Morten BrørupQuoted 30 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Sunday, 11 January 2026 17.01
To: [email protected]
Cc: Morten Brørup; [email protected]; Scott Mitchell
Subject: [PATCH v3 v3 2/2] mailmap: add Scott MitchellFrom: Scott Mitchell <[email protected]>
Add email mapping for consistent git attribution.
Signed-off-by Scott Mitchell <[email protected]>---
.mailmap | 1 +1 file changed, 1 insertion(+).mailmap +0
-0@@ -1437,6 +1437,7 @@ Saurabh Singhal <[email protected]>Savinay Dharmappa <[email protected]>
Scott Branden <[email protected]>
Scott Daniels <[email protected]>
+Scott Mitchell <[email protected]> <[email protected]> Scott W Taylor <[email protected]>
Scott Wasson <[email protected]>
Seán Harte <[email protected]>
--
2.39.5 (Apple Git-154)