From: Bruce Richardson <bruce.richardson@intel.com>
To: "Morten Brørup" <mb@smartsharesystems.com>
Cc: Andre Muezerie <andremue@linux.microsoft.com>, <dev@dpdk.org>
Subject: Re: [PATCH v2 2/5] lib/eal: add portable version of __builtin_add_overflow
Date: Mon, 6 Jan 2025 11:34:18 +0000 [thread overview]
Message-ID: <Z3u_uo_S4Ldz6LWR@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9F995@smartserver.smartshare.dk>
On Mon, Jan 06, 2025 at 12:21:39PM +0100, Morten Brørup wrote:
> > From: Bruce Richardson [mailto:bruce.richardson@intel.com]
> > Sent: Monday, 6 January 2025 12.07
> >
> > On Fri, Jan 03, 2025 at 12:39:38PM -0800, Andre Muezerie wrote:
> > > __builtin_add_overflow is gcc specific. There's a need for a portable
> > > version that can also be used with other compilers.
> > >
> > > This patch introduces rte_add_overflow.
> > >
> > > +/*
> > > + * Function that allows performing simple arithmetic operations
> > together with
> > > + * checking whether the operation overflowed.
> > > + * Example of usage:
> > > + * uint8_t overflow;
> > > + * uint16_t a, b, result;
> > > + * a = 1;
> > > + * b = 2;
> > > + * overflow = rte_add_overflow(a, b, &result);
> > > + */
> > > +#ifdef RTE_TOOLCHAIN_MSVC
> > > +#define rte_add_overflow(a, b, res) _Generic((a), \
> > > + uint8_t : _addcarry_u8, \
> > > + uint16_t : _addcarry_u16, \
> > > + uint32_t : _addcarry_u32, \
> > > + uint64_t : _addcarry_u64)(0, a, b, res)
> > > +#else
> > > +#define rte_add_overflow(a, b, res) _Generic((a), \
> > > + uint8_t : __builtin_add_overflow, \
> > > + uint16_t : __builtin_add_overflow, \
> > > + uint32_t : __builtin_add_overflow, \
> > > + uint64_t : __builtin_add_overflow)(a, b, res)
> > > +#endif
> >
> > For the gcc version, can you just simplify to the one-line below?
> >
> > #define rte_add_overflow __builtin_add_overflow
>
> Yes, but then GCC compilation would not fail if "a" has some other type than the four types explicitly supported.
> I prefer keeping the method used this v2 patch.
>
Is that really a problem? Should our DPDK macro not support all the types
that the GCC builtin supports?
/Bruce
next prev parent reply other threads:[~2025-01-06 11:34 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-02 22:32 [PATCH 0/5] " Andre Muezerie
2025-01-02 22:32 ` [PATCH 1/5] maintainers: " Andre Muezerie
2025-01-02 22:32 ` [PATCH 2/5] lib/eal: " Andre Muezerie
2025-01-03 8:19 ` Morten Brørup
2025-01-03 20:38 ` Andre Muezerie
2025-01-02 22:32 ` [PATCH 3/5] doc/api: " Andre Muezerie
2025-01-02 22:32 ` [PATCH 4/5] drivers/net: use " Andre Muezerie
2025-01-02 22:32 ` [PATCH 5/5] app/test: add tests for portable versions " Andre Muezerie
2025-01-02 23:51 ` [PATCH 0/5] add portable version " Stephen Hemminger
2025-01-03 0:15 ` Andre Muezerie
2025-01-03 0:41 ` Andre Muezerie
2025-01-03 20:39 ` [PATCH v2 " Andre Muezerie
2025-01-03 20:39 ` [PATCH v2 1/5] maintainers: " Andre Muezerie
2025-01-03 20:39 ` [PATCH v2 2/5] lib/eal: " Andre Muezerie
2025-01-06 11:07 ` Bruce Richardson
2025-01-06 11:21 ` Morten Brørup
2025-01-06 11:34 ` Bruce Richardson [this message]
2025-01-06 11:58 ` Morten Brørup
2025-01-03 20:39 ` [PATCH v2 3/5] doc/api: " Andre Muezerie
2025-01-03 20:39 ` [PATCH v2 4/5] drivers/net: use " Andre Muezerie
2025-01-03 20:39 ` [PATCH v2 5/5] app/test: add tests for " Andre Muezerie
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=Z3u_uo_S4Ldz6LWR@bricha3-mobl1.ger.corp.intel.com \
--to=bruce.richardson@intel.com \
--cc=andremue@linux.microsoft.com \
--cc=dev@dpdk.org \
--cc=mb@smartsharesystems.com \
/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).