]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/simd/tests/where.cc
1 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
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)
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.
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/>.
18 // expensive: * [1-9] * *
19 #include "bits/verify.h"
20 #include "bits/make_vec.h"
21 #include "bits/metahelpers.h"
26 operator V() const { return V(4); }
29 template <class M
, class T
>
31 where_is_ill_formed_impl(M
, const T
&, float)
36 template <class M
, class T
>
38 where_is_ill_formed_impl(M m
, const T
& v
, int)
39 -> std::conditional_t
<true, bool, decltype(std::experimental::where(m
, v
))>
44 template <class M
, class T
>
46 where_is_ill_formed(M m
, const T
& v
)
48 return where_is_ill_formed_impl(m
, v
, int());
55 using std::experimental::where
;
57 where(true, x
) = x
+ 1;
59 where(false, x
) = x
- 1;
61 where(true, x
) += T(1);
69 using M
= typename
V::mask_type
;
70 using T
= typename
V::value_type
;
71 where_fundamental
<T
>();
72 VERIFY(!(sfinae_is_callable
<V
>(
73 [](auto x
) -> decltype(where(true, x
))* { return nullptr; })));
75 const V
indexes([](int i
) { return i
+ 1; });
76 const M alternating_mask
= make_mask
<M
>({true, false});
78 where(alternating_mask
, x
) = indexes
;
79 COMPARE(alternating_mask
, x
== indexes
);
81 where(!alternating_mask
, x
) = T(2);
82 COMPARE(!alternating_mask
, x
== T(2)) << x
;
84 where(!alternating_mask
, x
) = Convertible
<V
>();
85 COMPARE(!alternating_mask
, x
== T(4));
89 where(alternating_mask
, x
) += indexes
;
90 COMPARE(alternating_mask
, x
== indexes
);
94 where(!alternating_mask
, x
) += T(1);
95 COMPARE(!alternating_mask
, x
== T(11));
96 where(alternating_mask
, x
) -= Convertible
<V
>();
97 COMPARE(alternating_mask
, x
== T(6));
98 constexpr bool fast_math
=
104 if constexpr (fast_math
&& std::is_floating_point_v
<T
>)
105 where(alternating_mask
, x
) *= T(.5);
107 where(alternating_mask
, x
) /= T(2);
108 COMPARE(alternating_mask
, x
== T(3)) << "\nx = " << x
;
109 where(alternating_mask
, x
) *= T(3);
110 COMPARE(alternating_mask
, x
== T(9));
111 COMPARE(!alternating_mask
, x
== T(11));
114 where(alternating_mask
, x
)++;
115 COMPARE(alternating_mask
, x
== T(11));
116 ++where(alternating_mask
, x
);
117 COMPARE(alternating_mask
, x
== T(12));
118 where(alternating_mask
, x
)--;
119 COMPARE(alternating_mask
, x
== T(11));
120 --where(alternating_mask
, x
);
121 --where(alternating_mask
, x
);
122 COMPARE(alternating_mask
, x
== T(9));
123 COMPARE(alternating_mask
, -where(alternating_mask
, x
) == T(-T(9)));
126 VERIFY(where_is_ill_formed(true, y
));
127 VERIFY(where_is_ill_formed(true, x
));
128 VERIFY(where_is_ill_formed(true, V(x
)));
130 M test
= alternating_mask
;
131 where(alternating_mask
, test
) = M(true);
132 COMPARE(test
, alternating_mask
);
133 where(alternating_mask
, test
) = M(false);
134 COMPARE(test
, M(false));
135 where(alternating_mask
, test
) = M(true);
136 COMPARE(test
, alternating_mask
);