From patchwork Thu Jan 25 11:52:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 136133 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 80186439C1; Thu, 25 Jan 2024 12:56:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7073442DE3; Thu, 25 Jan 2024 12:56:45 +0100 (CET) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by mails.dpdk.org (Postfix) with ESMTP id 4DB5942DE3 for ; Thu, 25 Jan 2024 12:56:44 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4TLK4x2Kqvz1Q81V; Thu, 25 Jan 2024 19:54:57 +0800 (CST) Received: from dggpeml500024.china.huawei.com (unknown [7.185.36.10]) by mail.maildlp.com (Postfix) with ESMTPS id D85C41404F7; Thu, 25 Jan 2024 19:56:27 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 25 Jan 2024 19:56:27 +0800 From: Chengwen Feng To: , , , CC: Subject: [PATCH v2 1/8] eal: introduce more macro for bit definition Date: Thu, 25 Jan 2024 11:52:22 +0000 Message-ID: <20240125115229.41402-2-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240125115229.41402-1-fengchengwen@huawei.com> References: <20231121122651.7078-1-fengchengwen@huawei.com> <20240125115229.41402-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500024.china.huawei.com (7.185.36.10) 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 Introduce macros: 1. RTE_SHIFT_VAL64: get the uint64_t value which shifted by nr. 2. RTE_SHIFT_VAL32: get the uint32_t value which shifted by nr. 3. RTE_GENMASK64: generate a contiguous 64bit bitmask starting at bit position low and ending at position high. 4. RTE_GENMASK32: generate a contiguous 32bit bitmask starting at bit position low and ending at position high. 5. RTE_FIELD_GET64: extract a 64bit field element. 6. RTE_FIELD_GET32: extract a 32bit field element. Signed-off-by: Chengwen Feng --- lib/eal/include/rte_bitops.h | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h index 6bd8bae21a..bab08d53ec 100644 --- a/lib/eal/include/rte_bitops.h +++ b/lib/eal/include/rte_bitops.h @@ -39,6 +39,70 @@ extern "C" { */ #define RTE_BIT32(nr) (UINT32_C(1) << (nr)) +/** + * Get the uint64_t value which shifted by nr. + * + * @param val + * The value to be shifted. + * @param nr + * The bit number in range of 0 to (64 - width of val). + */ +#define RTE_SHIFT_VAL64(val, nr) (UINT64_C(val) << (nr)) + +/** + * Get the uint32_t value which shifted by nr. + * + * @param val + * The value to be shifted. + * @param nr + * The bit number in range of 0 to (32 - width of val). + */ +#define RTE_SHIFT_VAL32(val, nr) (UINT32_C(val) << (nr)) + +/** + * Generate a contiguous 64bit bitmask starting at bit position low + * and ending at position high. + * + * @param high + * High bit position. + * @param low + * Low bit position. + */ +#define RTE_GENMASK64(high, low) (((~UINT64_C(0)) << (low)) & (~UINT64_C(0) >> (63u - (high)))) + +/** + * Generate a contiguous 32bit bitmask starting at bit position low + * and ending at position high. + * + * @param high + * High bit position. + * @param low + * Low bit position. + */ +#define RTE_GENMASK32(high, low) (((~UINT32_C(0)) << (low)) & (~UINT32_C(0) >> (31u - (high)))) + +/** + * Extract a 64bit field element. + * + * @param mask + * shifted mask. + * @param reg + * value of entire bitfield. + */ +#define RTE_FIELD_GET64(mask, reg) \ + ((typeof(mask))(((reg) & (mask)) >> rte_ctz64(mask))) + +/** + * Extract a 32bit field element. + * + * @param mask + * shifted mask. + * @param reg + * value of entire bitfield. + */ +#define RTE_FIELD_GET32(mask, reg) \ + ((typeof(mask))(((reg) & (mask)) >> rte_ctz32(mask))) + /*------------------------ 32-bit relaxed operations ------------------------*/ /**