From patchwork Wed Mar 20 21:24:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 138644 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 D34DE43D0A; Wed, 20 Mar 2024 22:24:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5B2C142E37; Wed, 20 Mar 2024 22:24:44 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 7D97942DF0 for ; Wed, 20 Mar 2024 22:24:41 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id BD85720B74C2; Wed, 20 Mar 2024 14:24:40 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BD85720B74C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1710969880; bh=dtBOzkA46rM1KI0WTIFF6Ulwp8sGxQQaFhWC+ev3QXo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TrR80MjLOd3fVD3sRw1uCuzPSe6znphP85lBfxzFwJySNI0Na2iaEYVdPfGz6vCGb pYOpdL0sqcxuqciH0TDxCBnzIXHkgAvj7MbHzqORbnSLDRVxdEhRy4SbyFvxRUBpR7 HMFAcQnhqGkbmWYpvbBOzPH8IKcrj5VDH0GjVwao= From: Tyler Retzlaff To: dev@dpdk.org Cc: Bruce Richardson , Joyce Kong , Konstantin Ananyev , Tyler Retzlaff Subject: [PATCH 2/2] eal: add rte ffs32 and rte ffs64 inline functions Date: Wed, 20 Mar 2024 14:24:39 -0700 Message-Id: <1710969879-23701-3-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1710969879-23701-1-git-send-email-roretzla@linux.microsoft.com> References: <1710969879-23701-1-git-send-email-roretzla@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 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 449565e..e157a45 100644 --- a/lib/eal/include/rte_bitops.h +++ b/lib/eal/include/rte_bitops.h @@ -405,6 +405,28 @@ return (unsigned int)__popcnt64(v); } +static inline unsigned int +rte_ffs32(uint32_t v) +{ + unsigned long rv; + + if (0 == _BitScanForward(&rv, v)) + return 0; + + return (unsigned int)rv + 1; +} + +static inline unsigned int +rte_ffs64(uint64_t v) +{ + unsigned long rv; + + if (0 == _BitScanForward64(&rv, v)) + return 0; + + return (unsigned int)rv + 1; +} + #else /** @@ -491,6 +513,18 @@ 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 /**