[dpdk-stable] patch 'eal: introduce rte version of fls' has been queued to LTS release 17.11.5

Yongseok Koh yskoh at mellanox.com
Fri Nov 30 00:11:32 CET 2018


Hi,

FYI, your patch has been queued to LTS release 17.11.5

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 12/01/18. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the patch applied
to the branch. If the code is different (ie: not only metadata diffs), due for example to
a change in context or macro names, please double check it.

Thanks.

Yongseok

---
>From 91580aacc86f33a96ca7ecbca42b1dd22fb358b5 Mon Sep 17 00:00:00 2001
From: Jerin Jacob <jerin.jacob at caviumnetworks.com>
Date: Wed, 7 Nov 2018 06:59:03 +0000
Subject: [PATCH] eal: introduce rte version of fls

The function returns the last (most-significant) bit set.
Added unit testcase to verify rte_fls_u32().

Signed-off-by: Jerin Jacob <jerin.jacob at caviumnetworks.com>
---
 lib/librte_eal/common/include/rte_common.h | 19 ++++++++++++++++++
 test/test/test_common.c                    | 32 ++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index f1d24b86d..63bf6b612 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -369,6 +369,25 @@ rte_log2_u32(uint32_t v)
 	return rte_bsf32(v);
 }
 
+
+/**
+ * Return the last (most-significant) bit set.
+ *
+ * @note The last (most significant) bit is at position 32.
+ * @note rte_fls_u32(0) = 0, rte_fls_u32(1) = 1, rte_fls_u32(0x80000000) = 32
+ *
+ * @param x
+ *     The input parameter.
+ * @return
+ *     The last (most-significant) bit set, or 0 if the input is 0.
+ */
+static inline int
+rte_fls_u32(uint32_t x)
+{
+	return (x == 0) ? 0 : 32 - __builtin_clz(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 ae3482da7..da2ff75b4 100644
--- a/test/test/test_common.c
+++ b/test/test/test_common.c
@@ -180,6 +180,37 @@ test_log2(void)
 }
 
 static int
+test_fls(void)
+{
+	struct fls_test_vector {
+		uint32_t arg;
+		int rc;
+	};
+	int expected, rc;
+	uint32_t i, arg;
+
+	const struct fls_test_vector test[] = {
+		{0x0, 0},
+		{0x1, 1},
+		{0x4000, 15},
+		{0x80000000, 32},
+	};
+
+	for (i = 0; i < RTE_DIM(test); i++) {
+		arg = test[i].arg;
+		rc = rte_fls_u32(arg);
+		expected = test[i].rc;
+		if (rc != expected) {
+			printf("Wrong rte_fls_u32(0x%x) rc=%d, expected=%d\n",
+				arg, rc, expected);
+			return TEST_FAILED;
+		}
+	}
+
+	return 0;
+}
+
+static int
 test_common(void)
 {
 	int ret = 0;
@@ -187,6 +218,7 @@ test_common(void)
 	ret |= test_macros(0);
 	ret |= test_misc();
 	ret |= test_log2();
+	ret |= test_fls();
 
 	return ret;
 }
-- 
2.11.0



More information about the stable mailing list