blob: 57a6cd57ee20110039c733c07fe5ed4f218525bb [file] [log] [blame]
Tim Shen403c6672018-04-23 21:54:06 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Shen403c6672018-04-23 21:54:06 +00006//
7//===----------------------------------------------------------------------===//
8
Tim Shen38cd7de2018-07-30 22:27:38 +00009// UNSUPPORTED: c++98, c++03, c++11, c++14
Tim Shen403c6672018-04-23 21:54:06 +000010
Tim Shen403c6672018-04-23 21:54:06 +000011// <experimental/simd>
12//
13// [simd.class]
14// template <class U> simd(U&& value);
15
16#include <cstdint>
17#include <experimental/simd>
18
Marshall Clow7fc6a552019-05-31 18:35:30 +000019#include "test_macros.h"
20
Tim Shen38cd7de2018-07-30 22:27:38 +000021namespace ex = std::experimental::parallelism_v2;
Tim Shen403c6672018-04-23 21:54:06 +000022
23template <class T, class... Args>
24auto not_supported_native_simd_ctor(Args&&... args)
Tim Shen38cd7de2018-07-30 22:27:38 +000025 -> decltype(ex::native_simd<T>(std::forward<Args>(args)...),
26 void()) = delete;
Tim Shen403c6672018-04-23 21:54:06 +000027
28template <class T>
29void not_supported_native_simd_ctor(...) {}
30
31template <class T, class... Args>
32auto supported_native_simd_ctor(Args&&... args)
Tim Shen38cd7de2018-07-30 22:27:38 +000033 -> decltype(ex::native_simd<T>(std::forward<Args>(args)...), void()) {}
Tim Shen403c6672018-04-23 21:54:06 +000034
35template <class T>
36void supported_native_simd_ctor(...) = delete;
37
38void compile_narrowing_conversion() {
39 supported_native_simd_ctor<int8_t>(3);
40 supported_native_simd_ctor<int16_t>(3);
41 supported_native_simd_ctor<int32_t>(3);
42 supported_native_simd_ctor<int64_t>(3);
43 supported_native_simd_ctor<uint8_t>(3);
44 supported_native_simd_ctor<uint16_t>(3);
45 supported_native_simd_ctor<uint32_t>(3);
46 supported_native_simd_ctor<uint64_t>(3);
47 supported_native_simd_ctor<float>(3.f);
48 supported_native_simd_ctor<double>(3.);
49 supported_native_simd_ctor<long double>(3.);
50
51 not_supported_native_simd_ctor<float>(3.);
52 not_supported_native_simd_ctor<int8_t>(long(3));
53 not_supported_native_simd_ctor<float>(long(3));
54 not_supported_native_simd_ctor<int>(3.);
55}
56
Tim Shen38cd7de2018-07-30 22:27:38 +000057void compile_convertible() {
58 struct ConvertibleToInt {
59 operator int64_t() const;
60 };
61 supported_native_simd_ctor<int64_t>(ConvertibleToInt());
62
63 struct NotConvertibleToInt {};
64 not_supported_native_simd_ctor<int64_t>(NotConvertibleToInt());
65}
66
67void compile_unsigned() {
68 not_supported_native_simd_ctor<int>(3u);
69 supported_native_simd_ctor<uint16_t>(3u);
70}
71
72template <typename SimdType>
73void test_broadcast() {
74 SimdType a(3);
75 for (size_t i = 0; i < a.size(); i++) {
76 assert(a[i] == 3);
77 }
78}
79
JF Bastien2df59c52019-02-04 20:31:13 +000080int main(int, char**) {
Tim Shen38cd7de2018-07-30 22:27:38 +000081 test_broadcast<ex::native_simd<int>>();
82 test_broadcast<ex::fixed_size_simd<int, 4>>();
83 test_broadcast<ex::fixed_size_simd<int, 15>>();
JF Bastien2df59c52019-02-04 20:31:13 +000084
85 return 0;
Tim Shen38cd7de2018-07-30 22:27:38 +000086}