162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
362306a36Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
462306a36Sopenharmony_ci * for more details.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci#ifndef _ASM_ARCH_HWEIGHT_H
862306a36Sopenharmony_ci#define _ASM_ARCH_HWEIGHT_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifdef ARCH_HAS_USABLE_BUILTIN_POPCOUNT
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <asm/types.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cistatic inline unsigned int __arch_hweight32(unsigned int w)
1562306a36Sopenharmony_ci{
1662306a36Sopenharmony_ci	return __builtin_popcount(w);
1762306a36Sopenharmony_ci}
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cistatic inline unsigned int __arch_hweight16(unsigned int w)
2062306a36Sopenharmony_ci{
2162306a36Sopenharmony_ci	return __builtin_popcount(w & 0xffff);
2262306a36Sopenharmony_ci}
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_cistatic inline unsigned int __arch_hweight8(unsigned int w)
2562306a36Sopenharmony_ci{
2662306a36Sopenharmony_ci	return __builtin_popcount(w & 0xff);
2762306a36Sopenharmony_ci}
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cistatic inline unsigned long __arch_hweight64(__u64 w)
3062306a36Sopenharmony_ci{
3162306a36Sopenharmony_ci	return __builtin_popcountll(w);
3262306a36Sopenharmony_ci}
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#else
3562306a36Sopenharmony_ci#include <asm-generic/bitops/arch_hweight.h>
3662306a36Sopenharmony_ci#endif
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#endif /* _ASM_ARCH_HWEIGHT_H */
39