provide toolchain abstraction for __builtin_ffs{,l,ll} gcc built-in
intrinsics.

Signed-off-by: Tyler Retzlaff <roret...@linux.microsoft.com>
---
 lib/eal/include/rte_bitops.h | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h
index 449565e..e157a45 100644
--- a/lib/eal/include/rte_bitops.h
+++ b/lib/eal/include/rte_bitops.h
@@ -405,6 +405,28 @@
        return (unsigned int)__popcnt64(v);
 }
 
+static inline unsigned int
+rte_ffs32(uint32_t v)
+{
+       unsigned long rv;
+
+       if (0 == _BitScanForward(&rv, v))
+               return 0;
+
+       return (unsigned int)rv + 1;
+}
+
+static inline unsigned int
+rte_ffs64(uint64_t v)
+{
+       unsigned long rv;
+
+       if (0 == _BitScanForward64(&rv, v))
+               return 0;
+
+       return (unsigned int)rv + 1;
+}
+
 #else
 
 /**
@@ -491,6 +513,18 @@
        return (unsigned int)__builtin_popcountll(v);
 }
 
+static inline unsigned int
+rte_ffs32(uint32_t v)
+{
+       return (unsigned int)__builtin_ffs(v);
+}
+
+static inline unsigned int
+rte_ffs64(uint64_t v)
+{
+       return (unsigned int)__builtin_ffsll(v);
+}
+
 #endif
 
 /**
-- 
1.8.3.1

Reply via email to