From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B556E45FFF; Mon, 6 Jan 2025 12:58:48 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 60FC240689; Mon, 6 Jan 2025 12:58:48 +0100 (CET) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 9701440687 for ; Mon, 6 Jan 2025 12:58:46 +0100 (CET) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id 3EF242027D; Mon, 6 Jan 2025 12:58:46 +0100 (CET) Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [PATCH v2 2/5] lib/eal: add portable version of __builtin_add_overflow Date: Mon, 6 Jan 2025 12:58:44 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35E9F996@smartserver.smartshare.dk> In-Reply-To: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH v2 2/5] lib/eal: add portable version of __builtin_add_overflow Thread-Index: AdtgLwK3OLWzarrMRBuG91j80eOfhAAACTBg References: <1735857169-19131-1-git-send-email-andremue@linux.microsoft.com> <1735936781-24199-1-git-send-email-andremue@linux.microsoft.com> <1735936781-24199-3-git-send-email-andremue@linux.microsoft.com> <98CBD80474FA8B44BF855DF32C47DC35E9F995@smartserver.smartshare.dk> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Bruce Richardson" Cc: "Andre Muezerie" , X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > From: Bruce Richardson [mailto:bruce.richardson@intel.com] > Sent: Monday, 6 January 2025 12.34 >=20 > On Mon, Jan 06, 2025 at 12:21:39PM +0100, Morten Br=F8rup 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 =3D 1; > > > > + * b =3D 2; > > > > + * overflow =3D 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? The DPDK macro should support all the types that both MSVC and GCC = supports. Using _Generic() for GCC is an improvement for the CI to catch MSVC = incompatible code when building for GCC. Only these four unsigned types are supported by the x86_64 intrinsics. I don't think we need support for more types; but if the need should = arise, it can be added later.