From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id B484245778;
	Fri,  9 Aug 2024 12:08:25 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 7413042EF5;
	Fri,  9 Aug 2024 12:08:11 +0200 (CEST)
Received: from EUR05-DB8-obe.outbound.protection.outlook.com
 (mail-db8eur05on2045.outbound.protection.outlook.com [40.107.20.45])
 by mails.dpdk.org (Postfix) with ESMTP id B2E65402C4
 for <dev@dpdk.org>; Fri,  9 Aug 2024 12:08:06 +0200 (CEST)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
 b=Chyy4nfqLgnU6Vi9h4u6lMRDAvl2+ZnodXjUIPgngsQ9XGlZHzrc32f5w7pP4dID7MF3wIMSfqUC/Yi9c978TqR0ljlqod/h1wUaS9DAp8/RD1dwWptZT4vr3ZGcScrSdnCE1p1FWAqzWSjMbp73EWn2rM88p8i8LsSb4+lunFO0hNTwhFS2e7FmMz/0d+oYuxWyKm1L0UcVjusJTS2irPAyJLMXvFyETTT7IB0a/1Sh7Jx2BdV79GJVTYzc0Os9QfS/yYc/YK2msthUuI81dXUpZEgWVMjyOL4ASI0h59tbKirsdMrDyofGwKOUgTQcvuIW1r4rgeKeD0+cApEmeg==
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=yT9/InfrNKgLxrg+7IONvBCaDCUWOGZoVI+shNYwzrg=;
 b=F1yY2thUWDhVBnMScxJGxpVPHeSXVGwOBCjpJEeNTZbSqhaV9eTKr8CcU32++g/TDT3osSn5mIiTVIZateWBsPCpaCKOYfC0VDbOBOcieKofJamqupakH49t5TXe2wbskC1bmJO/M60MslYKyMzECumkFGUmSQzFRDuS5PWOYeJzCJMJv8hV46r2J/3wdP4o02KnRz4UGBQTzHIiC58nLGAJ3LOqlxjM2DPcrQ6123FT5krErW9pOHb2e9B+VAHIE3mI0OltNqtPEN7UbpYUc+0Ry98k8NZMQF+txrAsOEKf29Go9OhcWQ9EeApJo5fDfyQ2Ew7Dl3y72PWL5CQF/Q==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is
 192.176.1.74) smtp.rcpttodomain=arm.com smtp.mailfrom=ericsson.com;
 dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; 
 dkim=none (message not signed); arc=none (0)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com;
 s=selector1;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=yT9/InfrNKgLxrg+7IONvBCaDCUWOGZoVI+shNYwzrg=;
 b=gaiA1KRtlr49mcLvWxiw9jlxqYwXE+XcDT5UOFIkJGtshzv5Abay5uCRnZue5hXV+0jYQWVbs/1G4UfPoWs44bJu7fJ9AfOCgeeMIQDQdk3g1yH+Ou52EJpUBwhAezpUPOCs1miJVEwgERaZpB5ZuTCG1mIpwTQSp3DmFsf68Ev2vhOGxZtkwooqIHz/f2VcmcBd04XiWU3u3ee5mFCMpIeYGPAt1TWvqxQEoO4g6+Y92b5a9Dp3E1jAZQ8i74k/nQA/ErpAzjWv3DtC8Rtr2y+qb35dlNnr8ODrDIFF2Km9Egw84Be7UwXrl8nMsS3Ptm9AAFTfHMIUNNC0nXjQtQ==
Received: from DB6PR0301CA0099.eurprd03.prod.outlook.com (2603:10a6:6:30::46)
 by VI1PR07MB10042.eurprd07.prod.outlook.com (2603:10a6:800:1d1::18)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.15; Fri, 9 Aug
 2024 10:08:04 +0000
Received: from DB1PEPF00039232.eurprd03.prod.outlook.com
 (2603:10a6:6:30:cafe::d6) by DB6PR0301CA0099.outlook.office365.com
 (2603:10a6:6:30::46) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.15 via Frontend
 Transport; Fri, 9 Aug 2024 10:08:04 +0000
X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74)
 smtp.mailfrom=ericsson.com; dkim=none (message not signed)
 header.d=none;dmarc=pass action=none header.from=ericsson.com;
Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates
 192.176.1.74 as permitted sender)
 receiver=protection.outlook.com; 
 client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C
Received: from oa.msg.ericsson.com (192.176.1.74) by
 DB1PEPF00039232.mail.protection.outlook.com (10.167.8.105) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.7849.8 via Frontend Transport; Fri, 9 Aug 2024 10:08:03 +0000
Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by
 smtp-central.internal.ericsson.com (100.87.178.67) with Microsoft SMTP Server
 id 15.2.1544.11; Fri, 9 Aug 2024 12:08:03 +0200
Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100])
 by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id
 8D73E1C006B; Fri,  9 Aug 2024 12:08:03 +0200 (CEST)
From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>
To: <dev@dpdk.org>
CC: <hofors@lysator.liu.se>, Heng Wang <heng.wang@ericsson.com>, "Stephen
 Hemminger" <stephen@networkplumber.org>, Joyce Kong <joyce.kong@arm.com>,
 Tyler Retzlaff <roretzla@linux.microsoft.com>,
 =?UTF-8?q?Morten=20Br=C3=B8rup?= <mb@smartsharesystems.com>,
 =?UTF-8?q?Mattias=20R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>
Subject: [PATCH v2 1/5] eal: extend bit manipulation functionality
Date: Fri, 9 Aug 2024 11:58:25 +0200
Message-ID: <20240809095829.589396-2-mattias.ronnblom@ericsson.com>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20240809095829.589396-1-mattias.ronnblom@ericsson.com>
References: <20240809090439.589295-2-mattias.ronnblom@ericsson.com>
 <20240809095829.589396-1-mattias.ronnblom@ericsson.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: DB1PEPF00039232:EE_|VI1PR07MB10042:EE_
X-MS-Office365-Filtering-Correlation-Id: de3dec6c-7911-48a8-0dfa-08dcb85b2877
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
 ARA:13230040|1800799024|36860700013|376014|82310400026; 
X-Microsoft-Antispam-Message-Info: =?utf-8?B?cXhIKzU0b1hoWnVVeGI3VVNmK1lqRllTUjVUdnhnNTZlajZOWFlpTzkvcGFV?=
 =?utf-8?B?YUdRQk91dnM1SDFpRzhJa0o1bnF4K200bVNwWnE1WDNoenBDMEkwblB4VTZp?=
 =?utf-8?B?Q3N6NkJXUjRObEZKVFRFOVZ4bnJDemRkd0ZwSUJ5TkJGblBLbWF0WVhYbmlo?=
 =?utf-8?B?RW9vL0kvdm5XTTB2Yk1NQjArelpGY2NLZEdNWlQzdnRVWkswV29nR084K3FJ?=
 =?utf-8?B?SnJYV0ZvT2hya2xFdkp2TFJqc1grbkwvQTY3ak12SklPeGFxMHd1SGpIRlhW?=
 =?utf-8?B?dXlyR1FrU1Y5ejdUakMrK3ZWNk5oNzNQRTJNK29Fc1NjR1JXMFlrSHdaVy9q?=
 =?utf-8?B?QzZuaHJoRnN2YU9tdGNCMlh4bTl1cy9RNzZLeDB4QlhWMlNrRCtaWnJrK3hO?=
 =?utf-8?B?enptM2VrcjJrTk5TVjVvc0hzOU9GdVZPdWlNeFM1eG50MGxSMGxDM3lQcXFu?=
 =?utf-8?B?VEpHbHlxZzhEeXFyRFB1Zng4dW9WemVkd2ZpMDNVU2RnN1FWRUpUM2xURXQz?=
 =?utf-8?B?c1laRzdEb3FOQTN4UXZSVU5CM0tUSzZFaG5Zcm14SmFQVUs0YnBobnhpVFZE?=
 =?utf-8?B?bGRYR2s5c2p4RXl2aExOeko1bHN5ay83aEd6dmpZZHMyNDg1N09IQTZrNktv?=
 =?utf-8?B?MklpaXBRelhjbFh3R1k3TURPY01hdXhPS0p0NXN6bS93bFlrNGU4WS9GeHht?=
 =?utf-8?B?Zm1wODlPU1NVQWh4anB5dWpFb0VBWWtXTFc3VlJHd3dJNHFWWWF1dlZxcU5S?=
 =?utf-8?B?M3hCMjZWLzM0UUU5d3NpUnlEdWtmZjQya092a0lleVM1Q0VWWk56dFRuRVZB?=
 =?utf-8?B?OGIxcFEydTFUUTdMaHVvSEdBTFFBY002NkZQeU5oVnorZ21NeTFGdWhhUDFR?=
 =?utf-8?B?dWlEKy9mSGJIY2YvTGh1dFo2ZWJnczRrNGZ2cE5XVUF6eEdJc1YvaGdtTWNG?=
 =?utf-8?B?bnVzd0Vod3ZhYWVNRkFBeElTbFZLTkpNamEvRG1vUkkvdFhqdG5MeGZlS01Z?=
 =?utf-8?B?M2IvTmpMbm5UaThEREpPRnk5M0kwL0VPUExZa2V2QllrRkxXOGlRQ0pkcWc5?=
 =?utf-8?B?SUJqR3dub3RLbW1GYVExdGtrVk0yb2Q3WkZTY2Rpb2VtTUFwNjZSSEdVbXRY?=
 =?utf-8?B?ZWF4aWlWOVVOWjczUytFKzZnb2JjK2MxSVdNRGZjMTJwakFsTDg3Y3p0ZE1H?=
 =?utf-8?B?Q1E0YzN1NndZYk13b0lHeE85R3QwcjMrU0haTFk4dDFyNXBtTXNsTTY3UXhi?=
 =?utf-8?B?andJK3VRVXlqN3JDdkdCZFVxODF1ZTRoRHhaZ09xdkd3YWhQdHM4U3Z0aU1j?=
 =?utf-8?B?akRDcndJbm1ZMXFoUklEVHhOYXZuWEdmSkJFSzBYNFBsUm5YY09qcDJoTHdu?=
 =?utf-8?B?RXMxbWpsRWh6WWNteE5jaW9SRGFTZzBzWmlGZlVXaGk5bCszcGVwQWs5aGN3?=
 =?utf-8?B?VGhRUVgzRTlzRE5aeWJJVTdUMlRsdHkrem9FZFB4QzFFbWVjemRaeVQzanA3?=
 =?utf-8?B?QWpoVk9OT1BtN0tqTUp6LytaeWRxZjRwd1RSN0ZCY0gzdkZ2MTdJV3VVQVYz?=
 =?utf-8?B?WlpYUEZPZFozZW1paHRoYys5QWw0Ym5TekZKdjZsWi9aTXA3YkpJY0ZLOTFN?=
 =?utf-8?B?b3hsTk5IQkpRRjRzM0xPSEljd2xMNjdlNVlHbDBWRVZuVWxSb2hlakRlZjRV?=
 =?utf-8?B?Y0ZydTFUZkV6dTk0dkxPblhjR2tBTUlOdlppQVZ4d0xDQ2syekxYck0zSEVr?=
 =?utf-8?B?cGpmYWgyVG95OHcxUHRXcEYxUitUWHVxL29uNmNmd2JhRmlwaENmQkltd0k3?=
 =?utf-8?B?WFhJUVZrdGhLVHZnbjZYQmN1NFFvVmhBK1U2WnVIbk9OT0wvSVZLSEdKektn?=
 =?utf-8?B?bm5TR25xMmFDZUtQV0RlamlBK2M1bXFCdWRyZmhHcU1EU0E9PQ==?=
X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net;
 CAT:NONE; SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026);
 DIR:OUT; SFP:1101; 
X-OriginatorOrg: ericsson.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2024 10:08:03.9256 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: de3dec6c-7911-48a8-0dfa-08dcb85b2877
X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f
X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74];
 Helo=[oa.msg.ericsson.com]
X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF00039232.eurprd03.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB10042
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Add functionality to test and modify the value of individual bits in
32-bit or 64-bit words.

These functions have no implications on memory ordering, atomicity and
does not use volatile and thus does not prevent any compiler
optimizations.

Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

--

RFC v6:
 * Have rte_bit_test() accept const-marked bitsets.

RFC v4:
 * Add rte_bit_flip() which, believe it or not, flips the value of a bit.
 * Mark macro-generated private functions as experimental.
 * Use macros to generate *assign*() functions.

RFC v3:
 * Work around lack of C++ support for _Generic (Tyler Retzlaff).
 * Fix ','-related checkpatch warnings.
---
 lib/eal/include/rte_bitops.h | 259 ++++++++++++++++++++++++++++++++++-
 1 file changed, 257 insertions(+), 2 deletions(-)

diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h
index 449565eeae..3297133e22 100644
--- a/lib/eal/include/rte_bitops.h
+++ b/lib/eal/include/rte_bitops.h
@@ -2,6 +2,7 @@
  * Copyright(c) 2020 Arm Limited
  * Copyright(c) 2010-2019 Intel Corporation
  * Copyright(c) 2023 Microsoft Corporation
+ * Copyright(c) 2024 Ericsson AB
  */
 
 #ifndef _RTE_BITOPS_H_
@@ -11,12 +12,14 @@
  * @file
  * Bit Operations
  *
- * This file defines a family of APIs for bit operations
- * without enforcing memory ordering.
+ * This file provides functionality for low-level, single-word
+ * arithmetic and bit-level operations, such as counting or
+ * setting individual bits.
  */
 
 #include <stdint.h>
 
+#include <rte_compat.h>
 #include <rte_debug.h>
 
 #ifdef __cplusplus
@@ -105,6 +108,196 @@ extern "C" {
 #define RTE_FIELD_GET64(mask, reg) \
 		((typeof(mask))(((reg) & (mask)) >> rte_ctz64(mask)))
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Test bit in word.
+ *
+ * Generic selection macro to test the value of a bit in a 32-bit or
+ * 64-bit word. The type of operation depends on the type of the @c
+ * addr parameter.
+ *
+ * This macro does not give any guarantees in regards to memory
+ * ordering or atomicity.
+ *
+ * @param addr
+ *   A pointer to the word to modify.
+ * @param nr
+ *   The index of the bit.
+ */
+#define rte_bit_test(addr, nr)					\
+	_Generic((addr),					\
+		uint32_t *: __rte_bit_test32,			\
+		const uint32_t *: __rte_bit_test32,		\
+		uint64_t *: __rte_bit_test64,			\
+		const uint64_t *: __rte_bit_test64)(addr, nr)
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Set bit in word.
+ *
+ * Generic selection macro to set a bit in a 32-bit or 64-bit
+ * word. The type of operation depends on the type of the @c addr
+ * parameter.
+ *
+ * This macro does not give any guarantees in regards to memory
+ * ordering or atomicity.
+ *
+ * @param addr
+ *   A pointer to the word to modify.
+ * @param nr
+ *   The index of the bit.
+ */
+#define rte_bit_set(addr, nr)				\
+	_Generic((addr),				\
+		 uint32_t *: __rte_bit_set32,		\
+		 uint64_t *: __rte_bit_set64)(addr, nr)
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Clear bit in word.
+ *
+ * Generic selection macro to clear a bit in a 32-bit or 64-bit
+ * word. The type of operation depends on the type of the @c addr
+ * parameter.
+ *
+ * This macro does not give any guarantees in regards to memory
+ * ordering or atomicity.
+ *
+ * @param addr
+ *   A pointer to the word to modify.
+ * @param nr
+ *   The index of the bit.
+ */
+#define rte_bit_clear(addr, nr)					\
+	_Generic((addr),					\
+		 uint32_t *: __rte_bit_clear32,			\
+		 uint64_t *: __rte_bit_clear64)(addr, nr)
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Assign a value to a bit in word.
+ *
+ * Generic selection macro to assign a value to a bit in a 32-bit or 64-bit
+ * word. The type of operation depends on the type of the @c addr parameter.
+ *
+ * This macro does not give any guarantees in regards to memory
+ * ordering or atomicity.
+ *
+ * @param addr
+ *   A pointer to the word to modify.
+ * @param nr
+ *   The index of the bit.
+ * @param value
+ *   The new value of the bit - true for '1', or false for '0'.
+ */
+#define rte_bit_assign(addr, nr, value)					\
+	_Generic((addr),						\
+		 uint32_t *: __rte_bit_assign32,			\
+		 uint64_t *: __rte_bit_assign64)(addr, nr, value)
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Flip a bit in word.
+ *
+ * Generic selection macro to change the value of a bit to '0' if '1'
+ * or '1' if '0' in a 32-bit or 64-bit word. The type of operation
+ * depends on the type of the @c addr parameter.
+ *
+ * This macro does not give any guarantees in regards to memory
+ * ordering or atomicity.
+ *
+ * @param addr
+ *   A pointer to the word to modify.
+ * @param nr
+ *   The index of the bit.
+ */
+#define rte_bit_flip(addr, nr)						\
+	_Generic((addr),						\
+		 uint32_t *: __rte_bit_flip32,				\
+		 uint64_t *: __rte_bit_flip64)(addr, nr)
+
+#define __RTE_GEN_BIT_TEST(family, fun, qualifier, size)		\
+	__rte_experimental						\
+	static inline bool						\
+	__rte_bit_ ## family ## fun ## size(const qualifier uint ## size ## _t *addr, \
+					    unsigned int nr)		\
+	{								\
+		RTE_ASSERT(nr < size);					\
+									\
+		uint ## size ## _t mask = (uint ## size ## _t)1 << nr;	\
+		return *addr & mask;					\
+	}
+
+#define __RTE_GEN_BIT_SET(family, fun, qualifier, size)			\
+	__rte_experimental						\
+	static inline void						\
+	__rte_bit_ ## family ## fun ## size(qualifier uint ## size ## _t *addr, \
+					    unsigned int nr)		\
+	{								\
+		RTE_ASSERT(nr < size);					\
+									\
+		uint ## size ## _t mask = (uint ## size ## _t)1 << nr;	\
+		*addr |= mask;						\
+	}								\
+
+#define __RTE_GEN_BIT_CLEAR(family, fun, qualifier, size)		\
+	__rte_experimental						\
+	static inline void						\
+	__rte_bit_ ## family ## fun ## size(qualifier uint ## size ## _t *addr, \
+					    unsigned int nr)		\
+	{								\
+		RTE_ASSERT(nr < size);					\
+									\
+		uint ## size ## _t mask = ~((uint ## size ## _t)1 << nr); \
+		(*addr) &= mask;					\
+	}								\
+
+#define __RTE_GEN_BIT_ASSIGN(family, fun, qualifier, size)		\
+	__rte_experimental						\
+	static inline void						\
+	__rte_bit_ ## family ## fun ## size(qualifier uint ## size ## _t *addr, \
+					    unsigned int nr, bool value) \
+	{								\
+		if (value)						\
+			__rte_bit_ ## family ## set ## size(addr, nr);	\
+		else							\
+			__rte_bit_ ## family ## clear ## size(addr, nr); \
+	}
+
+#define __RTE_GEN_BIT_FLIP(family, fun, qualifier, size)		\
+	__rte_experimental						\
+	static inline void						\
+	__rte_bit_ ## family ## fun ## size(qualifier uint ## size ## _t *addr, \
+					    unsigned int nr)		\
+	{								\
+		bool value;						\
+									\
+		value = __rte_bit_ ## family ## test ## size(addr, nr);	\
+		__rte_bit_ ## family ## assign ## size(addr, nr, !value); \
+	}
+
+__RTE_GEN_BIT_TEST(, test,, 32)
+__RTE_GEN_BIT_SET(, set,, 32)
+__RTE_GEN_BIT_CLEAR(, clear,, 32)
+__RTE_GEN_BIT_ASSIGN(, assign,, 32)
+__RTE_GEN_BIT_FLIP(, flip,, 32)
+
+__RTE_GEN_BIT_TEST(, test,, 64)
+__RTE_GEN_BIT_SET(, set,, 64)
+__RTE_GEN_BIT_CLEAR(, clear,, 64)
+__RTE_GEN_BIT_ASSIGN(, assign,, 64)
+__RTE_GEN_BIT_FLIP(, flip,, 64)
+
 /*------------------------ 32-bit relaxed operations ------------------------*/
 
 /**
@@ -787,6 +980,68 @@ rte_log2_u64(uint64_t v)
 
 #ifdef __cplusplus
 }
+
+/*
+ * Since C++ doesn't support generic selection (i.e., _Generic),
+ * function overloading is used instead. Such functions must be
+ * defined outside 'extern "C"' to be accepted by the compiler.
+ */
+
+#undef rte_bit_test
+#undef rte_bit_set
+#undef rte_bit_clear
+#undef rte_bit_assign
+#undef rte_bit_flip
+
+#define __RTE_BIT_OVERLOAD_SZ_2(fun, qualifier, size, arg1_type, arg1_name) \
+	static inline void						\
+	rte_bit_ ## fun(qualifier uint ## size ## _t *addr,		\
+			arg1_type arg1_name)				\
+	{								\
+		__rte_bit_ ## fun ## size(addr, arg1_name);		\
+	}
+
+#define __RTE_BIT_OVERLOAD_2(fun, qualifier, arg1_type, arg1_name)	\
+	__RTE_BIT_OVERLOAD_SZ_2(fun, qualifier, 32, arg1_type, arg1_name) \
+	__RTE_BIT_OVERLOAD_SZ_2(fun, qualifier, 64, arg1_type, arg1_name)
+
+#define __RTE_BIT_OVERLOAD_SZ_2R(fun, qualifier, size, ret_type, arg1_type, \
+				 arg1_name)				\
+	static inline ret_type						\
+	rte_bit_ ## fun(qualifier uint ## size ## _t *addr,		\
+			arg1_type arg1_name)				\
+	{								\
+		return __rte_bit_ ## fun ## size(addr, arg1_name);	\
+	}
+
+#define __RTE_BIT_OVERLOAD_2R(fun, qualifier, ret_type, arg1_type, arg1_name) \
+	__RTE_BIT_OVERLOAD_SZ_2R(fun, qualifier, 32, ret_type, arg1_type, \
+				 arg1_name)				\
+	__RTE_BIT_OVERLOAD_SZ_2R(fun, qualifier, 64, ret_type, arg1_type, \
+				 arg1_name)
+
+#define __RTE_BIT_OVERLOAD_SZ_3(fun, qualifier, size, arg1_type, arg1_name, \
+				arg2_type, arg2_name)			\
+	static inline void						\
+	rte_bit_ ## fun(uint ## size ## _t *addr, arg1_type arg1_name,	\
+			arg2_type arg2_name)				\
+	{								\
+		__rte_bit_ ## fun ## size(addr, arg1_name, arg2_name);	\
+	}
+
+#define __RTE_BIT_OVERLOAD_3(fun, qualifier, arg1_type, arg1_name, arg2_type, \
+			     arg2_name)					\
+	__RTE_BIT_OVERLOAD_SZ_3(fun, qualifier, 32, arg1_type, arg1_name, \
+				arg2_type, arg2_name)			\
+	__RTE_BIT_OVERLOAD_SZ_3(fun, qualifier, 64, arg1_type, arg1_name, \
+				arg2_type, arg2_name)
+
+__RTE_BIT_OVERLOAD_2R(test, const, bool, unsigned int, nr)
+__RTE_BIT_OVERLOAD_2(set,, unsigned int, nr)
+__RTE_BIT_OVERLOAD_2(clear,, unsigned int, nr)
+__RTE_BIT_OVERLOAD_3(assign,, unsigned int, nr, bool, value)
+__RTE_BIT_OVERLOAD_2(flip,, unsigned int, nr)
+
 #endif
 
 #endif /* _RTE_BITOPS_H_ */
-- 
2.34.1