blob: 0f571a3ba9aa2dff3df07f87977ad1069379315f [file] [log] [blame]
Mike Klein455c7472019-02-05 13:42:46 -05001/*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SKVX_DEFINED
9#define SKVX_DEFINED
10
11// skvx::Vec<N,T> are SIMD vectors of N T's, a v1.5 successor to SkNx<N,T>.
12//
13// This time we're leaning a bit less on platform-specific intrinsics and a bit
14// more on Clang/GCC vector extensions, but still keeping the option open to
15// drop in platform-specific intrinsics, actually more easily than before.
16//
17// We've also fixed a few of the caveats that used to make SkNx awkward to work
18// with across translation units. skvx::Vec<N,T> always has N*sizeof(T) size
Mike Klein96e4e532019-04-16 11:36:55 -050019// and alignment[1][2] and is safe to use across translation units freely.
20//
21// [1] Ideally we'd only align to T, but that tanks ARMv7 NEON codegen.
22// [2] Some compilers barf if we try to use N*sizeof(T), so instead we leave them at T.
Mike Klein455c7472019-02-05 13:42:46 -050023
Mike Klein7d3b27d2019-06-07 10:57:58 -050024// Please try to keep this file independent of Skia headers.
Mike Kleindcfc3ef2019-02-07 09:49:17 -050025#include <algorithm> // std::min, std::max
Mike Klein41b995c2019-02-27 10:24:55 -060026#include <cmath> // std::ceil, std::floor, std::trunc, std::round, std::sqrt, etc.
Mike Klein455c7472019-02-05 13:42:46 -050027#include <cstdint> // intXX_t
28#include <cstring> // memcpy()
Mike Klein455c7472019-02-05 13:42:46 -050029#include <initializer_list> // std::initializer_list
30
Mike Kleinec370972020-03-05 10:15:35 -060031#if defined(__SSE__) || defined(__AVX2__)
Mike Kleindcfc3ef2019-02-07 09:49:17 -050032 #include <immintrin.h>
Mike Klein7d3b27d2019-06-07 10:57:58 -050033#elif defined(__ARM_NEON)
Mike Kleindcfc3ef2019-02-07 09:49:17 -050034 #include <arm_neon.h>
35#endif
Mike Klein455c7472019-02-05 13:42:46 -050036
Mike Klein96e4e532019-04-16 11:36:55 -050037#if !defined(__clang__) && defined(__GNUC__) && defined(__mips64)
38 // GCC 7 hits an internal compiler error when targeting MIPS64.
39 #define SKVX_ALIGNMENT
40#elif !defined(__clang__) && defined(_MSC_VER) && defined(_M_IX86)
41 // Our SkVx unit tests fail when built by MSVC for 32-bit x86.
42 #define SKVX_ALIGNMENT
43#else
44 #define SKVX_ALIGNMENT alignas(N * sizeof(T))
45#endif
46
Mike Klein21ef0d52019-12-17 11:40:14 -060047#if defined(__GNUC__) && !defined(__clang__) && defined(__SSE__)
48 // GCC warns about ABI changes when returning >= 32 byte vectors when -mavx is not enabled.
49 // This only happens for types like VExt whose ABI we don't care about, not for Vec itself.
50 #pragma GCC diagnostic ignored "-Wpsabi"
51#endif
52
53// To avoid ODR violations, all methods must be force-inlined,
54// and all standalone functions must be static, perhaps using these helpers.
55#if defined(_MSC_VER)
56 #define SKVX_ALWAYS_INLINE __forceinline
57#else
58 #define SKVX_ALWAYS_INLINE __attribute__((always_inline))
59#endif
60
61#define SIT template < typename T> static inline
62#define SINT template <int N, typename T> static inline
63#define SINTU template <int N, typename T, typename U, \
64 typename=typename std::enable_if<std::is_convertible<U,T>::value>::type> \
65 static inline
Mike Klein41b995c2019-02-27 10:24:55 -060066
Mike Klein455c7472019-02-05 13:42:46 -050067namespace skvx {
68
69// All Vec have the same simple memory layout, the same as `T vec[N]`.
Mike Klein455c7472019-02-05 13:42:46 -050070template <int N, typename T>
Mike Klein96e4e532019-04-16 11:36:55 -050071struct SKVX_ALIGNMENT Vec {
72 static_assert((N & (N-1)) == 0, "N must be a power of 2.");
73 static_assert(sizeof(T) >= alignof(T), "What kind of crazy T is this?");
Mike Klein455c7472019-02-05 13:42:46 -050074
Mike Kleindcfc3ef2019-02-07 09:49:17 -050075 Vec<N/2,T> lo, hi;
Mike Klein455c7472019-02-05 13:42:46 -050076
Mike Klein42925152019-02-06 11:56:58 -050077 // Methods belong here in the class declaration of Vec only if:
78 // - they must be here, like constructors or operator[];
79 // - they'll definitely never want a specialized implementation.
80 // Other operations on Vec should be defined outside the type.
81
Mike Klein21ef0d52019-12-17 11:40:14 -060082 SKVX_ALWAYS_INLINE Vec() = default;
Mike Kleinf4438d52019-03-14 13:30:42 -050083
84 template <typename U,
85 typename=typename std::enable_if<std::is_convertible<U,T>::value>::type>
Mike Klein21ef0d52019-12-17 11:40:14 -060086 SKVX_ALWAYS_INLINE
Mike Kleinf4438d52019-03-14 13:30:42 -050087 Vec(U x) : lo(x), hi(x) {}
Mike Klein455c7472019-02-05 13:42:46 -050088
Mike Klein21ef0d52019-12-17 11:40:14 -060089 SKVX_ALWAYS_INLINE Vec(std::initializer_list<T> xs) {
Mike Kleindcfc3ef2019-02-07 09:49:17 -050090 T vals[N] = {0};
91 memcpy(vals, xs.begin(), std::min(xs.size(), (size_t)N)*sizeof(T));
Mike Klein455c7472019-02-05 13:42:46 -050092
Mike Kleindcfc3ef2019-02-07 09:49:17 -050093 lo = Vec<N/2,T>::Load(vals + 0);
94 hi = Vec<N/2,T>::Load(vals + N/2);
Mike Klein455c7472019-02-05 13:42:46 -050095 }
96
Mike Klein21ef0d52019-12-17 11:40:14 -060097 SKVX_ALWAYS_INLINE T operator[](int i) const { return i < N/2 ? lo[i] : hi[i-N/2]; }
98 SKVX_ALWAYS_INLINE T& operator[](int i) { return i < N/2 ? lo[i] : hi[i-N/2]; }
Mike Klein42925152019-02-06 11:56:58 -050099
Mike Klein21ef0d52019-12-17 11:40:14 -0600100 SKVX_ALWAYS_INLINE static Vec Load(const void* ptr) {
Mike Klein42925152019-02-06 11:56:58 -0500101 Vec v;
102 memcpy(&v, ptr, sizeof(Vec));
103 return v;
104 }
Mike Klein21ef0d52019-12-17 11:40:14 -0600105 SKVX_ALWAYS_INLINE void store(void* ptr) const {
Mike Klein42925152019-02-06 11:56:58 -0500106 memcpy(ptr, this, sizeof(Vec));
107 }
Mike Klein455c7472019-02-05 13:42:46 -0500108};
109
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500110template <typename T>
111struct Vec<1,T> {
112 T val;
Mike Klein455c7472019-02-05 13:42:46 -0500113
Mike Klein21ef0d52019-12-17 11:40:14 -0600114 SKVX_ALWAYS_INLINE Vec() = default;
Mike Kleinf4438d52019-03-14 13:30:42 -0500115
116 template <typename U,
117 typename=typename std::enable_if<std::is_convertible<U,T>::value>::type>
Mike Klein21ef0d52019-12-17 11:40:14 -0600118 SKVX_ALWAYS_INLINE
Mike Kleinf4438d52019-03-14 13:30:42 -0500119 Vec(U x) : val(x) {}
Mike Klein455c7472019-02-05 13:42:46 -0500120
Mike Klein21ef0d52019-12-17 11:40:14 -0600121 SKVX_ALWAYS_INLINE Vec(std::initializer_list<T> xs) : val(xs.size() ? *xs.begin() : 0) {}
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500122
Mike Klein21ef0d52019-12-17 11:40:14 -0600123 SKVX_ALWAYS_INLINE T operator[](int) const { return val; }
124 SKVX_ALWAYS_INLINE T& operator[](int) { return val; }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500125
Mike Klein21ef0d52019-12-17 11:40:14 -0600126 SKVX_ALWAYS_INLINE static Vec Load(const void* ptr) {
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500127 Vec v;
128 memcpy(&v, ptr, sizeof(Vec));
129 return v;
130 }
Mike Klein21ef0d52019-12-17 11:40:14 -0600131 SKVX_ALWAYS_INLINE void store(void* ptr) const {
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500132 memcpy(ptr, this, sizeof(Vec));
133 }
134};
Mike Klein455c7472019-02-05 13:42:46 -0500135
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500136template <typename D, typename S>
Mike Klein9a885b22019-04-16 12:07:23 -0500137static inline D bit_pun(const S& s) {
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500138 static_assert(sizeof(D) == sizeof(S), "");
139 D d;
140 memcpy(&d, &s, sizeof(D));
141 return d;
142}
Mike Klein455c7472019-02-05 13:42:46 -0500143
Mike Klein455c7472019-02-05 13:42:46 -0500144// Translate from a value type T to its corresponding Mask, the result of a comparison.
Mike Kleincd9ef732019-02-09 13:48:54 -0500145template <typename T> struct Mask { using type = T; };
146template <> struct Mask<float > { using type = int32_t; };
147template <> struct Mask<double> { using type = int64_t; };
148template <typename T> using M = typename Mask<T>::type;
Mike Klein455c7472019-02-05 13:42:46 -0500149
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500150// Join two Vec<N,T> into one Vec<2N,T>.
Mike Klein9a885b22019-04-16 12:07:23 -0500151SINT Vec<2*N,T> join(const Vec<N,T>& lo, const Vec<N,T>& hi) {
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500152 Vec<2*N,T> v;
153 v.lo = lo;
154 v.hi = hi;
155 return v;
Mike Klein455c7472019-02-05 13:42:46 -0500156}
Mike Klein455c7472019-02-05 13:42:46 -0500157
158// We have two default strategies for implementing most operations:
159// 1) lean on Clang/GCC vector extensions when available;
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500160// 2) recurse to scalar portable implementations when not.
161// At the end we can drop in platform-specific implementations that override either default.
Mike Klein455c7472019-02-05 13:42:46 -0500162
Mike Klein42925152019-02-06 11:56:58 -0500163#if !defined(SKNX_NO_SIMD) && (defined(__clang__) || defined(__GNUC__))
Mike Klein455c7472019-02-05 13:42:46 -0500164
165 // VExt<N,T> types have the same size as Vec<N,T> and support most operations directly.
166 // N.B. VExt<N,T> alignment is N*alignof(T), stricter than Vec<N,T>'s alignof(T).
Mike Klein455c7472019-02-05 13:42:46 -0500167 #if defined(__clang__)
168 template <int N, typename T>
169 using VExt = T __attribute__((ext_vector_type(N)));
170
171 #elif defined(__GNUC__)
172 template <int N, typename T>
173 struct VExtHelper {
174 typedef T __attribute__((vector_size(N*sizeof(T)))) type;
175 };
176
177 template <int N, typename T>
178 using VExt = typename VExtHelper<N,T>::type;
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500179
180 // For some reason some (new!) versions of GCC cannot seem to deduce N in the generic
181 // to_vec<N,T>() below for N=4 and T=float. This workaround seems to help...
Mike Kleinda7b0532019-04-10 12:40:31 -0500182 static inline Vec<4,float> to_vec(VExt<4,float> v) { return bit_pun<Vec<4,float>>(v); }
Mike Klein455c7472019-02-05 13:42:46 -0500183 #endif
184
Mike Klein9a885b22019-04-16 12:07:23 -0500185 SINT VExt<N,T> to_vext(const Vec<N,T>& v) { return bit_pun<VExt<N,T>>(v); }
186 SINT Vec <N,T> to_vec(const VExt<N,T>& v) { return bit_pun<Vec <N,T>>(v); }
Mike Klein455c7472019-02-05 13:42:46 -0500187
Mike Klein9a885b22019-04-16 12:07:23 -0500188 SINT Vec<N,T> operator+(const Vec<N,T>& x, const Vec<N,T>& y) { return to_vec<N,T>(to_vext(x) + to_vext(y)); }
189 SINT Vec<N,T> operator-(const Vec<N,T>& x, const Vec<N,T>& y) { return to_vec<N,T>(to_vext(x) - to_vext(y)); }
190 SINT Vec<N,T> operator*(const Vec<N,T>& x, const Vec<N,T>& y) { return to_vec<N,T>(to_vext(x) * to_vext(y)); }
191 SINT Vec<N,T> operator/(const Vec<N,T>& x, const Vec<N,T>& y) { return to_vec<N,T>(to_vext(x) / to_vext(y)); }
Mike Klein455c7472019-02-05 13:42:46 -0500192
Mike Klein9a885b22019-04-16 12:07:23 -0500193 SINT Vec<N,T> operator^(const Vec<N,T>& x, const Vec<N,T>& y) { return to_vec<N,T>(to_vext(x) ^ to_vext(y)); }
194 SINT Vec<N,T> operator&(const Vec<N,T>& x, const Vec<N,T>& y) { return to_vec<N,T>(to_vext(x) & to_vext(y)); }
195 SINT Vec<N,T> operator|(const Vec<N,T>& x, const Vec<N,T>& y) { return to_vec<N,T>(to_vext(x) | to_vext(y)); }
Mike Klein455c7472019-02-05 13:42:46 -0500196
Mike Klein9a885b22019-04-16 12:07:23 -0500197 SINT Vec<N,T> operator!(const Vec<N,T>& x) { return to_vec<N,T>(!to_vext(x)); }
198 SINT Vec<N,T> operator-(const Vec<N,T>& x) { return to_vec<N,T>(-to_vext(x)); }
199 SINT Vec<N,T> operator~(const Vec<N,T>& x) { return to_vec<N,T>(~to_vext(x)); }
Mike Klein455c7472019-02-05 13:42:46 -0500200
Mike Klein9a885b22019-04-16 12:07:23 -0500201 SINT Vec<N,T> operator<<(const Vec<N,T>& x, int bits) { return to_vec<N,T>(to_vext(x) << bits); }
202 SINT Vec<N,T> operator>>(const Vec<N,T>& x, int bits) { return to_vec<N,T>(to_vext(x) >> bits); }
Mike Klein455c7472019-02-05 13:42:46 -0500203
Mike Klein9a885b22019-04-16 12:07:23 -0500204 SINT Vec<N,M<T>> operator==(const Vec<N,T>& x, const Vec<N,T>& y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) == to_vext(y)); }
205 SINT Vec<N,M<T>> operator!=(const Vec<N,T>& x, const Vec<N,T>& y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) != to_vext(y)); }
206 SINT Vec<N,M<T>> operator<=(const Vec<N,T>& x, const Vec<N,T>& y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) <= to_vext(y)); }
207 SINT Vec<N,M<T>> operator>=(const Vec<N,T>& x, const Vec<N,T>& y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) >= to_vext(y)); }
208 SINT Vec<N,M<T>> operator< (const Vec<N,T>& x, const Vec<N,T>& y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) < to_vext(y)); }
209 SINT Vec<N,M<T>> operator> (const Vec<N,T>& x, const Vec<N,T>& y) { return bit_pun<Vec<N,M<T>>>(to_vext(x) > to_vext(y)); }
Mike Klein455c7472019-02-05 13:42:46 -0500210
211#else
212
213 // Either SKNX_NO_SIMD is defined, or Clang/GCC vector extensions are not available.
214 // We'll implement things portably, in a way that should be easily autovectorizable.
215
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500216 // N == 1 scalar implementations.
Mike Klein9a885b22019-04-16 12:07:23 -0500217 SIT Vec<1,T> operator+(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val + y.val; }
218 SIT Vec<1,T> operator-(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val - y.val; }
219 SIT Vec<1,T> operator*(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val * y.val; }
220 SIT Vec<1,T> operator/(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val / y.val; }
Mike Klein455c7472019-02-05 13:42:46 -0500221
Mike Klein9a885b22019-04-16 12:07:23 -0500222 SIT Vec<1,T> operator^(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val ^ y.val; }
223 SIT Vec<1,T> operator&(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val & y.val; }
224 SIT Vec<1,T> operator|(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val | y.val; }
Mike Klein455c7472019-02-05 13:42:46 -0500225
Mike Klein9a885b22019-04-16 12:07:23 -0500226 SIT Vec<1,T> operator!(const Vec<1,T>& x) { return !x.val; }
227 SIT Vec<1,T> operator-(const Vec<1,T>& x) { return -x.val; }
228 SIT Vec<1,T> operator~(const Vec<1,T>& x) { return ~x.val; }
Mike Klein455c7472019-02-05 13:42:46 -0500229
Mike Klein9a885b22019-04-16 12:07:23 -0500230 SIT Vec<1,T> operator<<(const Vec<1,T>& x, int bits) { return x.val << bits; }
231 SIT Vec<1,T> operator>>(const Vec<1,T>& x, int bits) { return x.val >> bits; }
Mike Klein455c7472019-02-05 13:42:46 -0500232
Mike Klein9a885b22019-04-16 12:07:23 -0500233 SIT Vec<1,M<T>> operator==(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val == y.val ? ~0 : 0; }
234 SIT Vec<1,M<T>> operator!=(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val != y.val ? ~0 : 0; }
235 SIT Vec<1,M<T>> operator<=(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val <= y.val ? ~0 : 0; }
236 SIT Vec<1,M<T>> operator>=(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val >= y.val ? ~0 : 0; }
237 SIT Vec<1,M<T>> operator< (const Vec<1,T>& x, const Vec<1,T>& y) { return x.val < y.val ? ~0 : 0; }
238 SIT Vec<1,M<T>> operator> (const Vec<1,T>& x, const Vec<1,T>& y) { return x.val > y.val ? ~0 : 0; }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500239
240 // All default N != 1 implementations just recurse on lo and hi halves.
Mike Klein9a885b22019-04-16 12:07:23 -0500241 SINT Vec<N,T> operator+(const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo + y.lo, x.hi + y.hi); }
242 SINT Vec<N,T> operator-(const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo - y.lo, x.hi - y.hi); }
243 SINT Vec<N,T> operator*(const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo * y.lo, x.hi * y.hi); }
244 SINT Vec<N,T> operator/(const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo / y.lo, x.hi / y.hi); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500245
Mike Klein9a885b22019-04-16 12:07:23 -0500246 SINT Vec<N,T> operator^(const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo ^ y.lo, x.hi ^ y.hi); }
247 SINT Vec<N,T> operator&(const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo & y.lo, x.hi & y.hi); }
248 SINT Vec<N,T> operator|(const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo | y.lo, x.hi | y.hi); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500249
Mike Klein9a885b22019-04-16 12:07:23 -0500250 SINT Vec<N,T> operator!(const Vec<N,T>& x) { return join(!x.lo, !x.hi); }
251 SINT Vec<N,T> operator-(const Vec<N,T>& x) { return join(-x.lo, -x.hi); }
252 SINT Vec<N,T> operator~(const Vec<N,T>& x) { return join(~x.lo, ~x.hi); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500253
Mike Klein9a885b22019-04-16 12:07:23 -0500254 SINT Vec<N,T> operator<<(const Vec<N,T>& x, int bits) { return join(x.lo << bits, x.hi << bits); }
255 SINT Vec<N,T> operator>>(const Vec<N,T>& x, int bits) { return join(x.lo >> bits, x.hi >> bits); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500256
Mike Klein9a885b22019-04-16 12:07:23 -0500257 SINT Vec<N,M<T>> operator==(const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo == y.lo, x.hi == y.hi); }
258 SINT Vec<N,M<T>> operator!=(const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo != y.lo, x.hi != y.hi); }
259 SINT Vec<N,M<T>> operator<=(const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo <= y.lo, x.hi <= y.hi); }
260 SINT Vec<N,M<T>> operator>=(const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo >= y.lo, x.hi >= y.hi); }
261 SINT Vec<N,M<T>> operator< (const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo < y.lo, x.hi < y.hi); }
262 SINT Vec<N,M<T>> operator> (const Vec<N,T>& x, const Vec<N,T>& y) { return join(x.lo > y.lo, x.hi > y.hi); }
Mike Klein455c7472019-02-05 13:42:46 -0500263#endif
264
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500265// Some operations we want are not expressible with Clang/GCC vector
266// extensions, so we implement them using the recursive approach.
Mike Klein455c7472019-02-05 13:42:46 -0500267
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500268// N == 1 scalar implementations.
Mike Klein9a885b22019-04-16 12:07:23 -0500269SIT Vec<1,T> if_then_else(const Vec<1,M<T>>& cond, const Vec<1,T>& t, const Vec<1,T>& e) {
Mike Kleincd9ef732019-02-09 13:48:54 -0500270 auto t_bits = bit_pun<M<T>>(t),
271 e_bits = bit_pun<M<T>>(e);
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500272 return bit_pun<T>( (cond.val & t_bits) | (~cond.val & e_bits) );
Mike Klein455c7472019-02-05 13:42:46 -0500273}
274
Mike Klein9a885b22019-04-16 12:07:23 -0500275SIT bool any(const Vec<1,T>& x) { return x.val != 0; }
276SIT bool all(const Vec<1,T>& x) { return x.val != 0; }
Mike Klein42925152019-02-06 11:56:58 -0500277
Mike Klein9a885b22019-04-16 12:07:23 -0500278SIT T min(const Vec<1,T>& x) { return x.val; }
279SIT T max(const Vec<1,T>& x) { return x.val; }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500280
Mike Klein9a885b22019-04-16 12:07:23 -0500281SIT Vec<1,T> min(const Vec<1,T>& x, const Vec<1,T>& y) { return std::min(x.val, y.val); }
282SIT Vec<1,T> max(const Vec<1,T>& x, const Vec<1,T>& y) { return std::max(x.val, y.val); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500283
Mike Klein9a885b22019-04-16 12:07:23 -0500284SIT Vec<1,T> ceil(const Vec<1,T>& x) { return std:: ceil(x.val); }
285SIT Vec<1,T> floor(const Vec<1,T>& x) { return std::floor(x.val); }
286SIT Vec<1,T> trunc(const Vec<1,T>& x) { return std::trunc(x.val); }
287SIT Vec<1,T> round(const Vec<1,T>& x) { return std::round(x.val); }
288SIT Vec<1,T> sqrt(const Vec<1,T>& x) { return std:: sqrt(x.val); }
289SIT Vec<1,T> abs(const Vec<1,T>& x) { return std:: abs(x.val); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500290
Mike Klein9a885b22019-04-16 12:07:23 -0500291SIT Vec<1,T> rcp(const Vec<1,T>& x) { return 1 / x.val; }
292SIT Vec<1,T> rsqrt(const Vec<1,T>& x) { return rcp(sqrt(x)); }
293SIT Vec<1,T> mad(const Vec<1,T>& f,
294 const Vec<1,T>& m,
295 const Vec<1,T>& a) { return f*m+a; }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500296
297// All default N != 1 implementations just recurse on lo and hi halves.
Mike Klein9a885b22019-04-16 12:07:23 -0500298SINT Vec<N,T> if_then_else(const Vec<N,M<T>>& cond, const Vec<N,T>& t, const Vec<N,T>& e) {
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500299 return join(if_then_else(cond.lo, t.lo, e.lo),
300 if_then_else(cond.hi, t.hi, e.hi));
301}
302
Mike Klein9a885b22019-04-16 12:07:23 -0500303SINT bool any(const Vec<N,T>& x) { return any(x.lo) || any(x.hi); }
304SINT bool all(const Vec<N,T>& x) { return all(x.lo) && all(x.hi); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500305
Mike Klein9a885b22019-04-16 12:07:23 -0500306SINT T min(const Vec<N,T>& x) { return std::min(min(x.lo), min(x.hi)); }
307SINT T max(const Vec<N,T>& x) { return std::max(max(x.lo), max(x.hi)); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500308
Mike Klein9a885b22019-04-16 12:07:23 -0500309SINT Vec<N,T> min(const Vec<N,T>& x, const Vec<N,T>& y) { return join(min(x.lo, y.lo), min(x.hi, y.hi)); }
310SINT Vec<N,T> max(const Vec<N,T>& x, const Vec<N,T>& y) { return join(max(x.lo, y.lo), max(x.hi, y.hi)); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500311
Mike Klein9a885b22019-04-16 12:07:23 -0500312SINT Vec<N,T> ceil(const Vec<N,T>& x) { return join( ceil(x.lo), ceil(x.hi)); }
313SINT Vec<N,T> floor(const Vec<N,T>& x) { return join(floor(x.lo), floor(x.hi)); }
314SINT Vec<N,T> trunc(const Vec<N,T>& x) { return join(trunc(x.lo), trunc(x.hi)); }
315SINT Vec<N,T> round(const Vec<N,T>& x) { return join(round(x.lo), round(x.hi)); }
316SINT Vec<N,T> sqrt(const Vec<N,T>& x) { return join( sqrt(x.lo), sqrt(x.hi)); }
317SINT Vec<N,T> abs(const Vec<N,T>& x) { return join( abs(x.lo), abs(x.hi)); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500318
Mike Klein9a885b22019-04-16 12:07:23 -0500319SINT Vec<N,T> rcp(const Vec<N,T>& x) { return join( rcp(x.lo), rcp(x.hi)); }
320SINT Vec<N,T> rsqrt(const Vec<N,T>& x) { return join(rsqrt(x.lo), rsqrt(x.hi)); }
321SINT Vec<N,T> mad(const Vec<N,T>& f,
322 const Vec<N,T>& m,
323 const Vec<N,T>& a) { return join(mad(f.lo, m.lo, a.lo), mad(f.hi, m.hi, a.hi)); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500324
Mike Klein455c7472019-02-05 13:42:46 -0500325
Mike Klein42925152019-02-06 11:56:58 -0500326// Scalar/vector operations just splat the scalar to a vector...
Mike Klein9a885b22019-04-16 12:07:23 -0500327SINTU Vec<N,T> operator+ (U x, const Vec<N,T>& y) { return Vec<N,T>(x) + y; }
328SINTU Vec<N,T> operator- (U x, const Vec<N,T>& y) { return Vec<N,T>(x) - y; }
329SINTU Vec<N,T> operator* (U x, const Vec<N,T>& y) { return Vec<N,T>(x) * y; }
330SINTU Vec<N,T> operator/ (U x, const Vec<N,T>& y) { return Vec<N,T>(x) / y; }
331SINTU Vec<N,T> operator^ (U x, const Vec<N,T>& y) { return Vec<N,T>(x) ^ y; }
332SINTU Vec<N,T> operator& (U x, const Vec<N,T>& y) { return Vec<N,T>(x) & y; }
333SINTU Vec<N,T> operator| (U x, const Vec<N,T>& y) { return Vec<N,T>(x) | y; }
334SINTU Vec<N,M<T>> operator==(U x, const Vec<N,T>& y) { return Vec<N,T>(x) == y; }
335SINTU Vec<N,M<T>> operator!=(U x, const Vec<N,T>& y) { return Vec<N,T>(x) != y; }
336SINTU Vec<N,M<T>> operator<=(U x, const Vec<N,T>& y) { return Vec<N,T>(x) <= y; }
337SINTU Vec<N,M<T>> operator>=(U x, const Vec<N,T>& y) { return Vec<N,T>(x) >= y; }
338SINTU Vec<N,M<T>> operator< (U x, const Vec<N,T>& y) { return Vec<N,T>(x) < y; }
339SINTU Vec<N,M<T>> operator> (U x, const Vec<N,T>& y) { return Vec<N,T>(x) > y; }
340SINTU Vec<N,T> min(U x, const Vec<N,T>& y) { return min(Vec<N,T>(x), y); }
341SINTU Vec<N,T> max(U x, const Vec<N,T>& y) { return max(Vec<N,T>(x), y); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500342
Mike Klein42925152019-02-06 11:56:58 -0500343// ... and same deal for vector/scalar operations.
Mike Klein9a885b22019-04-16 12:07:23 -0500344SINTU Vec<N,T> operator+ (const Vec<N,T>& x, U y) { return x + Vec<N,T>(y); }
345SINTU Vec<N,T> operator- (const Vec<N,T>& x, U y) { return x - Vec<N,T>(y); }
346SINTU Vec<N,T> operator* (const Vec<N,T>& x, U y) { return x * Vec<N,T>(y); }
347SINTU Vec<N,T> operator/ (const Vec<N,T>& x, U y) { return x / Vec<N,T>(y); }
348SINTU Vec<N,T> operator^ (const Vec<N,T>& x, U y) { return x ^ Vec<N,T>(y); }
349SINTU Vec<N,T> operator& (const Vec<N,T>& x, U y) { return x & Vec<N,T>(y); }
350SINTU Vec<N,T> operator| (const Vec<N,T>& x, U y) { return x | Vec<N,T>(y); }
351SINTU Vec<N,M<T>> operator==(const Vec<N,T>& x, U y) { return x == Vec<N,T>(y); }
352SINTU Vec<N,M<T>> operator!=(const Vec<N,T>& x, U y) { return x != Vec<N,T>(y); }
353SINTU Vec<N,M<T>> operator<=(const Vec<N,T>& x, U y) { return x <= Vec<N,T>(y); }
354SINTU Vec<N,M<T>> operator>=(const Vec<N,T>& x, U y) { return x >= Vec<N,T>(y); }
355SINTU Vec<N,M<T>> operator< (const Vec<N,T>& x, U y) { return x < Vec<N,T>(y); }
356SINTU Vec<N,M<T>> operator> (const Vec<N,T>& x, U y) { return x > Vec<N,T>(y); }
357SINTU Vec<N,T> min(const Vec<N,T>& x, U y) { return min(x, Vec<N,T>(y)); }
358SINTU Vec<N,T> max(const Vec<N,T>& x, U y) { return max(x, Vec<N,T>(y)); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500359
360// All vector/scalar combinations for mad() with at least one vector.
Mike Klein9a885b22019-04-16 12:07:23 -0500361SINTU Vec<N,T> mad(U f, const Vec<N,T>& m, const Vec<N,T>& a) { return Vec<N,T>(f)*m + a; }
362SINTU Vec<N,T> mad(const Vec<N,T>& f, U m, const Vec<N,T>& a) { return f*Vec<N,T>(m) + a; }
363SINTU Vec<N,T> mad(const Vec<N,T>& f, const Vec<N,T>& m, U a) { return f*m + Vec<N,T>(a); }
364SINTU Vec<N,T> mad(const Vec<N,T>& f, U m, U a) { return f*Vec<N,T>(m) + Vec<N,T>(a); }
365SINTU Vec<N,T> mad(U f, const Vec<N,T>& m, U a) { return Vec<N,T>(f)*m + Vec<N,T>(a); }
366SINTU Vec<N,T> mad(U f, U m, const Vec<N,T>& a) { return Vec<N,T>(f)*Vec<N,T>(m) + a; }
Mike Klein42925152019-02-06 11:56:58 -0500367
368// The various op= operators, for vectors...
Mike Klein9a885b22019-04-16 12:07:23 -0500369SINT Vec<N,T>& operator+=(Vec<N,T>& x, const Vec<N,T>& y) { return (x = x + y); }
370SINT Vec<N,T>& operator-=(Vec<N,T>& x, const Vec<N,T>& y) { return (x = x - y); }
371SINT Vec<N,T>& operator*=(Vec<N,T>& x, const Vec<N,T>& y) { return (x = x * y); }
372SINT Vec<N,T>& operator/=(Vec<N,T>& x, const Vec<N,T>& y) { return (x = x / y); }
373SINT Vec<N,T>& operator^=(Vec<N,T>& x, const Vec<N,T>& y) { return (x = x ^ y); }
374SINT Vec<N,T>& operator&=(Vec<N,T>& x, const Vec<N,T>& y) { return (x = x & y); }
375SINT Vec<N,T>& operator|=(Vec<N,T>& x, const Vec<N,T>& y) { return (x = x | y); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500376
Mike Klein42925152019-02-06 11:56:58 -0500377// ... for scalars...
Mike Kleinf4438d52019-03-14 13:30:42 -0500378SINTU Vec<N,T>& operator+=(Vec<N,T>& x, U y) { return (x = x + Vec<N,T>(y)); }
379SINTU Vec<N,T>& operator-=(Vec<N,T>& x, U y) { return (x = x - Vec<N,T>(y)); }
380SINTU Vec<N,T>& operator*=(Vec<N,T>& x, U y) { return (x = x * Vec<N,T>(y)); }
381SINTU Vec<N,T>& operator/=(Vec<N,T>& x, U y) { return (x = x / Vec<N,T>(y)); }
382SINTU Vec<N,T>& operator^=(Vec<N,T>& x, U y) { return (x = x ^ Vec<N,T>(y)); }
383SINTU Vec<N,T>& operator&=(Vec<N,T>& x, U y) { return (x = x & Vec<N,T>(y)); }
384SINTU Vec<N,T>& operator|=(Vec<N,T>& x, U y) { return (x = x | Vec<N,T>(y)); }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500385
Mike Klein42925152019-02-06 11:56:58 -0500386// ... and for shifts.
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500387SINT Vec<N,T>& operator<<=(Vec<N,T>& x, int bits) { return (x = x << bits); }
388SINT Vec<N,T>& operator>>=(Vec<N,T>& x, int bits) { return (x = x >> bits); }
Mike Klein455c7472019-02-05 13:42:46 -0500389
Mike Klein53a52982019-02-06 15:48:12 -0500390// cast() Vec<N,S> to Vec<N,D>, as if applying a C-cast to each lane.
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500391template <typename D, typename S>
Mike Klein9a885b22019-04-16 12:07:23 -0500392static inline Vec<1,D> cast(const Vec<1,S>& src) { return (D)src.val; }
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500393
Mike Klein42925152019-02-06 11:56:58 -0500394template <typename D, int N, typename S>
Mike Klein9a885b22019-04-16 12:07:23 -0500395static inline Vec<N,D> cast(const Vec<N,S>& src) {
Mike Klein42925152019-02-06 11:56:58 -0500396#if !defined(SKNX_NO_SIMD) && defined(__clang__)
Mike Kleinda7b0532019-04-10 12:40:31 -0500397 return to_vec(__builtin_convertvector(to_vext(src), VExt<N,D>));
Mike Klein42925152019-02-06 11:56:58 -0500398#else
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500399 return join(cast<D>(src.lo), cast<D>(src.hi));
Mike Klein42925152019-02-06 11:56:58 -0500400#endif
401}
402
Mike Klein53a52982019-02-06 15:48:12 -0500403// Shuffle values from a vector pretty arbitrarily:
404// skvx::Vec<4,float> rgba = {R,G,B,A};
405// shuffle<2,1,0,3> (rgba) ~> {B,G,R,A}
406// shuffle<2,1> (rgba) ~> {B,G}
407// shuffle<2,1,2,1,2,1,2,1>(rgba) ~> {B,G,B,G,B,G,B,G}
408// shuffle<3,3,3,3> (rgba) ~> {A,A,A,A}
409// The only real restriction is that the output also be a legal N=power-of-two sknx::Vec.
410template <int... Ix, int N, typename T>
Mike Klein9a885b22019-04-16 12:07:23 -0500411static inline Vec<sizeof...(Ix),T> shuffle(const Vec<N,T>& x) {
Mike Klein3bad19c2019-04-11 14:14:16 -0500412#if !defined(SKNX_NO_SIMD) && defined(__clang__)
413 return to_vec<sizeof...(Ix),T>(__builtin_shufflevector(to_vext(x), to_vext(x), Ix...));
414#else
Mike Klein53a52982019-02-06 15:48:12 -0500415 return { x[Ix]... };
Mike Klein3bad19c2019-04-11 14:14:16 -0500416#endif
Mike Klein53a52982019-02-06 15:48:12 -0500417}
Mike Klein42925152019-02-06 11:56:58 -0500418
Mike Kleinec370972020-03-05 10:15:35 -0600419// fma() delivers a fused mul-add, even if that's really expensive. Call it when you know it's not.
420static inline Vec<1,float> fma(const Vec<1,float>& x,
421 const Vec<1,float>& y,
422 const Vec<1,float>& z) {
423 return std::fma(x.val, y.val, z.val);
424}
425template <int N>
426static inline Vec<N,float> fma(const Vec<N,float>& x,
427 const Vec<N,float>& y,
428 const Vec<N,float>& z) {
429 return join(fma(x.lo, y.lo, z.lo),
430 fma(x.hi, y.hi, z.hi));
431}
432
Mike Klein4b44a0d2019-04-11 11:52:51 -0500433// div255(x) = (x + 127) / 255 is a bit-exact rounding divide-by-255, packing down to 8-bit.
434template <int N>
Mike Klein9a885b22019-04-16 12:07:23 -0500435static inline Vec<N,uint8_t> div255(const Vec<N,uint16_t>& x) {
Mike Klein4b44a0d2019-04-11 11:52:51 -0500436 return cast<uint8_t>( (x+127)/255 );
437}
438
439// approx_scale(x,y) approximates div255(cast<uint16_t>(x)*cast<uint16_t>(y)) within a bit,
440// and is always perfect when x or y is 0 or 255.
441template <int N>
Mike Klein9a885b22019-04-16 12:07:23 -0500442static inline Vec<N,uint8_t> approx_scale(const Vec<N,uint8_t>& x, const Vec<N,uint8_t>& y) {
Mike Klein4b44a0d2019-04-11 11:52:51 -0500443 // All of (x*y+x)/256, (x*y+y)/256, and (x*y+255)/256 meet the criteria above.
444 // We happen to have historically picked (x*y+x)/256.
445 auto X = cast<uint16_t>(x),
446 Y = cast<uint16_t>(y);
447 return cast<uint8_t>( (X*Y+X)/256 );
448}
449
Mike Klein7d3b27d2019-06-07 10:57:58 -0500450#if !defined(SKNX_NO_SIMD) && defined(__ARM_NEON)
Mike Klein9a885b22019-04-16 12:07:23 -0500451 // With NEON we can do eight u8*u8 -> u16 in one instruction, vmull_u8 (read, mul-long).
452 static inline Vec<8,uint16_t> mull(const Vec<8,uint8_t>& x,
453 const Vec<8,uint8_t>& y) {
454 return to_vec<8,uint16_t>(vmull_u8(to_vext(x),
455 to_vext(y)));
456 }
457
458 template <int N>
459 static inline typename std::enable_if<(N < 8),
460 Vec<N,uint16_t>>::type mull(const Vec<N,uint8_t>& x,
461 const Vec<N,uint8_t>& y) {
462 // N < 8 --> double up data until N == 8, returning the part we need.
463 return mull(join(x,x),
464 join(y,y)).lo;
465 }
466
467 template <int N>
468 static inline typename std::enable_if<(N > 8),
469 Vec<N,uint16_t>>::type mull(const Vec<N,uint8_t>& x,
470 const Vec<N,uint8_t>& y) {
471 // N > 8 --> usual join(lo,hi) strategy to recurse down to N == 8.
472 return join(mull(x.lo, y.lo),
473 mull(x.hi, y.hi));
474 }
475#else
476 // Nothing special when we don't have NEON... just cast up to 16-bit and multiply.
477 template <int N>
478 static inline Vec<N,uint16_t> mull(const Vec<N,uint8_t>& x,
479 const Vec<N,uint8_t>& y) {
480 return cast<uint16_t>(x)
481 * cast<uint16_t>(y);
482 }
483#endif
484
Mike Klein41b995c2019-02-27 10:24:55 -0600485#if !defined(SKNX_NO_SIMD)
Mike Klein7d3b27d2019-06-07 10:57:58 -0500486
Mike Klein41b995c2019-02-27 10:24:55 -0600487 // Platform-specific specializations and overloads can now drop in here.
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500488
Mike Klein7d3b27d2019-06-07 10:57:58 -0500489 #if defined(__SSE__)
Mike Klein9a885b22019-04-16 12:07:23 -0500490 static inline Vec<4,float> sqrt(const Vec<4,float>& x) {
Mike Kleinda7b0532019-04-10 12:40:31 -0500491 return bit_pun<Vec<4,float>>(_mm_sqrt_ps(bit_pun<__m128>(x)));
492 }
Mike Klein9a885b22019-04-16 12:07:23 -0500493 static inline Vec<4,float> rsqrt(const Vec<4,float>& x) {
Mike Kleinda7b0532019-04-10 12:40:31 -0500494 return bit_pun<Vec<4,float>>(_mm_rsqrt_ps(bit_pun<__m128>(x)));
495 }
Mike Klein9a885b22019-04-16 12:07:23 -0500496 static inline Vec<4,float> rcp(const Vec<4,float>& x) {
Mike Kleinda7b0532019-04-10 12:40:31 -0500497 return bit_pun<Vec<4,float>>(_mm_rcp_ps(bit_pun<__m128>(x)));
498 }
Mike Klein41b995c2019-02-27 10:24:55 -0600499
Mike Klein9a885b22019-04-16 12:07:23 -0500500 static inline Vec<2,float> sqrt(const Vec<2,float>& x) {
Mike Kleinda7b0532019-04-10 12:40:31 -0500501 return shuffle<0,1>( sqrt(shuffle<0,1,0,1>(x)));
502 }
Mike Klein9a885b22019-04-16 12:07:23 -0500503 static inline Vec<2,float> rsqrt(const Vec<2,float>& x) {
Mike Kleinda7b0532019-04-10 12:40:31 -0500504 return shuffle<0,1>(rsqrt(shuffle<0,1,0,1>(x)));
505 }
Mike Klein9a885b22019-04-16 12:07:23 -0500506 static inline Vec<2,float> rcp(const Vec<2,float>& x) {
Mike Kleinda7b0532019-04-10 12:40:31 -0500507 return shuffle<0,1>( rcp(shuffle<0,1,0,1>(x)));
508 }
509 #endif
Mike Klein41b995c2019-02-27 10:24:55 -0600510
Mike Klein7d3b27d2019-06-07 10:57:58 -0500511 #if defined(__SSE4_1__)
Mike Klein9a885b22019-04-16 12:07:23 -0500512 static inline Vec<4,float> if_then_else(const Vec<4,int >& c,
513 const Vec<4,float>& t,
514 const Vec<4,float>& e) {
Mike Kleinda7b0532019-04-10 12:40:31 -0500515 return bit_pun<Vec<4,float>>(_mm_blendv_ps(bit_pun<__m128>(e),
516 bit_pun<__m128>(t),
517 bit_pun<__m128>(c)));
518 }
Mike Klein7d3b27d2019-06-07 10:57:58 -0500519 #elif defined(__SSE__)
Mike Klein9a885b22019-04-16 12:07:23 -0500520 static inline Vec<4,float> if_then_else(const Vec<4,int >& c,
521 const Vec<4,float>& t,
522 const Vec<4,float>& e) {
Mike Kleinda7b0532019-04-10 12:40:31 -0500523 return bit_pun<Vec<4,float>>(_mm_or_ps(_mm_and_ps (bit_pun<__m128>(c),
524 bit_pun<__m128>(t)),
525 _mm_andnot_ps(bit_pun<__m128>(c),
526 bit_pun<__m128>(e))));
527 }
Mike Klein7d3b27d2019-06-07 10:57:58 -0500528 #elif defined(__ARM_NEON)
Mike Klein9a885b22019-04-16 12:07:23 -0500529 static inline Vec<4,float> if_then_else(const Vec<4,int >& c,
530 const Vec<4,float>& t,
531 const Vec<4,float>& e) {
Mike Kleinda7b0532019-04-10 12:40:31 -0500532 return bit_pun<Vec<4,float>>(vbslq_f32(bit_pun<uint32x4_t> (c),
533 bit_pun<float32x4_t>(t),
534 bit_pun<float32x4_t>(e)));
535 }
536 #endif
537
Mike Kleinec370972020-03-05 10:15:35 -0600538 #if defined(__AVX2__)
539 static inline Vec<4,float> fma(const Vec<4,float>& x,
540 const Vec<4,float>& y,
541 const Vec<4,float>& z) {
542 return bit_pun<Vec<4,float>>(_mm_fmadd_ps(bit_pun<__m128>(x),
543 bit_pun<__m128>(y),
544 bit_pun<__m128>(z)));
545 }
546
547 static inline Vec<8,float> fma(const Vec<8,float>& x,
548 const Vec<8,float>& y,
549 const Vec<8,float>& z) {
550 return bit_pun<Vec<8,float>>(_mm256_fmadd_ps(bit_pun<__m256>(x),
551 bit_pun<__m256>(y),
552 bit_pun<__m256>(z)));
553 }
554 #elif defined(__aarch64__)
555 static inline Vec<4,float> fma(const Vec<4,float>& x,
556 const Vec<4,float>& y,
557 const Vec<4,float>& z) {
558 // These instructions tend to work like z += xy, so the order here is z,x,y.
559 return bit_pun<Vec<4,float>>(vfmaq_f32(bit_pun<float32x4_t>(z),
560 bit_pun<float32x4_t>(x),
561 bit_pun<float32x4_t>(y)));
562 }
563 #endif
564
Mike Klein7d3b27d2019-06-07 10:57:58 -0500565#endif // !defined(SKNX_NO_SIMD)
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500566
567} // namespace skvx
568
Mike Kleinf4438d52019-03-14 13:30:42 -0500569#undef SINTU
Mike Kleindcfc3ef2019-02-07 09:49:17 -0500570#undef SINT
571#undef SIT
Mike Klein96e4e532019-04-16 11:36:55 -0500572#undef SKVX_ALIGNMENT
Mike Klein455c7472019-02-05 13:42:46 -0500573
574#endif//SKVX_DEFINED