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