broadcast.pass.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. // UNSUPPORTED: c++98, c++03, c++11, c++14
  9. // See GCC PR63723.
  10. // UNSUPPORTED: gcc-4.9
  11. // <experimental/simd>
  12. //
  13. // [simd.class]
  14. // template <class U> simd(U&& value);
  15. #include <cstdint>
  16. #include <experimental/simd>
  17. #include "test_macros.h"
  18. namespace ex = std::experimental::parallelism_v2;
  19. template <class T, class... Args>
  20. auto not_supported_native_simd_ctor(Args&&... args)
  21. -> decltype(ex::native_simd<T>(std::forward<Args>(args)...),
  22. void()) = delete;
  23. template <class T>
  24. void not_supported_native_simd_ctor(...) {}
  25. template <class T, class... Args>
  26. auto supported_native_simd_ctor(Args&&... args)
  27. -> decltype(ex::native_simd<T>(std::forward<Args>(args)...), void()) {}
  28. template <class T>
  29. void supported_native_simd_ctor(...) = delete;
  30. void compile_narrowing_conversion() {
  31. supported_native_simd_ctor<int8_t>(3);
  32. supported_native_simd_ctor<int16_t>(3);
  33. supported_native_simd_ctor<int32_t>(3);
  34. supported_native_simd_ctor<int64_t>(3);
  35. supported_native_simd_ctor<uint8_t>(3);
  36. supported_native_simd_ctor<uint16_t>(3);
  37. supported_native_simd_ctor<uint32_t>(3);
  38. supported_native_simd_ctor<uint64_t>(3);
  39. supported_native_simd_ctor<float>(3.f);
  40. supported_native_simd_ctor<double>(3.);
  41. supported_native_simd_ctor<long double>(3.);
  42. not_supported_native_simd_ctor<float>(3.);
  43. not_supported_native_simd_ctor<int8_t>(long(3));
  44. not_supported_native_simd_ctor<float>(long(3));
  45. not_supported_native_simd_ctor<int>(3.);
  46. }
  47. void compile_convertible() {
  48. struct ConvertibleToInt {
  49. operator int64_t() const;
  50. };
  51. supported_native_simd_ctor<int64_t>(ConvertibleToInt());
  52. struct NotConvertibleToInt {};
  53. not_supported_native_simd_ctor<int64_t>(NotConvertibleToInt());
  54. }
  55. void compile_unsigned() {
  56. not_supported_native_simd_ctor<int>(3u);
  57. supported_native_simd_ctor<uint16_t>(3u);
  58. }
  59. template <typename SimdType>
  60. void test_broadcast() {
  61. SimdType a(3);
  62. for (size_t i = 0; i < a.size(); i++) {
  63. assert(a[i] == 3);
  64. }
  65. }
  66. int main(int, char**) {
  67. test_broadcast<ex::native_simd<int>>();
  68. test_broadcast<ex::fixed_size_simd<int, 4>>();
  69. test_broadcast<ex::fixed_size_simd<int, 15>>();
  70. return 0;
  71. }