libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

store.pass.cpp (2557B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // UNSUPPORTED: c++98, c++03, c++11, c++14
     11 
     12 // <experimental/simd>
     13 //
     14 // // stores [simd.store]
     15 // template <class U, class Flags> void copy_to(U* mem, Flags f) const;
     16 
     17 #include <experimental/simd>
     18 #include <cstdint>
     19 
     20 #include "test_macros.h"
     21 
     22 namespace ex = std::experimental::parallelism_v2;
     23 
     24 template <typename SimdType>
     25 void test_store() {
     26   SimdType a([](int i) { return 4 - i; });
     27   {
     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);
     34   }
     35   {
     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);
     42   }
     43   {
     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);
     50   }
     51 
     52   {
     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);
     59   }
     60   {
     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);
     67   }
     68   {
     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);
     75   }
     76 }
     77 
     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.);
     87 }
     88 
     89 int main() {
     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>>();
     95 }