DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Bruce Richardson" <bruce.richardson@intel.com>,
	"Stephen Hemminger" <stephen@networkplumber.org>
Cc: <scott.k.mitch1@gmail.com>, <dev@dpdk.org>
Subject: RE: [PATCH 1/2] eal: RTE_PTR_ADD/SUB char* for compiler optimizations
Date: Mon, 12 Jan 2026 12:01:21 +0100	[thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35F65652@smartserver.smartshare.dk> (raw)
In-Reply-To: <aWS7YdU11DNPbz4o@bricha3-mobl1.ger.corp.intel.com>

> From: Bruce Richardson [mailto:bruce.richardson@intel.com]
> Sent: Monday, 12 January 2026 10.14
> 
> On Sun, Jan 11, 2026 at 07:59:19AM -0800, Stephen Hemminger wrote:
> > On Sun, 11 Jan 2026 10:00:32 -0500
> > scott.k.mitch1@gmail.com wrote:
> >
> > > +#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 \
> > > +		_Pragma("GCC diagnostic ignored \"-Wconditional-type-
> mismatch\"") \
> > > +		/* Uses uintptr_t arithmetic for integer types (API
> compatibility), \
> > > +		 * and char* arithmetic for pointer types (enables
> optimization). */ \
> > > +		__auto_type _ptr_result = _Generic((ptr), \
> > > +			unsigned long long: ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			long long:          ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			unsigned long:      ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			long:               ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			unsigned int:       ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			int:                ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			unsigned short:     ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			short:              ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			unsigned char:      ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			signed char:        ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			char:               ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			_Bool:              ((void *)((uintptr_t)(ptr) +
> (x))), \
> > > +			/* Ternary with null pointer constant: per C11, if
> one operand \
> > > +			 * is a null pointer constant and the other is a
> pointer, the \
> > > +			 * result type is qualified per the pointer operand,
> normalizing \
> > > +			 * const T* to const void* and T* to void*. */ \
> > > +			default: _Generic((1 ? (ptr) : (void *)0), \
> > > +				const void *: ((void *)((const char *)(ptr) +
> (x))), \
> > > +				default:      ((void *)((char *)(ptr) + (x))) \
> > > +			) \
> > > +		); \
> > > +		__rte_diagnostic_pop \
> > > +		_ptr_result; \
> > > +	}))
> >
> > Good idea in general but the macro is way to big and therefore hard
> to read.
> > The comments could be outside the macro.
> >
> > Any code that adds dependency on a pragma to work is brittle and
> likely
> > to allow bugs through. Please figure out how to do it without.
> 
> Do we need to handle the case of users calling RTE_PTR_ADD with integer
> values? Using this macro to essentially cast an integer to pointer
> seems
> strange. Even if it's occasionally used, I think keeping things simple
> and
> just globally changing to use "char *" is a better approach.
> 
> The only case where I'd consider trying to keep compatibility using
> uintptr_t is if the pointer parameter is a volatile one. Even then, we
> can
> probably handle that as with the "const" modifier, right?

None of the RTE_PTR_ macros can handle qualifiers (const, volatile).
Maybe it would be better to provide a new set of macros with a qualifier parameter, instead of adding new macros with e.g. _CONST in the names.


  reply	other threads:[~2026-01-12 11:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-11 15:00 [PATCH 0/2] " scott.k.mitch1
2026-01-11 15:00 ` [PATCH 1/2] " scott.k.mitch1
2026-01-11 15:59   ` Stephen Hemminger
2026-01-12  9:14     ` Bruce Richardson
2026-01-12 11:01       ` Morten Brørup [this message]
2026-01-12 11:11         ` Bruce Richardson
2026-01-12 11:25           ` Morten Brørup
2026-01-11 15:00 ` [PATCH 2/2] mailmap: add Scott Mitchell scott.k.mitch1

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=98CBD80474FA8B44BF855DF32C47DC35F65652@smartserver.smartshare.dk \
    --to=mb@smartsharesystems.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=scott.k.mitch1@gmail.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).