On 15-Nov-18 8:40 AM, Jerin Jacob wrote:
-----Original Message-----
Date: Wed, 14 Nov 2018 16:47:08 +0000
From: Anatoly Burakov <anatoly.bura...@intel.com>
To: dev@dpdk.org
CC: cristian.dumitre...@intel.com, tho...@monjalon.net,
bruce.richard...@intel.com, ferruh.yi...@intel.com,
jasvinder.si...@intel.com
Subject: [dpdk-dev] [PATCH v3 3/5] common: add missing implementations
X-Mailer: git-send-email 1.7.0.7
External Email
Implement missing functions for 32-bit safe bsf, as well as 64-bit
fls and log2.
Signed-off-by: Anatoly Burakov <anatoly.bura...@intel.com>
Acked-by: Cristian Dumitrescu <cristian.dumitre...@intel.com>
---
+/**
+ * Return the last (most-significant) bit set.
+ *
+ * @note The last (most significant) bit is at position 32.
s/position 32/position 64
+ * @note rte_fls_u32(0) = 0, rte_fls_u32(1) = 1, rte_fls_u32(0x80000000) = 32
Fix here too
IMO, it is better to add unit test case for newly added common functions
in test/test/test_common.c
Good catches and good ideas, thanks!
+ *
+ * @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);
+}
+
--
Thanks,
Anatoly