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 C344F4612D; Fri, 24 Jan 2025 17:14:19 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CDF9F427A4; Fri, 24 Jan 2025 17:14:15 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 10F41402A3 for ; Fri, 24 Jan 2025 17:14:13 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1213) id 71E9A210D0C5; Fri, 24 Jan 2025 08:14:12 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 71E9A210D0C5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1737735252; bh=fDiAwirU3vn9Y4t2BzheyrL0Vi7MeteHvmpr7aVyyKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j2IhltUMaMAx2zAFLerbAIGeOyJqMd6WvfhAtLb1QyPAjhqv244Nxl+HUz9NpBzpP TSnkkbpxsU80qcr++jRDY5y2QQ57Sr7si2Dg1Bc9jf7sN0mwvGYDzSYrqMdcShOAhv SZfFBJG9h6jIeGVKLw9ct56Nbhl8OB4/LUKGDVKc= From: Andre Muezerie To: dev@dpdk.org Cc: Tyler Retzlaff Subject: [PATCH v3 2/3] eal: add rte ffs32 and rte ffs64 inline functions Date: Fri, 24 Jan 2025 08:14:03 -0800 Message-Id: <1737735244-23234-3-git-send-email-andremue@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1737735244-23234-1-git-send-email-andremue@linux.microsoft.com> References: <1710969879-23701-1-git-send-email-roretzla@linux.microsoft.com> <1737735244-23234-1-git-send-email-andremue@linux.microsoft.com> 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 From: Tyler Retzlaff Provide toolchain abstraction for __builtin_ffs{,l,ll} gcc built-in intrinsics. Signed-off-by: Tyler Retzlaff --- lib/eal/include/rte_bitops.h | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h index deb1fd43f2..0862fd4008 100644 --- a/lib/eal/include/rte_bitops.h +++ b/lib/eal/include/rte_bitops.h @@ -958,6 +958,48 @@ rte_popcount64(uint64_t v) return (unsigned int)__popcnt64(v); } +/** + * Search v from least significant bit (LSB) to the most + * significant bit (MSB) for a set bit (1). + * + * @param v + * The value. + * @return + * Bit index + 1 if a set bit is found, zero otherwise. + */ +__rte_experimental +static inline unsigned int +rte_ffs32(uint32_t v) +{ + unsigned long rv; + + if (_BitScanForward(&rv, v) == 0) + return 0; + + return (unsigned int)rv + 1; +} + +/** + * Search v from least significant bit (LSB) to the most + * significant bit (MSB) for a set bit (1). + * + * @param v + * The value. + * @return + * Bit index + 1 if a set bit is found, zero otherwise. + */ +__rte_experimental +static inline unsigned int +rte_ffs64(uint64_t v) +{ + unsigned long rv; + + if (_BitScanForward64(&rv, v) == 0) + return 0; + + return (unsigned int)rv + 1; +} + #else /** @@ -1044,6 +1086,38 @@ rte_popcount64(uint64_t v) return (unsigned int)__builtin_popcountll(v); } +/** + * Search v from least significant bit (LSB) to the most + * significant bit (MSB) for a set bit (1). + * + * @param v + * The value. + * @return + * Bit index + 1 if a set bit is found, zero otherwise. + */ +__rte_experimental +static inline unsigned int +rte_ffs32(uint32_t v) +{ + return (unsigned int)__builtin_ffs(v); +} + +/** + * Search v from least significant bit (LSB) to the most + * significant bit (MSB) for a set bit (1). + * + * @param v + * The value. + * @return + * Bit index + 1 if a set bit is found, zero otherwise. + */ +__rte_experimental +static inline unsigned int +rte_ffs64(uint64_t v) +{ + return (unsigned int)__builtin_ffsll(v); +} + #endif /** -- 2.47.2.vfs.0.1