DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: Neil Horman <nhorman@tuxdriver.com>,
	John McNamara <john.mcnamara@intel.com>,
	Marko Kovacevic <marko.kovacevic@intel.com>,
	Cristian Dumitrescu <cristian.dumitrescu@intel.com>,
	thomas@monjalon.net, bruce.richardson@intel.com,
	ferruh.yigit@intel.com, jasvinder.singh@intel.com
Subject: [dpdk-dev] [PATCH v2 2/5] bitmap: rename rte_bsf64 and move to common header
Date: Wed, 14 Nov 2018 16:30:20 +0000	[thread overview]
Message-ID: <0c6c2e2b625a5ba43d94b1517d772590bff1a55b.1542212598.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <fbc68e4e563904b7758950cc50ecf0f753f4ec53.1542212598.git.anatoly.burakov@intel.com>
In-Reply-To: <9eb826f80f19422153d5a0ab611fb467a94eded0.1542197039.git.anatoly.burakov@intel.com>

Rename rte_bsf64 to rte_bsf64_safe (this is a "safe" version in
that it prevents undefined behavior by checking if incoming
parameter is zero) and move it to common header.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 doc/guides/rel_notes/deprecation.rst       |  5 +++++
 lib/librte_eal/common/include/rte_bitmap.h | 14 ++++----------
 lib/librte_eal/common/include/rte_common.h | 21 +++++++++++++++++++++
 3 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index 34b28234c..5d447e8eb 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -22,6 +22,11 @@ Deprecation Notices
 
     + ``rte_eal_devargs_type_count``
 
+* eal: function ``rte_bsf64`` in ``rte_bitmap.h`` has been renamed to
+  ``rte_bsf64_safe`` and moved to ``rte_common.h``. A new ``rte_bsf64`` function
+  will be added in release 19.05 in ``rte_common.h`` that follows convention set
+  by existing ``rte_bsf32`` function.
+
 * pci: Several exposed functions are misnamed.
   The following functions are deprecated starting from v17.11 and are replaced:
 
diff --git a/lib/librte_eal/common/include/rte_bitmap.h b/lib/librte_eal/common/include/rte_bitmap.h
index d2ed6204c..77727c828 100644
--- a/lib/librte_eal/common/include/rte_bitmap.h
+++ b/lib/librte_eal/common/include/rte_bitmap.h
@@ -93,14 +93,10 @@ __rte_bitmap_index2_set(struct rte_bitmap *bmp)
 	bmp->index2 = (((bmp->index1 << RTE_BITMAP_SLAB_BIT_SIZE_LOG2) + bmp->offset1) << RTE_BITMAP_CL_SLAB_SIZE_LOG2);
 }
 
-static inline int
+static inline int __rte_deprecated
 rte_bsf64(uint64_t slab, uint32_t *pos)
 {
-	if (slab == 0)
-		return 0;
-
-	*pos = __builtin_ctzll(slab);
-	return 1;
+	return rte_bsf64_safe(slab, pos);
 }
 
 static inline uint32_t
@@ -408,9 +404,8 @@ __rte_bitmap_scan_search(struct rte_bitmap *bmp)
 	value1 = bmp->array1[bmp->index1];
 	value1 &= __rte_bitmap_mask1_get(bmp);
 
-	if (rte_bsf64(value1, &bmp->offset1)) {
+	if (rte_bsf64_safe(value1, &bmp->offset1))
 		return 1;
-	}
 
 	__rte_bitmap_index1_inc(bmp);
 	bmp->offset1 = 0;
@@ -419,9 +414,8 @@ __rte_bitmap_scan_search(struct rte_bitmap *bmp)
 	for (i = 0; i < bmp->array1_size; i ++, __rte_bitmap_index1_inc(bmp)) {
 		value1 = bmp->array1[bmp->index1];
 
-		if (rte_bsf64(value1, &bmp->offset1)) {
+		if (rte_bsf64_safe(value1, &bmp->offset1))
 			return 1;
-		}
 	}
 
 	return 0;
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 87f0f6302..7609840da 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -491,6 +491,27 @@ rte_fls_u32(uint32_t x)
 	return (x == 0) ? 0 : 32 - __builtin_clz(x);
 }
 
+/**
+ * Searches the input parameter for the least significant set bit
+ * (starting from zero). Safe version (checks for input parameter being zero).
+ *
+ * @param v
+ *     The input parameter.
+ * @param pos
+ *     If ``v`` was not 0, this value will contain position of least significant
+ *     bit within the input parameter.
+ * @return
+ *     Returns 0 if ``v`` was 0, otherwise returns 1.
+ */
+static inline int
+rte_bsf64_safe(uint64_t v, uint32_t *pos)
+{
+	if (v == 0)
+		return 0;
+
+	*pos = __builtin_ctzll(v);
+	return 1;
+}
 
 #ifndef offsetof
 /** Return the offset of a field in a structure. */
-- 
2.17.1

  parent reply	other threads:[~2018-11-14 16:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-14 12:11 [dpdk-dev] [PATCH] bitmap: deprecate rte_bsf64 Anatoly Burakov
2018-11-14 16:30 ` [dpdk-dev] [PATCH v2 1/5] bitmap: remove useless code Anatoly Burakov
2018-11-14 16:40   ` Dumitrescu, Cristian
2018-11-14 16:47   ` [dpdk-dev] [PATCH v3 " Anatoly Burakov
2018-11-14 16:47   ` [dpdk-dev] [PATCH v3 2/5] bitmap: rename rte_bsf64 and move to common header Anatoly Burakov
2018-11-14 16:52     ` Singh, Jasvinder
2018-11-22 16:54       ` Hunt, David
2018-11-14 16:47   ` [dpdk-dev] [PATCH v3 3/5] common: add missing implementations Anatoly Burakov
2018-11-15  8:40     ` Jerin Jacob
2018-11-15 10:07       ` Burakov, Anatoly
2018-11-14 16:47   ` [dpdk-dev] [PATCH v3 4/5] memalloc: use library implementation of 64-bit log2 Anatoly Burakov
2018-11-14 16:47   ` [dpdk-dev] [PATCH v3 5/5] testpmd: " Anatoly Burakov
2018-11-15 10:08   ` [dpdk-dev] [PATCH v2 1/5] bitmap: remove useless code Burakov, Anatoly
2018-11-14 16:30 ` Anatoly Burakov [this message]
2018-11-14 16:30 ` [dpdk-dev] [PATCH v2 3/5] common: add missing implementations Anatoly Burakov
2018-11-14 16:30 ` [dpdk-dev] [PATCH v2 4/5] memalloc: use library implementation of 64-bit log2 Anatoly Burakov
2018-11-14 16:30 ` [dpdk-dev] [PATCH v2 5/5] testpmd: " Anatoly Burakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0c6c2e2b625a5ba43d94b1517d772590bff1a55b.1542212598.git.anatoly.burakov@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=jasvinder.singh@intel.com \
    --cc=john.mcnamara@intel.com \
    --cc=marko.kovacevic@intel.com \
    --cc=nhorman@tuxdriver.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).