-
Notifications
You must be signed in to change notification settings - Fork 1
/
simd.h
595 lines (490 loc) · 24.1 KB
/
simd.h
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
/* SPDX-License-Identifier: GPL-3.0-or-later WITH GCC-exception-3.1 */
/* Copyright © 2023-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
* Matthias Kretz <[email protected]>
*/
#ifndef PROTOTYPE_SIMD2_H_
#define PROTOTYPE_SIMD2_H_
#include "detail.h"
#include "simd_mask.h"
#include "flags.h"
#include "simd_iterator.h"
#include <span>
#include <iterator>
namespace std
{
// not supported:
// - deleted: dctor, dtor, cctor, cassign
// - no members except value_type, abi_type, and mask_type
template <typename _Tp, typename _Abi>
requires (__detail::_SimdTraits<_Tp, _Abi>::_S_size == 0)
class basic_simd<_Tp, _Abi>
{
public:
using value_type = _Tp;
using abi_type = _Abi;
using mask_type = std::basic_simd_mask<
sizeof(conditional_t<is_void_v<_Tp>, int, _Tp>), _Abi>;
basic_simd() = delete;
~basic_simd() = delete;
basic_simd(const basic_simd&) = delete;
basic_simd& operator=(const basic_simd&) = delete;
};
// --------------------------------------------------------------
// supported
template <typename _Tp, typename _Abi>
class basic_simd
{
static_assert(__detail::__vectorizable<_Tp> and __detail::__valid_abi_tag<_Abi, _Tp>);
using _Traits = __detail::_SimdTraits<_Tp, _Abi>;
using _MemberType = typename _Traits::_SimdMember;
static constexpr _Tp* _S_type_tag = nullptr;
alignas(_Traits::_S_simd_align) _MemberType _M_data;
public:
using _Impl = typename _Traits::_SimdImpl;
using reference = __detail::_SmartReference<_MemberType, _Impl, _Tp>;
using value_type = _Tp;
using abi_type = _Abi;
using mask_type = std::basic_simd_mask<sizeof(_Tp), _Abi>;
static constexpr auto size = __detail::__ic<_Traits::_S_size>;
using iterator = __simd_iterator<_Tp, _Abi>;
//static_assert(std::random_access_iterator<iterator>);
//static_assert(std::sentinel_for<__simd_iterator_sentinel, iterator>);
constexpr iterator
begin() const
{ return iterator(*this, 0); }
constexpr __simd_iterator_sentinel
end() const
{ return {}; }
constexpr
basic_simd() = default;
// ABI-specific conversions
template <typename _Up>
requires requires { _Traits::template _S_simd_conversion<_Up>(_M_data); }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr
operator _Up() const
{ return _Traits::template _S_simd_conversion<_Up>(_M_data); }
template <typename _Up>
requires (_Traits::template _S_is_simd_ctor_arg<_Up>)
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr
basic_simd(_Up __x)
: _M_data(_Traits::_S_simd_construction(__x))
{}
// implicit broadcast constructor
template <__detail::__broadcast_constructible<value_type> _Up>
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr
basic_simd(_Up&& __x) noexcept
: _M_data(_Impl::_S_broadcast(static_cast<_Tp>(__x)))
{}
// type conversion constructor
template <typename _Up, typename _UAbi>
requires(simd_size_v<_Up, _UAbi> == size() and std::constructible_from<_Tp, _Up>)
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr
explicit(not __detail::__value_preserving_convertible_to<_Up, value_type>
|| __detail::__higher_rank_than<_Up, value_type>)
basic_simd(const basic_simd<_Up, _UAbi>& __x) noexcept
: _M_data(__detail::_SimdConverter<_Up, _UAbi, _Tp, _Abi>()(__data(__x)))
{}
// generator constructor
template <__detail::__simd_broadcast_invokable<value_type, size()> _Fp>
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr explicit
basic_simd(_Fp&& __gen) noexcept
: _M_data(_Impl::template _S_generator<value_type>(static_cast<_Fp&&>(__gen)))
{}
// load constructor
template <typename _It, typename... _Flags>
requires __detail::__loadstore_convertible_to<std::iter_value_t<_It>, value_type, _Flags...>
and std::contiguous_iterator<_It>
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr // TODO explicit
basic_simd(_It __first, simd_flags<_Flags...> __flags = {})
: _M_data(_Impl::_S_load(__flags.template _S_adjust_pointer<basic_simd>(
std::to_address(__first)), _S_type_tag))
{}
template <typename _It, typename... _Flags>
requires __detail::__loadstore_convertible_to<std::iter_value_t<_It>, value_type, _Flags...>
and std::contiguous_iterator<_It>
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr // TODO explicit
basic_simd(_It __first, const mask_type& __k, simd_flags<_Flags...> __flags = {})
: _M_data(_Impl::_S_masked_load(_MemberType(), __data(__k),
__flags.template _S_adjust_pointer<basic_simd>(
std::to_address(__first))))
{}
////////////////////////////////////////////////////////////////////////////////////////////
// begin exploration
// construction from span of static extent is simple
// basic_simd(std::span<_Tp, size()> __mem)
//
// but let's add conversions and flags
template <typename _Up, typename... _Flags>
requires __detail::__loadstore_convertible_to<_Up, value_type, _Flags...>
constexpr // TODO explicit?
basic_simd(std::span<_Up, size()> __mem, simd_flags<_Flags...> __flags = {})
: basic_simd(__mem.begin(), __flags)
{}
// ranges typically don't have a static size() function :(
// but if one does, this ctor is useful
template <std::ranges::contiguous_range _Rg, typename... _Flags>
requires __detail::__loadstore_convertible_to<std::ranges::range_value_t<_Rg>,
value_type, _Flags...>
and (__detail::__static_range_size<_Rg> == size.value)
constexpr // TODO explicit?
basic_simd(_Rg&& __range, simd_flags<_Flags...> __flags = {})
: basic_simd(std::ranges::begin(__range), __flags)
{}
template <std::ranges::contiguous_range _Rg, typename... _Flags>
requires __detail::__loadstore_convertible_to<std::ranges::range_value_t<_Rg>,
value_type, _Flags...>
and (__detail::__static_range_size<_Rg> == std::dynamic_extent)
constexpr // TODO explicit?
basic_simd(_Rg&& __range, simd_flags<_Flags...> __f = {})
{
const auto* __ptr = __f.template _S_adjust_pointer<basic_simd>(std::ranges::data(__range));
if(std::ranges::size(__range) >= size())
_M_data = _Impl::_S_load(__ptr, _S_type_tag);
else
{
*this = _Tp();
__builtin_memcpy(&_M_data, __ptr, size() - std::ranges::size(__range));
}
}
/* This constructor makes loads from C-arrays ambiguous because they are contiguous iterators
* (decay to pointer) as well as contiguous ranges.
*
template <std::ranges::random_access_range _Rg>
requires(std::convertible_to<std::ranges::range_value_t<_Rg>, _Tp>)
constexpr explicit (not std::same_as<std::ranges::range_value_t<_Rg>, _Tp>)
basic_simd(const _Rg& __range)
: basic_simd([&__range](auto __i) -> _Tp { return __range[__i]; })
{}*/
template <std::ranges::contiguous_range _Rg, typename... _Flags>
requires std::ranges::output_range<_Rg, value_type>
and __detail::__loadstore_convertible_to<
value_type, std::ranges::range_value_t<_Rg>, _Flags...>
and (__detail::__static_range_size<_Rg> == std::dynamic_extent
or __detail::__static_range_size<_Rg> == size.value)
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr void
copy_to(_Rg&& __range, simd_flags<_Flags...> __f = {})
{
const auto* __ptr = __f.template _S_adjust_pointer<basic_simd>(std::ranges::data(__range));
if constexpr (__detail::__static_range_size<_Rg> == std::dynamic_extent)
{
if(std::ranges::size(__range) >= size())
_Impl::_S_store(_M_data, __ptr, _S_type_tag);
else
__builtin_memcpy(__ptr, &_M_data, size() - std::ranges::size(__range));
}
else
_Impl::_S_store(_M_data, __ptr, _S_type_tag);
}
// end exploration
////////////////////////////////////////////////////////////////////////////////////////////
// private init
_GLIBCXX_SIMD_INTRINSIC constexpr
basic_simd(__detail::_PrivateInit, const _MemberType& __init)
: _M_data(__init)
{}
// loads and stores
template <std::contiguous_iterator _It, typename... _Flags>
requires __detail::__loadstore_convertible_to<std::iter_value_t<_It>, value_type, _Flags...>
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr void
copy_from(_It __first, simd_flags<_Flags...> __flags = {})
{
_M_data = _Impl::_S_load(__flags.template _S_adjust_pointer<basic_simd>(
std::to_address(__first)), _S_type_tag);
}
template <std::contiguous_iterator _It, typename... _Flags>
requires __detail::__loadstore_convertible_to<std::iter_value_t<_It>, value_type, _Flags...>
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr void
copy_from(_It __first, const mask_type& __k, simd_flags<_Flags...> __flags = {})
{
_M_data = _Impl::_S_masked_load(_M_data, __data(__k),
__flags.template _S_adjust_pointer<basic_simd>(
std::to_address(__first)));
}
template <std::contiguous_iterator _It, typename... _Flags>
requires std::output_iterator<_It, _Tp>
and __detail::__loadstore_convertible_to<value_type, std::iter_value_t<_It>, _Flags...>
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr void
copy_to(_It __first, simd_flags<_Flags...> __flags = {}) const
{
_Impl::_S_store(_M_data, __flags.template _S_adjust_pointer<basic_simd>(
std::to_address(__first)), _S_type_tag);
}
template <std::contiguous_iterator _It, typename... _Flags>
requires std::output_iterator<_It, _Tp>
and __detail::__loadstore_convertible_to<value_type, std::iter_value_t<_It>, _Flags...>
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr void
copy_to(_It __first, const mask_type& __k, simd_flags<_Flags...> __flags = {}) const
{
_Impl::_S_masked_store(
__data(*this), __flags.template _S_adjust_pointer<basic_simd>(std::to_address(__first)),
__data(__k));
}
// unary operators (for any _Tp)
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr mask_type
operator!() const
requires requires(value_type __a) { {!__a} -> same_as<bool>; }
{ return {__detail::__private_init, _Impl::_S_negate(__data(*this))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr basic_simd
operator+() const
requires requires(value_type __a) { +__a; }
{ return *this; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr basic_simd
operator-() const
requires requires(value_type __a) { -__a; }
{ return {__detail::__private_init, _Impl::_S_unary_minus(__data(*this))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr basic_simd
operator~() const
requires requires(value_type __a) { ~__a; }
{ return {__detail::__private_init, _Impl::_S_complement(__data(*this))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr basic_simd&
operator++()
requires requires(value_type __a) { ++__a; }
{
_Impl::_S_increment(_M_data);
return *this;
}
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr basic_simd
operator++(int)
requires requires(value_type __a) { __a++; }
{
basic_simd __r = *this;
_Impl::_S_increment(_M_data);
return __r;
}
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr basic_simd&
operator--()
requires requires(value_type __a) { --__a; }
{
_Impl::_S_decrement(_M_data);
return *this;
}
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr basic_simd
operator--(int)
requires requires(value_type __a) { __a--; }
{
basic_simd __r = *this;
_Impl::_S_decrement(_M_data);
return __r;
}
// compound assignment [basic_simd.cassign]
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator+=(basic_simd& __lhs, const basic_simd& __x)
requires requires(value_type __a, value_type __b) { __a + __b; }
{ return __lhs = __lhs + __x; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator-=(basic_simd& __lhs, const basic_simd& __x)
requires requires(value_type __a, value_type __b) { __a - __b; }
{ return __lhs = __lhs - __x; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator*=(basic_simd& __lhs, const basic_simd& __x)
requires requires(value_type __a, value_type __b) { __a * __b; }
{ return __lhs = __lhs * __x; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator/=(basic_simd& __lhs, const basic_simd& __x)
requires requires(value_type __a, value_type __b) { __a / __b; }
{ return __lhs = __lhs / __x; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator%=(basic_simd& __lhs, const basic_simd& __x)
requires requires(value_type __a, value_type __b) { __a % __b; }
{ return __lhs = __lhs % __x; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator&=(basic_simd& __lhs, const basic_simd& __x)
requires requires(value_type __a, value_type __b) { __a & __b; }
{ return __lhs = __lhs & __x; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator|=(basic_simd& __lhs, const basic_simd& __x)
requires requires(value_type __a, value_type __b) { __a | __b; }
{ return __lhs = __lhs | __x; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator^=(basic_simd& __lhs, const basic_simd& __x)
requires requires(value_type __a, value_type __b) { __a ^ __b; }
{ return __lhs = __lhs ^ __x; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator<<=(basic_simd& __lhs, const basic_simd& __x)
requires requires(value_type __a, value_type __b) { __a << __b; }
{ return __lhs = __lhs << __x; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator>>=(basic_simd& __lhs, const basic_simd& __x)
requires requires(value_type __a, value_type __b) { __a >> __b; }
{ return __lhs = __lhs >> __x; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator<<=(basic_simd& __lhs, int __x)
requires requires(value_type __a, int __b) { __a << __b; }
{ return __lhs = __lhs << __x; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd&
operator>>=(basic_simd& __lhs, int __x)
requires requires(value_type __a, int __b) { __a >> __b; }
{ return __lhs = __lhs >> __x; }
// binary operators [basic_simd.binary]
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator+(const basic_simd& __x, const basic_simd& __y)
requires requires(value_type __a) { __a + __a; }
{ return {__detail::__private_init, _Impl::_S_plus(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator-(const basic_simd& __x, const basic_simd& __y)
requires requires(value_type __a) { __a - __a; }
{ return {__detail::__private_init, _Impl::_S_minus(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator*(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a * __a; }
{ return {__detail::__private_init, _Impl::_S_multiplies(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator/(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a / __a; }
{ return {__detail::__private_init, _Impl::_S_divides(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator%(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a % __a; }
{ return {__detail::__private_init, _Impl::_S_modulus(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator&(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a & __a; }
{ return {__detail::__private_init, _Impl::_S_bit_and(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator|(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a | __a; }
{ return {__detail::__private_init, _Impl::_S_bit_or(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator^(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a ^ __a; }
{ return {__detail::__private_init, _Impl::_S_bit_xor(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator>>(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a >> __a; }
{ return {__detail::__private_init, _Impl::_S_bit_shift_right(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator<<(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a << __a; }
{ return {__detail::__private_init, _Impl::_S_bit_shift_left(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator>>(const basic_simd& __x, int __y)
requires requires (value_type __a, int __b) { __a >> __b; }
{ return {__detail::__private_init, _Impl::_S_bit_shift_right(__data(__x), __y)}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend basic_simd
operator<<(const basic_simd& __x, int __y)
requires requires (value_type __a, int __b) { __a << __b; }
{ return {__detail::__private_init, _Impl::_S_bit_shift_left(__data(__x), __y)}; }
// compares [basic_simd.comparison]
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend mask_type
operator==(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a == __a; }
{ return {__detail::__private_init, _Impl::_S_equal_to(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend mask_type
operator!=(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a != __a; }
{ return {__detail::__private_init, _Impl::_S_not_equal_to(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend mask_type
operator<(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a < __a; }
{ return {__detail::__private_init, _Impl::_S_less(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend mask_type
operator<=(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a <= __a; }
{ return {__detail::__private_init, _Impl::_S_less_equal(__data(__x), __data(__y))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend mask_type
operator>(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a > __a; }
{ return {__detail::__private_init, _Impl::_S_less(__data(__y), __data(__x))}; }
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr friend mask_type
operator>=(const basic_simd& __x, const basic_simd& __y)
requires requires (value_type __a) { __a >= __a; }
{ return {__detail::__private_init, _Impl::_S_less_equal(__data(__y), __data(__x))}; }
constexpr std::array<_Tp, size()>
to_array() const noexcept
{
std::array<_Tp, size()> __r = {};
this->copy_to(__r.data(), simd_flag_default);
return __r;
}
explicit
operator std::array<_Tp, size()>() const noexcept
{ return to_array(); }
_GLIBCXX_SIMD_ALWAYS_INLINE friend constexpr basic_simd
simd_select_impl(const mask_type& __k, const basic_simd& __t, const basic_simd& __f)
{
auto __ret = __f;
_Impl::_S_masked_assign(__data(__k), __ret._M_data, __t._M_data);
return __ret;
}
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr reference
operator[](__detail::_SimdSizeType __i) &
{
if (__i >= size.value or __i < 0)
__detail::__invoke_ub("Subscript %d is out of range [0, %d]", __i, size() - 1);
return {_M_data, __i};
}
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr value_type
operator[](__detail::_SimdSizeType __i) const&
{
if (__i >= size.value or __i < 0)
__detail::__invoke_ub("Subscript %d is out of range [0, %d]", __i, size() - 1);
return _Impl::_S_get(_M_data, __i);
}
///////////////////////
// P2664::begin
template <std::integral _Up, typename _Ap>
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr simd<_Tp, simd_size_v<_Up, _Ap>>
operator[](basic_simd<_Up, _Ap> const& __idx) const noexcept
{
using _Rp = simd<_Tp, simd_size_v<_Up, _Ap>>;
const basic_simd& __v = *this;
return _Rp([&](auto __i) {
return __v[__idx[__i]];
});
}
// P2664::end
///////////////////////
friend constexpr const auto& __data(const basic_simd& __x)
{ return __x._M_data; }
friend constexpr auto& __data(basic_simd& __x)
{ return __x._M_data; }
_GLIBCXX_SIMD_INTRINSIC constexpr bool
_M_is_constprop() const
{
if constexpr (requires {_Impl::_S_is_constprop(_M_data);})
return _Impl::_S_is_constprop(_M_data);
else if constexpr (requires {_M_data._M_is_constprop();})
return _M_data._M_is_constprop();
else
return __builtin_constant_p(_M_data);
}
};
template <typename _Tp, typename _Abi>
struct is_simd<basic_simd<_Tp, _Abi>>
: is_default_constructible<basic_simd<_Tp, _Abi>>
{};
template <class _Tp, size_t _Extent>
basic_simd(std::span<_Tp, _Extent>) -> basic_simd<_Tp, __detail::__deduce_t<_Tp, _Extent>>;
template <std::ranges::contiguous_range _Rg>
basic_simd(const _Rg& x)
-> basic_simd<std::ranges::range_value_t<_Rg>,
__detail::__deduce_t<std::ranges::range_value_t<_Rg>,
__detail::__static_range_size<_Rg>>>;
template <size_t _Bs, typename _Abi>
basic_simd(std::basic_simd_mask<_Bs, _Abi>)
-> basic_simd<__detail::__mask_integer_from<_Bs>,
__detail::__simd_abi_for_mask_t<_Bs, _Abi>>;
template <__detail::__vectorizable _Tp, __detail::__simd_type _Simd>
struct rebind_simd<_Tp, _Simd>
{ using type = simd<_Tp, _Simd::size()>; };
template <__detail::__vectorizable _Tp, __detail::__mask_type _Mask>
struct rebind_simd<_Tp, _Mask>
{ using type = simd_mask<_Tp, _Mask::size()>; };
template <__detail::_SimdSizeType _Np, __detail::__simd_type _Simd>
struct resize_simd<_Np, _Simd>
{ using type = simd<typename _Simd::value_type, _Np>; };
template <__detail::_SimdSizeType _Np, __detail::__mask_type _Mask>
struct resize_simd<_Np, _Mask>
{ using type = simd_mask<typename decltype(+_Mask())::value_type, _Np>; };
template <typename _Tp, typename _Abi, __detail::__vectorizable _Up>
struct simd_alignment<basic_simd<_Tp, _Abi>, _Up>
: std::integral_constant<size_t, alignof(rebind_simd_t<_Up, basic_simd<_Tp, _Abi>>)>
{};
template <size_t _Bs, typename _Abi>
struct simd_alignment<basic_simd_mask<_Bs, _Abi>, bool>
: std::integral_constant<size_t, alignof(simd<__detail::__make_unsigned_int_t<bool>,
basic_simd_mask<_Bs, _Abi>::size()>)>
{};
}
#endif // PROTOTYPE_SIMD2_H_
// vim: et ts=8 sw=2 tw=100 cc=101