Ginkgo  Generated from pipelines/1330831941 branch based on master. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
intrinsics.hpp
1 // SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_BASE_INTRINSICS_HPP_
6 #define GKO_PUBLIC_CORE_BASE_INTRINSICS_HPP_
7 
8 
9 #include <bitset>
10 
11 
12 #include <ginkgo/core/base/types.hpp>
13 
14 
15 namespace gko {
16 namespace detail {
17 
18 
22 GKO_ATTRIBUTES GKO_INLINE int popcount(uint32 bitmask)
23 {
24 #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
25  return __popc(bitmask);
26 #else
27  std::bitset<32> bits{bitmask};
28  return bits.count();
29 #endif
30 }
31 
32 
36 GKO_ATTRIBUTES GKO_INLINE int popcount(uint64 bitmask)
37 {
38 #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
39  return __popcll(bitmask);
40 #else
41  std::bitset<64> bits{bitmask};
42  return bits.count();
43 #endif
44 }
45 
46 
47 } // namespace detail
48 } // namespace gko
49 
50 #endif // GKO_PUBLIC_CORE_BASE_INTRINSICS_HPP_
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::uint32
std::uint32_t uint32
32-bit unsigned integral type.
Definition: types.hpp:148
gko::uint64
std::uint64_t uint64
64-bit unsigned integral type.
Definition: types.hpp:154