summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/experimental/simd/simd.cons
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test/std/experimental/simd/simd.cons')
-rw-r--r--libcxx/test/std/experimental/simd/simd.cons/broadcast.pass.cpp38
-rw-r--r--libcxx/test/std/experimental/simd/simd.cons/default.pass.cpp28
-rw-r--r--libcxx/test/std/experimental/simd/simd.cons/generator.pass.cpp73
-rw-r--r--libcxx/test/std/experimental/simd/simd.cons/load.pass.cpp118
4 files changed, 238 insertions, 19 deletions
diff --git a/libcxx/test/std/experimental/simd/simd.cons/broadcast.pass.cpp b/libcxx/test/std/experimental/simd/simd.cons/broadcast.pass.cpp
index 60230cc6373..49b2b557284 100644
--- a/libcxx/test/std/experimental/simd/simd.cons/broadcast.pass.cpp
+++ b/libcxx/test/std/experimental/simd/simd.cons/broadcast.pass.cpp
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++98, c++03
+// UNSUPPORTED: c++98, c++03, c++11, c++14
// See GCC PR63723.
// UNSUPPORTED: gcc-4.9
@@ -20,18 +20,19 @@
#include <cstdint>
#include <experimental/simd>
-using namespace std::experimental::parallelism_v2;
+namespace ex = std::experimental::parallelism_v2;
template <class T, class... Args>
auto not_supported_native_simd_ctor(Args&&... args)
- -> decltype(native_simd<T>(std::forward<Args>(args)...), void()) = delete;
+ -> 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(native_simd<T>(std::forward<Args>(args)...), void()) {}
+ -> decltype(ex::native_simd<T>(std::forward<Args>(args)...), void()) {}
template <class T>
void supported_native_simd_ctor(...) = delete;
@@ -55,4 +56,31 @@ void compile_narrowing_conversion() {
not_supported_native_simd_ctor<int>(3.);
}
-int main() {}
+void compile_convertible() {
+ struct ConvertibleToInt {
+ operator int64_t() const;
+ };
+ supported_native_simd_ctor<int64_t>(ConvertibleToInt());
+
+ struct NotConvertibleToInt {};
+ not_supported_native_simd_ctor<int64_t>(NotConvertibleToInt());
+}
+
+void compile_unsigned() {
+ not_supported_native_simd_ctor<int>(3u);
+ supported_native_simd_ctor<uint16_t>(3u);
+}
+
+template <typename SimdType>
+void test_broadcast() {
+ SimdType a(3);
+ for (size_t i = 0; i < a.size(); i++) {
+ assert(a[i] == 3);
+ }
+}
+
+int main() {
+ test_broadcast<ex::native_simd<int>>();
+ test_broadcast<ex::fixed_size_simd<int, 4>>();
+ test_broadcast<ex::fixed_size_simd<int, 15>>();
+}
diff --git a/libcxx/test/std/experimental/simd/simd.cons/default.pass.cpp b/libcxx/test/std/experimental/simd/simd.cons/default.pass.cpp
new file mode 100644
index 00000000000..0f12eced0aa
--- /dev/null
+++ b/libcxx/test/std/experimental/simd/simd.cons/default.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+// <experimental/simd>
+//
+// [simd.class]
+// simd() = default;
+
+#include <cstdint>
+#include <experimental/simd>
+
+namespace ex = std::experimental::parallelism_v2;
+
+int main() {
+ static_assert(ex::native_simd<int32_t>().size() > 0, "");
+ static_assert(ex::fixed_size_simd<int32_t, 4>().size() == 4, "");
+ static_assert(ex::fixed_size_simd<int32_t, 5>().size() == 5, "");
+ static_assert(ex::fixed_size_simd<int32_t, 1>().size() == 1, "");
+ static_assert(ex::fixed_size_simd<char, 32>().size() == 32, "");
+}
diff --git a/libcxx/test/std/experimental/simd/simd.cons/generator.pass.cpp b/libcxx/test/std/experimental/simd/simd.cons/generator.pass.cpp
index baf7d936c6a..43273e896b4 100644
--- a/libcxx/test/std/experimental/simd/simd.cons/generator.pass.cpp
+++ b/libcxx/test/std/experimental/simd/simd.cons/generator.pass.cpp
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++98, c++03
+// UNSUPPORTED: c++98, c++03, c++11, c++14
// See GCC PR63723.
// UNSUPPORTED: gcc-4.9
@@ -17,30 +17,75 @@
// [simd.class]
// template <class G> explicit simd(G&& gen);
-#include <cstdint>
#include <experimental/simd>
+#include <cstdint>
-using namespace std::experimental::parallelism_v2;
+namespace ex = std::experimental::parallelism_v2;
template <class T, class... Args>
-auto not_supported_native_simd_ctor(Args&&... args)
- -> decltype(native_simd<T>(std::forward<Args>(args)...), void()) = delete;
+auto not_supported_simd128_ctor(Args&&... args) -> decltype(
+ ex::fixed_size_simd<T, 16 / sizeof(T)>(std::forward<Args>(args)...),
+ void()) = delete;
template <class T>
-void not_supported_native_simd_ctor(...) {}
+void not_supported_simd128_ctor(...) {}
template <class T, class... Args>
-auto supported_native_simd_ctor(Args&&... args)
- -> decltype(native_simd<T>(std::forward<Args>(args)...), void()) {}
+auto supported_simd128_ctor(Args&&... args) -> decltype(
+ ex::fixed_size_simd<T, 16 / sizeof(T)>(std::forward<Args>(args)...),
+ void()) {}
template <class T>
-void supported_native_simd_ctor(...) = delete;
+void supported_simd128_ctor(...) = delete;
+
+struct identity {
+ template <size_t value>
+ int operator()(std::integral_constant<size_t, value>) const {
+ return value;
+ }
+};
void compile_generator() {
- supported_native_simd_ctor<int>([](int i) { return i; });
- not_supported_native_simd_ctor<int>([](int i) { return float(i); });
- not_supported_native_simd_ctor<int>([](intptr_t i) { return (int*)(i); });
- not_supported_native_simd_ctor<int>([](int* i) { return i; });
+ supported_simd128_ctor<int>(identity());
+ not_supported_simd128_ctor<int>([](int i) { return float(i); });
+ not_supported_simd128_ctor<int>([](intptr_t i) { return (int*)(i); });
+ not_supported_simd128_ctor<int>([](int* i) { return i; });
}
-int main() {}
+struct limited_identity {
+ template <size_t value>
+ typename std::conditional<value <= 2, int32_t, int64_t>::type
+ operator()(std::integral_constant<size_t, value>) const {
+ return value;
+ }
+};
+
+void compile_limited_identity() {
+ supported_simd128_ctor<int64_t>(limited_identity());
+ not_supported_simd128_ctor<int32_t>(limited_identity());
+}
+
+template <typename SimdType>
+void test_generator() {
+ {
+ SimdType a([](int i) { return i; });
+ assert(a[0] == 0);
+ assert(a[1] == 1);
+ assert(a[2] == 2);
+ assert(a[3] == 3);
+ }
+ {
+ SimdType a([](int i) { return 2 * i - 1; });
+ assert(a[0] == -1);
+ assert(a[1] == 1);
+ assert(a[2] == 3);
+ assert(a[3] == 5);
+ }
+}
+
+int main() {
+ // TODO: adjust the tests when this assertion fails.
+ assert(ex::native_simd<int32_t>::size() >= 4);
+ test_generator<ex::native_simd<int32_t>>();
+ test_generator<ex::fixed_size_simd<int32_t, 4>>();
+}
diff --git a/libcxx/test/std/experimental/simd/simd.cons/load.pass.cpp b/libcxx/test/std/experimental/simd/simd.cons/load.pass.cpp
new file mode 100644
index 00000000000..8c87fe7a555
--- /dev/null
+++ b/libcxx/test/std/experimental/simd/simd.cons/load.pass.cpp
@@ -0,0 +1,118 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+// <experimental/simd>
+//
+// [simd.class]
+// template <class U, class Flags> simd(const U* mem, Flags f);
+
+#include <cstdint>
+#include <experimental/simd>
+
+#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() {
+ // 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>>();
+}
OpenPOWER on IntegriCloud