1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
12 // <experimental/simd>
14 // // stores [simd.store]
15 // template <class U, class Flags> void copy_to(U* mem, Flags f) const;
17 #include <experimental/simd>
20 #include "test_macros.h"
22 namespace ex = std::experimental::parallelism_v2;
24 template <typename SimdType>
26 SimdType a([](int i) { return 4 - i; });
28 alignas(32) int32_t buffer[4] = {0};
29 a.copy_to(buffer, ex::element_aligned_tag());
30 assert(buffer[0] == 4);
31 assert(buffer[1] == 3);
32 assert(buffer[2] == 2);
33 assert(buffer[3] == 1);
36 alignas(32) int32_t buffer[4] = {0};
37 a.copy_to(buffer, ex::vector_aligned_tag());
38 assert(buffer[0] == 4);
39 assert(buffer[1] == 3);
40 assert(buffer[2] == 2);
41 assert(buffer[3] == 1);
44 alignas(32) int32_t buffer[4] = {0};
45 a.copy_to(buffer, ex::overaligned_tag<32>());
46 assert(buffer[0] == 4);
47 assert(buffer[1] == 3);
48 assert(buffer[2] == 2);
49 assert(buffer[3] == 1);
53 alignas(32) int32_t buffer[4] = {0};
54 a.copy_to(buffer, ex::element_aligned);
55 assert(buffer[0] == 4);
56 assert(buffer[1] == 3);
57 assert(buffer[2] == 2);
58 assert(buffer[3] == 1);
61 alignas(32) int32_t buffer[4] = {0};
62 a.copy_to(buffer, ex::vector_aligned);
63 assert(buffer[0] == 4);
64 assert(buffer[1] == 3);
65 assert(buffer[2] == 2);
66 assert(buffer[3] == 1);
69 alignas(32) int32_t buffer[4] = {0};
70 a.copy_to(buffer, ex::overaligned<32>);
71 assert(buffer[0] == 4);
72 assert(buffer[1] == 3);
73 assert(buffer[2] == 2);
74 assert(buffer[3] == 1);
78 template <typename SimdType>
79 void test_converting_store() {
80 float buffer[4] = {0.};
81 SimdType a([](int i) { return 1 << i; });
82 a.copy_to(buffer, ex::element_aligned_tag());
83 assert(buffer[0] == 1.);
84 assert(buffer[1] == 2.);
85 assert(buffer[2] == 4.);
86 assert(buffer[3] == 8.);
90 // TODO: adjust the tests when this assertion fails.
91 test_store<ex::native_simd<int32_t>>();
92 test_store<ex::fixed_size_simd<int32_t, 4>>();
93 test_converting_store<ex::native_simd<int32_t>>();
94 test_converting_store<ex::fixed_size_simd<int32_t, 4>>();