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 380EE45E3C; Thu, 5 Dec 2024 21:36:16 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5F2DC40B9C; Thu, 5 Dec 2024 21:36:12 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id EA7B040A73 for ; Thu, 5 Dec 2024 21:36:09 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1213) id 4760220ACD86; Thu, 5 Dec 2024 12:36:09 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4760220ACD86 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1733430969; bh=ipP59q4a8bU8s687NkQfrAHZeX5VlXdNr+dNKGeKz0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Asb5bw2EfDLvw70X1CykMAuL03Ud9zadbWWp6htbFnoUgSchAO866BZB9ozselPN2 zsw7XPvap1G0qXmdW7Ym3q4uTqlbjPARuFGC1a/mrdcqQ1jqVQ4X/RRnEQpblGJm1R AD8JPdJDwFscuXjZA9UctNtvTTIW33IjoHnPwH/w= From: Andre Muezerie To: dev@dpdk.org Cc: Tyler Retzlaff Subject: [PATCH v2 2/3] eal: add rte ffs32 and rte ffs64 inline functions Date: Thu, 5 Dec 2024 12:35:49 -0800 Message-Id: <1733430950-10412-3-git-send-email-andremue@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1733430950-10412-1-git-send-email-andremue@linux.microsoft.com> References: <1710969879-23701-1-git-send-email-roretzla@linux.microsoft.com> <1733430950-10412-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 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h index deb1fd43f2..14074850ec 100644 --- a/lib/eal/include/rte_bitops.h +++ b/lib/eal/include/rte_bitops.h @@ -958,6 +958,28 @@ rte_popcount64(uint64_t v) return (unsigned int)__popcnt64(v); } +static inline unsigned int +rte_ffs32(uint32_t v) +{ + unsigned long rv; + + if (_BitScanForward(&rv, v) == 0) + return 0; + + return (unsigned int)rv + 1; +} + +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 +1066,18 @@ rte_popcount64(uint64_t v) return (unsigned int)__builtin_popcountll(v); } +static inline unsigned int +rte_ffs32(uint32_t v) +{ + return (unsigned int)__builtin_ffs(v); +} + +static inline unsigned int +rte_ffs64(uint64_t v) +{ + return (unsigned int)__builtin_ffsll(v); +} + #endif /** -- 2.47.0.vfs.0.3