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 // <experimental/simd> 12 // 13 // // stores [simd.store] 14 // template <class U, class Flags> void copy_to(U* mem, Flags f) const; 15 16 #include <experimental/simd> 17 #include <cstdint> 18 19 #include "test_macros.h" 20 21 namespace ex = std::experimental::parallelism_v2; 22 23 template <typename SimdType> 24 void test_store() { 25 SimdType a([](int i) { return 4 - i; }); 26 { 27 alignas(32) int32_t buffer[4] = {0}; 28 a.copy_to(buffer, ex::element_aligned_tag()); 29 assert(buffer[0] == 4); 30 assert(buffer[1] == 3); 31 assert(buffer[2] == 2); 32 assert(buffer[3] == 1); 33 } 34 { 35 alignas(32) int32_t buffer[4] = {0}; 36 a.copy_to(buffer, ex::vector_aligned_tag()); 37 assert(buffer[0] == 4); 38 assert(buffer[1] == 3); 39 assert(buffer[2] == 2); 40 assert(buffer[3] == 1); 41 } 42 { 43 alignas(32) int32_t buffer[4] = {0}; 44 a.copy_to(buffer, ex::overaligned_tag<32>()); 45 assert(buffer[0] == 4); 46 assert(buffer[1] == 3); 47 assert(buffer[2] == 2); 48 assert(buffer[3] == 1); 49 } 50 51 { 52 alignas(32) int32_t buffer[4] = {0}; 53 a.copy_to(buffer, ex::element_aligned); 54 assert(buffer[0] == 4); 55 assert(buffer[1] == 3); 56 assert(buffer[2] == 2); 57 assert(buffer[3] == 1); 58 } 59 { 60 alignas(32) int32_t buffer[4] = {0}; 61 a.copy_to(buffer, ex::vector_aligned); 62 assert(buffer[0] == 4); 63 assert(buffer[1] == 3); 64 assert(buffer[2] == 2); 65 assert(buffer[3] == 1); 66 } 67 { 68 alignas(32) int32_t buffer[4] = {0}; 69 a.copy_to(buffer, ex::overaligned<32>); 70 assert(buffer[0] == 4); 71 assert(buffer[1] == 3); 72 assert(buffer[2] == 2); 73 assert(buffer[3] == 1); 74 } 75 } 76 77 template <typename SimdType> 78 void test_converting_store() { 79 float buffer[4] = {0.}; 80 SimdType a([](int i) { return 1 << i; }); 81 a.copy_to(buffer, ex::element_aligned_tag()); 82 assert(buffer[0] == 1.); 83 assert(buffer[1] == 2.); 84 assert(buffer[2] == 4.); 85 assert(buffer[3] == 8.); 86 } 87 88 int main(int, char**) { 89 // TODO: adjust the tests when this assertion fails. 90 test_store<ex::native_simd<int32_t>>(); 91 test_store<ex::fixed_size_simd<int32_t, 4>>(); 92 test_converting_store<ex::native_simd<int32_t>>(); 93 test_converting_store<ex::fixed_size_simd<int32_t, 4>>(); 94 95 return 0; 96 } 97