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 C6FD445FFF; Mon, 6 Jan 2025 12:07:54 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5B40C40673; Mon, 6 Jan 2025 12:07:54 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by mails.dpdk.org (Postfix) with ESMTP id BB2DC4014F for ; Mon, 6 Jan 2025 12:07:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1736161672; x=1767697672; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=efiGIV9alVR5YN7H2TRxiAJdAsf3oT/EE2w6IbWwCmU=; b=YyEPE9op2Idri4FVudhWAvu4u4a69Nao/bfBlQB6mvvSEl9JZqI+3Cbg EEUPSOTCSpWlpz1+T1I9Q3F0iQ4cMcyc5+2/RxzYSOov2CtQ92cWVAwn2 8NKH5mL93WeR0DBj6nVchTJjUxNGbjj7TuXXHMZcuQSnr7Dh1nv8jcAYR pM4QfMyXPDq72WbDQ/BiE4Z2QeS27/A30QueUM1yNhEIrM5rSVFS2WgHO oI2UADwKKucQPyW4d3qAxadckol6piAkfetG8iaFvSSLTJhjQibqI3MSF 3EJcsk3yzpipMo1cpr+rKgHfJ9jbBgtpSBQjOKwo2zVR+u4Ntk/phCSxc w==; X-CSE-ConnectionGUID: 8PXTkEM7Q7axnOGQTkmljQ== X-CSE-MsgGUID: 0t2yS7sXRVeQ4wvRJM9CBA== X-IronPort-AV: E=McAfee;i="6700,10204,11307"; a="58768263" X-IronPort-AV: E=Sophos;i="6.12,292,1728975600"; d="scan'208";a="58768263" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2025 03:07:50 -0800 X-CSE-ConnectionGUID: idAIJSfdQ7Wea74EmAl5ZQ== X-CSE-MsgGUID: a55ViU+7TNudhUrngsNzWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="102913997" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orviesa007.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 06 Jan 2025 03:07:50 -0800 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.44; Mon, 6 Jan 2025 03:07:49 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.44 via Frontend Transport; Mon, 6 Jan 2025 03:07:49 -0800 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.45) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.44; Mon, 6 Jan 2025 03:07:49 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Kx8qU3OXbj4S1QBL7Z0jvHQxIQ/WHxUhcx21SPtRa/GLX0A4C05OQggK+He/J4BFi5tXNAGLE0PoTf8BYF5eQxybiAhsJyqh8i9aNVwBBFG+7VXS9AIywcPI1AtA3nOXdgBoPOSHnmwnFnEbBk3gV/w4Z8TLLo6JHxAA0CJYW6G095wIiFEEVrq3nlbCcLXsn/69WDs+qy2G98V93wjeaQoHsgS9DyUZWgjv3i584FqgwNft0GrKR6zBFWVCNsLUForu2MepsPm+U6J+02Xfu0DHiSL1DpX4eBkeoLa+BU67N4qBvgs4OzXFHHiYmxDlkfXmUdkcvMj3U4g9OIKiwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nDmkJ0o6Krp6qrzTpmg9XFa2TYVpUXyzXi/IN64Wejc=; b=UyVheYQFAty0k/jHuo6GZrA1AfXAm/TtH4SZH0j1/7joFQ2FpZYuGvcM+HVUtL2ysjkTenO/C94qIxw+Q1/OJivzvRtcfeuVb48I/GCQwy6uvCwF6XPDWaGAz+VKHVrCPN1DuoWqCA4XUROxut6iV9pnwvPHQLHcPT7gZGGXih2jEZtN4W0DDqAB0J7hM8o3rRuHn1qOqydVNkM/wjRCEKxN3m2/mqbakr1x+39VkHI/wm3oE3a3DjOvQhxkyA1u1TB7G+CATLsqlG/HVtFUj7VrW5rwSVd2k+gDLt0mpbiV/5LjJ6KlWmDFG0TiaqNG87eVbWXcPUa0gmQkcMskjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) by PH7PR11MB7515.namprd11.prod.outlook.com (2603:10b6:510:278::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Mon, 6 Jan 2025 11:07:16 +0000 Received: from DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::f120:cc1f:d78d:ae9b]) by DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::f120:cc1f:d78d:ae9b%5]) with mapi id 15.20.8314.015; Mon, 6 Jan 2025 11:07:16 +0000 Date: Mon, 6 Jan 2025 11:07:11 +0000 From: Bruce Richardson To: Andre Muezerie CC: , Subject: Re: [PATCH v2 2/5] lib/eal: add portable version of __builtin_add_overflow Message-ID: 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> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1735936781-24199-3-git-send-email-andremue@linux.microsoft.com> X-ClientProxiedBy: DUZPR01CA0331.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b8::24) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|PH7PR11MB7515:EE_ X-MS-Office365-Filtering-Correlation-Id: b9556fa8-68e5-488a-71c4-08dd2e4247a7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?e640pOwqA4tL/hT6NUR4mw1wxVeLKUNOg+eKHkqEmINf4ETpuSiPQ0dcEWu6?= =?us-ascii?Q?3sddJDxWM4bw5ahr+rIhntsHeaCkg8xon4PcoM2HQthDxTolzksFF8AW8PJR?= =?us-ascii?Q?nHBPt7h9vBec6M2/4UuJIcLolpeX5Hz6WiwG3K22qlU2Y7cq3t0YtBSowpv4?= =?us-ascii?Q?ATFxas8D5c13ujWNFdU7p/vtDypfeJcOEh/vg1B0Clqse2FeINoL8H7ogiVM?= =?us-ascii?Q?tBorc47NNv1d1mB5BVzp+D+nrcBc2/VALSbidlI6Ciux+Ey/SRHXPW3pUOWa?= =?us-ascii?Q?iv/Y6WsQEeTLPIbAcXc3SKZK67PeIQRW+4i+6l53csSytGdBpojS+Os8Pjk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M6qCF/LAY2Aw0qeyASIBNItKzK5NQLb?= =?us-ascii?Q?Z0skDaYteVUxh5J6oQglN14ZKgmqrQXo1/yU49M0KX3Mlq/zY+S/mgjcyeux?= =?us-ascii?Q?tX+uZi8I0yJJyzMEHiS2WQHMXNynzBDBUj2sP1u0NC+wDeaYYjXXw2nLJs4S?= =?us-ascii?Q?JC9cNiQ/EyXjrRnycfzUOqaOnXxg?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7309.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(7053199007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?bW86EPG3LUxoFruwpdAgeg+RPsiX8ZWVjBMW1qSSB2Ne9atfjuBx2n5dxIAj?= =?us-ascii?Q?FGZQcGk4u+TAQCWM39lOnm+DbrHYzI6rSra64Cjd/4SRtqq3IB5NlK7OJ/a3?= =?us-ascii?Q?W8LYysjel0x1VWQk8DBZ6yMhHtK903qF5kaPEjqZuzsmboBxLB9ZWh3y3LoA?= =?us-ascii?Q?CrAwKPTuc3MQMtQj8rvgj7ma3tacut7EdGJFn9AlMFy/gcJZUcIzyYY0df6/?= =?us-ascii?Q?GzAggPYAp8nI3hEMJSY30IhZzqnZwNaVrVS5Kb5PKB+z7uqcN4VFabHiqZAj?= =?us-ascii?Q?0Hwzs2Vc5v9nbZ/4iCD8baQb43I1wgJWJ7Svj4eRVy8gile6QjgITrgh3lvM?= =?us-ascii?Q?kahTY4b10wB8GmQ+JPbNgekCL/Mln1SJOh642Mz1UHfQMLFPCs730LYtT3Qz?= =?us-ascii?Q?2qnVb6o+pg1Fzjj+UMUa5nXc6wJnZ7l3p9ow/1X5Rz1Hnmy0zvfD41ZA0a15?= =?us-ascii?Q?j54qVpCYA7XRPZiN6KpW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ascii?Q?SbdX8Jvvr5TCn8p8Y6yGg04j3dOJAJefPsLDeM5vlcjs2oqp4mpwxW5Vku1H?= =?us-ascii?Q?daVRaj0P9nkyfiG0Bstlk55pPchQNBJTrjoXt4Smpi3jNy3NjopN30S8vwN7?= =?us-ascii?Q?WiqwiUcySB3bDyCyRUz18b/vdQlMSxBO19jWKRT7fbWcztpN4W6OL+7b0Spt?= =?us-ascii?Q?v0rko3ilcsn47sXNTCpzHnMPBwEU3BF/8Lz04L3z7tyo3ODqYRXIj6pXn4YA?= =?us-ascii?Q?2g=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: b9556fa8-68e5-488a-71c4-08dd2e4247a7 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7309.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 11:07:16.2449 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: J5vS7F6/wGBDFQ8puw6VT+1xvcJkFuUjIG1iuB5wNLaipzhTvVC/MZjzDXtKMrf3iQtU8CuZsiff6puuxPWw6S3WZfN+TC8JK5iDEYon4JY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB7515 X-OriginatorOrg: intel.com 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 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. > > Signed-off-by: Andre Muezerie > --- > lib/eal/include/meson.build | 1 + > lib/eal/include/rte_math.h | 46 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 47 insertions(+) > create mode 100644 lib/eal/include/rte_math.h > > diff --git a/lib/eal/include/meson.build b/lib/eal/include/meson.build > index d903577caa..041a4105b5 100644 > --- a/lib/eal/include/meson.build > +++ b/lib/eal/include/meson.build > @@ -31,6 +31,7 @@ headers += files( > 'rte_lcore_var.h', > 'rte_lock_annotations.h', > 'rte_malloc.h', > + 'rte_math.h', > 'rte_mcslock.h', > 'rte_memory.h', > 'rte_memzone.h', > diff --git a/lib/eal/include/rte_math.h b/lib/eal/include/rte_math.h > new file mode 100644 > index 0000000000..2f4581f81b > --- /dev/null > +++ b/lib/eal/include/rte_math.h > @@ -0,0 +1,46 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2025 Microsoft Corporation > + */ > + > +#ifndef _RTE_MATH_H_ > +#define _RTE_MATH_H_ > + > +/** > + * @file > + * > + * Math function definitions for DPDK. > + */ > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +/* > + * 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 /Bruce