1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// <experimental/simd>
//
// [simd.class]
// template <class U, class Flags> simd(const U* mem, Flags f);
#include <experimental/simd>
#include <cstdint>
#include <cassert>
#include "test_macros.h"
namespace ex = std::experimental::parallelism_v2;
template <class T, class... Args>
auto not_supported_native_simd_ctor(Args&&... args)
-> decltype(ex::native_simd<T>(std::forward<Args>(args)...),
void()) = delete;
template <class T>
void not_supported_native_simd_ctor(...) {}
template <class T, class... Args>
auto supported_native_simd_ctor(Args&&... args)
-> decltype(ex::native_simd<T>(std::forward<Args>(args)...), void()) {}
template <class T>
void supported_native_simd_ctor(...) = delete;
void compile_load_ctor() {
supported_native_simd_ctor<int>((int*)nullptr, ex::element_aligned_tag());
supported_native_simd_ctor<uint32_t>((int*)nullptr,
ex::element_aligned_tag());
supported_native_simd_ctor<double>((float*)nullptr,
ex::element_aligned_tag());
supported_native_simd_ctor<uint16_t>((unsigned int*)nullptr,
ex::element_aligned_tag());
supported_native_simd_ctor<uint32_t>((float*)nullptr,
ex::element_aligned_tag());
not_supported_native_simd_ctor<int>((int*)nullptr, int());
}
template <typename SimdType>
void test_load_ctor() {
alignas(32) int32_t buffer[] = {4, 3, 2, 1};
{
SimdType a(buffer, ex::element_aligned_tag());
assert(a[0] == 4);
assert(a[1] == 3);
assert(a[2] == 2);
assert(a[3] == 1);
}
{
SimdType a(buffer, ex::vector_aligned_tag());
assert(a[0] == 4);
assert(a[1] == 3);
assert(a[2] == 2);
assert(a[3] == 1);
}
{
SimdType a(buffer, ex::overaligned_tag<32>());
assert(a[0] == 4);
assert(a[1] == 3);
assert(a[2] == 2);
assert(a[3] == 1);
}
{
SimdType a(buffer, ex::element_aligned);
assert(a[0] == 4);
assert(a[1] == 3);
assert(a[2] == 2);
assert(a[3] == 1);
}
{
SimdType a(buffer, ex::vector_aligned);
assert(a[0] == 4);
assert(a[1] == 3);
assert(a[2] == 2);
assert(a[3] == 1);
}
{
SimdType a(buffer, ex::overaligned<32>);
assert(a[0] == 4);
assert(a[1] == 3);
assert(a[2] == 2);
assert(a[3] == 1);
}
}
template <typename SimdType>
void test_converting_load_ctor() {
float buffer[] = {1., 2., 4., 8.};
SimdType a(buffer, ex::element_aligned_tag());
assert(a[0] == 1);
assert(a[1] == 2);
assert(a[2] == 4);
assert(a[3] == 8);
}
int main(int, char**) {
// TODO: adjust the tests when this assertion fails.
assert(ex::native_simd<int32_t>::size() >= 4);
test_load_ctor<ex::native_simd<int32_t>>();
test_load_ctor<ex::fixed_size_simd<int32_t, 4>>();
test_converting_load_ctor<ex::native_simd<int32_t>>();
test_converting_load_ctor<ex::fixed_size_simd<int32_t, 4>>();
return 0;
}
|