|
| 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-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +// UNSUPPORTED: c++03, c++11, c++14 |
| 10 | + |
| 11 | +// <experimental/simd> |
| 12 | +// |
| 13 | +// [simd.reference] |
| 14 | +// template<class U> reference+=(U&& x) && noexcept; |
| 15 | +// template<class U> reference-=(U&& x) && noexcept; |
| 16 | +// template<class U> reference*=(U&& x) && noexcept; |
| 17 | +// template<class U> reference/=(U&& x) && noexcept; |
| 18 | +// template<class U> reference%=(U&& x) && noexcept; |
| 19 | +// template<class U> reference|=(U&& x) && noexcept; |
| 20 | +// template<class U> reference&=(U&& x) && noexcept; |
| 21 | +// template<class U> reference^=(U&& x) && noexcept; |
| 22 | +// template<class U> reference<<=(U&& x) && noexcept; |
| 23 | +// template<class U> reference>>=(U&& x) && noexcept; |
| 24 | + |
| 25 | +#include "../test_utils.h" |
| 26 | +#include <experimental/simd> |
| 27 | + |
| 28 | +namespace ex = std::experimental::parallelism_v2; |
| 29 | + |
| 30 | +#define LIBCXX_SIMD_REFERENCE_OP_(op, name) \ |
| 31 | + template <class T, class SimdAbi> \ |
| 32 | + struct SimdReferenceOperatorHelper##name { \ |
| 33 | + template <class U> \ |
| 34 | + void operator()() const { \ |
| 35 | + ex::simd<T, SimdAbi> origin_simd([](T i) { return i; }); \ |
| 36 | + for (size_t i = 0; i < origin_simd.size(); ++i) { \ |
| 37 | + static_assert(noexcept(origin_simd[i] op## = static_cast<U>(2))); \ |
| 38 | + origin_simd[i] op## = static_cast<U>(2); \ |
| 39 | + assert((T)origin_simd[i] == (T)(static_cast<T>(i) op static_cast<T>(std::forward<U>(2)))); \ |
| 40 | + } \ |
| 41 | + } \ |
| 42 | + }; |
| 43 | +LIBCXX_SIMD_REFERENCE_OP_(+, Plus) |
| 44 | +LIBCXX_SIMD_REFERENCE_OP_(-, Minus) |
| 45 | +LIBCXX_SIMD_REFERENCE_OP_(*, Multiplies) |
| 46 | +LIBCXX_SIMD_REFERENCE_OP_(/, Divides) |
| 47 | +LIBCXX_SIMD_REFERENCE_OP_(%, Modulus) |
| 48 | +LIBCXX_SIMD_REFERENCE_OP_(&, BitAnd) |
| 49 | +LIBCXX_SIMD_REFERENCE_OP_(|, BitOr) |
| 50 | +LIBCXX_SIMD_REFERENCE_OP_(^, BitXor) |
| 51 | +LIBCXX_SIMD_REFERENCE_OP_(<<, ShiftLeft) |
| 52 | +LIBCXX_SIMD_REFERENCE_OP_(>>, ShiftRight) |
| 53 | +#undef LIBCXX_SIMD_REFERENCE_OP_ |
| 54 | + |
| 55 | +#define LIBCXX_SIMD_MASK_REFERENCE_OP_(op, name) \ |
| 56 | + template <class T, class SimdAbi> \ |
| 57 | + struct MaskReferenceOperatorHelper##name { \ |
| 58 | + template <class U> \ |
| 59 | + void operator()() const { \ |
| 60 | + ex::simd<T, SimdAbi> origin_simd_mask(true); \ |
| 61 | + for (size_t i = 0; i < origin_simd_mask.size(); ++i) { \ |
| 62 | + static_assert(noexcept(origin_simd_mask[i] op## = static_cast<U>(i % 2))); \ |
| 63 | + origin_simd_mask[i] op## = static_cast<U>(i % 2); \ |
| 64 | + assert((bool)origin_simd_mask[i] == (bool)(true op static_cast<bool>(std::forward<U>(i % 2)))); \ |
| 65 | + } \ |
| 66 | + } \ |
| 67 | + }; |
| 68 | +LIBCXX_SIMD_MASK_REFERENCE_OP_(&, BitAnd) |
| 69 | +LIBCXX_SIMD_MASK_REFERENCE_OP_(|, BitOr) |
| 70 | +LIBCXX_SIMD_MASK_REFERENCE_OP_(^, BitXor) |
| 71 | +#undef LIBCXX_SIMD_MASK_REFERENCE_OP_ |
| 72 | + |
| 73 | +template <class T, std::size_t> |
| 74 | +struct CheckReferenceArithOperators { |
| 75 | + template <class SimdAbi> |
| 76 | + void operator()() { |
| 77 | + types::for_each(simd_test_types(), SimdReferenceOperatorHelperPlus<T, SimdAbi>()); |
| 78 | + types::for_each(simd_test_types(), SimdReferenceOperatorHelperMinus<T, SimdAbi>()); |
| 79 | + types::for_each(simd_test_types(), SimdReferenceOperatorHelperMultiplies<T, SimdAbi>()); |
| 80 | + types::for_each(simd_test_types(), SimdReferenceOperatorHelperDivides<T, SimdAbi>()); |
| 81 | + } |
| 82 | +}; |
| 83 | + |
| 84 | +template <class T, std::size_t> |
| 85 | +struct CheckReferenceIntOperators { |
| 86 | + template <class SimdAbi> |
| 87 | + void operator()() { |
| 88 | + types::for_each(simd_test_integer_types(), SimdReferenceOperatorHelperModulus<T, SimdAbi>()); |
| 89 | + types::for_each(simd_test_integer_types(), SimdReferenceOperatorHelperBitAnd<T, SimdAbi>()); |
| 90 | + types::for_each(simd_test_integer_types(), SimdReferenceOperatorHelperBitOr<T, SimdAbi>()); |
| 91 | + types::for_each(simd_test_integer_types(), SimdReferenceOperatorHelperBitXor<T, SimdAbi>()); |
| 92 | + types::for_each(simd_test_integer_types(), SimdReferenceOperatorHelperShiftLeft<T, SimdAbi>()); |
| 93 | + types::for_each(simd_test_integer_types(), SimdReferenceOperatorHelperShiftRight<T, SimdAbi>()); |
| 94 | + |
| 95 | + types::for_each(simd_test_integer_types(), MaskReferenceOperatorHelperBitAnd<T, SimdAbi>()); |
| 96 | + types::for_each(simd_test_integer_types(), MaskReferenceOperatorHelperBitOr<T, SimdAbi>()); |
| 97 | + types::for_each(simd_test_integer_types(), MaskReferenceOperatorHelperBitXor<T, SimdAbi>()); |
| 98 | + } |
| 99 | +}; |
| 100 | + |
| 101 | +int main(int, char**) { |
| 102 | + test_all_simd_abi<CheckReferenceArithOperators>(); |
| 103 | + types::for_each(types::integer_types(), TestAllSimdAbiFunctor<CheckReferenceIntOperators>()); |
| 104 | + return 0; |
| 105 | +} |
0 commit comments