From patchwork Wed Nov 23 22:14:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 120120 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 C920FA00C2; Wed, 23 Nov 2022 23:14:57 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7C0A642DAE; Wed, 23 Nov 2022 23:14:55 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 5980942DA9 for ; Wed, 23 Nov 2022 23:14:53 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id 8A5A220B83C2; Wed, 23 Nov 2022 14:14:52 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8A5A220B83C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669241692; bh=dUG2lrQsCT8l01AEIVtNeEp90jAmY60yp1geVthNGzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=paqB24eAF9bcwNumVK5k+YhZkpC6VxVD2p5O7WdhRxS0Ba8NPgoRpLv9XWG05PHFO SO2iA1XvoAlG8vpmVg71p8dnljD2QD6HKh5Y/JE8bzEme36V8pQQz+et7mJJRB0oeq Xb99t1ebJQpHCLHnBMmQGZv3Oh7EO1xOwFT/muVc= From: Tyler Retzlaff To: dev@dpdk.org Cc: Tyler Retzlaff Subject: [PATCH 1/2] eal: provide leading and trailing zero bit count abstraction Date: Wed, 23 Nov 2022 14:14:46 -0800 Message-Id: <1669241687-18810-2-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669241687-18810-1-git-send-email-roretzla@linux.microsoft.com> References: <1669241687-18810-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 an abstraction for leading and trailing zero bit counting functions to hide compiler specific intrinsics and builtins. Signed-off-by: Tyler Retzlaff --- lib/eal/include/meson.build | 1 + lib/eal/include/rte_bitcount.h | 257 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 lib/eal/include/rte_bitcount.h diff --git a/lib/eal/include/meson.build b/lib/eal/include/meson.build index cfcd40a..8ff1d65 100644 --- a/lib/eal/include/meson.build +++ b/lib/eal/include/meson.build @@ -5,6 +5,7 @@ includes += include_directories('.') headers += files( 'rte_alarm.h', + 'rte_bitcount.h', 'rte_bitmap.h', 'rte_bitops.h', 'rte_branch_prediction.h', diff --git a/lib/eal/include/rte_bitcount.h b/lib/eal/include/rte_bitcount.h new file mode 100644 index 0000000..2f4dd38 --- /dev/null +++ b/lib/eal/include/rte_bitcount.h @@ -0,0 +1,257 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (C) 2022 Microsoft Corporation + */ + +#ifndef EAL_BITCOUNT_H +#define EAL_BITCOUNT_H + +#include + +#ifdef RTE_TOOLCHAIN_MSVC + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of leading 0-bits in v. + * + * @param v + * The value. + * @return + * The count of leading zero bits. + */ +__rte_experimental +static inline unsigned +rte_clz(unsigned int v) +{ + unsigned long rv; + + (void)_BitScanReverse(&rv, v); + + return (unsigned)rv; +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of leading 0-bits in v. + * + * @param v + * The value. + * @return + * The count of leading zero bits. + */ +__rte_experimental +static inline unsigned +rte_clzl(unsigned long v) +{ + unsigned long rv; + + (void)_BitScanReverse(&rv, v); + + return (unsigned)rv; +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of leading 0-bits in v. + * + * @param v + * The value. + * @return + * The count of leading zero bits. + */ +__rte_experimental +static inline unsigned +rte_clzll(unsigned long long v) +{ + unsigned long rv; + + (void)_BitScanReverse64(&rv, v); + + return (unsigned)rv; +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of trailing 0-bits in v. + * + * @param v + * The value. + * @return + * The count of trailing zero bits. + */ +__rte_experimental +static inline unsigned +rte_ctz(unsigned int v) +{ + unsigned long rv; + + (void)_BitScanForward(&rv, v); + + return (unsigned)rv; +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of trailing 0-bits in v. + * + * @param v + * The value. + * @return + * The count of trailing zero bits. + */ +__rte_experimental +static inline unsigned +rte_ctzl(unsigned long v) +{ + unsigned long rv; + + (void)_BitScanForward(&rv, v); + + return (unsigned)rv; +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of trailing 0-bits in v. + * + * @param v + * The value. + * @return + * The count of trailing zero bits. + */ +__rte_experimental +static inline unsigned +rte_ctzll(unsigned long long v) +{ + unsigned long rv; + + (void)_BitScanForward64(&rv, v); + + return (unsigned)rv; +} + +#else + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of leading 0-bits in v. + * + * @param v + * The value. + * @return + * The count of leading zero bits. + */ +__rte_experimental +static inline unsigned +rte_clz(unsigned int v) +{ + return (unsigned)__builtin_clz(v); +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of leading 0-bits in v. + * + * @param v + * The value. + * @return + * The count of leading zero bits. + */ +__rte_experimental +static inline unsigned +rte_clzl(unsigned long v) +{ + return (unsigned)__builtin_clzl(v); +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of leading 0-bits in v. + * + * @param v + * The value. + * @return + * The count of leading zero bits. + */ +__rte_experimental +static inline unsigned +rte_clzll(unsigned long v) +{ + return (unsigned)__builtin_clzll(v); +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of trailing 0-bits in v. + * + * @param v + * The value. + * @return + * The count of trailing zero bits. + */ +__rte_experimental +static inline unsigned +rte_ctz(unsigned int v) +{ + return (unsigned)__builtin_ctz(v); +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of trailing 0-bits in v. + * + * @param v + * The value. + * @return + * The count of trailing zero bits. + */ +__rte_experimental +static inline unsigned +rte_ctzl(unsigned long v) +{ + return (unsigned)__builtin_ctzl(v); +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Get the count of trailing 0-bits in v. + * + * @param v + * The value. + * @return + * The count of trailing zero bits. + */ +__rte_experimental +static inline unsigned +rte_ctzll(unsigned long v) +{ + return (unsigned)__builtin_ctzll(v); +} + +#endif + +#endif /* EAL_BITCOUNT_H */ + From patchwork Wed Nov 23 22:14:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 120121 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 5599DA00C2; Wed, 23 Nov 2022 23:15:03 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 73AD840E5A; Wed, 23 Nov 2022 23:14:56 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 000D742DA9 for ; Wed, 23 Nov 2022 23:14:53 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id 5CED420B83CB; Wed, 23 Nov 2022 14:14:53 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5CED420B83CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669241693; bh=shh2OIO65oOPvBzjsYO7wj7MYFqMwSukc3FDBi30hdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TgLLMvwNm5hZ2+BpoYPAy/NYaZd7hPO3NhsySar9jSfIZ1F/v/PIssfYcbyZF1YbP 19JPB5gWkEzho+LKrWNDMEP+adaSbROO0hSzvJLpA4iMld++cqapPa7i9PI4fiWYR0 oq0GVFh48ZfRjzVq3BsapSb2VQJpsJFi2E401yfo= From: Tyler Retzlaff To: dev@dpdk.org Cc: Tyler Retzlaff Subject: [PATCH 2/2] test/bitcount: add bitcount tests Date: Wed, 23 Nov 2022 14:14:47 -0800 Message-Id: <1669241687-18810-3-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669241687-18810-1-git-send-email-roretzla@linux.microsoft.com> References: <1669241687-18810-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 basic unit test of following functions rte_clz rte_clzl rte_clzll rte_ctz rte_ctzl rte_ctzll Signed-off-by: Tyler Retzlaff --- app/test/meson.build | 2 ++ app/test/test_bitcount.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 app/test/test_bitcount.c diff --git a/app/test/meson.build b/app/test/meson.build index f34d19e..d1277bc 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -13,6 +13,7 @@ test_sources = files( 'test_alarm.c', 'test_atomic.c', 'test_barrier.c', + 'test_bitcount.c', 'test_bitops.c', 'test_bitmap.c', 'test_bpf.c', @@ -160,6 +161,7 @@ test_deps += ['bus_pci', 'bus_vdev'] fast_tests = [ ['acl_autotest', true, true], ['atomic_autotest', false, true], + ['bitcount_autotest', true, true], ['bitmap_autotest', true, true], ['bpf_autotest', true, true], ['bpf_convert_autotest', true, true], diff --git a/app/test/test_bitcount.c b/app/test/test_bitcount.c new file mode 100644 index 0000000..7b71fdf --- /dev/null +++ b/app/test/test_bitcount.c @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (C) 2022 Microsoft Corporation + */ + +#include + +#include +#include + +#include "test.h" + +RTE_LOG_REGISTER(bitcount_logtype_test, test.bitcount, INFO); + +static int +test_clz(void) +{ + unsigned int v = 1; + RTE_TEST_ASSERT(rte_clz(v) == sizeof(v) * CHAR_BIT - 1, + "Unexpected count."); + + return 0; +} + +static int +test_clzl(void) +{ + unsigned long v = 1; + RTE_TEST_ASSERT(rte_clzl(v) == sizeof(v) * CHAR_BIT - 1, + "Unexpected count."); + + return 0; +} + +static int +test_clzll(void) +{ + unsigned long long v = 1; + RTE_TEST_ASSERT(rte_clzll(v) == sizeof(v) * CHAR_BIT - 1, + "Unexpected count."); + + return 0; +} + +static int +test_ctz(void) +{ + unsigned int v = 2; + RTE_TEST_ASSERT(rte_ctz(v) == 1, "Unexpected count."); + + return 0; +} + +static int +test_ctzl(void) +{ + unsigned long v = 2; + RTE_TEST_ASSERT(rte_ctzl(v) == 1, "Unexpected count."); + + return 0; +} + +static int +test_ctzll(void) +{ + unsigned long long v = 2; + RTE_TEST_ASSERT(rte_ctzll(v) == 1, "Unexpected count."); + + return 0; +} + +static struct unit_test_suite bitcount_test_suite = { + .suite_name = "bitcount autotest", + .setup = NULL, + .teardown = NULL, + .unit_test_cases = { + TEST_CASE(test_clz), + TEST_CASE(test_clzl), + TEST_CASE(test_clzll), + TEST_CASE(test_ctz), + TEST_CASE(test_ctzl), + TEST_CASE(test_ctzll), + TEST_CASES_END() + } +}; + +static int +test_bitcount(void) +{ + return unit_test_suite_runner(&bitcount_test_suite); +} + +REGISTER_TEST_COMMAND(bitcount_autotest, test_bitcount); From patchwork Sat Apr 1 00:45:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 125708 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 82DB54288E; Sat, 1 Apr 2023 02:45:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0953440DD8; Sat, 1 Apr 2023 02:45:12 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 5A43540223 for ; Sat, 1 Apr 2023 02:45:10 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 9075720FFE1C; Fri, 31 Mar 2023 17:45:09 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9075720FFE1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680309909; bh=34IKYBunb04HS1qRooiE4p8NYIncGboyuj7EPIu8p0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dHaF/J4BZoqva7aBLf4OMUzHNRTSYBmF7vDkUlwQOQdGcdQqfg/WXayWJ5GXif9sa 86ZLIVJmS9MonESw09F6h0V3YqMQdgu5KYpBID06VnHpNrE0j0Q1U5u/AOK2Py2D9u SwFRIkJq86mLtwVNVVq5Hm7BHwvaTj3el2veWdEE= From: Tyler Retzlaff To: dev@dpdk.org Cc: thomas@monjalon.net, stephen@networkplumber.org, mb@smartsharesystems.com, bruce.richardson@intel.com, ferruh.yigit@amd.com, david.marchand@redhat.com, Tyler Retzlaff Subject: [PATCH v7 3/4] pipeline: add include of bitops Date: Fri, 31 Mar 2023 17:45:06 -0700 Message-Id: <1680309907-30879-4-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1680309907-30879-1-git-send-email-roretzla@linux.microsoft.com> References: <1669241687-18810-1-git-send-email-roretzla@linux.microsoft.com> <1680309907-30879-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 Include rte_bitops.h with the inline functions moving this include is now needed. Signed-off-by: Tyler Retzlaff --- lib/pipeline/rte_swx_pipeline_internal.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h index 2f24e1a..a67b6e9 100644 --- a/lib/pipeline/rte_swx_pipeline_internal.h +++ b/lib/pipeline/rte_swx_pipeline_internal.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include