Debian Codegraph @

libstdc++-v3/testsuite/experimental/simd/tests/mask_broadcast.cc

raw
1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
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
18 // expensive: * [1-9] * *
19 #include "bits/main.h"
20
21 template <typename V>
22 void
23 test()
24 {
25 using M = typename V::mask_type;
26 static_assert(std::is_convertible<typename M::reference, bool>::value,
27 "A smart_reference<simd_mask> must be convertible to bool.");
28 static_assert(
29 std::is_same<bool, decltype(std::declval<const typename M::reference&>()
30 == true)>::value,
31 "A smart_reference<simd_mask> must be comparable against bool.");
32 static_assert(
33 vir::test::sfinae_is_callable<typename M::reference&&, bool>(
34 [](auto&& a, auto&& b) -> decltype(std::declval<decltype(a)>()
35 == std::declval<decltype(b)>()) {
36 return {};
37 }),
38 "A smart_reference<simd_mask> must be comparable against bool.");
39 VERIFY(std::experimental::is_simd_mask_v<M>);
40
41 {
42 M x; // uninitialized
43 x = M{}; // default broadcasts 0
44 COMPARE(x, M(false));
45 COMPARE(x, M());
46 COMPARE(x, M{});
47 x = M(); // default broadcasts 0
48 COMPARE(x, M(false));
49 COMPARE(x, M());
50 COMPARE(x, M{});
51 x = x;
52 for (std::size_t i = 0; i < M::size(); ++i)
53 {
54 COMPARE(x[i], false);
55 }
56 }
57
58 M x(true);
59 M y(false);
60 for (std::size_t i = 0; i < M::size(); ++i)
61 {
62 COMPARE(x[i], true);
63 COMPARE(y[i], false);
64 }
65 y = M(true);
66 COMPARE(x, y);
67 }