/* SPDX-License-Identifier: GPL-2.0 */1#include <linux/export.h>2#include <linux/linkage.h>3#include <linux/objtool.h>45#include <asm/asm.h>67/*8* unsigned int __sw_hweight32(unsigned int w)9* %rdi: w10*/11SYM_FUNC_START(__sw_hweight32)12ANNOTATE_NOENDBR1314#ifdef CONFIG_X86_6415movl %edi, %eax # w16#endif17__ASM_SIZE(push,) %__ASM_REG(dx)18movl %eax, %edx # w -> t19shrl %edx # t >>= 120andl $0x55555555, %edx # t &= 0x5555555521subl %edx, %eax # w -= t2223movl %eax, %edx # w -> t24shrl $2, %eax # w_tmp >>= 225andl $0x33333333, %edx # t &= 0x3333333326andl $0x33333333, %eax # w_tmp &= 0x3333333327addl %edx, %eax # w = w_tmp + t2829movl %eax, %edx # w -> t30shrl $4, %edx # t >>= 431addl %edx, %eax # w_tmp += t32andl $0x0f0f0f0f, %eax # w_tmp &= 0x0f0f0f0f33imull $0x01010101, %eax, %eax # w_tmp *= 0x0101010134shrl $24, %eax # w = w_tmp >> 2435__ASM_SIZE(pop,) %__ASM_REG(dx)36RET37SYM_FUNC_END(__sw_hweight32)38EXPORT_SYMBOL(__sw_hweight32)3940/*41* No 32-bit variant, because it's implemented as an inline wrapper42* on top of __arch_hweight32():43*/44#ifdef CONFIG_X86_6445SYM_FUNC_START(__sw_hweight64)46ANNOTATE_NOENDBR47pushq %rdi48pushq %rdx4950movq %rdi, %rdx # w -> t51movabsq $0x5555555555555555, %rax52shrq %rdx # t >>= 153andq %rdx, %rax # t &= 0x555555555555555554movabsq $0x3333333333333333, %rdx55subq %rax, %rdi # w -= t5657movq %rdi, %rax # w -> t58shrq $2, %rdi # w_tmp >>= 259andq %rdx, %rax # t &= 0x333333333333333360andq %rdi, %rdx # w_tmp &= 0x333333333333333361addq %rdx, %rax # w = w_tmp + t6263movq %rax, %rdx # w -> t64shrq $4, %rdx # t >>= 465addq %rdx, %rax # w_tmp += t66movabsq $0x0f0f0f0f0f0f0f0f, %rdx67andq %rdx, %rax # w_tmp &= 0x0f0f0f0f0f0f0f0f68movabsq $0x0101010101010101, %rdx69imulq %rdx, %rax # w_tmp *= 0x010101010101010170shrq $56, %rax # w = w_tmp >> 567172popq %rdx73popq %rdi74RET75SYM_FUNC_END(__sw_hweight64)76EXPORT_SYMBOL(__sw_hweight64)77#endif787980