Skip to content

Commit

Permalink
hv: lib: add ffz64_ex
Browse files Browse the repository at this point in the history
Add ffz64_ex to find the first zero bit in a uint64_t array.
Note: the API is lockless.

Signed-off-by: Li, Fei1 <fei1.li@intel.com>
  • Loading branch information
lifeix authored and lijinxia committed Aug 17, 2018
1 parent 5381738 commit 709cd57
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions hypervisor/include/lib/bits.h
Expand Up @@ -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.
*
Expand Down

0 comments on commit 709cd57

Please sign in to comment.