Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/125712/?format=api
https://patches.dpdk.org/api/patches/125712/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1680309907-30879-3-git-send-email-roretzla@linux.microsoft.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<1680309907-30879-3-git-send-email-roretzla@linux.microsoft.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1680309907-30879-3-git-send-email-roretzla@linux.microsoft.com", "date": "2023-04-01T00:45:05", "name": "[v7,2/4] eal: provide abstracted bit count functions", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "7fc09a446ffcbdd343acffa9a9063f34b59f6348", "submitter": { "id": 2077, "url": "https://patches.dpdk.org/api/people/2077/?format=api", "name": "Tyler Retzlaff", "email": "roretzla@linux.microsoft.com" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1680309907-30879-3-git-send-email-roretzla@linux.microsoft.com/mbox/", "series": [ { "id": 27599, "url": "https://patches.dpdk.org/api/series/27599/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=27599", "date": "2023-04-01T00:45:03", "name": "eal: provide abstracted bit counting functions", "version": 7, "mbox": "https://patches.dpdk.org/series/27599/mbox/" } ], "comments": "https://patches.dpdk.org/api/patches/125712/comments/", "check": "success", "checks": "https://patches.dpdk.org/api/patches/125712/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "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])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 79BBE4288E;\n\tSat, 1 Apr 2023 02:45:37 +0200 (CEST)", "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id CCCC242D0D;\n\tSat, 1 Apr 2023 02:45:16 +0200 (CEST)", "from linux.microsoft.com (linux.microsoft.com [13.77.154.182])\n by mails.dpdk.org (Postfix) with ESMTP id 888AC410D1\n for <dev@dpdk.org>; Sat, 1 Apr 2023 02:45:10 +0200 (CEST)", "by linux.microsoft.com (Postfix, from userid 1086)\n id 83E7E20FFE18; Fri, 31 Mar 2023 17:45:09 -0700 (PDT)" ], "DKIM-Filter": "OpenDKIM Filter v2.11.0 linux.microsoft.com 83E7E20FFE18", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com;\n s=default; t=1680309909;\n bh=BCRpFAY6oJ7fHGCDde8UK3c6BsWpsC1AhapJh4VNZUY=;\n h=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n b=cESloz1TNDrTt5jyblnLR8SaNCz8mRWAgjk84DEhgmTg9/v9JhRHAeGSF7ioya58w\n jOqB2O79jsAUJKkVOVw/47CcY67dCv8/IFc48zaykIR1v6ep555C2f1IKMlvhExi5G\n lTnts8ooJmyiZmSlvkeh1O9CGM0tZFr46OP5Pgw4=", "From": "Tyler Retzlaff <roretzla@linux.microsoft.com>", "To": "dev@dpdk.org", "Cc": "thomas@monjalon.net, stephen@networkplumber.org, mb@smartsharesystems.com,\n bruce.richardson@intel.com, ferruh.yigit@amd.com,\n david.marchand@redhat.com, Tyler Retzlaff <roretzla@linux.microsoft.com>", "Subject": "[PATCH v7 2/4] eal: provide abstracted bit count functions", "Date": "Fri, 31 Mar 2023 17:45:05 -0700", "Message-Id": "<1680309907-30879-3-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>\n <1680309907-30879-1-git-send-email-roretzla@linux.microsoft.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org" }, "content": "Provide abstracted bit counting functions for count, leading and\ntrailing bits in v to hide compiler specific intrinsics and builtins.\n\nInclude basic unit test of following functions added.\n\n rte_clz32\n rte_clz64\n rte_ctz32\n rte_ctz64\n rte_popcount32\n rte_popcount64\n\nSigned-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>\nAcked-by: Morten Brørup <mb@smartsharesystems.com>\nAcked-by: Bruce Richardson <bruce.richardson@intel.com>\n---\n app/test/meson.build | 2 +\n app/test/test_bitcount.c | 136 ++++++++++++++++++++++++\n lib/eal/include/rte_bitops.h | 240 +++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 378 insertions(+)\n create mode 100644 app/test/test_bitcount.c", "diff": "diff --git a/app/test/meson.build b/app/test/meson.build\nindex b9b5432..dafd509 100644\n--- a/app/test/meson.build\n+++ b/app/test/meson.build\n@@ -13,6 +13,7 @@ test_sources = files(\n 'test_alarm.c',\n 'test_atomic.c',\n 'test_barrier.c',\n+ 'test_bitcount.c',\n 'test_bitops.c',\n 'test_bitmap.c',\n 'test_bpf.c',\n@@ -161,6 +162,7 @@ test_deps += ['bus_pci', 'bus_vdev']\n fast_tests = [\n ['acl_autotest', true, true],\n ['atomic_autotest', false, true],\n+ ['bitcount_autotest', true, true],\n ['bitmap_autotest', true, true],\n ['bpf_autotest', true, true],\n ['bpf_convert_autotest', true, true],\ndiff --git a/app/test/test_bitcount.c b/app/test/test_bitcount.c\nnew file mode 100644\nindex 0000000..5287ef7\n--- /dev/null\n+++ b/app/test/test_bitcount.c\n@@ -0,0 +1,136 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright (C) 2022 Microsoft Corporation\n+ */\n+\n+#include <limits.h>\n+#include <string.h>\n+\n+#include <rte_bitops.h>\n+#include <rte_debug.h>\n+\n+#include \"test.h\"\n+\n+RTE_LOG_REGISTER(bitcount_logtype_test, test.bitcount, INFO);\n+\n+static int\n+test_clz32(void)\n+{\n+\tsize_t leading;\n+\tuint32_t v = 0xffffffff;\n+\n+\tfor (leading = 0; v; leading++) {\n+\t\tRTE_TEST_ASSERT(rte_clz32(v) == leading,\n+\t\t \"Unexpected count.\");\n+\t\tv >>= 1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+test_clz64(void)\n+{\n+\tsize_t leading;\n+\tuint64_t v = 0xffffffffffffffff;\n+\n+\tfor (leading = 0; v; leading++) {\n+\t\tRTE_TEST_ASSERT(rte_clz64(v) == leading,\n+\t\t \"Unexpected count.\");\n+\t\tv >>= 1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+test_ctz32(void)\n+{\n+\tsize_t trailing;\n+\tuint32_t v = 1;\n+\n+\tfor (trailing = 0; v; trailing++) {\n+\t\tRTE_TEST_ASSERT(rte_ctz32(v) == trailing,\n+\t\t \"Unexpected count.\");\n+\t\tv <<= 1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+test_ctz64(void)\n+{\n+\tsize_t trailing;\n+\tuint64_t v = 1;\n+\n+\tfor (trailing = 0; v; trailing++) {\n+\t\tRTE_TEST_ASSERT(rte_ctz64(v) == trailing,\n+\t\t \"Unexpected count.\");\n+\t\tv <<= 1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+test_popcount32(void)\n+{\n+\tsize_t shift;\n+\tuint32_t v = 0;\n+\tconst size_t bits = sizeof(v) * CHAR_BIT;\n+\n+\tfor (shift = 0; shift < bits; shift++) {\n+\t\tRTE_TEST_ASSERT(rte_popcount32(v) == shift,\n+\t\t \"Unexpected count.\");\n+\t\tv <<= 1;\n+\t\tv |= 1;\n+\t}\n+\n+\tRTE_TEST_ASSERT(rte_popcount32(v) == bits,\n+\t \"Unexpected count.\");\n+\n+\treturn 0;\n+}\n+\n+static int\n+test_popcount64(void)\n+{\n+\tsize_t shift;\n+\tuint64_t v = 0;\n+\tconst size_t bits = sizeof(v) * CHAR_BIT;\n+\n+\tfor (shift = 0; shift < bits; shift++) {\n+\t\tRTE_TEST_ASSERT(rte_popcount64(v) == shift,\n+\t\t \"Unexpected count.\");\n+\t\tv <<= 1;\n+\t\tv |= 1;\n+\t}\n+\n+\tRTE_TEST_ASSERT(rte_popcount64(v) == bits,\n+\t \"Unexpected count.\");\n+\n+\treturn 0;\n+}\n+\n+static struct unit_test_suite bitcount_test_suite = {\n+\t.suite_name = \"bitcount autotest\",\n+\t.setup = NULL,\n+\t.teardown = NULL,\n+\t.unit_test_cases = {\n+\t\tTEST_CASE(test_clz32),\n+\t\tTEST_CASE(test_clz64),\n+\t\tTEST_CASE(test_ctz32),\n+\t\tTEST_CASE(test_ctz64),\n+\t\tTEST_CASE(test_popcount32),\n+\t\tTEST_CASE(test_popcount64),\n+\t\tTEST_CASES_END()\n+\t}\n+};\n+\n+static int\n+test_bitcount(void)\n+{\n+\treturn unit_test_suite_runner(&bitcount_test_suite);\n+}\n+\n+REGISTER_TEST_COMMAND(bitcount_autotest, test_bitcount);\ndiff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h\nindex 531479e..d45aa54 100644\n--- a/lib/eal/include/rte_bitops.h\n+++ b/lib/eal/include/rte_bitops.h\n@@ -1,5 +1,7 @@\n /* SPDX-License-Identifier: BSD-3-Clause\n * Copyright(c) 2020 Arm Limited\n+ * Copyright(c) 2010-2019 Intel Corporation\n+ * Copyright(c) 2023 Microsoft Corporation\n */\n \n #ifndef _RTE_BITOPS_H_\n@@ -275,6 +277,244 @@\n \treturn val & mask;\n }\n \n+#ifdef RTE_TOOLCHAIN_MSVC\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of leading 0-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of leading zero bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_clz32(uint32_t v)\n+{\n+\tunsigned long rv;\n+\n+\t(void)_BitScanReverse(&rv, v);\n+\n+\treturn (unsigned int)(sizeof(v) * CHAR_BIT - 1 - rv);\n+}\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of leading 0-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of leading zero bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_clz64(uint64_t v)\n+{\n+\tunsigned long rv;\n+\n+\t(void)_BitScanReverse64(&rv, v);\n+\n+\treturn (unsigned int)(sizeof(v) * CHAR_BIT - 1 - rv);\n+}\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of trailing 0-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of trailing zero bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_ctz32(uint32_t v)\n+{\n+\tunsigned long rv;\n+\n+\t(void)_BitScanForward(&rv, v);\n+\n+\treturn (unsigned int)rv;\n+}\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of trailing 0-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of trailing zero bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_ctz64(uint64_t v)\n+{\n+\tunsigned long rv;\n+\n+\t(void)_BitScanForward64(&rv, v);\n+\n+\treturn (unsigned int)rv;\n+}\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of 1-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of 1-bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_popcount32(uint32_t v)\n+{\n+\treturn (unsigned int)__popcnt(v);\n+}\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of 1-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of 1-bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_popcount64(uint64_t v)\n+{\n+\treturn (unsigned int)__popcnt64(v);\n+}\n+\n+#else\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of leading 0-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of leading zero bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_clz32(uint32_t v)\n+{\n+\treturn (unsigned int)__builtin_clz(v);\n+}\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of leading 0-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of leading zero bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_clz64(uint64_t v)\n+{\n+\treturn (unsigned int)__builtin_clzll(v);\n+}\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of trailing 0-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of trailing zero bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_ctz32(uint32_t v)\n+{\n+\treturn (unsigned int)__builtin_ctz(v);\n+}\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of trailing 0-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of trailing zero bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_ctz64(uint64_t v)\n+{\n+\treturn (unsigned int)__builtin_ctzll(v);\n+}\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of 1-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of 1-bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_popcount32(uint32_t v)\n+{\n+\treturn (unsigned int)__builtin_popcount(v);\n+}\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice\n+ *\n+ * Get the count of 1-bits in v.\n+ *\n+ * @param v\n+ * The value.\n+ * @return\n+ * The count of 1-bits.\n+ */\n+__rte_experimental\n+static inline unsigned int\n+rte_popcount64(uint64_t v)\n+{\n+\treturn (unsigned int)__builtin_popcountll(v);\n+}\n+\n+#endif\n+\n /**\n * Combines 32b inputs most significant set bits into the least\n * significant bits to construct a value with the same MSBs as x\n", "prefixes": [ "v7", "2/4" ] }{ "id": 125712, "url": "