-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgeneric-traits_tests.cpp
More file actions
228 lines (192 loc) · 8.99 KB
/
Copy pathgeneric-traits_tests.cpp
File metadata and controls
228 lines (192 loc) · 8.99 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/* SPDX-License-Identifier: BSD-3-Clause */
/* Copyright © 2025–2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
* Matthias Kretz <m.kretz@gsi.de>
*/
#define _GLIBCXX_SIMD_THROW_ON_BAD_VALUE 1
#include "include/bits/simd_details.h"
#include "include/bits/simd_flags.h"
#include <complex>
#include <stdfloat>
namespace simd = std::simd;
using std::complex;
using std::float16_t;
using std::float32_t;
using std::float64_t;
using namespace std::simd;
void test()
{
template for (auto t : {float(), double(), float16_t(), float32_t(), float64_t()})
{
using T = decltype(t);
static_assert(__vectorizable<T>);
static_assert(__complex_like<complex<T>>);
static_assert(__complex_like<const complex<T>&>);
static_assert(__vectorizable<complex<T>>);
}
static_assert(!__vectorizable<const float>);
static_assert(!__vectorizable<float&>);
static_assert(!__vectorizable<std::bfloat16_t>);
template for (constexpr int N : {1, 2, 4, 8})
{
static_assert(std::signed_integral<__integer_from<N>>);
static_assert(sizeof(__integer_from<N>) == N);
static_assert(__vectorizable<__integer_from<N>>);
}
template for (constexpr int N : {2, 4, 8})
{
static_assert(std::floating_point<__float_from<N>>);
static_assert(sizeof(__float_from<N>) == N);
static_assert(__vectorizable<__float_from<N>>);
}
static_assert(__div_ceil(5, 3) == 2);
static_assert(sizeof(_Bitmask<3>) == 1);
static_assert(sizeof(_Bitmask<30>) == 4);
static_assert(__scalar_abi_tag<_Abi_t<1, 1>>);
static_assert(__scalar_abi_tag<_Abi_t<2, 2>>);
static_assert(!__scalar_abi_tag<_Abi_t<2, 1>>);
static_assert(__abi_tag<_Abi_t<2, 1, _AbiVariant::_CxIleav>>);
static_assert(__abi_tag<_Abi_t<2, 1, _AbiVariant::_CxCtgus>>);
using AN = decltype(__native_abi<float>());
using A1 = decltype(__native_abi<float>()._S_resize<1>());
static_assert(A1::_S_size == 1);
static_assert(A1::_S_nreg == 1);
static_assert(A1::_S_variant == AN::_S_variant);
static_assert(std::is_same_v<decltype(__abi_rebind<float, AN::_S_size, A1>()), AN>);
if constexpr (AN::_S_size >= 2) // the target has SIMD support for float
{
{
using A2 = decltype(__abi_rebind<float, 2, AN>());
static_assert(__scalar_abi_tag<A2> == __scalar_abi_tag<AN>);
static_assert(A2::_S_size == 2);
static_assert(A2::_S_nreg == 1);
static_assert(A2::_S_variant == AN::_S_variant);
using A2x = decltype(__abi_rebind<float, 2, decltype(__abi_rebind<float, 1, A2>())>());
static_assert(std::is_same_v<A2, A2x>);
}
using A4 = decltype(__abi_rebind<float, 4, AN>());
static_assert(A4::_S_size == 4);
// at this point we unconditionally expect _CxIleav from __abi_rebind:
using AC2 = decltype(__abi_rebind<complex<float>, 2, AN>());
static_assert(AC2::_S_size == 2);
static_assert(AC2::_S_nreg == A4::_S_nreg);
static_assert(AC2::_S_variant != A4::_S_variant);
static_assert(__filter_abi_variant(AC2::_S_variant, _AbiVariant::_MaskVariants)
== A4::_S_variant);
static_assert(__filter_abi_variant(AC2::_S_variant, _AbiVariant::_CxVariants)
== _AbiVariant::_CxIleav);
static_assert(AC2::_S_is_cx_ileav);
static_assert(!AC2::_S_is_cx_ctgus);
}
{
using ACx2 = _Abi_t<2, 2, _AbiVariant::_CxIleav>;
static_assert(__abi_tag<ACx2>);
static_assert(__scalar_abi_tag<ACx2>);
using AM4 = decltype(__abi_rebind<__float_from<2>, ACx2::_S_size * 2, ACx2>());
static_assert(__abi_tag<AM4>);
static_assert(__scalar_abi_tag<AM4>);
static_assert(AM4::_S_size == ACx2::_S_size * 2);
static_assert(!AM4::_S_is_cx_ileav);
}
static_assert(__streq_to_1("1"));
static_assert(!__streq_to_1(""));
static_assert(!__streq_to_1(nullptr));
static_assert(!__streq_to_1("0"));
static_assert(!__streq_to_1("1 "));
static_assert(__static_sized_range<int[4]>);
static_assert(__static_sized_range<int[4], 4>);
static_assert(__static_sized_range<std::array<int, 4>, 4>);
static_assert( __value_preserving_convertible_to<int, double>);
static_assert(!__value_preserving_convertible_to<int, float>);
static_assert( __value_preserving_convertible_to<float, double>);
static_assert(!__value_preserving_convertible_to<double, float>);
static_assert( __value_preserving_convertible_to<float, complex<float>>);
static_assert( __value_preserving_convertible_to<float, complex<double>>);
static_assert( __value_preserving_convertible_to<double, complex<double>>);
static_assert(!__value_preserving_convertible_to<double, complex<float>>);
static_assert(__explicitly_convertible_to<float, float16_t>);
static_assert(__explicitly_convertible_to<long, float16_t>);
static_assert(__constexpr_wrapper_like<std::constant_wrapper<2>>);
static_assert(__constexpr_wrapper_like<std::integral_constant<int, 1>>);
static_assert(!__broadcast_constructible<int, float>);
static_assert(!__broadcast_constructible<int&, float>);
static_assert(!__broadcast_constructible<int&&, float>);
static_assert(!__broadcast_constructible<const int&, float>);
static_assert(!__broadcast_constructible<const int, float>);
static_assert(__broadcast_constructible<decltype(std::cw<2>), float>);
static_assert(__broadcast_constructible<decltype(std::cw<0.f>), std::float16_t>);
static_assert( __broadcast_constructible<complex<float>, complex<float>>);
static_assert( __broadcast_constructible<complex<float>, complex<double>>);
static_assert(!__broadcast_constructible<complex<double>, complex<float>>);
static_assert(__higher_rank_than<long, int>);
static_assert(__higher_rank_than<long long, long>);
static_assert(__higher_rank_than<int, short>);
static_assert(__higher_rank_than<short, char>);
static_assert(!__higher_rank_than<char, signed char>);
static_assert(!__higher_rank_than<signed char, char>);
static_assert(!__higher_rank_than<char, unsigned char>);
static_assert(!__higher_rank_than<unsigned char, char>);
static_assert(__higher_rank_than<unsigned int, short>);
static_assert(__higher_rank_than<unsigned long, int>);
static_assert(__higher_rank_than<unsigned long long, long>);
static_assert(__higher_rank_than<float, float16_t>);
static_assert(__higher_rank_than<float32_t, float>);
static_assert(__higher_rank_than<double, float32_t>);
static_assert(__higher_rank_than<double, float>);
static_assert(__higher_rank_than<float64_t, float32_t>);
static_assert(__higher_rank_than<float64_t, float>);
static_assert(__higher_rank_than<float64_t, double>);
static_assert(__loadstore_convertible_to<float, double>);
static_assert(__loadstore_convertible_to<int, double>);
static_assert(!__loadstore_convertible_to<int, float>);
static_assert(!__loadstore_convertible_to<int, float, __aligned_flag>);
static_assert(__loadstore_convertible_to<int, float, __convert_flag>);
static_assert(__loadstore_convertible_to<int, float, __aligned_flag, __convert_flag>);
static_assert(__mask_element_size<basic_mask<4>> == 4);
static_assert(__highest_bit(0b1000u) == 3);
static_assert(__highest_bit(0b10000001000ull) == 10);
}
consteval bool
throws(auto f)
{
try { f(); }
catch (...) { return true; }
return false;
}
static_assert(!throws([] { __value_preserving_cast<float>(1); }));
static_assert(!throws([] { __value_preserving_cast<float>(1.5); }));
static_assert(throws([] { __value_preserving_cast<float>(0x5EAF00D); }));
static_assert(throws([] { __value_preserving_cast<unsigned>(-1); }));
static_assert(!throws([] { __value_preserving_cast<unsigned short>(0xffff); }));
static_assert(throws([] { __value_preserving_cast<unsigned short>(0x10000); }));
static_assert(__converts_trivially<int, unsigned>);
#if __SIZEOF_LONG__ == __SIZEOF_LONG_LONG__
static_assert(__converts_trivially<long long, long>);
#elif __SIZEOF_INT__ == __SIZEOF_LONG__
static_assert(__converts_trivially<int, long>);
#endif
static_assert(__converts_trivially<float, float32_t>);
static_assert([] {
bool to_find[10] = {0, 1, 1, 1, 0, 1, 0, 0, 1};
__bit_foreach(0b100101110u, [&](int i) {
if (!to_find[i]) throw false;
to_find[i] = false;
});
for (bool b : to_find)
if (b)
return false;
return true;
}());
// flags ////////////////////////
static_assert(std::is_same_v<decltype(flag_default | flag_default), flags<>>);
static_assert(std::is_same_v<decltype(flag_convert | flag_default), flags<__convert_flag>>);
static_assert(std::is_same_v<decltype(flag_convert | flag_convert), flags<__convert_flag>>);
static_assert(std::is_same_v<decltype(flag_aligned | flag_convert),
flags<__aligned_flag, __convert_flag>>);
static_assert(std::is_same_v<decltype(flag_aligned | flag_convert | flag_aligned),
flags<__aligned_flag, __convert_flag>>);
static_assert(std::is_same_v<decltype(flag_aligned | (flag_convert | flag_aligned)),
flags<__aligned_flag, __convert_flag>>);
static_assert(!flag_default._S_test(flag_convert));
static_assert(flag_convert._S_test(flag_convert));
static_assert(!flag_convert._S_test(flag_aligned));
static_assert((flag_overaligned<32> | flag_convert | flag_aligned)._S_test(flag_convert));