From d5887039761e42b91498f27a320afffa517d0a1a Mon Sep 17 00:00:00 2001 From: Shuo A Liu Date: Thu, 23 May 2019 13:27:40 +0800 Subject: [PATCH] hv: Add a helper to account bitmap weight Sometimes we need know the number of 1 in one bitmap. This patch provide a inline function bitmap_weight for it. Tracked-On: #3663 Signed-off-by: Jason Chen CJ Signed-off-by: Yu Wang Signed-off-by: Shuo A Liu Reviewed-by: Yin Fengwei Acked-by: Eddie Dong --- hypervisor/include/arch/x86/lib/bits.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hypervisor/include/arch/x86/lib/bits.h b/hypervisor/include/arch/x86/lib/bits.h index 3783f444a..addf22bad 100644 --- a/hypervisor/include/arch/x86/lib/bits.h +++ b/hypervisor/include/arch/x86/lib/bits.h @@ -291,4 +291,9 @@ build_bitmap_testandclear(bitmap_test_and_clear_lock, "q", uint64_t, BUS_LOCK) build_bitmap_testandclear(bitmap32_test_and_clear_nolock, "l", uint32_t, "") build_bitmap_testandclear(bitmap32_test_and_clear_lock, "l", uint32_t, BUS_LOCK) +static inline uint16_t bitmap_weight(uint64_t bits) +{ + return __builtin_popcountl(bits); +} + #endif /* BITS_H*/