SeqAn3 3.4.3-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-2026 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2026 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 { simd[0] };
87 }
89struct builtin_simd_traits_helper<builtin_simd_t>
90{
94 static constexpr auto length = sizeof(builtin_simd_t) / sizeof(scalar_type);
95
98 static constexpr bool value =
100 && std::is_same_v<builtin_simd_t, transformation_trait_or_t<builtin_simd<scalar_type, length>, void>>;
101};
102
111template <typename builtin_simd_t>
112struct is_builtin_simd : std::bool_constant<builtin_simd_traits_helper<builtin_simd_t>::value>
113{};
114
120template <typename builtin_simd_t>
122
131template <>
132inline constexpr auto default_simd_max_length<builtin_simd> = []()
133{
134#if defined(__AVX512F__)
135 return min_viable_uint_v<64u>;
136#elif defined(__AVX2__)
137 return min_viable_uint_v<32u>;
138#elif defined(__SSE4_1__) && defined(__SSE4_2__)
139 return min_viable_uint_v<16u>;
140#else
141 return min_viable_uint_v<0u>;
142#endif
143}();
144
157template <typename builtin_simd_t>
159 std::bool_constant<(default_simd_max_length<builtin_simd> != 0)
160 && ((builtin_simd_traits_helper<builtin_simd_t>::length
161 * sizeof(typename builtin_simd_traits_helper<builtin_simd_t>::scalar_type))
162 >= 16)
163 && ((builtin_simd_traits_helper<builtin_simd_t>::length
164 * sizeof(typename builtin_simd_traits_helper<builtin_simd_t>::scalar_type))
165 <= 64)>
166{};
167
173template <typename builtin_simd_t>
175
176} // namespace seqan3::detail
177
178namespace seqan3
179{
180
181inline namespace simd
182{
183
189template <typename builtin_simd_t>
190// \cond
192// \endcond
193struct simd_traits<builtin_simd_t>
194{
200 static constexpr auto max_length = length == 1u ? length : sizeof(scalar_type) * length;
201
202 static_assert(std::is_integral_v<scalar_type>, "For now we assume that builtin simd can only be integers");
204 using mask_type = decltype(std::declval<builtin_simd_t>() == std::declval<builtin_simd_t>());
207
209 template <typename new_scalar_type>
210 // \cond
211 requires (sizeof(scalar_type) == sizeof(new_scalar_type))
212 // \endcond
214};
215
216} // namespace simd
217
218} // 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:121
constexpr bool is_native_builtin_simd_v
Helper variable to test whether a type is a native simd builtin type.
Definition builtin_simd.hpp:174
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:132
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:113
This class inherits from std::true_type, iff the builtin simd type is supported by the current archit...
Definition builtin_simd.hpp:166
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:206
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:204
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:213
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:196
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