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 9E87843C3A; Sat, 2 Mar 2024 15:02:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D8A1942DA7; Sat, 2 Mar 2024 15:02:19 +0100 (CET) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2052.outbound.protection.outlook.com [40.107.22.52]) by mails.dpdk.org (Postfix) with ESMTP id 21B56402BF 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=ZmdsXWvxmWs15gkVdQeBLRS7XL9peUBPaHskJ2Y7NTHDjPyv3eyhi1bYNYlsnWX7vZd7ka20KC6FrruULWgkzAwALPU9YZZaVQZvkqr0w36YYEpOi7ISsV8bWx/omCr5XN+KdGBo7A050k5reZAJ4vxmkr/1KUtELhxJILD2K0u88XfBpn0kU9BHFnlZLyjRzPWz7L0r829/fx5gyuuqR2b5zR13S6SVBAZdMcwJcimuw1YEGEFhU10usY4UDBgrhDbCNvOKGVMkzS+54AvQSxuxI0YDmX6QkAb+mfjmCKV6WDIm1G5Sp9QhkcPmaZjRjjjLrcCuTtGPo+UkxJBbFg== 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=8z3Sa+R7lxDoOAiWDmTLT1QEsTh2Vl65n2WcREml0WU=; b=igJMC3WOoeoQHZHMI3ZnZCo05DkeJ1Ox4rdcdaHFnzMTpV4FiHgMRR+66EzRu8jl3HbHTk08LgqON29vPtgFT4uj9ZyxCrhQdgk7DeDHvwe4tI4oCCwm9ExRXa+0kiBlnBeP1ZgNLo4vkPjbv6wSCoKp1ayGOUNS5Tz1HSk0qCuYb6ZWyDEBLC8UfOz6WvZv3/j9TOdv+hSVqN/FzCnY2ure4JIWsG6T4gzVWkJ24u/XzJCfIRwSw3khkCA+BoJDlU1BxViWdW+2AQfIbGJ2IR7ldzUB+L3EbokLOsvTf/m1sV4vOU2c0W/ZXrzWXom0PCqteEoOCtkw6aLyWYQzJg== 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=8z3Sa+R7lxDoOAiWDmTLT1QEsTh2Vl65n2WcREml0WU=; b=kVK1ZPRmkvcxOpW+cOW/fORJoFFaXgqjb/+EM+WsSmQcABiW5VAiH2/01s6viZq0Gxr42UIqf1N5v3z4cOO5eVM/7ASJqM8B6g+SusKedVs4g1MLBlKA0FHPNqCyN1PFepmTysw/mMGxG7JCgE6JaSCsAQ3eABxq3qkrODSU9gsdEWQp8qewPbfsqreCCiZO0738e3O3J8q8WmEhcPjZmFKdF2VkdvJG13vgfz2cfigpS8P5YU/1rjbUXPLE9awkuz0X5t9oxctXfFwoHUh1ZOKoSVj6enesOBfG7yszeU+Y/Iy2yqzK4TpxwmG+JPB2Rhjqf4RfV3lJBEHg32FPbw== Received: from AM5PR0101CA0007.eurprd01.prod.exchangelabs.com (2603:10a6:206:16::20) by AM8PR07MB8215.eurprd07.prod.outlook.com (2603:10a6:20b:322::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.41; Sat, 2 Mar 2024 14:02:16 +0000 Received: from AMS0EPF000001A8.eurprd05.prod.outlook.com (2603:10a6:206:16:cafe::17) by AM5PR0101CA0007.outlook.office365.com (2603:10a6:206:16::20) 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: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 AMS0EPF000001A8.mail.protection.outlook.com (10.167.16.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 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.63) with Microsoft SMTP Server id 15.2.1258.12; Sat, 2 Mar 2024 15:02:16 +0100 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 1F5621C006A; Sat, 2 Mar 2024 15:02:16 +0100 (CET) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , Heng Wang , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [RFC 4/7] eal: add generic once-type bit operations macros Date: Sat, 2 Mar 2024 14:53:25 +0100 Message-ID: <20240302135328.531940-5-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: AMS0EPF000001A8:EE_|AM8PR07MB8215:EE_ X-MS-Office365-Filtering-Correlation-Id: 35456850-a03f-4bba-374d-08dc3ac15e6e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UXuxOG1auY9dSvHEFHjTVNmVZvZIQ7+O8zJ+xw6Ii4O2WOYAJ76RJl9Hr+LPrL9LwJEUZJtmBnGuzJ0KM8XN1y7SkI5TWfWW05IWFV1eYc4BNt7mXC4llC2Vb94OerVZfKv8JWkqGc8IPLo53fmDhktmYBkumx/JHscgy0hA4Sb5Tp/P7K97FDJ87W0HDXkso2fAJiWcO1YR6ksSzxR0+j0xWzgdge4Hh3QLZM1nCxcr9oFBZGnq1PmngXk8L0YyiBmsXDwCYooOBlTOwcebw3wRBi8CvMQRG9hVslez5wLS3M3n+I1T2hzHvZtVoEu9s8MsbyTbLwvMeC1z6XWQbCQEtXQn8FvLy0fwfUdKZ3Bv6aRK4EzE8YghF8KWV9H5ghd0jhp/X/rFozHaoTjKOCaQEEcqaOnelW+71VedGzBrLV1rLMTVjOQLPRRdA8ntwejRpdI6BhEpJMq4/tYd5n1jC5pQaK9tC9qwpipfcf1qGB4r1YsAzU8hmp+mIbH+jaQvy8xgJ1ACLosS0VE403PJLGmXME5UvO6RIDvrLmZMmo4fg57T4W40MtlRf0J5lkzQNcZTwVUF4aTXS4/q3wp68jeJ0QR9ap/973SLL4FKX0p6dJis+U+aMpTOqBirGLN36Cb5AyNaVBij44+hkdNso3AFTpzt1iuoNH8i5Bd3O3SD877+6PSGwGynUesKl5g4KmWgEYJcGRvAI4aDu+L97T4aybrAQa77o7ChsCcO0tDpdMl+oRPJ2EeihpnT 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)(376005)(36860700004)(82310400014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2024 14:02:16.6523 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 35456850-a03f-4bba-374d-08dc3ac15e6e 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: AMS0EPF000001A8.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR07MB8215 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 macros for once-type bit operations 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 | 101 +++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h index 3118c51748..450334c751 100644 --- a/lib/eal/include/rte_bitops.h +++ b/lib/eal/include/rte_bitops.h @@ -188,6 +188,107 @@ extern "C" { uint32_t *: rte_bit_assign32, \ uint64_t *: rte_bit_assign64)(addr, nr, value) +/** + * Test exactly once if a particular bit in a word is set. + * + * Generic selection macro to exactly once 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 is guaranteed to result in exactly one memory load. See + * rte_bit_once_test32() for more information and uses cases for the + * "once" class of functions. + * + * rte_bit_once_test() does give any guarantees in regards to memory + * ordering or atomicity. + * + * @param addr + * A pointer to the word to query. + * @param nr + * The index of the bit. + * @return + * Returns true if the bit is set, and false otherwise. + */ + +#define rte_bit_once_test(addr, nr) \ + _Generic((addr), \ + uint32_t *: rte_bit_once_test32, \ + uint64_t *: rte_bit_once_test64)(addr, nr) + +/** + * Set bit in word exactly once. + * + * Set bit specified by @c nr in the word pointed to by @c addr to '1' + * exactly once. + * + * This function is guaranteed to result in exactly one memory load + * and exactly one memory store, *or* an atomic bit set operation. + * + * See rte_bit_test_once32() for more information and uses cases for + * the "once" class of functions. + * + * 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_once_set(addr, nr) \ + _Generic((addr), \ + uint32_t *: rte_bit_once_set32, \ + uint64_t *: rte_bit_once_set64)(addr, nr) + +/** + * Clear bit in word exactly once. + * + * Set bit specified by @c nr in the word pointed to by @c addr to '0' + * exactly once. + * + * This function is guaranteed to result in exactly one memory load + * and exactly one memory store, *or* an atomic bit clear operation. + * + * See rte_bit_test_once32() for more information and uses cases for + * the "once" class of functions. + * + * 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_once_clear(addr, nr) \ + _Generic((addr), \ + uint32_t *: rte_bit_once_clear32, \ + uint64_t *: rte_bit_once_clear64)(addr, nr) + +/** + * Assign a value to bit in a word exactly once. + * + * Set bit specified by @c nr in the word pointed to by @c addr to the + * value indicated by @c value exactly once. + * + * This function is guaranteed to result in exactly one memory load + * and exactly one memory store, *or* an atomic bit clear operation. + * + * This function 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_once_assign(addr, nr, value) \ + _Generic((addr), \ + uint32_t *: rte_bit_once_assign32, \ + uint64_t *: rte_bit_once_assign64)(addr, nr, value) + /** * Test if a particular bit in a 32-bit word is set. * -- 2.34.1