11#include <xvec/detail/config.hpp>
24#include <xvec/detail/compat.hpp>
26namespace _XVEC_NAMESPACE::simd {
29using simd_size_type = int;
32template <simd_
size_type _Np>
using size_constant = std::integral_constant<simd_size_type, _Np>;
39inline constexpr bool isLlvm =
true;
52template <
typename _Tp>
53concept complex_number = std::is_same_v<std::remove_cvref_t<_Tp>, std::complex<typename _Tp::value_type>>;
57template<
class T,
class... Us>
58inline constexpr bool any_same_v = (std::same_as<std::remove_cvref_t<T>, Us> || ...);
63 unsigned char,
unsigned short,
unsigned int,
64 unsigned long,
unsigned long long>;
71template<
typename _Tp>
struct element_type {
using value_type = _Tp; };
72template<complex_number _Tp>
struct element_type<_Tp> {
using value_type =
typename _Tp::value_type; };
73template<
typename _Tp>
using element_type_t =
typename element_type<_Tp>::value_type;
87#if defined(__FLT16_MIN__)
88template<
typename _T>
inline constexpr bool is_fp16_v = std::same_as<std::remove_cvref_t<_T>, _Float16>;
90template<
typename _T>
inline constexpr bool is_fp16_v =
false;
93template <
typename _T>
struct is_fp16 : std::bool_constant<is_fp16_v<_T>> {};
117template<
typename _Parent,
typename _Type>
126template<std::
size_t _Bytes>
127using container_for_num_bytes =
typename std::tuple_element_t<std::bit_width(std::bit_ceil(_Bytes)),
containers_for_num_bytes>;
129template<
typename _Tp>
using container_for_type = container_for_num_bytes<
sizeof(_Tp)>;
134 : std::disjunction<std::is_floating_point<_Tp>, is_fp16<_Tp>> {};
142inline constexpr bool is_arithmetic_like_v = std::is_integral_v<std::remove_cvref_t<T>> || is_floating_point_v<T>;
148template<
typename _Tp>
using make_signed_t =
typename unsigned_to_signed<_Tp>::value_type;
163template<
typename _Tp>
struct element_storage {
using value_type = container_for_type<_Tp>; };
164template<complex_number _Tp>
struct element_storage<_Tp> {
using value_type =
typename _Tp::value_type; };
165template<
typename _Tp>
requires (std::is_enum_v<_Tp>)
struct element_storage<_Tp> {
using value_type = std::underlying_type_t<_Tp>; };
166template<
typename _Tp>
requires (std::is_arithmetic_v<_Tp> || is_floating_point_v<_Tp>)
struct element_storage<_Tp> {
using value_type = _Tp; };
167template<
typename _Tp>
using element_storage_t =
typename element_storage<_Tp>::value_type;
171template<
typename _Tp>
173 if constexpr (
requires { std::span{in}; })
175 return std::integral_constant<std::size_t,
decltype(std::span{in})::extent>{};
177 return std::integral_constant<std::size_t, std::dynamic_extent>{};
180template<
class _Span>
inline constexpr std::size_t span_extent_v =
decltype(get_span_static_extent(std::declval<_Span>()))::value;
184template<
typename _Span>
186 if constexpr (
requires { std::span{in}; })
188 return typename decltype(std::span{in})::value_type();
193template<
class _Span>
using span_element_type =
decltype(get_span_element_type_helper(std::declval<_Span>()));
199template<
typename _Vec, std::
size_t _Extent,
typename _Mask =
bool>
200constexpr void checkStaticMemoryBounds([[maybe_unused]]
const std::string& op_name,
201 [[maybe_unused]] std::span<typename _Vec::value_type, _Extent> mem_span,
202 [[maybe_unused]] _Mask m = _Mask())
204 constexpr bool opIsMasked = !std::same_as<_Mask, bool>;
213 static_assert(opIsMasked || _Vec::size <= _Extent,
214 "Memory span is not big enough for simd load/store operation");
216#if defined(XVEC_ALWAYS_RANGE_CHECK_MEMORY)
217 auto opSize = _Vec::size;
219 if constexpr (opIsMasked) {
222 auto outOfRangeBits = !_Mask::__mask_from_count(mem_span.size());
223 if (
any_of(outOfRangeBits & m))
226 "xvec masked range error for " + op_name +
". Range size:" + std::to_string(mem_span.size()) +
227 " Mask:" + m.to_bitset().to_string();
228 throw std::out_of_range(msg);
231 else if (opSize > mem_span.size()) {
233 "xvec range error for " + op_name +
". Range size:" + std::to_string(mem_span.size()) +
234 " simd size:" + std::to_string(opSize);
235 throw std::out_of_range(msg);
244template<
typename _Vec>
245constexpr void checkStaticMemoryBounds([[maybe_unused]]
const std::string& op_name,
246 [[maybe_unused]]
const _Vec& indexes,
247 [[maybe_unused]] std::size_t range_size,
248 [[maybe_unused]]
typename _Vec::mask_type m =
typename _Vec::mask_type(
true))
250#if defined(XVEC_ALWAYS_RANGE_CHECK_MEMORY)
252 if (std::size_t(biggestIndex) >= range_size)
255 "xvec range error for " + op_name +
". Range size:" + std::to_string(range_size) +
256 " maxIndex:" + std::to_string(biggestIndex);
257 throw std::out_of_range(msg);
264template <
int X>
inline constexpr std::integral_constant<int, X> cw{};
271#if defined(_IOSTREAM_) || defined(_CPP_IOSTREAM) || \
272 defined(_GLIBCXX_IOSTREAM) || defined(_LIBCPP_IOSTREAM)
273#define _XVEC_DEFINE_OUTPUT_OPERATORS
Detect whether a given type is std::complex.
Definition utilities.hpp:53
Detect a fundamental unsigned integer type.
Definition utilities.hpp:62
constexpr bool any_of(const mask_type auto &mask) noexcept
Return true if any mask element is true.
Definition mask.hpp:471
constexpr _V::value_type reduce_max(const _V &v) noexcept
Return the maximum vector element.
Definition reduce.hpp:187
constexpr bool any_same_v
Definition utilities.hpp:58
constexpr bool is_fp16_v
Definition utilities.hpp:90
std::tuple< void, std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t, __uint128_t > containers_for_num_bytes
Definition utilities.hpp:124
constexpr bool dependent_false
Definition utilities.hpp:103
typename std::conditional< true, _Type, _Parent >::type dependent_type
Definition utilities.hpp:118
constexpr auto get_span_static_extent(const _Tp &in)
Query the extent of a given type.
Definition utilities.hpp:172
constexpr auto get_span_element_type_helper(const _Span &in)
Definition utilities.hpp:185
constexpr simd_size_type max_native_size
The maximum native size of a register containing the given types.
Definition utilities.hpp:151
constexpr bool isLlvm
Compile time flag to indicate whether the LLVM compiler is being used.
Definition utilities.hpp:41
constexpr simd_size_type max_fixed_size
Definition utilities.hpp:155
constexpr int maxBytesInVec
Definition target_config.hpp:148
Definition utilities.hpp:79
Definition utilities.hpp:79
Definition utilities.hpp:163
Definition utilities.hpp:71
Temporary floating-point test. Used to handle half/_Float16 until the compiler catches up.
Definition utilities.hpp:134
Definition utilities.hpp:93
Allow overloaded lambdas to be used for target-specific code. Described at https://www....
Definition utilities.hpp:48
Definition utilities.hpp:146