summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/experimental/simd/tests/broadcast.cc
blob: 846bc9876efb27884f57fb96ae2e362964122353 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (C) 2020-2022 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// expensive: * [1-9] * *
#include "bits/verify.h"
#include "bits/metahelpers.h"

enum unscoped_enum
{ foo };

enum class scoped_enum
{ bar };

struct convertible
{
  operator int();
  operator float();
};

template <typename V>
  void
  test()
  {
    using T = typename V::value_type;
    VERIFY(std::experimental::is_simd_v<V>);
    VERIFY(std::experimental::is_abi_tag_v<typename V::abi_type>);

    {
      V x;     // not initialized
      x = V{}; // default broadcasts 0
      COMPARE(x, V(0));
      COMPARE(x, V());
      COMPARE(x, V{});
      x = V(); // default broadcasts 0
      COMPARE(x, V(0));
      COMPARE(x, V());
      COMPARE(x, V{});
      x = 0;
      COMPARE(x, V(0));
      COMPARE(x, V());
      COMPARE(x, V{});

      for (std::size_t i = 0; i < V::size(); ++i)
	{
	  COMPARE(T(x[i]), T(0)) << "i = " << i;
	  COMPARE(x[i], T(0)) << "i = " << i;
	}
    }

    V x = 3;
    V y = T(0);
    for (std::size_t i = 0; i < V::size(); ++i)
      {
	COMPARE(x[i], T(3)) << "i = " << i;
	COMPARE(y[i], T(0)) << "i = " << i;
      }
    y = 3;
    COMPARE(x, y);

    VERIFY(!(is_substitution_failure<V&, unscoped_enum, assignment>) );
    VERIFY((is_substitution_failure<V&, scoped_enum, assignment>) );
    COMPARE((is_substitution_failure<V&, convertible, assignment>),
	    (!std::is_convertible<convertible, T>::value));
    COMPARE((is_substitution_failure<V&, long double, assignment>),
	    (sizeof(long double) > sizeof(T) || std::is_integral<T>::value));
    COMPARE((is_substitution_failure<V&, double, assignment>),
	    (sizeof(double) > sizeof(T) || std::is_integral<T>::value));
    COMPARE((is_substitution_failure<V&, float, assignment>),
	    (sizeof(float) > sizeof(T) || std::is_integral<T>::value));
    COMPARE((is_substitution_failure<V&, long long, assignment>),
	    (has_less_bits<T, long long>() || std::is_unsigned<T>::value));
    COMPARE((is_substitution_failure<V&, unsigned long long, assignment>),
	    (has_less_bits<T, unsigned long long>()));
    COMPARE((is_substitution_failure<V&, long, assignment>),
	    (has_less_bits<T, long>() || std::is_unsigned<T>::value));
    COMPARE((is_substitution_failure<V&, unsigned long, assignment>),
	    (has_less_bits<T, unsigned long>()));
    // int broadcast *always* works:
    VERIFY(!(is_substitution_failure<V&, int, assignment>) );
    // uint broadcast works for any unsigned T:
    COMPARE((is_substitution_failure<V&, unsigned int, assignment>),
	    (!std::is_unsigned<T>::value && has_less_bits<T, unsigned int>()));
    COMPARE((is_substitution_failure<V&, short, assignment>),
	    (has_less_bits<T, short>() || std::is_unsigned<T>::value));
    COMPARE((is_substitution_failure<V&, unsigned short, assignment>),
	    (has_less_bits<T, unsigned short>()));
    COMPARE((is_substitution_failure<V&, signed char, assignment>),
	    (has_less_bits<T, signed char>() || std::is_unsigned<T>::value));
    COMPARE((is_substitution_failure<V&, unsigned char, assignment>),
	    (has_less_bits<T, unsigned char>()));
  }