//===----------------------------------------------------------------------===// // // 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 // // // [simd.class] // template simd(const U* mem, Flags f); #include #include #include #include "test_macros.h" namespace ex = std::experimental::parallelism_v2; template auto not_supported_native_simd_ctor(Args&&... args) -> decltype(ex::native_simd(std::forward(args)...), void()) = delete; template void not_supported_native_simd_ctor(...) {} template auto supported_native_simd_ctor(Args&&... args) -> decltype(ex::native_simd(std::forward(args)...), void()) {} template void supported_native_simd_ctor(...) = delete; void compile_load_ctor() { supported_native_simd_ctor((int*)nullptr, ex::element_aligned_tag()); supported_native_simd_ctor((int*)nullptr, ex::element_aligned_tag()); supported_native_simd_ctor((float*)nullptr, ex::element_aligned_tag()); supported_native_simd_ctor((unsigned int*)nullptr, ex::element_aligned_tag()); supported_native_simd_ctor((float*)nullptr, ex::element_aligned_tag()); not_supported_native_simd_ctor((int*)nullptr, int()); } template 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 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::size() >= 4); test_load_ctor>(); test_load_ctor>(); test_converting_load_ctor>(); test_converting_load_ctor>(); return 0; }