hv: lib: add ffz64_ex
Add ffz64_ex to find the first zero bit in a uint64_t array.
Note: the API is lockless.
@@ -129,6 +129,22 @@ static inline uint16_t ffz64(uint64_t value)
return ffs64(~value);
}
+
+/*
+ * find the first zero bit in a uint64_t array.
+ * @pre: the size must be multiple of 64.
+ */
+static inline uint64_t ffz64_ex(const uint64_t *addr, uint64_t size)
+{
+ uint64_t idx;
+
+ for (idx = 0; (idx << 6U) < size; idx++) {
+ if (addr[idx] != ~0UL)
+ return (idx << 6U) + ffz64(addr[idx]);
+ }
+
+ return size;
+}
/**
* Counts leading zeros.
*
