Commit ac70b5aa authored by Jean-Philippe Brucker's avatar Jean-Philippe Brucker Committed by Will Deacon
Browse files

Add fls_long and roundup_pow_of_two helpers



It's always nice to have a log2 handy, and the vfio-pci code will need to
perform power of two allocation from an arbitrary size. Add fls_long and
roundup_pow_of_two, based on the GCC builtin.
Reviewed-by: default avatarPunit Agrawal <punit.agrawal@arm.com>
Signed-off-by: default avatarJean-Philippe Brucker <jean-philippe.brucker@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent b70d1b9f
......@@ -90,6 +90,20 @@ static inline void msleep(unsigned int msecs)
usleep(MSECS_TO_USECS(msecs));
}
/*
* Find last (most significant) bit set. Same implementation as Linux:
* fls(0) = 0, fls(1) = 1, fls(1UL << 63) = 64
*/
static inline int fls_long(unsigned long x)
{
return x ? sizeof(x) * 8 - __builtin_clzl(x) : 0;
}
static inline unsigned long roundup_pow_of_two(unsigned long x)
{
return x ? 1UL << fls_long(x - 1) : 0;
}
struct kvm;
void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size);
void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *hugetlbfs_path, u64 size);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment