93 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// <experimental/simd>12//13// [simd.traits]14//template <class T, class Abi = simd_abi::compatible<T>> struct simd_size;15//template <class T, class Abi = simd_abi::compatible<T>>16//inline constexpr std::size_t ex::simd_size_v = ex::simd_size<T, Abi>::value;17 18#include "../test_utils.h"19 20namespace ex = std::experimental::parallelism_v2;21 22struct CheckSimdSizeFixedDeduce {23 template <class T, std::size_t N>24 void check() {25 static_assert(ex::simd_size_v<T, ex::simd_abi::fixed_size<N>> == N, "Simd size mismatch with abi fixed_size");26 static_assert(ex::simd_size<T, ex::simd_abi::fixed_size<N>>::value == N, "Simd size mismatch with abi fixed_size");27 28 static_assert(ex::simd_size_v<T, ex::simd_abi::deduce_t<T, N>> == N, "Simd size mismatch with abi deduce");29 static_assert(ex::simd_size<T, ex::simd_abi::deduce_t<T, N>>::value == N, "Simd size mismatch with abi deduce");30 }31 32 template <class T, std::size_t... N>33 void performChecks(std::index_sequence<N...>) {34 (check<T, N + 1>(), ...);35 }36 37 template <class T>38 void operator()() {39 performChecks<T>(std::make_index_sequence<max_simd_size>{});40 }41};42 43struct CheckSimdSizeScalarNativeCompatible {44 template <class T>45 void operator()() {46 static_assert(ex::simd_size_v<T, ex::simd_abi::scalar> == 1);47 static_assert(ex::simd_size<T, ex::simd_abi::scalar>::value == 1);48 49 LIBCPP_STATIC_ASSERT(ex::simd_size<T, ex::simd_abi::compatible<T>>::value == 16 / sizeof(T));50 LIBCPP_STATIC_ASSERT(ex::simd_size_v<T, ex::simd_abi::compatible<T>> == 16 / sizeof(T));51 52 LIBCPP_STATIC_ASSERT(53 ex::simd_size<T, ex::simd_abi::native<T>>::value == _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(T));54 LIBCPP_STATIC_ASSERT(ex::simd_size_v<T, ex::simd_abi::native<T>> == _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(T));55 }56};57 58template <class T, class Abi = ex::simd_abi::compatible<T>, class = void>59struct has_simd_size : std::false_type {};60 61template <class T, class Abi>62struct has_simd_size<T, Abi, std::void_t<decltype(ex::simd_size<T, Abi>::value)>> : std::true_type {};63 64struct CheckSimdSizeTraits {65 template <class T>66 void operator()() {67 static_assert(has_simd_size<T>::value);68 static_assert(!has_simd_size<ex::native_simd<T>>::value);69 70 static_assert(has_simd_size<T, ex::simd_abi::scalar>::value);71 static_assert(has_simd_size<T, ex::simd_abi::fixed_size<4>>::value);72 static_assert(has_simd_size<T, ex::simd_abi::native<T>>::value);73 static_assert(has_simd_size<T, ex::simd_abi::compatible<T>>::value);74 75 static_assert(!has_simd_size<ex::simd_abi::native<T>, ex::simd_abi::native<T>>::value);76 static_assert(!has_simd_size<ex::native_simd<T>, ex::simd_abi::native<T>>::value);77 static_assert(!has_simd_size<ex::fixed_size_simd<T, 3>, ex::simd_abi::native<T>>::value);78 static_assert(!has_simd_size<ex::fixed_size_simd_mask<T, 4>, ex::simd_abi::native<T>>::value);79 80 static_assert(!has_simd_size<T, T>::value);81 static_assert(!has_simd_size<T, ex::native_simd<T>>::value);82 static_assert(!has_simd_size<T, ex::fixed_size_simd<T, 3>>::value);83 static_assert(!has_simd_size<T, ex::fixed_size_simd_mask<T, 4>>::value);84 }85};86 87int main(int, char**) {88 types::for_each(arithmetic_no_bool_types(), CheckSimdSizeFixedDeduce());89 types::for_each(arithmetic_no_bool_types(), CheckSimdSizeScalarNativeCompatible());90 types::for_each(arithmetic_no_bool_types(), CheckSimdSizeTraits());91 return 0;92}93