blob: 6effad901ef7a1c886c2411b89f263acc05f1106 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Anton Blanchard64ff3122010-08-12 16:28:09 +00002/*
Anton Blanchard64ff3122010-08-12 16:28:09 +00003 *
4 * Copyright (C) IBM Corporation, 2010
5 *
6 * Author: Anton Blanchard <anton@au.ibm.com>
7 */
8#include <asm/processor.h>
9#include <asm/ppc_asm.h>
Al Viro9445aa12016-01-13 23:33:46 -050010#include <asm/export.h>
Christophe Leroy2c86cd12018-07-05 16:25:01 +000011#include <asm/feature-fixups.h>
Anton Blanchard64ff3122010-08-12 16:28:09 +000012
13/* Note: This code relies on -mminimal-toc */
14
15_GLOBAL(__arch_hweight8)
16BEGIN_FTR_SECTION
Anton Blanchardb1576fe2014-02-04 16:04:35 +110017 b __sw_hweight8
Anton Blanchard64ff3122010-08-12 16:28:09 +000018 nop
19 nop
20FTR_SECTION_ELSE
Michael Neulingc75df6f2012-06-25 13:33:10 +000021 PPC_POPCNTB(R3,R3)
Anton Blanchard64ff3122010-08-12 16:28:09 +000022 clrldi r3,r3,64-8
23 blr
24ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB)
Al Viro9445aa12016-01-13 23:33:46 -050025EXPORT_SYMBOL(__arch_hweight8)
Anton Blanchard64ff3122010-08-12 16:28:09 +000026
27_GLOBAL(__arch_hweight16)
28BEGIN_FTR_SECTION
Anton Blanchardb1576fe2014-02-04 16:04:35 +110029 b __sw_hweight16
Anton Blanchard64ff3122010-08-12 16:28:09 +000030 nop
31 nop
32 nop
33 nop
34FTR_SECTION_ELSE
35 BEGIN_FTR_SECTION_NESTED(50)
Michael Neulingc75df6f2012-06-25 13:33:10 +000036 PPC_POPCNTB(R3,R3)
Anton Blanchard64ff3122010-08-12 16:28:09 +000037 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
Michael Neulingc75df6f2012-06-25 13:33:10 +000043 PPC_POPCNTW(R3,R3)
Anton Blanchard64ff3122010-08-12 16:28:09 +000044 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)
Al Viro9445aa12016-01-13 23:33:46 -050048EXPORT_SYMBOL(__arch_hweight16)
Anton Blanchard64ff3122010-08-12 16:28:09 +000049
50_GLOBAL(__arch_hweight32)
51BEGIN_FTR_SECTION
Anton Blanchardb1576fe2014-02-04 16:04:35 +110052 b __sw_hweight32
Anton Blanchard64ff3122010-08-12 16:28:09 +000053 nop
54 nop
55 nop
56 nop
57 nop
58 nop
59FTR_SECTION_ELSE
60 BEGIN_FTR_SECTION_NESTED(51)
Michael Neulingc75df6f2012-06-25 13:33:10 +000061 PPC_POPCNTB(R3,R3)
Anton Blanchard64ff3122010-08-12 16:28:09 +000062 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)
Michael Neulingc75df6f2012-06-25 13:33:10 +000069 PPC_POPCNTW(R3,R3)
Anton Blanchard64ff3122010-08-12 16:28:09 +000070 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)
Al Viro9445aa12016-01-13 23:33:46 -050074EXPORT_SYMBOL(__arch_hweight32)
Anton Blanchard64ff3122010-08-12 16:28:09 +000075
76_GLOBAL(__arch_hweight64)
77BEGIN_FTR_SECTION
Anton Blanchardb1576fe2014-02-04 16:04:35 +110078 b __sw_hweight64
Anton Blanchard64ff3122010-08-12 16:28:09 +000079 nop
80 nop
81 nop
82 nop
83 nop
84 nop
85 nop
86 nop
87FTR_SECTION_ELSE
88 BEGIN_FTR_SECTION_NESTED(52)
Michael Neulingc75df6f2012-06-25 13:33:10 +000089 PPC_POPCNTB(R3,R3)
Anton Blanchard64ff3122010-08-12 16:28:09 +000090 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)
Michael Neulingc75df6f2012-06-25 13:33:10 +000099 PPC_POPCNTD(R3,R3)
Anton Blanchard64ff3122010-08-12 16:28:09 +0000100 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)
Al Viro9445aa12016-01-13 23:33:46 -0500104EXPORT_SYMBOL(__arch_hweight64)