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 CA8F0463A8; Thu, 13 Mar 2025 21:00:50 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 98C754025A; Thu, 13 Mar 2025 21:00:50 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 3558C40144 for ; Thu, 13 Mar 2025 21:00:49 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1213) id 8B6DF2033436; Thu, 13 Mar 2025 13:00:48 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8B6DF2033436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1741896048; bh=pHItFjMCC+GecCq+QW/0n3IcWF7d/kQMXF3CPl7gwGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hqY9JZzB2s2PNqAQEY0RDPV0lXlUwhS2kULiLpQSX7RrGpCCuZSg0VQPH8lkYaF65 fwVkdc3MN2jkZu+HsQUExfexcab8W1WgXH34E9Leh0DXPgfqozDqsqU1Dkn/6ADk+r g0iQb9dnwkjMVfUz5NrZVS/vADx8d7UXoZ+yYws4= From: Andre Muezerie To: andremue@linux.microsoft.com Cc: dev@dpdk.org, mb@smartsharesystems.com Subject: [PATCH v4 2/5] eal: add portable version of __builtin_add_overflow Date: Thu, 13 Mar 2025 13:00:40 -0700 Message-Id: <1741896043-10115-3-git-send-email-andremue@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1741896043-10115-1-git-send-email-andremue@linux.microsoft.com> References: <1735857169-19131-1-git-send-email-andremue@linux.microsoft.com> <1741896043-10115-1-git-send-email-andremue@linux.microsoft.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 __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 + +#ifdef __cplusplus +} +#endif + +#endif -- 2.48.1.vfs.0.1