xref: /aosp_15_r20/prebuilts/sdk/renderscript/clang-include/popcntintrin.h (revision 344a7f5ef16c479e7a7f54ee6567a9d112f9e72b)
1*344a7f5eSAndroid Build Coastguard Worker /*===---- popcntintrin.h - POPCNT intrinsics -------------------------------===
2*344a7f5eSAndroid Build Coastguard Worker  *
3*344a7f5eSAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a copy
4*344a7f5eSAndroid Build Coastguard Worker  * of this software and associated documentation files (the "Software"), to deal
5*344a7f5eSAndroid Build Coastguard Worker  * in the Software without restriction, including without limitation the rights
6*344a7f5eSAndroid Build Coastguard Worker  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*344a7f5eSAndroid Build Coastguard Worker  * copies of the Software, and to permit persons to whom the Software is
8*344a7f5eSAndroid Build Coastguard Worker  * furnished to do so, subject to the following conditions:
9*344a7f5eSAndroid Build Coastguard Worker  *
10*344a7f5eSAndroid Build Coastguard Worker  * The above copyright notice and this permission notice shall be included in
11*344a7f5eSAndroid Build Coastguard Worker  * all copies or substantial portions of the Software.
12*344a7f5eSAndroid Build Coastguard Worker  *
13*344a7f5eSAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14*344a7f5eSAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15*344a7f5eSAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16*344a7f5eSAndroid Build Coastguard Worker  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17*344a7f5eSAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18*344a7f5eSAndroid Build Coastguard Worker  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19*344a7f5eSAndroid Build Coastguard Worker  * THE SOFTWARE.
20*344a7f5eSAndroid Build Coastguard Worker  *
21*344a7f5eSAndroid Build Coastguard Worker  *===-----------------------------------------------------------------------===
22*344a7f5eSAndroid Build Coastguard Worker  */
23*344a7f5eSAndroid Build Coastguard Worker 
24*344a7f5eSAndroid Build Coastguard Worker #ifndef _POPCNTINTRIN_H
25*344a7f5eSAndroid Build Coastguard Worker #define _POPCNTINTRIN_H
26*344a7f5eSAndroid Build Coastguard Worker 
27*344a7f5eSAndroid Build Coastguard Worker /* Define the default attributes for the functions in this file. */
28*344a7f5eSAndroid Build Coastguard Worker #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("popcnt")))
29*344a7f5eSAndroid Build Coastguard Worker 
30*344a7f5eSAndroid Build Coastguard Worker /// \brief Counts the number of bits in the source operand having a value of 1.
31*344a7f5eSAndroid Build Coastguard Worker ///
32*344a7f5eSAndroid Build Coastguard Worker /// \headerfile <x86intrin.h>
33*344a7f5eSAndroid Build Coastguard Worker ///
34*344a7f5eSAndroid Build Coastguard Worker /// This intrinsic corresponds to the \c POPCNT instruction.
35*344a7f5eSAndroid Build Coastguard Worker ///
36*344a7f5eSAndroid Build Coastguard Worker /// \param __A
37*344a7f5eSAndroid Build Coastguard Worker ///    An unsigned 32-bit integer operand.
38*344a7f5eSAndroid Build Coastguard Worker /// \returns A 32-bit integer containing the number of bits with value 1 in the
39*344a7f5eSAndroid Build Coastguard Worker ///    source operand.
40*344a7f5eSAndroid Build Coastguard Worker static __inline__ int __DEFAULT_FN_ATTRS
_mm_popcnt_u32(unsigned int __A)41*344a7f5eSAndroid Build Coastguard Worker _mm_popcnt_u32(unsigned int __A)
42*344a7f5eSAndroid Build Coastguard Worker {
43*344a7f5eSAndroid Build Coastguard Worker   return __builtin_popcount(__A);
44*344a7f5eSAndroid Build Coastguard Worker }
45*344a7f5eSAndroid Build Coastguard Worker 
46*344a7f5eSAndroid Build Coastguard Worker /// \brief Counts the number of bits in the source operand having a value of 1.
47*344a7f5eSAndroid Build Coastguard Worker ///
48*344a7f5eSAndroid Build Coastguard Worker /// \headerfile <x86intrin.h>
49*344a7f5eSAndroid Build Coastguard Worker ///
50*344a7f5eSAndroid Build Coastguard Worker /// This intrinsic corresponds to the \c POPCNT instruction.
51*344a7f5eSAndroid Build Coastguard Worker ///
52*344a7f5eSAndroid Build Coastguard Worker /// \param __A
53*344a7f5eSAndroid Build Coastguard Worker ///    A signed 32-bit integer operand.
54*344a7f5eSAndroid Build Coastguard Worker /// \returns A 32-bit integer containing the number of bits with value 1 in the
55*344a7f5eSAndroid Build Coastguard Worker ///    source operand.
56*344a7f5eSAndroid Build Coastguard Worker static __inline__ int __DEFAULT_FN_ATTRS
_popcnt32(int __A)57*344a7f5eSAndroid Build Coastguard Worker _popcnt32(int __A)
58*344a7f5eSAndroid Build Coastguard Worker {
59*344a7f5eSAndroid Build Coastguard Worker   return __builtin_popcount(__A);
60*344a7f5eSAndroid Build Coastguard Worker }
61*344a7f5eSAndroid Build Coastguard Worker 
62*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
63*344a7f5eSAndroid Build Coastguard Worker /// \brief Counts the number of bits in the source operand having a value of 1.
64*344a7f5eSAndroid Build Coastguard Worker ///
65*344a7f5eSAndroid Build Coastguard Worker /// \headerfile <x86intrin.h>
66*344a7f5eSAndroid Build Coastguard Worker ///
67*344a7f5eSAndroid Build Coastguard Worker /// This intrinsic corresponds to the \c POPCNT instruction.
68*344a7f5eSAndroid Build Coastguard Worker ///
69*344a7f5eSAndroid Build Coastguard Worker /// \param __A
70*344a7f5eSAndroid Build Coastguard Worker ///    An unsigned 64-bit integer operand.
71*344a7f5eSAndroid Build Coastguard Worker /// \returns A 64-bit integer containing the number of bits with value 1 in the
72*344a7f5eSAndroid Build Coastguard Worker ///    source operand.
73*344a7f5eSAndroid Build Coastguard Worker static __inline__ long long __DEFAULT_FN_ATTRS
_mm_popcnt_u64(unsigned long long __A)74*344a7f5eSAndroid Build Coastguard Worker _mm_popcnt_u64(unsigned long long __A)
75*344a7f5eSAndroid Build Coastguard Worker {
76*344a7f5eSAndroid Build Coastguard Worker   return __builtin_popcountll(__A);
77*344a7f5eSAndroid Build Coastguard Worker }
78*344a7f5eSAndroid Build Coastguard Worker 
79*344a7f5eSAndroid Build Coastguard Worker /// \brief Counts the number of bits in the source operand having a value of 1.
80*344a7f5eSAndroid Build Coastguard Worker ///
81*344a7f5eSAndroid Build Coastguard Worker /// \headerfile <x86intrin.h>
82*344a7f5eSAndroid Build Coastguard Worker ///
83*344a7f5eSAndroid Build Coastguard Worker /// This intrinsic corresponds to the \c POPCNT instruction.
84*344a7f5eSAndroid Build Coastguard Worker ///
85*344a7f5eSAndroid Build Coastguard Worker /// \param __A
86*344a7f5eSAndroid Build Coastguard Worker ///    A signed 64-bit integer operand.
87*344a7f5eSAndroid Build Coastguard Worker /// \returns A 64-bit integer containing the number of bits with value 1 in the
88*344a7f5eSAndroid Build Coastguard Worker ///    source operand.
89*344a7f5eSAndroid Build Coastguard Worker static __inline__ long long __DEFAULT_FN_ATTRS
_popcnt64(long long __A)90*344a7f5eSAndroid Build Coastguard Worker _popcnt64(long long __A)
91*344a7f5eSAndroid Build Coastguard Worker {
92*344a7f5eSAndroid Build Coastguard Worker   return __builtin_popcountll(__A);
93*344a7f5eSAndroid Build Coastguard Worker }
94*344a7f5eSAndroid Build Coastguard Worker #endif /* __x86_64__ */
95*344a7f5eSAndroid Build Coastguard Worker 
96*344a7f5eSAndroid Build Coastguard Worker #undef __DEFAULT_FN_ATTRS
97*344a7f5eSAndroid Build Coastguard Worker 
98*344a7f5eSAndroid Build Coastguard Worker #endif /* _POPCNTINTRIN_H */
99