vppinfra: few bitops inlines 25/34825/2
authorDamjan Marion <damarion@cisco.com>
Wed, 5 Jan 2022 13:06:34 +0000 (14:06 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Wed, 5 Jan 2022 17:01:49 +0000 (17:01 +0000)
Change-Id: I9aa01fafd5329a399aa9d72a6e2cc6c9d65dc85c
Type: improvement
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/vppinfra/bitops.h

index 17ad49f..0436569 100644 (file)
@@ -176,6 +176,32 @@ do {                                                                       \
     }                                                                  \
 } while (0)
 
+static_always_inline u64
+reset_lowest_set_bit (u64 x)
+{
+#ifdef __BMI__
+  return _blsr_u64 (x);
+#else
+  return x & (x - 1);
+#endif
+}
+
+static_always_inline u64
+get_lowest_set_bit (u64 x)
+{
+#ifdef __BMI__
+  return _blsi_u64 (x);
+#else
+  return x & -x;
+#endif
+}
+
+static_always_inline u64
+get_lowest_set_bit_index (u64 x)
+{
+  return __builtin_ctzll (x);
+}
+
 #endif /* included_clib_bitops_h */
 
 /*