18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
38c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
48c2ecf20Sopenharmony_ci * for more details.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#ifndef _ASM_ARCH_HWEIGHT_H
88c2ecf20Sopenharmony_ci#define _ASM_ARCH_HWEIGHT_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifdef ARCH_HAS_USABLE_BUILTIN_POPCOUNT
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <asm/types.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistatic inline unsigned int __arch_hweight32(unsigned int w)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	return __builtin_popcount(w);
178c2ecf20Sopenharmony_ci}
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistatic inline unsigned int __arch_hweight16(unsigned int w)
208c2ecf20Sopenharmony_ci{
218c2ecf20Sopenharmony_ci	return __builtin_popcount(w & 0xffff);
228c2ecf20Sopenharmony_ci}
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic inline unsigned int __arch_hweight8(unsigned int w)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	return __builtin_popcount(w & 0xff);
278c2ecf20Sopenharmony_ci}
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic inline unsigned long __arch_hweight64(__u64 w)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	return __builtin_popcountll(w);
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#else
358c2ecf20Sopenharmony_ci#include <asm-generic/bitops/arch_hweight.h>
368c2ecf20Sopenharmony_ci#endif
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#endif /* _ASM_ARCH_HWEIGHT_H */
39