1 /*
2 * Copyright 2020 Google LLC.
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 GrVx_DEFINED
9 #define GrVx_DEFINED
10
11 #include "include/core/SkTypes.h"
12 #include "include/private/SkVx.h"
13
14 // grvx is Ganesh's addendum to skvx, Skia's SIMD library. Here we introduce functions that are
15 // approximate and/or have LSB differences from platform to platform (e.g., by using hardware FMAs
16 // when available). When a function is approximate, its error range is well documented and tested.
17 namespace grvx {
18
19 // Use familiar type names and functions from SkSL and GLSL.
20 template<int N> using vec = skvx::Vec<N, float>;
21 using float2 = vec<2>;
22 using float4 = vec<4>;
23
24 template<int N> using ivec = skvx::Vec<N, int32_t>;
25 using int2 = ivec<2>;
26 using int4 = ivec<4>;
27
28 template<int N> using uvec = skvx::Vec<N, uint32_t>;
29 using uint2 = uvec<2>;
30 using uint4 = uvec<4>;
31
dot(float2 a,float2 b)32 static SK_ALWAYS_INLINE float dot(float2 a, float2 b) {
33 float2 ab = a*b;
34 return ab[0] + ab[1];
35 }
36
cross(float2 a,float2 b)37 static SK_ALWAYS_INLINE float cross(float2 a, float2 b) {
38 float2 x = a*skvx::shuffle<1,0>(b);
39 return x[0] - x[1];
40 }
41 }; // namespace grvx
42
43 #endif
44