From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 8CA421BC7F for ; Thu, 20 Dec 2018 13:09:59 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Dec 2018 04:09:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,376,1539673200"; d="scan'208";a="260997380" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga004.jf.intel.com with ESMTP; 20 Dec 2018 04:09:57 -0800 Received: from sivswdev05.ir.intel.com (sivswdev05.ir.intel.com [10.243.17.64]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id wBKC9uME014135; Thu, 20 Dec 2018 12:09:56 GMT Received: from sivswdev05.ir.intel.com (localhost [127.0.0.1]) by sivswdev05.ir.intel.com with ESMTP id wBKC9uYk001199; Thu, 20 Dec 2018 12:09:56 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id wBKC9u1k001195; Thu, 20 Dec 2018 12:09:56 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: jerin.jacob@caviumnetworks.com, thomas@monjalon.net Date: Thu, 20 Dec 2018 12:09:49 +0000 Message-Id: <223b9255bd5283abab2d69dfb18e1b5ac12f6eef.1545307762.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> References: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> Subject: [dpdk-dev] [PATCH v2 3/4] common: add 64-bit fls function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Dec 2018 12:10:00 -0000 Add missing implementation for 64-bit fls function, and extend unit test to test the new function as well. Signed-off-by: Anatoly Burakov --- lib/librte_eal/common/include/rte_common.h | 18 ++++++++++++++++++ test/test/test_common.c | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index d102f2cec..7b50b8479 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -547,6 +547,24 @@ rte_bsf64_safe(uint64_t v, uint32_t *pos) return 1; } +/** + * Return the last (most-significant) bit set. + * + * @note The last (most significant) bit is at position 64. + * @note rte_fls_u64(0) = 0, rte_fls_u64(1) = 1, + * rte_fls_u64(0x8000000000000000) = 64 + * + * @param x + * The input parameter. + * @return + * The last (most-significant) bit set, or 0 if the input is 0. + */ +static inline int +rte_fls_u64(uint64_t x) +{ + return (x == 0) ? 0 : 64 - __builtin_clzll(x); +} + #ifndef offsetof /** Return the offset of a field in a structure. */ #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) diff --git a/test/test/test_common.c b/test/test/test_common.c index 4a42aaed8..f6dd4c18d 100644 --- a/test/test/test_common.c +++ b/test/test/test_common.c @@ -242,6 +242,8 @@ test_fls(void) }; for (i = 0; i < RTE_DIM(test); i++) { + uint64_t arg64; + arg = test[i].arg; rc = rte_fls_u32(arg); expected = test[i].rc; @@ -250,6 +252,25 @@ test_fls(void) arg, rc, expected); return TEST_FAILED; } + /* 64-bit version */ + arg = test[i].arg; + rc = rte_fls_u64(arg); + expected = test[i].rc; + if (rc != expected) { + printf("Wrong rte_fls_u64(0x%x) rc=%d, expected=%d\n", + arg, rc, expected); + return TEST_FAILED; + } + /* 64-bit version shifted by 32 bits */ + arg64 = (uint64_t)test[i].arg << 32; + rc = rte_fls_u64(arg64); + /* don't shift zero */ + expected = test[i].rc == 0 ? 0 : test[i].rc + 32; + if (rc != expected) { + printf("Wrong rte_fls_u64(0x%" PRIx64 ") rc=%d, expected=%d\n", + arg64, rc, expected); + return TEST_FAILED; + } } return 0; -- 2.17.1