xref: /freebsd/contrib/llvm-project/clang/lib/Headers/popcntintrin.h (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric /*===---- popcntintrin.h - POPCNT intrinsics -------------------------------===
20b57cec5SDimitry Andric  *
30b57cec5SDimitry Andric  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric  * See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric  *
70b57cec5SDimitry Andric  *===-----------------------------------------------------------------------===
80b57cec5SDimitry Andric  */
90b57cec5SDimitry Andric 
100b57cec5SDimitry Andric #ifndef __POPCNTINTRIN_H
110b57cec5SDimitry Andric #define __POPCNTINTRIN_H
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric /* Define the default attributes for the functions in this file. */
140b57cec5SDimitry Andric #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("popcnt")))
150b57cec5SDimitry Andric 
16*e8d8bef9SDimitry Andric #if defined(__cplusplus) && (__cplusplus >= 201103L)
17*e8d8bef9SDimitry Andric #define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
18*e8d8bef9SDimitry Andric #else
19*e8d8bef9SDimitry Andric #define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
20*e8d8bef9SDimitry Andric #endif
21*e8d8bef9SDimitry Andric 
220b57cec5SDimitry Andric /// Counts the number of bits in the source operand having a value of 1.
230b57cec5SDimitry Andric ///
240b57cec5SDimitry Andric /// \headerfile <x86intrin.h>
250b57cec5SDimitry Andric ///
260b57cec5SDimitry Andric /// This intrinsic corresponds to the <c> POPCNT </c> instruction.
270b57cec5SDimitry Andric ///
280b57cec5SDimitry Andric /// \param __A
290b57cec5SDimitry Andric ///    An unsigned 32-bit integer operand.
300b57cec5SDimitry Andric /// \returns A 32-bit integer containing the number of bits with value 1 in the
310b57cec5SDimitry Andric ///    source operand.
32*e8d8bef9SDimitry Andric static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
_mm_popcnt_u32(unsigned int __A)330b57cec5SDimitry Andric _mm_popcnt_u32(unsigned int __A)
340b57cec5SDimitry Andric {
350b57cec5SDimitry Andric   return __builtin_popcount(__A);
360b57cec5SDimitry Andric }
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric #ifdef __x86_64__
390b57cec5SDimitry Andric /// Counts the number of bits in the source operand having a value of 1.
400b57cec5SDimitry Andric ///
410b57cec5SDimitry Andric /// \headerfile <x86intrin.h>
420b57cec5SDimitry Andric ///
430b57cec5SDimitry Andric /// This intrinsic corresponds to the <c> POPCNT </c> instruction.
440b57cec5SDimitry Andric ///
450b57cec5SDimitry Andric /// \param __A
460b57cec5SDimitry Andric ///    An unsigned 64-bit integer operand.
470b57cec5SDimitry Andric /// \returns A 64-bit integer containing the number of bits with value 1 in the
480b57cec5SDimitry Andric ///    source operand.
49*e8d8bef9SDimitry Andric static __inline__ long long __DEFAULT_FN_ATTRS_CONSTEXPR
_mm_popcnt_u64(unsigned long long __A)500b57cec5SDimitry Andric _mm_popcnt_u64(unsigned long long __A)
510b57cec5SDimitry Andric {
520b57cec5SDimitry Andric   return __builtin_popcountll(__A);
530b57cec5SDimitry Andric }
540b57cec5SDimitry Andric #endif /* __x86_64__ */
550b57cec5SDimitry Andric 
560b57cec5SDimitry Andric #undef __DEFAULT_FN_ATTRS
57*e8d8bef9SDimitry Andric #undef __DEFAULT_FN_ATTRS_CONSTEXPR
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric #endif /* __POPCNTINTRIN_H */
60