1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2/* 3 * 4 * Copyright (C) IBM Corporation, 2010 5 * 6 * Author: Anton Blanchard <anton@au.ibm.com> 7 */ 8#include <linux/export.h> 9#include <asm/processor.h> 10#include <asm/ppc_asm.h> 11#include <asm/feature-fixups.h> 12 13/* Note: This code relies on -mminimal-toc */ 14 15_GLOBAL(__arch_hweight8) 16BEGIN_FTR_SECTION 17 b CFUNC(__sw_hweight8) 18 nop 19 nop 20FTR_SECTION_ELSE 21 PPC_POPCNTB(R3,R3) 22 clrldi r3,r3,64-8 23 blr 24ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB) 25EXPORT_SYMBOL(__arch_hweight8) 26 27_GLOBAL(__arch_hweight16) 28BEGIN_FTR_SECTION 29 b CFUNC(__sw_hweight16) 30 nop 31 nop 32 nop 33 nop 34FTR_SECTION_ELSE 35 BEGIN_FTR_SECTION_NESTED(50) 36 PPC_POPCNTB(R3,R3) 37 srdi r4,r3,8 38 add r3,r4,r3 39 clrldi r3,r3,64-8 40 blr 41 FTR_SECTION_ELSE_NESTED(50) 42 clrlwi r3,r3,16 43 PPC_POPCNTW(R3,R3) 44 clrldi r3,r3,64-8 45 blr 46 ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_POPCNTD, 50) 47ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB) 48EXPORT_SYMBOL(__arch_hweight16) 49 50_GLOBAL(__arch_hweight32) 51BEGIN_FTR_SECTION 52 b CFUNC(__sw_hweight32) 53 nop 54 nop 55 nop 56 nop 57 nop 58 nop 59FTR_SECTION_ELSE 60 BEGIN_FTR_SECTION_NESTED(51) 61 PPC_POPCNTB(R3,R3) 62 srdi r4,r3,16 63 add r3,r4,r3 64 srdi r4,r3,8 65 add r3,r4,r3 66 clrldi r3,r3,64-8 67 blr 68 FTR_SECTION_ELSE_NESTED(51) 69 PPC_POPCNTW(R3,R3) 70 clrldi r3,r3,64-8 71 blr 72 ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_POPCNTD, 51) 73ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB) 74EXPORT_SYMBOL(__arch_hweight32) 75 76_GLOBAL(__arch_hweight64) 77BEGIN_FTR_SECTION 78 b CFUNC(__sw_hweight64) 79 nop 80 nop 81 nop 82 nop 83 nop 84 nop 85 nop 86 nop 87FTR_SECTION_ELSE 88 BEGIN_FTR_SECTION_NESTED(52) 89 PPC_POPCNTB(R3,R3) 90 srdi r4,r3,32 91 add r3,r4,r3 92 srdi r4,r3,16 93 add r3,r4,r3 94 srdi r4,r3,8 95 add r3,r4,r3 96 clrldi r3,r3,64-8 97 blr 98 FTR_SECTION_ELSE_NESTED(52) 99 PPC_POPCNTD(R3,R3) 100 clrldi r3,r3,64-8 101 blr 102 ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_POPCNTD, 52) 103ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB) 104EXPORT_SYMBOL(__arch_hweight64) 105