alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
include
alpaka
simd
internal
utility.hpp
Go to the documentation of this file.
1
/* Copyright 2025 René Widera
2
* SPDX-License-Identifier: MPL-2.0
3
*/
4
5
#pragma once
6
7
#include <cstdint>
8
#include <type_traits>
9
10
namespace
alpaka::internal
11
{
12
13
/** Convert a bool value into a mask type for SIMD
14
*
15
* @return
16
*/
17
template
<
typename
T>
18
constexpr
auto
valueMaskCast(
bool
condition)
19
{
20
return
condition;
21
}
22
23
/** specialization for 4 and 8 byte types
24
*
25
* @return value type where all bits are 1 if condition is true, else all bit are zero
26
*/
27
template
<
typename
T>
28
requires
(
sizeof
(T) == 4u ||
sizeof
(T) == 8u)
29
constexpr
auto
valueMaskCast(
bool
condition)
30
{
31
using
ValueMaskType = std::conditional_t<
sizeof
(T) == 4u, uint32_t, uint64_t>;
32
// if condition is true value will be 1 and negated to set all bits
33
return
-
static_cast<
ValueMaskType
>
(condition);
34
}
35
}
// namespace alpaka::internal
Generated on
for alpaka by
1.16.1