batmat main
Batched linear algebra routines
Loading...
Searching...
No Matches
mask.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <batmat/simd.hpp>
4#include <type_traits>
5
6namespace batmat::ops::detail {
7
8template <class T, class Abi>
9struct mask_type {
11};
12
13template <class T, class AbiT>
15
16/// Convert a SIMD mask to the appropriate intrinsic type. If @p M is not a mask type, its values
17/// are compared to zero to create a mask.
18/// @todo GCC's <experimental/simd> does not allow casting from std::experimental::simd_mask to
19/// intrinsic types, so I'm not using simd_mask for now.
20template <class T, class AbiT, class M>
21[[gnu::always_inline]] inline mask_type_t<T, AbiT> convert_mask(M mask) {
22#if BATMAT_WITH_GSI_HPC_SIMD
23 auto m = mask != M{0};
24 if constexpr (std::is_convertible_v<decltype(m), mask_type_t<T, AbiT>>)
25 return mask_type_t<T, AbiT>{m};
26 else
27 return mask_type_t<T, AbiT>{[&](auto i) -> bool { return m[i]; }}; // TODO: suboptimal
28#else
29 return (mask != 0).__cvt();
30#endif
31}
32
33template <class T, class Abi>
34[[gnu::always_inline]] inline auto compare_ge_0(datapar::simd<T, Abi> x) {
35 return x >= datapar::simd<T, Abi>{};
36}
37
38} // namespace batmat::ops::detail
39
40#if defined(__AVX512F__)
41#include <batmat/ops/avx-512/mask.hpp>
42#elif defined(__AVX2__)
43#include <batmat/ops/avx2/mask.hpp>
44#endif
stdx::simd< Tp, Abi > simd
Definition simd.hpp:99
mask_type_t< T, AbiT > convert_mask(M mask)
Convert a SIMD mask to the appropriate intrinsic type.
Definition mask.hpp:21
typename datapar::simd< T, Abi >::mask_type type
Definition mask.hpp:10
auto compare_ge_0(datapar::simd< T, Abi > x)
Definition mask.hpp:34
typename mask_type< T, AbiT >::type mask_type_t
Definition mask.hpp:14