blob: 1cfedf3d66503bee41a846f2d8eb0e7717fa647e [file] [log] [blame]
/*
* Copyright 2020 Google LLC.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrVx_DEFINED
#define GrVx_DEFINED
#include "include/core/SkTypes.h"
#include "include/private/SkVx.h"
// grvx is Ganesh's addendum to skvx, Skia's SIMD library. Here we introduce functions that are
// approximate and/or have LSB differences from platform to platform (e.g., by using hardware FMAs
// when available). When a function is approximate, its error range is well documented and tested.
namespace grvx {
// Allow floating point contraction. e.g., allow a*x + y to be compiled to a single FMA even though
// it introduces LSB differences on platforms that don't have an FMA instruction.
#if defined(__clang__)
#pragma STDC FP_CONTRACT ON
#endif
// Use familiar type names and functions from SkSL and GLSL.
template<int N> using vec = skvx::Vec<N, float>;
using float2 = vec<2>;
using float4 = vec<4>;
template<int N> using ivec = skvx::Vec<N, int32_t>;
using int2 = ivec<2>;
using int4 = ivec<4>;
template<int N> using uvec = skvx::Vec<N, uint32_t>;
using uint2 = uvec<2>;
using uint4 = uvec<4>;
static SK_ALWAYS_INLINE float dot(float2 a, float2 b) {
float2 ab = a*b;
return ab[0] + ab[1];
}
static SK_ALWAYS_INLINE float cross(float2 a, float2 b) {
float2 x = a*skvx::shuffle<1,0>(b);
return x[0] - x[1];
}
#if defined(__clang__)
#pragma STDC FP_CONTRACT DEFAULT
#endif
}; // namespace grvx
#endif