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 2C13743C3A; Sat, 2 Mar 2024 15:02:40 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1FA3742D91; Sat, 2 Mar 2024 15:02:21 +0100 (CET) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2051.outbound.protection.outlook.com [40.107.6.51]) by mails.dpdk.org (Postfix) with ESMTP id 43A0C42D7F for ; Sat, 2 Mar 2024 15:02:18 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QeCCt5RuI75IPKzqiB7IetXF8fViaPSQ0Ttz1VyYla31hQCHUcULrx5sA/hjF/duVviLHQGKq3f0MSGo4JPkzXKsUeOovRXjl2OJWUP7f2ujKg7+pSQ6aP8FHb89fv3+wGtAwHRRmaqdrZshTVtvaTe5TN6kdrHN5JFdehvlHBdv+vpTCfJEstk+VajHtrX09HFnPSyci2KEOn7amKDD0w2Bv/1A8NGFf1yMVaG7O0k9MyL8eg+R27UONV+f8G9EjdffW/4tpctbN+TijisRBRJ1+m75TmvaAC93kiq0BiBGhUfOzAYJ96XCLm+ggS7vZ1ai8XvGM4KOH8ZwIuuigQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=ATefPDKtaeL69j85TFk+28OGJG3zToY8nOp0+gXqdwo=; b=RUZKst7jxtAe6okgRFEMhAL8jKU+Ecktl37hEhaEu51noNXPVHVpsx4J8UO/ge6Th1gSj5jGXDq3pU0dCPwcSbpBqHvm0s0NyDSWHwsYMtPIx1sWrRtI9lHji9tCbuuMp12X2uwG3DBNTbO8MAYbpKaVkHc5dAQhErCucftt4iUExpvmP212JOuPgV8zHQJuCYl5gu9/AFY/nXT+fwWU0otxaWjcvM7oBQKpjfAtZPO/31FQ3Ju2PtiSAgPSznZ6A3R/tqoeIMIhcaRS9j2MGULfbV1w60wdorNfz0W2gMhhjpszcGWgg6BdxefSz5tfTQBSkWQ1B3AOyaqz2PfGoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org 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=ATefPDKtaeL69j85TFk+28OGJG3zToY8nOp0+gXqdwo=; b=fmEap0AIl+tmNzSjFsXN2EuQ8NGUAxkfH7Nn0hiFXv3UTTLcuWQmC8mYY5VT8e9F0B+XE7XFUMiQqpIunNg1ufK8K5AaBynTzgXHJi5598uzQLgPjC9Fys9nJlP1mO2wYvF3x9dGK/5NJdBVZCx8zuTQknE4/m38Va3nz5uVKTHRmd/u7K6NXcDgyq2yrfkRNGU1LzWZeVrjjJpSTmjoWwUhrhQYMlTspAXI85aKOVDPdL3AMiV1bIsKUtk8/hNWx8EsPoNaV2+ipaDiO5GiUpiLmC8S4XsaTSKJnd61CdIeRR8i41LtEyxiIweUZmLy8G8Ev2pXzkK7yyWuyIIk5Q== Received: from DUZPR01CA0262.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b9::24) by AS8PR07MB7893.eurprd07.prod.outlook.com (2603:10a6:20b:39a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.36; Sat, 2 Mar 2024 14:02:17 +0000 Received: from DB1PEPF000509EF.eurprd03.prod.outlook.com (2603:10a6:10:4b9:cafe::fb) by DUZPR01CA0262.outlook.office365.com (2603:10a6:10:4b9::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.37 via Frontend Transport; Sat, 2 Mar 2024 14:02:17 +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 DB1PEPF000509EF.mail.protection.outlook.com (10.167.242.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Sat, 2 Mar 2024 14:02:16 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.61) with Microsoft SMTP Server id 15.2.1258.12; Sat, 2 Mar 2024 15:02:14 +0100 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 8A6741C006A; Sat, 2 Mar 2024 15:02:14 +0100 (CET) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , Heng Wang , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [RFC 2/7] eal: add generic bit manipulation macros Date: Sat, 2 Mar 2024 14:53:23 +0100 Message-ID: <20240302135328.531940-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240302135328.531940-1-mattias.ronnblom@ericsson.com> References: <20240302135328.531940-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: DB1PEPF000509EF:EE_|AS8PR07MB7893:EE_ X-MS-Office365-Filtering-Correlation-Id: 880724f5-f97d-497a-eca3-08dc3ac15e71 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 18Ymoka2Y63erc42Ffhuv6QJr2VGdC1UtlXuE/Qct6jOlnbIRypl55XWg7VwyyFpS4tof8BUguTesTSO6LtgaKMjxs2fBjP/U6JNKU8H8IDEWcYgUmh6zXzpyv/0wuHNybMHZBK9jM3VRqG+spmPWEd/qYH863Sa9HOUTRFYp4eFhNxEBRbpk3SPFzkfDCPzD5xDkYgDCLD1pDgKwVvCxV0AS+Ihc3V5pBRvZioAvXhqJwlXof9lzsbRQ2Icq0jCT3jSmFt0mfQojL+W8Foz9JpvipvvCi14JeFtWwpbjnn9Yw+vmi7shpU0IwMigrVP2IllpdO44z/aDeGLNz/0qrSw3I3X9ZAi59wzWxEzPBn1iX6ez+XdZq61rCa3jNXJEPtLrBELVoHTLJQAZh5+SYcZP/U87eHDkPTZfEHw96p/WHh2cMEbwRHXVfn31g1MrybBdKaH7X1vDyCuAeO+HcxONQ/ujYiA2PJO2BFTh0T9khVwQHKH3dPzndeXc3CCD7kHaj1k5MLDV2gV+RV1DVgvyNFA2pvl4ROue4JYNPGGRDDdodWEQYbgHrs9SLLJq6H10uNLza09DCzvkBOsjzrMijaxTc9BEB5+oWS37F3KIXV4dVAtU3349bDuK/F6qVKkoeCxwKqAyyBbkQWz9CbdMoadMXpQmzCAAH8VILu8u/wzJE2W+n1m7hsIFbDr4vJwzLz4KeLCZ3iqw1upFkIXYgBWzAX23nyy5eQCF8mEMQnEWbKBmtIpfpsCPO/O 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:(13230031)(36860700004)(82310400014)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2024 14:02:16.6609 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 880724f5-f97d-497a-eca3-08dc3ac15e71 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: DB1PEPF000509EF.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR07MB7893 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 Add bit-level test/set/clear/assign macros operating on both 32-bit and 64-bit words by means of C11 generic selection. Signed-off-by: Mattias Rönnblom --- lib/eal/include/rte_bitops.h | 81 ++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h index 9a368724d5..afd0f11033 100644 --- a/lib/eal/include/rte_bitops.h +++ b/lib/eal/include/rte_bitops.h @@ -107,6 +107,87 @@ extern "C" { #define RTE_FIELD_GET64(mask, reg) \ ((typeof(mask))(((reg) & (mask)) >> rte_ctz64(mask))) +/** + * 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, \ + uint64_t *: rte_bit_test64)(addr, nr) + +/** + * 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) + +/** + * 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) + +/** + * 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) + /** * Test if a particular bit in a 32-bit word is set. * -- 2.34.1