Lines Matching full:t
11 // skvx::Vec<N,T> are SIMD vectors of N T's, a v1.5 successor to SkNx<N,T>.
18 // with across translation units. skvx::Vec<N,T> always has N*sizeof(T) size
19 // and alignof(T) alignment and is safe to use across translation units freely.
37 // All Vec have the same simple memory layout, the same as `T vec[N]`.
40 template <int N, typename T>
44 Vec<N/2,T> lo, hi;
52 Vec(T x) : lo(x), hi(x) {} in Vec()
54 Vec(std::initializer_list<T> xs) { in Vec()
55 T vals[N] = {0}; in Vec()
56 memcpy(vals, xs.begin(), std::min(xs.size(), (size_t)N)*sizeof(T)); in Vec()
58 lo = Vec<N/2,T>::Load(vals + 0); in Vec()
59 hi = Vec<N/2,T>::Load(vals + N/2); in Vec()
62 T operator[](int i) const { return i < N/2 ? lo[i] : hi[i-N/2]; }
63 T& operator[](int i) { return i < N/2 ? lo[i] : hi[i-N/2]; }
75 template <typename T>
76 struct Vec<1,T> {
77 T val;
80 Vec(T x) : val(x) {}
82 Vec(std::initializer_list<T> xs) : val(xs.size() ? *xs.begin() : 0) {}
84 T operator[](int) const { return val; }
85 T& operator[](int) { return val; }
99 // This only happens for types like VExt whose ABI we don't care about, not for Vec itself.
104 #define SINT template <int N, typename T> static inline
105 #define SIT template < typename T> static inline
116 // Translate from a value type T to its corresponding Mask, the result of a comparison.
117 template <typename T> struct Mask { using type = T; };
120 template <typename T> using M = typename Mask<T>::type;
122 // Join two Vec<N,T> into one Vec<2N,T>.
123 SINT Vec<2*N,T> join(Vec<N,T> lo, Vec<N,T> hi) {
124 Vec<2*N,T> v;
137 // VExt<N,T> types have the same size as Vec<N,T> and support most operations directly.
138 // N.B. VExt<N,T> alignment is N*alignof(T), stricter than Vec<N,T>'s alignof(T).
140 template <int N, typename T>
141 using VExt = T __attribute__((ext_vector_type(N)));
144 template <int N, typename T>
146 typedef T __attribute__((vector_size(N*sizeof(T)))) type;
149 template <int N, typename T>
150 using VExt = typename VExtHelper<N,T>::type;
153 // to_vec<N,T>() below for N=4 and T=float. This workaround seems to help...
157 SINT VExt<N,T> to_vext(Vec<N,T> v) { return bit_pun<VExt<N,T>>(v); }
158 SINT Vec <N,T> to_vec(VExt<N,T> v) { return bit_pun<Vec <N,T>>(v); }
160 SINT Vec<N,T> operator+(Vec<N,T> x, Vec<N,T> y) { return to_vec(to_vext(x) + to_vext(y)); }
161 SINT Vec<N,T> operator-(Vec<N,T> x, Vec<N,T> y) { return to_vec(to_vext(x) - to_vext(y)); }
162 SINT Vec<N,T> operator*(Vec<N,T> x, Vec<N,T> y) { return to_vec(to_vext(x) * to_vext(y)); }
163 SINT Vec<N,T> operator/(Vec<N,T> x, Vec<N,T> y) { return to_vec(to_vext(x) / to_vext(y)); }
165 SINT Vec<N,T> operator^(Vec<N,T> x, Vec<N,T> y) { return to_vec(to_vext(x) ^ to_vext(y)); }
166 SINT Vec<N,T> operator&(Vec<N,T> x, Vec<N,T> y) { return to_vec(to_vext(x) & to_vext(y)); }
167 SINT Vec<N,T> operator|(Vec<N,T> x, Vec<N,T> y) { return to_vec(to_vext(x) | to_vext(y)); }
169 SINT Vec<N,T> operator!(Vec<N,T> x) { return to_vec(!to_vext(x)); }
170 SINT Vec<N,T> operator-(Vec<N,T> x) { return to_vec(-to_vext(x)); }
171 SINT Vec<N,T> operator~(Vec<N,T> x) { return to_vec(~to_vext(x)); }
173 SINT Vec<N,T> operator<<(Vec<N,T> x, int bits) { return to_vec(to_vext(x) << bits); }
174 SINT Vec<N,T> operator>>(Vec<N,T> x, int bits) { return to_vec(to_vext(x) >> bits); }
176 …SINT Vec<N,M<T>> operator==(Vec<N,T> x, Vec<N,T> y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) == to…
177 …SINT Vec<N,M<T>> operator!=(Vec<N,T> x, Vec<N,T> y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) != to…
178 …SINT Vec<N,M<T>> operator<=(Vec<N,T> x, Vec<N,T> y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) <= to…
179 …SINT Vec<N,M<T>> operator>=(Vec<N,T> x, Vec<N,T> y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) >= to…
180 …SINT Vec<N,M<T>> operator< (Vec<N,T> x, Vec<N,T> y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) < to…
181 …SINT Vec<N,M<T>> operator> (Vec<N,T> x, Vec<N,T> y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) > to…
189 SIT Vec<1,T> operator+(Vec<1,T> x, Vec<1,T> y) { return x.val + y.val; }
190 SIT Vec<1,T> operator-(Vec<1,T> x, Vec<1,T> y) { return x.val - y.val; }
191 SIT Vec<1,T> operator*(Vec<1,T> x, Vec<1,T> y) { return x.val * y.val; }
192 SIT Vec<1,T> operator/(Vec<1,T> x, Vec<1,T> y) { return x.val / y.val; }
194 SIT Vec<1,T> operator^(Vec<1,T> x, Vec<1,T> y) { return x.val ^ y.val; }
195 SIT Vec<1,T> operator&(Vec<1,T> x, Vec<1,T> y) { return x.val & y.val; }
196 SIT Vec<1,T> operator|(Vec<1,T> x, Vec<1,T> y) { return x.val | y.val; }
198 SIT Vec<1,T> operator!(Vec<1,T> x) { return !x.val; }
199 SIT Vec<1,T> operator-(Vec<1,T> x) { return -x.val; }
200 SIT Vec<1,T> operator~(Vec<1,T> x) { return ~x.val; }
202 SIT Vec<1,T> operator<<(Vec<1,T> x, int bits) { return x.val << bits; }
203 SIT Vec<1,T> operator>>(Vec<1,T> x, int bits) { return x.val >> bits; }
205 SIT Vec<1,M<T>> operator==(Vec<1,T> x, Vec<1,T> y) { return x.val == y.val ? ~0 : 0; }
206 SIT Vec<1,M<T>> operator!=(Vec<1,T> x, Vec<1,T> y) { return x.val != y.val ? ~0 : 0; }
207 SIT Vec<1,M<T>> operator<=(Vec<1,T> x, Vec<1,T> y) { return x.val <= y.val ? ~0 : 0; }
208 SIT Vec<1,M<T>> operator>=(Vec<1,T> x, Vec<1,T> y) { return x.val >= y.val ? ~0 : 0; }
209 SIT Vec<1,M<T>> operator< (Vec<1,T> x, Vec<1,T> y) { return x.val < y.val ? ~0 : 0; }
210 SIT Vec<1,M<T>> operator> (Vec<1,T> x, Vec<1,T> y) { return x.val > y.val ? ~0 : 0; }
213 SINT Vec<N,T> operator+(Vec<N,T> x, Vec<N,T> y) { return join(x.lo + y.lo, x.hi + y.hi); }
214 SINT Vec<N,T> operator-(Vec<N,T> x, Vec<N,T> y) { return join(x.lo - y.lo, x.hi - y.hi); }
215 SINT Vec<N,T> operator*(Vec<N,T> x, Vec<N,T> y) { return join(x.lo * y.lo, x.hi * y.hi); }
216 SINT Vec<N,T> operator/(Vec<N,T> x, Vec<N,T> y) { return join(x.lo / y.lo, x.hi / y.hi); }
218 SINT Vec<N,T> operator^(Vec<N,T> x, Vec<N,T> y) { return join(x.lo ^ y.lo, x.hi ^ y.hi); }
219 SINT Vec<N,T> operator&(Vec<N,T> x, Vec<N,T> y) { return join(x.lo & y.lo, x.hi & y.hi); }
220 SINT Vec<N,T> operator|(Vec<N,T> x, Vec<N,T> y) { return join(x.lo | y.lo, x.hi | y.hi); }
222 SINT Vec<N,T> operator!(Vec<N,T> x) { return join(!x.lo, !x.hi); }
223 SINT Vec<N,T> operator-(Vec<N,T> x) { return join(-x.lo, -x.hi); }
224 SINT Vec<N,T> operator~(Vec<N,T> x) { return join(~x.lo, ~x.hi); }
226 SINT Vec<N,T> operator<<(Vec<N,T> x, int bits) { return join(x.lo << bits, x.hi << bits); }
227 SINT Vec<N,T> operator>>(Vec<N,T> x, int bits) { return join(x.lo >> bits, x.hi >> bits); }
229 SINT Vec<N,M<T>> operator==(Vec<N,T> x, Vec<N,T> y) { return join(x.lo == y.lo, x.hi == y.hi); }
230 SINT Vec<N,M<T>> operator!=(Vec<N,T> x, Vec<N,T> y) { return join(x.lo != y.lo, x.hi != y.hi); }
231 SINT Vec<N,M<T>> operator<=(Vec<N,T> x, Vec<N,T> y) { return join(x.lo <= y.lo, x.hi <= y.hi); }
232 SINT Vec<N,M<T>> operator>=(Vec<N,T> x, Vec<N,T> y) { return join(x.lo >= y.lo, x.hi >= y.hi); }
233 SINT Vec<N,M<T>> operator< (Vec<N,T> x, Vec<N,T> y) { return join(x.lo < y.lo, x.hi < y.hi); }
234 SINT Vec<N,M<T>> operator> (Vec<N,T> x, Vec<N,T> y) { return join(x.lo > y.lo, x.hi > y.hi); }
241 SIT Vec<1,T> if_then_else(Vec<1,M<T>> cond, Vec<1,T> t, Vec<1,T> e) {
242 auto t_bits = bit_pun<M<T>>(t),
243 e_bits = bit_pun<M<T>>(e);
244 return bit_pun<T>( (cond.val & t_bits) | (~cond.val & e_bits) );
247 SIT bool any(Vec<1,T> x) { return x.val != 0; }
248 SIT bool all(Vec<1,T> x) { return x.val != 0; }
250 SIT T min(Vec<1,T> x) { return x.val; }
251 SIT T max(Vec<1,T> x) { return x.val; }
253 SIT Vec<1,T> min(Vec<1,T> x, Vec<1,T> y) { return std::min(x.val, y.val); }
254 SIT Vec<1,T> max(Vec<1,T> x, Vec<1,T> y) { return std::max(x.val, y.val); }
256 SIT Vec<1,T> ceil(Vec<1,T> x) { return std:: ceil(x.val); }
257 SIT Vec<1,T> floor(Vec<1,T> x) { return std::floor(x.val); }
258 SIT Vec<1,T> trunc(Vec<1,T> x) { return std::trunc(x.val); }
259 SIT Vec<1,T> round(Vec<1,T> x) { return std::round(x.val); }
260 SIT Vec<1,T> sqrt(Vec<1,T> x) { return std:: sqrt(x.val); }
261 SIT Vec<1,T> abs(Vec<1,T> x) { return std:: abs(x.val); }
263 SIT Vec<1,T> rcp(Vec<1,T> x) { return 1 / x.val; }
264 SIT Vec<1,T> rsqrt(Vec<1,T> x) { return rcp(sqrt(x)); }
265 SIT Vec<1,T> mad(Vec<1,T> f,
266 Vec<1,T> m,
267 Vec<1,T> a) { return f*m+a; }
270 SINT Vec<N,T> if_then_else(Vec<N,M<T>> cond, Vec<N,T> t, Vec<N,T> e) {
271 return join(if_then_else(cond.lo, t.lo, e.lo),
272 if_then_else(cond.hi, t.hi, e.hi));
275 SINT bool any(Vec<N,T> x) { return any(x.lo) || any(x.hi); }
276 SINT bool all(Vec<N,T> x) { return all(x.lo) && all(x.hi); }
278 SINT T min(Vec<N,T> x) { return std::min(min(x.lo), min(x.hi)); }
279 SINT T max(Vec<N,T> x) { return std::max(max(x.lo), max(x.hi)); }
281 SINT Vec<N,T> min(Vec<N,T> x, Vec<N,T> y) { return join(min(x.lo, y.lo), min(x.hi, y.hi)); }
282 SINT Vec<N,T> max(Vec<N,T> x, Vec<N,T> y) { return join(max(x.lo, y.lo), max(x.hi, y.hi)); }
284 SINT Vec<N,T> ceil(Vec<N,T> x) { return join( ceil(x.lo), ceil(x.hi)); }
285 SINT Vec<N,T> floor(Vec<N,T> x) { return join(floor(x.lo), floor(x.hi)); }
286 SINT Vec<N,T> trunc(Vec<N,T> x) { return join(trunc(x.lo), trunc(x.hi)); }
287 SINT Vec<N,T> round(Vec<N,T> x) { return join(round(x.lo), round(x.hi)); }
288 SINT Vec<N,T> sqrt(Vec<N,T> x) { return join( sqrt(x.lo), sqrt(x.hi)); }
289 SINT Vec<N,T> abs(Vec<N,T> x) { return join( abs(x.lo), abs(x.hi)); }
291 SINT Vec<N,T> rcp(Vec<N,T> x) { return join( rcp(x.lo), rcp(x.hi)); }
292 SINT Vec<N,T> rsqrt(Vec<N,T> x) { return join(rsqrt(x.lo), rsqrt(x.hi)); }
293 SINT Vec<N,T> mad(Vec<N,T> f,
294 Vec<N,T> m,
295 Vec<N,T> a) { return join(mad(f.lo, m.lo, a.lo), mad(f.hi, m.hi, a.hi)); }
299 SINT Vec<N,T> operator+ (T x, Vec<N,T> y) { return Vec<N,T>(x) + y; }
300 SINT Vec<N,T> operator- (T x, Vec<N,T> y) { return Vec<N,T>(x) - y; }
301 SINT Vec<N,T> operator* (T x, Vec<N,T> y) { return Vec<N,T>(x) * y; }
302 SINT Vec<N,T> operator/ (T x, Vec<N,T> y) { return Vec<N,T>(x) / y; }
303 SINT Vec<N,T> operator^ (T x, Vec<N,T> y) { return Vec<N,T>(x) ^ y; }
304 SINT Vec<N,T> operator& (T x, Vec<N,T> y) { return Vec<N,T>(x) & y; }
305 SINT Vec<N,T> operator| (T x, Vec<N,T> y) { return Vec<N,T>(x) | y; }
306 SINT Vec<N,M<T>> operator==(T x, Vec<N,T> y) { return Vec<N,T>(x) == y; }
307 SINT Vec<N,M<T>> operator!=(T x, Vec<N,T> y) { return Vec<N,T>(x) != y; }
308 SINT Vec<N,M<T>> operator<=(T x, Vec<N,T> y) { return Vec<N,T>(x) <= y; }
309 SINT Vec<N,M<T>> operator>=(T x, Vec<N,T> y) { return Vec<N,T>(x) >= y; }
310 SINT Vec<N,M<T>> operator< (T x, Vec<N,T> y) { return Vec<N,T>(x) < y; }
311 SINT Vec<N,M<T>> operator> (T x, Vec<N,T> y) { return Vec<N,T>(x) > y; }
312 SINT Vec<N,T> min(T x, Vec<N,T> y) { return min(Vec<N,T>(x), y); }
313 SINT Vec<N,T> max(T x, Vec<N,T> y) { return max(Vec<N,T>(x), y); }
316 SINT Vec<N,T> operator+ (Vec<N,T> x, T y) { return x + Vec<N,T>(y); }
317 SINT Vec<N,T> operator- (Vec<N,T> x, T y) { return x - Vec<N,T>(y); }
318 SINT Vec<N,T> operator* (Vec<N,T> x, T y) { return x * Vec<N,T>(y); }
319 SINT Vec<N,T> operator/ (Vec<N,T> x, T y) { return x / Vec<N,T>(y); }
320 SINT Vec<N,T> operator^ (Vec<N,T> x, T y) { return x ^ Vec<N,T>(y); }
321 SINT Vec<N,T> operator& (Vec<N,T> x, T y) { return x & Vec<N,T>(y); }
322 SINT Vec<N,T> operator| (Vec<N,T> x, T y) { return x | Vec<N,T>(y); }
323 SINT Vec<N,M<T>> operator==(Vec<N,T> x, T y) { return x == Vec<N,T>(y); }
324 SINT Vec<N,M<T>> operator!=(Vec<N,T> x, T y) { return x != Vec<N,T>(y); }
325 SINT Vec<N,M<T>> operator<=(Vec<N,T> x, T y) { return x <= Vec<N,T>(y); }
326 SINT Vec<N,M<T>> operator>=(Vec<N,T> x, T y) { return x >= Vec<N,T>(y); }
327 SINT Vec<N,M<T>> operator< (Vec<N,T> x, T y) { return x < Vec<N,T>(y); }
328 SINT Vec<N,M<T>> operator> (Vec<N,T> x, T y) { return x > Vec<N,T>(y); }
329 SINT Vec<N,T> min(Vec<N,T> x, T y) { return min(x, Vec<N,T>(y)); }
330 SINT Vec<N,T> max(Vec<N,T> x, T y) { return max(x, Vec<N,T>(y)); }
333 SINT Vec<N,T> mad(T f, Vec<N,T> m, Vec<N,T> a) { return Vec<N,T>(f)*m + a; }
334 SINT Vec<N,T> mad(Vec<N,T> f, T m, Vec<N,T> a) { return f*Vec<N,T>(m) + a; }
335 SINT Vec<N,T> mad(Vec<N,T> f, Vec<N,T> m, T a) { return f*m + Vec<N,T>(a); }
336 SINT Vec<N,T> mad(Vec<N,T> f, T m, T a) { return f*Vec<N,T>(m) + Vec<N,T>(a); }
337 SINT Vec<N,T> mad(T f, Vec<N,T> m, T a) { return Vec<N,T>(f)*m + Vec<N,T>(a); }
338 SINT Vec<N,T> mad(T f, T m, Vec<N,T> a) { return Vec<N,T>(f)*Vec<N,T>(m) + a; }
341 SINT Vec<N,T>& operator+=(Vec<N,T>& x, Vec<N,T> y) { return (x = x + y); }
342 SINT Vec<N,T>& operator-=(Vec<N,T>& x, Vec<N,T> y) { return (x = x - y); }
343 SINT Vec<N,T>& operator*=(Vec<N,T>& x, Vec<N,T> y) { return (x = x * y); }
344 SINT Vec<N,T>& operator/=(Vec<N,T>& x, Vec<N,T> y) { return (x = x / y); }
345 SINT Vec<N,T>& operator^=(Vec<N,T>& x, Vec<N,T> y) { return (x = x ^ y); }
346 SINT Vec<N,T>& operator&=(Vec<N,T>& x, Vec<N,T> y) { return (x = x & y); }
347 SINT Vec<N,T>& operator|=(Vec<N,T>& x, Vec<N,T> y) { return (x = x | y); }
350 SINT Vec<N,T>& operator+=(Vec<N,T>& x, T y) { return (x = x + Vec<N,T>(y)); }
351 SINT Vec<N,T>& operator-=(Vec<N,T>& x, T y) { return (x = x - Vec<N,T>(y)); }
352 SINT Vec<N,T>& operator*=(Vec<N,T>& x, T y) { return (x = x * Vec<N,T>(y)); }
353 SINT Vec<N,T>& operator/=(Vec<N,T>& x, T y) { return (x = x / Vec<N,T>(y)); }
354 SINT Vec<N,T>& operator^=(Vec<N,T>& x, T y) { return (x = x ^ Vec<N,T>(y)); }
355 SINT Vec<N,T>& operator&=(Vec<N,T>& x, T y) { return (x = x & Vec<N,T>(y)); }
356 SINT Vec<N,T>& operator|=(Vec<N,T>& x, T y) { return (x = x | Vec<N,T>(y)); }
359 SINT Vec<N,T>& operator<<=(Vec<N,T>& x, int bits) { return (x = x << bits); }
360 SINT Vec<N,T>& operator>>=(Vec<N,T>& x, int bits) { return (x = x >> bits); }
366 // but since they operate only on skvx::Vec, that shouldn't be a big deal.
388 template <int... Ix, int N, typename T>
389 SI skvx::Vec<sizeof...(Ix),T> shuffle(skvx::Vec<N,T> x) {
414 SI Vec<4,float> if_then_else(Vec<4,int> c, Vec<4,float> t, Vec<4,float> e) {
416 bit_pun<__m128>(t),
420 SI Vec<4,float> if_then_else(Vec<4,int> c, Vec<4,float> t, Vec<4,float> e) {
422 bit_pun<__m128>(t)),
427 SI Vec<4,float> if_then_else(Vec<4,int> c, Vec<4,float> t, Vec<4,float> e) {
429 bit_pun<float32x4_t>(t),