alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
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
9namespace 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 interface::Implements<ConceptIntrinsic, IntrinsicFallback>
44 {
45 };
46
47 namespace trait
48 {
49 template<>
50 struct Popcount<IntrinsicFallback>
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<>
64 struct Ffs<IntrinsicFallback>
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.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto ffs(TIntrinsic const &intrinsic, std::int32_t value) -> std::int32_t
Returns the 1-based position of the least significant bit set to 1 in the given 32-bit value....
Definition Traits.hpp:65
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto popcount(TIntrinsic const &intrinsic, std::uint32_t value) -> std::int32_t
Returns the number of 1 bits in the given 32-bit value.
Definition Traits.hpp:38
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition Interface.hpp:15