]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/simd/tests/broadcast.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / simd / tests / broadcast.cc
CommitLineData
7adcbafe 1// Copyright (C) 2020-2022 Free Software Foundation, Inc.
02e32295
MK
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8//
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
aa89c53c 18// expensive: * [1-9] * *
02e32295
MK
19#include "bits/verify.h"
20#include "bits/metahelpers.h"
21
22enum unscoped_enum
23{ foo };
24
25enum class scoped_enum
26{ bar };
27
28struct convertible
29{
30 operator int();
31 operator float();
32};
33
34template <typename V>
35 void
36 test()
37 {
38 using T = typename V::value_type;
39 VERIFY(std::experimental::is_simd_v<V>);
40 VERIFY(std::experimental::is_abi_tag_v<typename V::abi_type>);
41
42 {
43 V x; // not initialized
44 x = V{}; // default broadcasts 0
45 COMPARE(x, V(0));
46 COMPARE(x, V());
47 COMPARE(x, V{});
48 x = V(); // default broadcasts 0
49 COMPARE(x, V(0));
50 COMPARE(x, V());
51 COMPARE(x, V{});
52 x = 0;
53 COMPARE(x, V(0));
54 COMPARE(x, V());
55 COMPARE(x, V{});
56
57 for (std::size_t i = 0; i < V::size(); ++i)
58 {
59 COMPARE(T(x[i]), T(0)) << "i = " << i;
60 COMPARE(x[i], T(0)) << "i = " << i;
61 }
62 }
63
64 V x = 3;
65 V y = T(0);
66 for (std::size_t i = 0; i < V::size(); ++i)
67 {
68 COMPARE(x[i], T(3)) << "i = " << i;
69 COMPARE(y[i], T(0)) << "i = " << i;
70 }
71 y = 3;
72 COMPARE(x, y);
73
74 VERIFY(!(is_substitution_failure<V&, unscoped_enum, assignment>) );
75 VERIFY((is_substitution_failure<V&, scoped_enum, assignment>) );
76 COMPARE((is_substitution_failure<V&, convertible, assignment>),
77 (!std::is_convertible<convertible, T>::value));
78 COMPARE((is_substitution_failure<V&, long double, assignment>),
79 (sizeof(long double) > sizeof(T) || std::is_integral<T>::value));
80 COMPARE((is_substitution_failure<V&, double, assignment>),
81 (sizeof(double) > sizeof(T) || std::is_integral<T>::value));
82 COMPARE((is_substitution_failure<V&, float, assignment>),
83 (sizeof(float) > sizeof(T) || std::is_integral<T>::value));
84 COMPARE((is_substitution_failure<V&, long long, assignment>),
85 (has_less_bits<T, long long>() || std::is_unsigned<T>::value));
86 COMPARE((is_substitution_failure<V&, unsigned long long, assignment>),
87 (has_less_bits<T, unsigned long long>()));
88 COMPARE((is_substitution_failure<V&, long, assignment>),
89 (has_less_bits<T, long>() || std::is_unsigned<T>::value));
90 COMPARE((is_substitution_failure<V&, unsigned long, assignment>),
91 (has_less_bits<T, unsigned long>()));
92 // int broadcast *always* works:
93 VERIFY(!(is_substitution_failure<V&, int, assignment>) );
94 // uint broadcast works for any unsigned T:
95 COMPARE((is_substitution_failure<V&, unsigned int, assignment>),
96 (!std::is_unsigned<T>::value && has_less_bits<T, unsigned int>()));
97 COMPARE((is_substitution_failure<V&, short, assignment>),
98 (has_less_bits<T, short>() || std::is_unsigned<T>::value));
99 COMPARE((is_substitution_failure<V&, unsigned short, assignment>),
100 (has_less_bits<T, unsigned short>()));
101 COMPARE((is_substitution_failure<V&, signed char, assignment>),
102 (has_less_bits<T, signed char>() || std::is_unsigned<T>::value));
103 COMPARE((is_substitution_failure<V&, unsigned char, assignment>),
104 (has_less_bits<T, unsigned char>()));
105 }