Tim Shen | 403c667 | 2018-04-23 21:54:06 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Tim Shen | 38cd7de | 2018-07-30 22:27:38 +0000 | [diff] [blame^] | 10 | // UNSUPPORTED: c++98, c++03, c++11, c++14 |
Tim Shen | 403c667 | 2018-04-23 21:54:06 +0000 | [diff] [blame] | 11 | |
| 12 | // See GCC PR63723. |
| 13 | // UNSUPPORTED: gcc-4.9 |
| 14 | |
| 15 | // <experimental/simd> |
| 16 | // |
| 17 | // [simd.class] |
| 18 | // template <class U> simd(U&& value); |
| 19 | |
| 20 | #include <cstdint> |
| 21 | #include <experimental/simd> |
| 22 | |
Tim Shen | 38cd7de | 2018-07-30 22:27:38 +0000 | [diff] [blame^] | 23 | namespace ex = std::experimental::parallelism_v2; |
Tim Shen | 403c667 | 2018-04-23 21:54:06 +0000 | [diff] [blame] | 24 | |
| 25 | template <class T, class... Args> |
| 26 | auto not_supported_native_simd_ctor(Args&&... args) |
Tim Shen | 38cd7de | 2018-07-30 22:27:38 +0000 | [diff] [blame^] | 27 | -> decltype(ex::native_simd<T>(std::forward<Args>(args)...), |
| 28 | void()) = delete; |
Tim Shen | 403c667 | 2018-04-23 21:54:06 +0000 | [diff] [blame] | 29 | |
| 30 | template <class T> |
| 31 | void not_supported_native_simd_ctor(...) {} |
| 32 | |
| 33 | template <class T, class... Args> |
| 34 | auto supported_native_simd_ctor(Args&&... args) |
Tim Shen | 38cd7de | 2018-07-30 22:27:38 +0000 | [diff] [blame^] | 35 | -> decltype(ex::native_simd<T>(std::forward<Args>(args)...), void()) {} |
Tim Shen | 403c667 | 2018-04-23 21:54:06 +0000 | [diff] [blame] | 36 | |
| 37 | template <class T> |
| 38 | void supported_native_simd_ctor(...) = delete; |
| 39 | |
| 40 | void compile_narrowing_conversion() { |
| 41 | supported_native_simd_ctor<int8_t>(3); |
| 42 | supported_native_simd_ctor<int16_t>(3); |
| 43 | supported_native_simd_ctor<int32_t>(3); |
| 44 | supported_native_simd_ctor<int64_t>(3); |
| 45 | supported_native_simd_ctor<uint8_t>(3); |
| 46 | supported_native_simd_ctor<uint16_t>(3); |
| 47 | supported_native_simd_ctor<uint32_t>(3); |
| 48 | supported_native_simd_ctor<uint64_t>(3); |
| 49 | supported_native_simd_ctor<float>(3.f); |
| 50 | supported_native_simd_ctor<double>(3.); |
| 51 | supported_native_simd_ctor<long double>(3.); |
| 52 | |
| 53 | not_supported_native_simd_ctor<float>(3.); |
| 54 | not_supported_native_simd_ctor<int8_t>(long(3)); |
| 55 | not_supported_native_simd_ctor<float>(long(3)); |
| 56 | not_supported_native_simd_ctor<int>(3.); |
| 57 | } |
| 58 | |
Tim Shen | 38cd7de | 2018-07-30 22:27:38 +0000 | [diff] [blame^] | 59 | void compile_convertible() { |
| 60 | struct ConvertibleToInt { |
| 61 | operator int64_t() const; |
| 62 | }; |
| 63 | supported_native_simd_ctor<int64_t>(ConvertibleToInt()); |
| 64 | |
| 65 | struct NotConvertibleToInt {}; |
| 66 | not_supported_native_simd_ctor<int64_t>(NotConvertibleToInt()); |
| 67 | } |
| 68 | |
| 69 | void compile_unsigned() { |
| 70 | not_supported_native_simd_ctor<int>(3u); |
| 71 | supported_native_simd_ctor<uint16_t>(3u); |
| 72 | } |
| 73 | |
| 74 | template <typename SimdType> |
| 75 | void test_broadcast() { |
| 76 | SimdType a(3); |
| 77 | for (size_t i = 0; i < a.size(); i++) { |
| 78 | assert(a[i] == 3); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | int main() { |
| 83 | test_broadcast<ex::native_simd<int>>(); |
| 84 | test_broadcast<ex::fixed_size_simd<int, 4>>(); |
| 85 | test_broadcast<ex::fixed_size_simd<int, 15>>(); |
| 86 | } |