blob: c4b352acf98085b5672a19ad565a9bc79a55cd55 [file] [log] [blame]
Tim Shen38cd7de2018-07-30 22:27:38 +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 Shen38cd7de2018-07-30 22:27:38 +00006//
7//===----------------------------------------------------------------------===//
8
Louis Dionne31cbe0f2020-06-01 10:38:23 -04009// UNSUPPORTED: c++03, c++11, c++14
Tim Shen38cd7de2018-07-30 22:27:38 +000010
11// <experimental/simd>
12//
13// [simd.class]
14// template <class U, class Flags> simd(const U* mem, Flags f);
15
Tim Shen38cd7de2018-07-30 22:27:38 +000016#include <experimental/simd>
David Zarzyckia0686012019-09-26 11:12:29 +000017#include <cstdint>
18#include <cassert>
Tim Shen38cd7de2018-07-30 22:27:38 +000019
20#include "test_macros.h"
21
22namespace ex = std::experimental::parallelism_v2;
23
24template <class T, class... Args>
25auto not_supported_native_simd_ctor(Args&&... args)
26 -> decltype(ex::native_simd<T>(std::forward<Args>(args)...),
27 void()) = delete;
28
29template <class T>
30void not_supported_native_simd_ctor(...) {}
31
32template <class T, class... Args>
33auto supported_native_simd_ctor(Args&&... args)
34 -> decltype(ex::native_simd<T>(std::forward<Args>(args)...), void()) {}
35
36template <class T>
37void supported_native_simd_ctor(...) = delete;
38
39void compile_load_ctor() {
40 supported_native_simd_ctor<int>((int*)nullptr, ex::element_aligned_tag());
41 supported_native_simd_ctor<uint32_t>((int*)nullptr,
42 ex::element_aligned_tag());
43 supported_native_simd_ctor<double>((float*)nullptr,
44 ex::element_aligned_tag());
45 supported_native_simd_ctor<uint16_t>((unsigned int*)nullptr,
46 ex::element_aligned_tag());
47 supported_native_simd_ctor<uint32_t>((float*)nullptr,
48 ex::element_aligned_tag());
49
50 not_supported_native_simd_ctor<int>((int*)nullptr, int());
51}
52
53template <typename SimdType>
54void test_load_ctor() {
55 alignas(32) int32_t buffer[] = {4, 3, 2, 1};
56 {
57 SimdType a(buffer, ex::element_aligned_tag());
58 assert(a[0] == 4);
59 assert(a[1] == 3);
60 assert(a[2] == 2);
61 assert(a[3] == 1);
62 }
63 {
64 SimdType a(buffer, ex::vector_aligned_tag());
65 assert(a[0] == 4);
66 assert(a[1] == 3);
67 assert(a[2] == 2);
68 assert(a[3] == 1);
69 }
70 {
71 SimdType a(buffer, ex::overaligned_tag<32>());
72 assert(a[0] == 4);
73 assert(a[1] == 3);
74 assert(a[2] == 2);
75 assert(a[3] == 1);
76 }
77
78 {
79 SimdType a(buffer, ex::element_aligned);
80 assert(a[0] == 4);
81 assert(a[1] == 3);
82 assert(a[2] == 2);
83 assert(a[3] == 1);
84 }
85 {
86 SimdType a(buffer, ex::vector_aligned);
87 assert(a[0] == 4);
88 assert(a[1] == 3);
89 assert(a[2] == 2);
90 assert(a[3] == 1);
91 }
92 {
93 SimdType a(buffer, ex::overaligned<32>);
94 assert(a[0] == 4);
95 assert(a[1] == 3);
96 assert(a[2] == 2);
97 assert(a[3] == 1);
98 }
99}
100
101template <typename SimdType>
102void test_converting_load_ctor() {
103 float buffer[] = {1., 2., 4., 8.};
104 SimdType a(buffer, ex::element_aligned_tag());
105 assert(a[0] == 1);
106 assert(a[1] == 2);
107 assert(a[2] == 4);
108 assert(a[3] == 8);
109}
110
JF Bastien2df59c52019-02-04 20:31:13 +0000111int main(int, char**) {
Tim Shen38cd7de2018-07-30 22:27:38 +0000112 // TODO: adjust the tests when this assertion fails.
113 assert(ex::native_simd<int32_t>::size() >= 4);
114 test_load_ctor<ex::native_simd<int32_t>>();
115 test_load_ctor<ex::fixed_size_simd<int32_t, 4>>();
116 test_converting_load_ctor<ex::native_simd<int32_t>>();
117 test_converting_load_ctor<ex::fixed_size_simd<int32_t, 4>>();
JF Bastien2df59c52019-02-04 20:31:13 +0000118
119 return 0;
Tim Shen38cd7de2018-07-30 22:27:38 +0000120}