util: New function zero_rightmost_1bit().
[sliver-openvswitch.git] / lib / util.h
index 57527fc..8c9103c 100644 (file)
@@ -103,6 +103,14 @@ rightmost_1bit(uintmax_t x)
     return x & -x;
 }
 
+/* Returns 'x' with its rightmost 1-bit changed to a zero (e.g. 01011000 =>
+ * 01010000), or 0 if 'x' is 0. */
+static inline uintmax_t
+zero_rightmost_1bit(uintmax_t x)
+{
+    return x & (x - 1);
+}
+
 #ifndef MIN
 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
 #endif