alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
intrinsic.hpp
Go to the documentation of this file.
1/* Copyright 2025 Luca Venerando Greco, René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
7#include "alpaka/api/api.hpp"
11
12#include <climits>
13
14namespace alpaka
15{
16 /** Returns the number of bits set to 1. */
17 constexpr int32_t popcount(auto const& arg)
18 requires(sizeof(ALPAKA_TYPEOF(arg)) == 4u || sizeof(ALPAKA_TYPEOF(arg)) == 8u)
19 {
20 constexpr auto intrinsicImpl = trait::getIntrinsicImpl(thisApi());
21 return internal::intrinsic::Popcount::Op<ALPAKA_TYPEOF(intrinsicImpl), ALPAKA_TYPEOF(arg)>{}(
22 intrinsicImpl,
23 arg);
24 }
25
26 /* Position of the least significant bit set to 1.
27 *
28 * @return 1-based position of the first set bit, zero for input value 0.
29 */
30 constexpr int32_t ffs(auto const& arg)
31 requires(sizeof(ALPAKA_TYPEOF(arg)) == 4u || sizeof(ALPAKA_TYPEOF(arg)) == 8u)
32 {
33 constexpr auto intrinsicImpl = trait::getIntrinsicImpl(thisApi());
34 return internal::intrinsic::Ffs::Op<ALPAKA_TYPEOF(intrinsicImpl), ALPAKA_TYPEOF(arg)>{}(intrinsicImpl, arg);
35 }
36
37 /* Return the number of most significant zero bits
38 *
39 * @return number consecutive most significant zero bits, zero for input value 0.
40 */
41 constexpr int32_t clz(auto const& arg)
42 requires(sizeof(ALPAKA_TYPEOF(arg)) == 4u || sizeof(ALPAKA_TYPEOF(arg)) == 8u)
43 {
44 constexpr auto intrinsicImpl = alpaka::trait::getIntrinsicImpl(thisApi());
45 return internal::intrinsic::Clz::Op<ALPAKA_TYPEOF(intrinsicImpl), ALPAKA_TYPEOF(arg)>{}(intrinsicImpl, arg);
46 }
47} // namespace alpaka
#define ALPAKA_TYPEOF(...)
Get the type of instance.
Definition common.hpp:154
constexpr decltype(auto) getIntrinsicImpl(T_Api const api)
Definition trait.hpp:55
main alpaka namespace.
Definition alpaka.hpp:76
constexpr int32_t popcount(auto const &arg)
Returns the number of bits set to 1.
Definition intrinsic.hpp:17
constexpr auto thisApi()
provides the API used during the execution of the current code path
Definition api.hpp:26
constexpr int32_t clz(auto const &arg)
Definition intrinsic.hpp:41
constexpr int32_t ffs(auto const &arg)
Definition intrinsic.hpp:30