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 8597745777;
	Fri,  9 Aug 2024 11:14:19 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 76ADA42DC9;
	Fri,  9 Aug 2024 11:14:19 +0200 (CEST)
Received: from EUR03-DBA-obe.outbound.protection.outlook.com
 (mail-dbaeur03on2045.outbound.protection.outlook.com [40.107.104.45])
 by mails.dpdk.org (Postfix) with ESMTP id 78D7C40274
 for <dev@dpdk.org>; Fri,  9 Aug 2024 11:14:18 +0200 (CEST)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
 b=D6CvFyOCtZIq4YuPsUv98IOGtkv4sc6KGO4OdOsj1gAO119Etek0Qz4fdJZXKNkhc7NinSFGY64w3p8FejNkyV5WHbiJuw63gprE7b8LXEOMNdDtYrXxFgDLAOM6Ne5oRKVHfwg1DioUp4ydcGpEYfWQL+6fBE3onJMqWvBrjXwZqvSgxVGnTDJcBNWVpDNsKZZe7uQOmS1aM2NzgGnToNq656ob8kknB7iuoxPkl5wcS0z2BvbBQuYTiwpclsItPWc6P2w/xBt8rMLZHd1KZ3xSczsmgo09UyMIfmAMzojdJcQV2wFCjfBcl0oElFoOIPPAgZDOfLSuJdYLsGct7A==
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=uGaYNBWczZiaiy2F567USLR166LHBzCdDI8GvTpYwsg=;
 b=SL+HijfozMKAin7iDP2TIEtOnod416MLhLhXOCkakISukzvf/1hxjChjTZDaBqi+GHUizQ5ATOJf+UymR0YdbXuNr+A6+GBzcsnmK6D96e7l0BjnkniQouFrW9eF6XG/Pc7tQquoy3+hUCiCa0OUCUQdIf1l6ZUcHoT6kJo6gE2uwUugMSNAqR8xm0mQRSQi7lhy9a4MJdx4ANhZmUHlQv4uA7eE3bSkwvmc+DrEPjfe3S2cIH6UUWZsObDJmJTIJLvl/VrgP4l1E2YGXGGDt/nlhL3EcyhQtnzuCz8EHsRSgNkho0qhHFL22CJOvEpE+a6kC7F56zDIAAlM0Hm/AQ==
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=uGaYNBWczZiaiy2F567USLR166LHBzCdDI8GvTpYwsg=;
 b=nzGx8jaAsLtV4srtwPWa4O6SjpjrMxq4m3DusTGPkPf46Xm3qtj+zmO8j0olLB0cWjG3+X8gsO5N0d5FzvDl+YKs3KaPDKxhV4tgFkmM+kxTKgTrF95J2+/tR/ryDkAEn3zXli+/wBkVCAXOc5SPs0RLxQtGx00qZHkQJ0MQ7UiL/fSWzQvoPw3kyv/AZKIUkEdFZz3avWazp/vgz1bYJ9DFP6o43OB2EKyqw+lWqKOjT+/956ESxZN2+YFdCfcqsiqLWxoK8lHGsxvbUSOU/n7tHKHFZrXsOngeKOy4fvdI4qbLAoAlc5la+B6BdufP7sSvKDI6w9uzDU/5A5RJbg==
Received: from PR2P264CA0003.FRAP264.PROD.OUTLOOK.COM (2603:10a6:101::15) by
 AM7PR07MB6849.eurprd07.prod.outlook.com (2603:10a6:20b:1c1::9) 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 09:14:16 +0000
Received: from AM4PEPF00025F98.EURPRD83.prod.outlook.com
 (2603:10a6:101:0:cafe::e2) by PR2P264CA0003.outlook.office365.com
 (2603:10a6:101::15) 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 09:14:16 +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
 AM4PEPF00025F98.mail.protection.outlook.com (10.167.16.7) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.7875.2 via Frontend Transport; Fri, 9 Aug 2024 09:14:16 +0000
Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by
 smtp-central.internal.ericsson.com (100.87.178.63) with Microsoft SMTP Server
 id 15.2.1544.11; Fri, 9 Aug 2024 11:14:15 +0200
Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100])
 by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id
 8D5CE1C006B; Fri,  9 Aug 2024 11:14:15 +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 1/5] eal: extend bit manipulation functionality
Date: Fri, 9 Aug 2024 11:04:35 +0200
Message-ID: <20240809090439.589295-2-mattias.ronnblom@ericsson.com>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20240809090439.589295-1-mattias.ronnblom@ericsson.com>
References: <20240505083737.118649-2-mattias.ronnblom@ericsson.com>
 <20240809090439.589295-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: AM4PEPF00025F98:EE_|AM7PR07MB6849:EE_
X-MS-Office365-Filtering-Correlation-Id: 66e43faf-4b08-4850-0f0a-08dcb853a476
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
 ARA:13230040|1800799024|36860700013|82310400026|376014; 
X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZjMwMmZ4aFMrSmNEa0pzS2JUMnNneWYramZOdHMyZXQzOUloTDJPalluL3Zm?=
 =?utf-8?B?dFEyREtMUWJrNlYzS0hXcE1KcHY5RHZXdnVSZldiWDMzRzBaRjRYWHVBdHZL?=
 =?utf-8?B?cHlIb1AvWjNwSHdZSE4waC9maXZsb1lyY0VlMTV4UWRTMm5VNGtMYVBRbGIy?=
 =?utf-8?B?K3Y4aE5TYTg5dTJab1U5Qk5nME5lUUZsaWNHeDBiNDRVbTB6ZzBQNTRIR1Ni?=
 =?utf-8?B?Y0hYZXdPQncyVXhRMGZrMzNSZDl3bzJMVnZqajI2SFdIamFNTGYrZFQ2bTZ1?=
 =?utf-8?B?bUtCbThkY0kraE9pVk1tUUpKaFlmVG9EbzVsSHZPYm93VENHZHQ0Yk03dFgy?=
 =?utf-8?B?M2dsMi9ZWnRUTVVBNWNSVnNQR0tSVVZnYnJqc2MybUVDelZMN0hQeWd0OTBM?=
 =?utf-8?B?SUVrRVBkZXMzUjdVcEVHTkFEVUZNbEhNK01WSjdLWkwzRUdiOUVjR2cwVFdr?=
 =?utf-8?B?Qlp0eVk1WG5VblY4eERkMFc0a1E3RXVHQ2lidnlIUkY1NzI5WVFQU2VhYzAx?=
 =?utf-8?B?d3RXL1g4VUxaVzRjUnN0OE1BY2xqNEZRZHBhNmExTlY5dWFCdUd5bC84MmY1?=
 =?utf-8?B?SU0rQmFiSkRoYm5UcnlVbmFUcVBuU2dhNDFrYnhBRFA3SzNCZlBkanR3djhV?=
 =?utf-8?B?UjA0Sk4vOXR4aUhQSElPUmtuc2drKzhGeGhGMUlZcllidEp0TitKUGtPZ0tJ?=
 =?utf-8?B?VnZlOGJlbmNIckNJU05kY25NemY2VzNPTVRoZG5HRXVCWmkxNzczMzlQWnMz?=
 =?utf-8?B?Y0Q1OVlrNjllM1MwcEtaWDVrZmttTkhvcUFmbkNaSHhaWlZpeG5CaGRNWm91?=
 =?utf-8?B?RFI5TmtuRlpjZTE3S3RWVE1DcUxSUUVTV3FTSi9LL0tTYkFlcG5uS0Z6N0Za?=
 =?utf-8?B?Vjlvd3N3S1VNcEhDbFZwR3JYT3psTWl3bTZ2dUNyS0ZnNmh0N1VTVThnWTVV?=
 =?utf-8?B?Tk82UExjeUVVRXFGWXVtNTFjeUR2UUNFOE5EdWN0UkhkRy91bHdYS2RURnRP?=
 =?utf-8?B?eVptNkNVaVQvSXpjdXJlQ0Z4OGo2ajFyLzcwN1hPUHFZSUxTL2k5dFNjdElB?=
 =?utf-8?B?WXZZaWxlYzZNQkhXZDNrWSs2dEFsMWJRQlpUdll0c2V3K2ZkdUZOd0J3TitL?=
 =?utf-8?B?OEh4d0pGSE5aWE9jaUFjaEFoZUhsdE1TekhXZERGM0FreDR3OURYd0xTMmZj?=
 =?utf-8?B?MHU3UUVlZVhkQ29qdFdZVDJpazg0Q3Zkdlh1cHhGL3pMNEd4SktmYjljTlpv?=
 =?utf-8?B?d2twRDk1aElZSjdMZmpXNlNkTTZXWWdObnFJUVJOZ014bjRvbUZHV2lBeUJn?=
 =?utf-8?B?am44U1FGWWNwUVozVGJBbm10NVJsVk1zb1lwSzB0R3poV1dURysyVnZ5L2cx?=
 =?utf-8?B?VFh0eFpwN202VDM0T2hVYi9vQ1NRVW5QdC8vL0c4R1BQNDRlU1h3Qjl5c0RR?=
 =?utf-8?B?bGNERlV1MGU5T3E0UG81QUtkZjJydXhFWEd0ZEQySm9EK2VBYmxJSXVaRTZP?=
 =?utf-8?B?bUgvaTJBajc4UTdIdHVEMU1URy9QdFExMTE4djhyL2FXRU8rZUxValZZL0Ja?=
 =?utf-8?B?YmwwM1VUZFY0SHZuZG92a2hUSytmamFxbXhDdUkvM1JLRmVXTk9yWGcwbmdz?=
 =?utf-8?B?YW9ZRzhyKzNWeG5ieHJVNmJYSm5UVGhDUXM0MGJzaUw3emRCbUljUEx0WWNp?=
 =?utf-8?B?SkNiVkNvQkxreitLbGd1R3RVOUt4ZXllSzRLeGtTREhvTkZ3NlJJS1FCZE95?=
 =?utf-8?B?d1oxNDlhTkdhcWlhb3YwVmVnVW0rdjk5QUtGdW91bFFHSXgwVmpwY2lmdzRY?=
 =?utf-8?B?N1JqYzJOZkdCV3grWU9UeHQwTTIzb3NldGc5K2dVd0tieDh1WS9IaE5uMWpI?=
 =?utf-8?B?ckNIanA0cE1kQWE2UWVFMGZDZFJwK240V3I3ck4wU2kwQkE9PQ==?=
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)(82310400026)(376014);
 DIR:OUT; SFP:1101; 
X-OriginatorOrg: ericsson.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2024 09:14:16.0295 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 66e43faf-4b08-4850-0f0a-08dcb853a476
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: AM4PEPF00025F98.EURPRD83.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR07MB6849
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.

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.

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>
---
 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