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++98, c++03, c++11, c++14
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 
22 #include "test_macros.h"
23 
24 namespace ex = std::experimental::parallelism_v2;
25 
26 template <class T, class... Args>
27 auto not_supported_native_simd_ctor(Args&&... args)
28     -> decltype(ex::native_simd<T>(std::forward<Args>(args)...),
29                 void()) = delete;
30 
31 template <class T>
32 void not_supported_native_simd_ctor(...) {}
33 
34 template <class T, class... Args>
35 auto supported_native_simd_ctor(Args&&... args)
36     -> decltype(ex::native_simd<T>(std::forward<Args>(args)...), void()) {}
37 
38 template <class T>
39 void supported_native_simd_ctor(...) = delete;
40 
41 void compile_narrowing_conversion() {
42   supported_native_simd_ctor<int8_t>(3);
43   supported_native_simd_ctor<int16_t>(3);
44   supported_native_simd_ctor<int32_t>(3);
45   supported_native_simd_ctor<int64_t>(3);
46   supported_native_simd_ctor<uint8_t>(3);
47   supported_native_simd_ctor<uint16_t>(3);
48   supported_native_simd_ctor<uint32_t>(3);
49   supported_native_simd_ctor<uint64_t>(3);
50   supported_native_simd_ctor<float>(3.f);
51   supported_native_simd_ctor<double>(3.);
52   supported_native_simd_ctor<long double>(3.);
53 
54   not_supported_native_simd_ctor<float>(3.);
55   not_supported_native_simd_ctor<int8_t>(long(3));
56   not_supported_native_simd_ctor<float>(long(3));
57   not_supported_native_simd_ctor<int>(3.);
58 }
59 
60 void compile_convertible() {
61   struct ConvertibleToInt {
62     operator int64_t() const;
63   };
64   supported_native_simd_ctor<int64_t>(ConvertibleToInt());
65 
66   struct NotConvertibleToInt {};
67   not_supported_native_simd_ctor<int64_t>(NotConvertibleToInt());
68 }
69 
70 void compile_unsigned() {
71   not_supported_native_simd_ctor<int>(3u);
72   supported_native_simd_ctor<uint16_t>(3u);
73 }
74 
75 template <typename SimdType>
76 void test_broadcast() {
77   SimdType a(3);
78   for (size_t i = 0; i < a.size(); i++) {
79     assert(a[i] == 3);
80   }
81 }
82 
83 int main(int, char**) {
84   test_broadcast<ex::native_simd<int>>();
85   test_broadcast<ex::fixed_size_simd<int, 4>>();
86   test_broadcast<ex::fixed_size_simd<int, 15>>();
87 
88   return 0;
89 }
90