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 0773845FFF; Mon, 6 Jan 2025 12:21:43 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7A28F40676; Mon, 6 Jan 2025 12:21:43 +0100 (CET) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id A36FE4014F for ; Mon, 6 Jan 2025 12:21:41 +0100 (CET) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id 587022027D; Mon, 6 Jan 2025 12:21:41 +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:21:39 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35E9F995@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: AdtgKz3ADP4+y7IZTpi+uj36uSzq8AAAPN5w 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> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Bruce Richardson" , "Andre Muezerie" Cc: 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.07 >=20 > 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 >=20 > For the gcc version, can you just simplify to the one-line below? >=20 > #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.