From: Andre Muezerie <andremue@linux.microsoft.com>
To: Tyler Retzlaff <roretzla@linux.microsoft.com>
Cc: dev@dpdk.org, Andre Muezerie <andremue@linux.microsoft.com>
Subject: [PATCH 2/5] lib/eal: add portable version of __builtin_add_overflow
Date: Thu, 2 Jan 2025 14:32:45 -0800 [thread overview]
Message-ID: <1735857169-19131-3-git-send-email-andremue@linux.microsoft.com> (raw)
In-Reply-To: <1735857169-19131-1-git-send-email-andremue@linux.microsoft.com>
__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_u8, __rte_add_overflow_u16
and __rte_add_overflow_u32.
Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
lib/eal/include/meson.build | 1 +
lib/eal/include/rte_math.h | 42 +++++++++++++++++++++++++++++++++++++
2 files changed, 43 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..df2f3d4d34
--- /dev/null
+++ b/lib/eal/include/rte_math.h
@@ -0,0 +1,42 @@
+/* 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
+
+/*
+ * Functions that allow performing simple arithmetic operations together with
+ * checking whether the operations overflowed.
+ * Example of usage:
+ * uint8_t overflow;
+ * uint16_t a, b, result;
+ * a = 1;
+ * b = 2;
+ * overflow = __rte_add_overflow_u16(a, b, &result);
+ */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_add_overflow_u8(a, b, res) _addcarry_u8(0, a, b, res)
+#define __rte_add_overflow_u16(a, b, res) _addcarry_u16(0, a, b, res)
+#define __rte_add_overflow_u32(a, b, res) _addcarry_u32(0, a, b, res)
+#else
+#define __rte_add_overflow_u8(a, b, res) __builtin_add_overflow(a, b, res)
+#define __rte_add_overflow_u16(a, b, res) __builtin_add_overflow(a, b, res)
+#define __rte_add_overflow_u32(a, b, res) __builtin_add_overflow(a, b, res)
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--
2.47.0.vfs.0.3
next prev parent reply other threads:[~2025-01-02 22:33 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 ` Andre Muezerie [this message]
2025-01-03 8:19 ` [PATCH 2/5] lib/eal: " 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
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=1735857169-19131-3-git-send-email-andremue@linux.microsoft.com \
--to=andremue@linux.microsoft.com \
--cc=dev@dpdk.org \
--cc=roretzla@linux.microsoft.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).