-
Notifications
You must be signed in to change notification settings - Fork 1
/
simd_iterator.h
237 lines (187 loc) · 6.5 KB
/
simd_iterator.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
/* 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_RANGES_INTEGRATION_ITERATOR_H_
#define PROTOTYPE_RANGES_INTEGRATION_ITERATOR_H_
#include "fwddecl.h"
namespace std
{
class __simd_iterator_sentinel
{};
template <typename _Tp, typename _Abi>
class __simd_iterator
{
using _Vp = basic_simd<_Tp, _Abi>;
const _Vp* _M_data = nullptr;
int _M_offset = 0;
public:
using value_type = _Tp;
using iterator_category = std::random_access_iterator_tag;
using difference_type = int;
constexpr __simd_iterator() = default;
constexpr
__simd_iterator(const _Vp& __d, int __x)
: _M_data(&__d), _M_offset(__x)
{}
constexpr
__simd_iterator(const __simd_iterator &) = default;
constexpr __simd_iterator&
operator=(const __simd_iterator &) = default;
constexpr value_type
operator*() const
{ return (*_M_data)[_M_offset]; }
constexpr __simd_iterator&
operator++()
{
++_M_offset;
return *this;
}
constexpr __simd_iterator
operator++(int)
{
__simd_iterator r = *this;
++_M_offset;
return r;
}
constexpr __simd_iterator&
operator--()
{
--_M_offset;
return *this;
}
constexpr __simd_iterator
operator--(int)
{
__simd_iterator r = *this;
--_M_offset;
return r;
}
constexpr difference_type
operator-(__simd_iterator __rhs) const
{ return _M_offset - __rhs._M_offset; }
constexpr friend difference_type
operator-(__simd_iterator __it, __simd_iterator_sentinel)
{ return __it._M_offset - difference_type(_Vp::size.value); }
constexpr friend difference_type
operator-(__simd_iterator_sentinel, __simd_iterator __it)
{ return difference_type(_Vp::size.value) - __it._M_offset; }
constexpr friend __simd_iterator
operator+(difference_type __x, const __simd_iterator& __it)
{ return __simd_iterator(*__it._M_data, __it._M_offset + __x); }
constexpr friend __simd_iterator
operator+(const __simd_iterator& __it, difference_type __x)
{ return __simd_iterator(*__it._M_data, __it._M_offset + __x); }
constexpr friend __simd_iterator
operator-(difference_type __x, const __simd_iterator& __it)
{ return __simd_iterator(*__it._M_data, __it._M_offset - __x); }
constexpr friend __simd_iterator
operator-(const __simd_iterator& __it, difference_type __x)
{ return __simd_iterator(*__it._M_data, __it._M_offset - __x); }
constexpr __simd_iterator&
operator+=(difference_type __x)
{
_M_offset += __x;
return *this;
}
constexpr __simd_iterator&
operator-=(difference_type __x)
{
_M_offset -= __x;
return *this;
}
constexpr value_type
operator[](difference_type __i) const
{ return (*_M_data)[_M_offset + __i]; }
constexpr friend auto operator<=>(__simd_iterator __a, __simd_iterator __b)
{ return __a._M_offset <=> __b._M_offset; }
constexpr friend bool operator==(__simd_iterator __a, __simd_iterator __b) = default;
constexpr friend bool operator==(__simd_iterator __a, __simd_iterator_sentinel)
{ return __a._M_offset == difference_type(_Vp::size.value); }
};
template <size_t _Bs, typename _Abi>
class __simd_mask_iterator
{
using _Vp = basic_simd_mask<_Bs, _Abi>;
const _Vp* _M_data = nullptr;
int _M_offset = 0;
public:
using value_type = bool;
using iterator_category = std::random_access_iterator_tag;
using difference_type = int;
constexpr __simd_mask_iterator() = default;
constexpr
__simd_mask_iterator(const _Vp& __d, int __x)
: _M_data(&__d), _M_offset(__x)
{}
constexpr
__simd_mask_iterator(const __simd_mask_iterator &) = default;
constexpr __simd_mask_iterator&
operator=(const __simd_mask_iterator &) = default;
constexpr value_type
operator*() const
{ return (*_M_data)[_M_offset]; }
constexpr __simd_mask_iterator&
operator++()
{
++_M_offset;
return *this;
}
constexpr __simd_mask_iterator
operator++(int)
{
__simd_mask_iterator r = *this;
++_M_offset;
return r;
}
constexpr __simd_mask_iterator&
operator--()
{
--_M_offset;
return *this;
}
constexpr __simd_mask_iterator
operator--(int)
{
__simd_mask_iterator r = *this;
--_M_offset;
return r;
}
constexpr difference_type
operator-(__simd_mask_iterator __rhs) const
{ return _M_offset - __rhs._M_offset; }
constexpr friend __simd_mask_iterator
operator+(difference_type __x, const __simd_mask_iterator& __it)
{ return __simd_mask_iterator(*__it._M_data, __it._M_offset + __x); }
constexpr friend __simd_mask_iterator
operator+(const __simd_mask_iterator& __it, difference_type __x)
{ return __simd_mask_iterator(*__it._M_data, __it._M_offset + __x); }
constexpr friend __simd_mask_iterator
operator-(difference_type __x, const __simd_mask_iterator& __it)
{ return __simd_mask_iterator(*__it._M_data, __it._M_offset - __x); }
constexpr friend __simd_mask_iterator
operator-(const __simd_mask_iterator& __it, difference_type __x)
{ return __simd_mask_iterator(*__it._M_data, __it._M_offset - __x); }
constexpr __simd_mask_iterator&
operator+=(difference_type __x)
{
_M_offset += __x;
return *this;
}
constexpr __simd_mask_iterator&
operator-=(difference_type __x)
{
_M_offset -= __x;
return *this;
}
constexpr value_type
operator[](difference_type __i) const
{ return (*_M_data)[_M_offset + __i]; }
constexpr friend auto operator<=>(__simd_mask_iterator __a, __simd_mask_iterator __b)
{ return __a._M_offset <=> __b._M_offset; }
constexpr friend bool operator==(__simd_mask_iterator __a, __simd_mask_iterator __b) = default;
constexpr friend bool operator==(__simd_mask_iterator __a, __simd_iterator_sentinel)
{ return __a._M_offset == difference_type(_Vp::size.value); }
};
}
#endif // PROTOTYPE_RANGES_INTEGRATION_ITERATOR_H_