alpaka
Abstraction Library for Parallel Kernel Acceleration
IntrinsicFallback.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Sergei Bastrakov, Jeffrey Kelling, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
8 
9 namespace alpaka
10 {
11  namespace detail
12  {
13  //! Fallback implementation of popcount.
14  template<typename TValue>
15  static auto popcountFallback(TValue value) -> std::int32_t
16  {
17  TValue count = 0;
18  while(value != 0)
19  {
20  count += value & 1u;
21  value >>= 1u;
22  }
23  return static_cast<std::int32_t>(count);
24  }
25 
26  //! Fallback implementation of ffs.
27  template<typename TValue>
28  static auto ffsFallback(TValue value) -> std::int32_t
29  {
30  if(value == 0)
31  return 0;
32  std::int32_t result = 1;
33  while((value & 1) == 0)
34  {
35  value >>= 1;
36  result++;
37  }
38  return result;
39  }
40  } // namespace detail
41 
42  //! The Fallback intrinsic.
43  class IntrinsicFallback : public concepts::Implements<ConceptIntrinsic, IntrinsicFallback>
44  {
45  };
46 
47  namespace trait
48  {
49  template<>
51  {
52  static auto popcount(IntrinsicFallback const& /*intrinsic*/, std::uint32_t value) -> std::int32_t
53  {
55  }
56 
57  static auto popcount(IntrinsicFallback const& /*intrinsic*/, std::uint64_t value) -> std::int32_t
58  {
60  }
61  };
62 
63  template<>
65  {
66  static auto ffs(IntrinsicFallback const& /*intrinsic*/, std::int32_t value) -> std::int32_t
67  {
68  return alpaka::detail::ffsFallback(value);
69  }
70 
71  static auto ffs(IntrinsicFallback const& /*intrinsic*/, std::int64_t value) -> std::int32_t
72  {
73  return alpaka::detail::ffsFallback(value);
74  }
75  };
76  } // namespace trait
77 } // namespace alpaka
The Fallback intrinsic.
static auto popcountFallback(TValue value) -> std::int32_t
Fallback implementation of popcount.
static auto ffsFallback(TValue value) -> std::int32_t
Fallback implementation of ffs.
The alpaka accelerator library.
Tag used in class inheritance hierarchies that describes that a specific concept (TConcept) is implem...
Definition: Concepts.hpp:15
static auto ffs(IntrinsicFallback const &, std::int32_t value) -> std::int32_t
static auto ffs(IntrinsicFallback const &, std::int64_t value) -> std::int32_t
The ffs trait.
Definition: Traits.hpp:28
static auto popcount(IntrinsicFallback const &, std::uint32_t value) -> std::int32_t
static auto popcount(IntrinsicFallback const &, std::uint64_t value) -> std::int32_t
The popcount trait.
Definition: Traits.hpp:24