1/* 2 * This program is free software; you can redistribute it and/or modify 3 * it under the terms of the GNU General Public License as published by 4 * the Free Software Foundation; either version 2 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 * 16 * Copyright (C) IBM Corporation, 2010 17 * 18 * Author: Anton Blanchard <anton@au.ibm.com> 19 */ 20#include <asm/processor.h> 21#include <asm/ppc_asm.h> 22#include <asm/export.h> 23#include <asm/feature-fixups.h> 24 25/* Note: This code relies on -mminimal-toc */ 26 27_GLOBAL(__arch_hweight8) 28BEGIN_FTR_SECTION 29 b __sw_hweight8 30 nop 31 nop 32FTR_SECTION_ELSE 33 PPC_POPCNTB(R3,R3) 34 clrldi r3,r3,64-8 35 blr 36ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB) 37EXPORT_SYMBOL(__arch_hweight8) 38 39_GLOBAL(__arch_hweight16) 40BEGIN_FTR_SECTION 41 b __sw_hweight16 42 nop 43 nop 44 nop 45 nop 46FTR_SECTION_ELSE 47 BEGIN_FTR_SECTION_NESTED(50) 48 PPC_POPCNTB(R3,R3) 49 srdi r4,r3,8 50 add r3,r4,r3 51 clrldi r3,r3,64-8 52 blr 53 FTR_SECTION_ELSE_NESTED(50) 54 clrlwi r3,r3,16 55 PPC_POPCNTW(R3,R3) 56 clrldi r3,r3,64-8 57 blr 58 ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_POPCNTD, 50) 59ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB) 60EXPORT_SYMBOL(__arch_hweight16) 61 62_GLOBAL(__arch_hweight32) 63BEGIN_FTR_SECTION 64 b __sw_hweight32 65 nop 66 nop 67 nop 68 nop 69 nop 70 nop 71FTR_SECTION_ELSE 72 BEGIN_FTR_SECTION_NESTED(51) 73 PPC_POPCNTB(R3,R3) 74 srdi r4,r3,16 75 add r3,r4,r3 76 srdi r4,r3,8 77 add r3,r4,r3 78 clrldi r3,r3,64-8 79 blr 80 FTR_SECTION_ELSE_NESTED(51) 81 PPC_POPCNTW(R3,R3) 82 clrldi r3,r3,64-8 83 blr 84 ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_POPCNTD, 51) 85ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB) 86EXPORT_SYMBOL(__arch_hweight32) 87 88_GLOBAL(__arch_hweight64) 89BEGIN_FTR_SECTION 90 b __sw_hweight64 91 nop 92 nop 93 nop 94 nop 95 nop 96 nop 97 nop 98 nop 99FTR_SECTION_ELSE 100 BEGIN_FTR_SECTION_NESTED(52) 101 PPC_POPCNTB(R3,R3) 102 srdi r4,r3,32 103 add r3,r4,r3 104 srdi r4,r3,16 105 add r3,r4,r3 106 srdi r4,r3,8 107 add r3,r4,r3 108 clrldi r3,r3,64-8 109 blr 110 FTR_SECTION_ELSE_NESTED(52) 111 PPC_POPCNTD(R3,R3) 112 clrldi r3,r3,64-8 113 blr 114 ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_POPCNTD, 52) 115ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB) 116EXPORT_SYMBOL(__arch_hweight64) 117