SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
builtin_simd.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
11#pragma once
12
13#include <bit>
14#include <type_traits>
15
20
21namespace seqan3::detail
22{
23
49template <typename scalar_t, size_t length>
51
54template <typename scalar_t, size_t length>
55 requires (std::has_single_bit(length))
57{
59#if SEQAN3_DOXYGEN_ONLY(1) 0
60 using type = scalar_t __attribute__((vector_size(sizeof(scalar_t) * length))));
61 // doxygen 1.8.13 does not support c++11 attributes, thus this doxygen-only definition
62#elif defined(__clang__)
63 using type = scalar_t __attribute__((ext_vector_type(length)));
64#else
65 using type [[gnu::vector_size(sizeof(scalar_t) * length)]] = scalar_t;
66#endif
67};
68
73template <typename builtin_simd_t>
76
81template <typename builtin_simd_t>
83// NOTE: gcc throws a compile time error if builtin_simd_t is a pointer of an incomplete type. To tackle this we
84// short-circuit the requires with is_pointer_v. See builtin_simd_test.cpp for a test case for this.
85 requires (!std::is_pointer_v<std::decay_t<builtin_simd_t>>) && requires (builtin_simd_t simd) {
86 {
87 simd[0]
88 };
89 }
91struct builtin_simd_traits_helper<builtin_simd_t>
92{
96 static constexpr auto length = sizeof(builtin_simd_t) / sizeof(scalar_type);
97
100 static constexpr bool value =
101 std::has_single_bit(length)
102 && std::is_same_v<builtin_simd_t, transformation_trait_or_t<builtin_simd<scalar_type, length>, void>>;
103};
104
113template <typename builtin_simd_t>
114struct is_builtin_simd : std::bool_constant<builtin_simd_traits_helper<builtin_simd_t>::value>
115{};
116
122template <typename builtin_simd_t>
124
133template <>
134inline constexpr auto default_simd_max_length<builtin_simd> = []()
135{
136#if defined(__AVX512F__)
137 return min_viable_uint_v<64u>;
138#elif defined(__AVX2__)
139 return min_viable_uint_v<32u>;
140#elif defined(__SSE4_1__) && defined(__SSE4_2__)
141 return min_viable_uint_v<16u>;
142#else
143 return min_viable_uint_v<0u>;
144#endif
145}();
146
159template <typename builtin_simd_t>
161 std::bool_constant<(default_simd_max_length<builtin_simd> != 0)
162 && ((builtin_simd_traits_helper<builtin_simd_t>::length
163 * sizeof(typename builtin_simd_traits_helper<builtin_simd_t>::scalar_type))
164 >= 16)
165 && ((builtin_simd_traits_helper<builtin_simd_t>::length
166 * sizeof(typename builtin_simd_traits_helper<builtin_simd_t>::scalar_type))
167 <= 64)>
168{};
169
175template <typename builtin_simd_t>
177
178} // namespace seqan3::detail
179
180namespace seqan3
181{
182
183inline namespace simd
184{
185
191template <typename builtin_simd_t>
192// \cond
194// \endcond
195struct simd_traits<builtin_simd_t>
196{
202 static constexpr auto max_length = length == 1u ? length : sizeof(scalar_type) * length;
203
204 static_assert(std::is_integral_v<scalar_type>, "For now we assume that builtin simd can only be integers");
206 using mask_type = decltype(std::declval<builtin_simd_t>() == std::declval<builtin_simd_t>());
209
211 template <typename new_scalar_type>
212 // \cond
213 requires (sizeof(scalar_type) == sizeof(new_scalar_type))
214 // \endcond
216};
217
218} // namespace simd
219
220} // namespace seqan3
Provides seqan3::detail::default_simd_length and seqan3::detail::default_simd_max_length.
constexpr bool is_builtin_simd_v
Helper variable to test whether a type is a simd builtin type.
Definition builtin_simd.hpp:123
constexpr bool is_native_builtin_simd_v
Helper variable to test whether a type is a native simd builtin type.
Definition builtin_simd.hpp:176
constexpr auto default_simd_max_length< builtin_simd >
This function specializes seqan3::detail::default_simd_max_length for seqan3::detail::builtin_simd.
Definition builtin_simd.hpp:134
T has_single_bit(T... args)
Provides metaprogramming utilities for integer types.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Provides seqan3::simd::simd_traits.
scalar_t __attribute__((vector_size(sizeof(scalar_t) *length)))) type
The type of the builtin simd.
Definition builtin_simd.hpp:60
Helper struct for seqan3::detail::is_builtin_simd.
Definition builtin_simd.hpp:75
A class that holds the type of a simd implementation called [vector extension] (https://gcc....
Definition builtin_simd.hpp:50
This class inherits from std::true_type, iff seqan3::detail::builtin_simd<scalar_t,...
Definition builtin_simd.hpp:115
This class inherits from std::true_type, iff the builtin simd type is supported by the current archit...
Definition builtin_simd.hpp:168
typename detail::builtin_simd< uint8_t, max_length >::type swizzle_type
The type used to define how to swizzle a simd vector (is not defined if simd_t does not model seqan3:...
Definition builtin_simd.hpp:208
decltype(std::declval< builtin_simd_t >()==std::declval< builtin_simd_t >()) mask_type
The type returned by comparison operators (is not defined if simd_t does not model seqan3::simd::simd...
Definition builtin_simd.hpp:206
typename detail::builtin_simd< new_scalar_type, length >::type rebind
The type used to rebind a simd vector to another scalar_type (is not defined if simd_t does not model...
Definition builtin_simd.hpp:215
typename detail::builtin_simd_traits_helper< builtin_simd_t >::scalar_type scalar_type
The underlying type of a simd vector (is not defined if simd_t does not model seqan3::simd::simd)
Definition builtin_simd.hpp:198
seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of sim...
Definition simd_traits.hpp:38
static constexpr auto length
The number of packed values in a simd vector (is not defined if simd_t does not model seqan3::simd::s...
Definition simd_traits.hpp:46
IMPLEMENTATION_DEFINED scalar_type
The underlying type of a simd vector (is not defined if simd_t does not model seqan3::simd::simd)
Definition simd_traits.hpp:42
static constexpr auto max_length
The maximum number of packable values in a simd vector, if the underlying type would be [u]int8_t (is...
Definition simd_traits.hpp:51
Provides seqan3::detail::transformation_trait_or.
Hide me