Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
skvx Namespace Reference

Classes

struct  Mask
 
struct  Mask< double >
 
struct  Mask< float >
 
class  ScaledDividerU32
 
struct  Vec
 
struct  Vec< 1, T >
 
struct  Vec< 2, T >
 
struct  Vec< 4, T >
 

Typedefs

template<typename T >
using M = typename Mask< T >::type
 
using float2 = Vec< 2, float >
 
using float4 = Vec< 4, float >
 
using float8 = Vec< 8, float >
 
using double2 = Vec< 2, double >
 
using double4 = Vec< 4, double >
 
using double8 = Vec< 8, double >
 
using byte2 = Vec< 2, uint8_t >
 
using byte4 = Vec< 4, uint8_t >
 
using byte8 = Vec< 8, uint8_t >
 
using byte16 = Vec< 16, uint8_t >
 
using int2 = Vec< 2, int32_t >
 
using int4 = Vec< 4, int32_t >
 
using int8 = Vec< 8, int32_t >
 
using ushort2 = Vec< 2, uint16_t >
 
using ushort4 = Vec< 4, uint16_t >
 
using ushort8 = Vec< 8, uint16_t >
 
using uint2 = Vec< 2, uint32_t >
 
using uint4 = Vec< 4, uint32_t >
 
using uint8 = Vec< 8, uint32_t >
 
using long2 = Vec< 2, int64_t >
 
using long4 = Vec< 4, int64_t >
 
using long8 = Vec< 8, int64_t >
 
using half2 = Vec< 2, uint16_t >
 
using half4 = Vec< 4, uint16_t >
 
using half8 = Vec< 8, uint16_t >
 

Functions

template<int... Ix, int N, typename T >
SI Vec< sizeof...(Ix), Tshuffle (const Vec< N, T > &)
 
SINT Vec< 2 *N, Tjoin (const Vec< N, T > &lo, const Vec< N, T > &hi)
 
SIT Vec< 1, Toperator+ (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, Toperator- (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, Toperator* (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, Toperator/ (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, Toperator^ (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, Toperator& (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, Toperator| (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, Toperator! (const Vec< 1, T > &x)
 
SIT Vec< 1, Toperator- (const Vec< 1, T > &x)
 
SIT Vec< 1, Toperator~ (const Vec< 1, T > &x)
 
SIT Vec< 1, Toperator<< (const Vec< 1, T > &x, int k)
 
SIT Vec< 1, Toperator>> (const Vec< 1, T > &x, int k)
 
SIT Vec< 1, M< T > > operator== (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, M< T > > operator!= (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, M< T > > operator<= (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, M< T > > operator>= (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, M< T > > operator< (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SIT Vec< 1, M< T > > operator> (const Vec< 1, T > &x, const Vec< 1, T > &y)
 
SINT Vec< N, Toperator+ (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, Toperator- (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, Toperator* (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, Toperator/ (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, Toperator^ (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, Toperator& (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, Toperator| (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, Toperator! (const Vec< N, T > &x)
 
SINT Vec< N, Toperator- (const Vec< N, T > &x)
 
SINT Vec< N, Toperator~ (const Vec< N, T > &x)
 
SINT Vec< N, Toperator<< (const Vec< N, T > &x, int k)
 
SINT Vec< N, Toperator>> (const Vec< N, T > &x, int k)
 
SINT Vec< N, M< T > > operator== (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, M< T > > operator!= (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, M< T > > operator<= (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, M< T > > operator>= (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, M< T > > operator< (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, M< T > > operator> (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINTU Vec< N, Toperator+ (U x, const Vec< N, T > &y)
 
SINTU Vec< N, Toperator- (U x, const Vec< N, T > &y)
 
SINTU Vec< N, Toperator* (U x, const Vec< N, T > &y)
 
SINTU Vec< N, Toperator/ (U x, const Vec< N, T > &y)
 
SINTU Vec< N, Toperator^ (U x, const Vec< N, T > &y)
 
SINTU Vec< N, Toperator& (U x, const Vec< N, T > &y)
 
SINTU Vec< N, Toperator| (U x, const Vec< N, T > &y)
 
SINTU Vec< N, M< T > > operator== (U x, const Vec< N, T > &y)
 
SINTU Vec< N, M< T > > operator!= (U x, const Vec< N, T > &y)
 
SINTU Vec< N, M< T > > operator<= (U x, const Vec< N, T > &y)
 
SINTU Vec< N, M< T > > operator>= (U x, const Vec< N, T > &y)
 
SINTU Vec< N, M< T > > operator< (U x, const Vec< N, T > &y)
 
SINTU Vec< N, M< T > > operator> (U x, const Vec< N, T > &y)
 
SINTU Vec< N, Toperator+ (const Vec< N, T > &x, U y)
 
SINTU Vec< N, Toperator- (const Vec< N, T > &x, U y)
 
SINTU Vec< N, Toperator* (const Vec< N, T > &x, U y)
 
SINTU Vec< N, Toperator/ (const Vec< N, T > &x, U y)
 
SINTU Vec< N, Toperator^ (const Vec< N, T > &x, U y)
 
SINTU Vec< N, Toperator& (const Vec< N, T > &x, U y)
 
SINTU Vec< N, Toperator| (const Vec< N, T > &x, U y)
 
SINTU Vec< N, M< T > > operator== (const Vec< N, T > &x, U y)
 
SINTU Vec< N, M< T > > operator!= (const Vec< N, T > &x, U y)
 
SINTU Vec< N, M< T > > operator<= (const Vec< N, T > &x, U y)
 
SINTU Vec< N, M< T > > operator>= (const Vec< N, T > &x, U y)
 
SINTU Vec< N, M< T > > operator< (const Vec< N, T > &x, U y)
 
SINTU Vec< N, M< T > > operator> (const Vec< N, T > &x, U y)
 
SINT Vec< N, T > & operator+= (Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, T > & operator-= (Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, T > & operator*= (Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, T > & operator/= (Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, T > & operator^= (Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, T > & operator&= (Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, T > & operator|= (Vec< N, T > &x, const Vec< N, T > &y)
 
SINTU Vec< N, T > & operator+= (Vec< N, T > &x, U y)
 
SINTU Vec< N, T > & operator-= (Vec< N, T > &x, U y)
 
SINTU Vec< N, T > & operator*= (Vec< N, T > &x, U y)
 
SINTU Vec< N, T > & operator/= (Vec< N, T > &x, U y)
 
SINTU Vec< N, T > & operator^= (Vec< N, T > &x, U y)
 
SINTU Vec< N, T > & operator&= (Vec< N, T > &x, U y)
 
SINTU Vec< N, T > & operator|= (Vec< N, T > &x, U y)
 
SINT Vec< N, T > & operator<<= (Vec< N, T > &x, int bits)
 
SINT Vec< N, T > & operator>>= (Vec< N, T > &x, int bits)
 
SINT Vec< N, Tnaive_if_then_else (const Vec< N, M< T > > &cond, const Vec< N, T > &t, const Vec< N, T > &e)
 
SIT Vec< 1, Tif_then_else (const Vec< 1, M< T > > &cond, const Vec< 1, T > &t, const Vec< 1, T > &e)
 
SINT Vec< N, Tif_then_else (const Vec< N, M< T > > &cond, const Vec< N, T > &t, const Vec< N, T > &e)
 
SIT bool any (const Vec< 1, T > &x)
 
SINT bool any (const Vec< N, T > &x)
 
SIT bool all (const Vec< 1, T > &x)
 
SINT bool all (const Vec< N, T > &x)
 
template<typename D , typename S >
SI Vec< 1, Dcast (const Vec< 1, S > &src)
 
template<typename D , int N, typename S >
SI Vec< N, Dcast (const Vec< N, S > &src)
 
SIT T min (const Vec< 1, T > &x)
 
SIT T max (const Vec< 1, T > &x)
 
SINT T min (const Vec< N, T > &x)
 
SINT T max (const Vec< N, T > &x)
 
SINT Vec< N, Tmin (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINT Vec< N, Tmax (const Vec< N, T > &x, const Vec< N, T > &y)
 
SINTU Vec< N, Tmin (const Vec< N, T > &x, U y)
 
SINTU Vec< N, Tmax (const Vec< N, T > &x, U y)
 
SINTU Vec< N, Tmin (U x, const Vec< N, T > &y)
 
SINTU Vec< N, Tmax (U x, const Vec< N, T > &y)
 
SINT Vec< N, Tpin (const Vec< N, T > &x, const Vec< N, T > &lo, const Vec< N, T > &hi)
 
template<typename Fn , typename... Args, size_t... I>
SI auto map (std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
 
template<typename Fn , int N, typename T , typename... Rest>
auto map (Fn &&fn, const Vec< N, T > &first, const Rest &... rest)
 
SIN Vec< N, float > ceil (const Vec< N, float > &x)
 
SIN Vec< N, float > floor (const Vec< N, float > &x)
 
SIN Vec< N, float > trunc (const Vec< N, float > &x)
 
SIN Vec< N, float > round (const Vec< N, float > &x)
 
SIN Vec< N, float > sqrt (const Vec< N, float > &x)
 
SIN Vec< N, float > abs (const Vec< N, float > &x)
 
SIN Vec< N, float > fma (const Vec< N, float > &x, const Vec< N, float > &y, const Vec< N, float > &z)
 
SI Vec< 1, intlrint (const Vec< 1, float > &x)
 
SIN Vec< N, intlrint (const Vec< N, float > &x)
 
SIN Vec< N, float > fract (const Vec< N, float > &x)
 
SIN Vec< N, uint16_t > to_half (const Vec< N, float > &x)
 
SIN Vec< N, float > from_half (const Vec< N, uint16_t > &x)
 
SIN Vec< N, uint8_t > div255 (const Vec< N, uint16_t > &x)
 
SIN Vec< N, uint8_t > approx_scale (const Vec< N, uint8_t > &x, const Vec< N, uint8_t > &y)
 
SINT std::enable_if_t< std::is_unsigned_v< T >, Vec< N, T > > saturated_add (const Vec< N, T > &x, const Vec< N, T > &y)
 
SIN Vec< N, uint16_t > mull (const Vec< N, uint8_t > &x, const Vec< N, uint8_t > &y)
 
SIN Vec< N, uint32_t > mull (const Vec< N, uint16_t > &x, const Vec< N, uint16_t > &y)
 
SIN Vec< N, uint16_t > mulhi (const Vec< N, uint16_t > &x, const Vec< N, uint16_t > &y)
 
SINT T dot (const Vec< N, T > &a, const Vec< N, T > &b)
 
SIT T cross (const Vec< 2, T > &a, const Vec< 2, T > &b)
 
SIN float length (const Vec< N, float > &v)
 
SIN double length (const Vec< N, double > &v)
 
SIN Vec< N, float > normalize (const Vec< N, float > &v)
 
SIN Vec< N, double > normalize (const Vec< N, double > &v)
 
SINT bool isfinite (const Vec< N, T > &v)
 
SIT void strided_load4 (const T *v, Vec< 1, T > &a, Vec< 1, T > &b, Vec< 1, T > &c, Vec< 1, T > &d)
 
SINT void strided_load4 (const T *v, Vec< N, T > &a, Vec< N, T > &b, Vec< N, T > &c, Vec< N, T > &d)
 
SI void strided_load4 (const float *v, Vec< 4, float > &a, Vec< 4, float > &b, Vec< 4, float > &c, Vec< 4, float > &d)
 
SIT void strided_load2 (const T *v, Vec< 1, T > &a, Vec< 1, T > &b)
 
SINT void strided_load2 (const T *v, Vec< N, T > &a, Vec< N, T > &b)
 
 DEF_TEST (SkVx, r)
 
 DEF_TEST (SkVx_xy, r)
 
 DEF_TEST (SkVx_xyzw, r)
 
 DEF_TEST (SkVx_cross_dot, r)
 
template<int N, typename T >
void check_strided_loads (skiatest::Reporter *r)
 
template<typename T >
void check_strided_loads (skiatest::Reporter *r)
 
 DEF_TEST (SkVx_strided_loads, r)
 
 DEF_TEST (SkVx_ScaledDividerU32, r)
 
 DEF_TEST (SkVx_saturated_add, r)
 
 DEF_TEST (SkVx_length, r)
 
 DEF_TEST (SkVx_normalize, r)
 
 DEF_TEST (SkVx_normalize_infinity_and_nan, r)
 
 DEF_TEST (SkVx_isfinite, r)
 

Typedef Documentation

◆ byte16

using skvx::byte16 = typedef Vec<16, uint8_t>

Definition at line 1156 of file SkVx.h.

◆ byte2

using skvx::byte2 = typedef Vec< 2, uint8_t>

Definition at line 1153 of file SkVx.h.

◆ byte4

using skvx::byte4 = typedef Vec< 4, uint8_t>

Definition at line 1154 of file SkVx.h.

◆ byte8

using skvx::byte8 = typedef Vec< 8, uint8_t>

Definition at line 1155 of file SkVx.h.

◆ double2

using skvx::double2 = typedef Vec< 2, double>

Definition at line 1149 of file SkVx.h.

◆ double4

using skvx::double4 = typedef Vec< 4, double>

Definition at line 1150 of file SkVx.h.

◆ double8

using skvx::double8 = typedef Vec< 8, double>

Definition at line 1151 of file SkVx.h.

◆ float2

using skvx::float2 = typedef Vec< 2, float>

Definition at line 1145 of file SkVx.h.

◆ float4

using skvx::float4 = typedef Vec< 4, float>

Definition at line 1146 of file SkVx.h.

◆ float8

using skvx::float8 = typedef Vec< 8, float>

Definition at line 1147 of file SkVx.h.

◆ half2

using skvx::half2 = typedef Vec< 2, uint16_t>

Definition at line 1175 of file SkVx.h.

◆ half4

using skvx::half4 = typedef Vec< 4, uint16_t>

Definition at line 1176 of file SkVx.h.

◆ half8

using skvx::half8 = typedef Vec< 8, uint16_t>

Definition at line 1177 of file SkVx.h.

◆ int2

using skvx::int2 = typedef Vec< 2, int32_t>

Definition at line 1158 of file SkVx.h.

◆ int4

using skvx::int4 = typedef Vec< 4, int32_t>

Definition at line 1159 of file SkVx.h.

◆ int8

using skvx::int8 = typedef Vec< 8, int32_t>

Definition at line 1160 of file SkVx.h.

◆ long2

using skvx::long2 = typedef Vec< 2, int64_t>

Definition at line 1170 of file SkVx.h.

◆ long4

using skvx::long4 = typedef Vec< 4, int64_t>

Definition at line 1171 of file SkVx.h.

◆ long8

using skvx::long8 = typedef Vec< 8, int64_t>

Definition at line 1172 of file SkVx.h.

◆ M

template<typename T >
using skvx::M = typedef typename Mask<T>::type

Definition at line 239 of file SkVx.h.

◆ uint2

using skvx::uint2 = typedef Vec< 2, uint32_t>

Definition at line 1166 of file SkVx.h.

◆ uint4

using skvx::uint4 = typedef Vec< 4, uint32_t>

Definition at line 1167 of file SkVx.h.

◆ uint8

using skvx::uint8 = typedef Vec< 8, uint32_t>

Definition at line 1168 of file SkVx.h.

◆ ushort2

using skvx::ushort2 = typedef Vec< 2, uint16_t>

Definition at line 1162 of file SkVx.h.

◆ ushort4

using skvx::ushort4 = typedef Vec< 4, uint16_t>

Definition at line 1163 of file SkVx.h.

◆ ushort8

using skvx::ushort8 = typedef Vec< 8, uint16_t>

Definition at line 1164 of file SkVx.h.

Function Documentation

◆ abs()

SIN Vec< N, float > skvx::abs ( const Vec< N, float > &  x)

Definition at line 707 of file SkVx.h.

707{ return map( fabsf, x); }
double x
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
Definition SkVx.h:680

◆ all() [1/2]

SIT bool skvx::all ( const Vec< 1, T > &  x)

Definition at line 582 of file SkVx.h.

582{ return x.val != 0; }

◆ all() [2/2]

SINT bool skvx::all ( const Vec< N, T > &  x)

Definition at line 583 of file SkVx.h.

583 {
584// Unlike any(), we have to respect the lane layout, or we'll miss cases where a
585// true lane has a mix of 0 and 1 bits.
586#if SKVX_USE_SIMD && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
587 // Unfortunately, the _mm_testc intrinsics don't let us avoid the comparison to 0 for all()'s
588 // correctness, so always just use the plain SSE version.
589 if constexpr (N == 4 && sizeof(T) == 4) {
590 return _mm_movemask_ps(_mm_cmpneq_ps(sk_bit_cast<__m128>(x), _mm_set1_ps(0))) == 0b1111;
591 }
592#endif
593#if SKVX_USE_SIMD && defined(__aarch64__)
594 // On 64-bit NEON, take the min across the lanes, which will be non-zero if all lanes are != 0.
595 if constexpr (sizeof(T)==1 && N==8) {return vminv_u8 (sk_bit_cast<uint8x8_t> (x)) > 0;}
596 if constexpr (sizeof(T)==1 && N==16) {return vminvq_u8 (sk_bit_cast<uint8x16_t>(x)) > 0;}
597 if constexpr (sizeof(T)==2 && N==4) {return vminv_u16 (sk_bit_cast<uint16x4_t>(x)) > 0;}
598 if constexpr (sizeof(T)==2 && N==8) {return vminvq_u16(sk_bit_cast<uint16x8_t>(x)) > 0;}
599 if constexpr (sizeof(T)==4 && N==2) {return vminv_u32 (sk_bit_cast<uint32x2_t>(x)) > 0;}
600 if constexpr (sizeof(T)==4 && N==4) {return vminvq_u32(sk_bit_cast<uint32x4_t>(x)) > 0;}
601#endif
602#if SKVX_USE_SIMD && defined(__wasm_simd128__)
603 if constexpr (N == 4 && sizeof(T) == 4) {
604 return wasm_i32x4_all_true(sk_bit_cast<VExt<4,int>>(x));
605 }
606#endif
607#if SKVX_USE_SIMD && SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LASX
608 if constexpr (N == 8 && sizeof(T) == 4) {
609 v8i32 retv = (v8i32)__lasx_xvmskltz_w(__lasx_xvslt_wu(__lasx_xvldi(0),
610 sk_bit_cast<__m256i>(x)));
611 return (retv[0] & retv[4]) == 0b1111;
612 }
613#endif
614#if SKVX_USE_SIMD && SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LSX
615 if constexpr (N == 4 && sizeof(T) == 4) {
616 v4i32 retv = (v4i32)__lsx_vmskltz_w(__lsx_vslt_wu(__lsx_vldi(0),
617 sk_bit_cast<__m128i>(x)));
618 return retv[0] == 0b1111;
619 }
620#endif
621 return all(x.lo)
622 && all(x.hi);
623}
static SK_ALWAYS_INLINE Dst SK_FP_SAFE_ABI sk_bit_cast(const Src &src)
Definition SkUtils.h:68
#define N
Definition beziers.cpp:19
SIT bool all(const Vec< 1, T > &x)
Definition SkVx.h:582
#define T

◆ any() [1/2]

SIT bool skvx::any ( const Vec< 1, T > &  x)

Definition at line 530 of file SkVx.h.

530{ return x.val != 0; }

◆ any() [2/2]

SINT bool skvx::any ( const Vec< N, T > &  x)

Definition at line 531 of file SkVx.h.

531 {
532 // For any(), the _mm_testz intrinsics are correct and don't require comparing 'x' to 0, so it's
533 // lower latency compared to _mm_movemask + _mm_compneq on plain SSE.
534#if SKVX_USE_SIMD && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2
535 if constexpr (N*sizeof(T) == 32) {
536 return !_mm256_testz_si256(sk_bit_cast<__m256i>(x), _mm256_set1_epi32(-1));
537 }
538#endif
539#if SKVX_USE_SIMD && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE41
540 if constexpr (N*sizeof(T) == 16) {
541 return !_mm_testz_si128(sk_bit_cast<__m128i>(x), _mm_set1_epi32(-1));
542 }
543#endif
544#if SKVX_USE_SIMD && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
545 if constexpr (N*sizeof(T) == 16) {
546 // On SSE, movemask checks only the MSB in each lane, which is fine if the lanes were set
547 // directly from a comparison op (which sets all bits to 1 when true), but skvx::Vec<>
548 // treats any non-zero value as true, so we have to compare 'x' to 0 before calling movemask
549 return _mm_movemask_ps(_mm_cmpneq_ps(sk_bit_cast<__m128>(x), _mm_set1_ps(0))) != 0b0000;
550 }
551#endif
552#if SKVX_USE_SIMD && defined(__aarch64__)
553 // On 64-bit NEON, take the max across lanes, which will be non-zero if any lane was true.
554 // The specific lane-size doesn't really matter in this case since it's really any set bit
555 // that we're looking for.
556 if constexpr (N*sizeof(T) == 8 ) { return vmaxv_u8 (sk_bit_cast<uint8x8_t> (x)) > 0; }
557 if constexpr (N*sizeof(T) == 16) { return vmaxvq_u8(sk_bit_cast<uint8x16_t>(x)) > 0; }
558#endif
559#if SKVX_USE_SIMD && defined(__wasm_simd128__)
560 if constexpr (N == 4 && sizeof(T) == 4) {
561 return wasm_i32x4_any_true(sk_bit_cast<VExt<4,int>>(x));
562 }
563#endif
564#if SKVX_USE_SIMD && SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LASX
565 if constexpr (N*sizeof(T) == 32) {
566 v8i32 retv = (v8i32)__lasx_xvmskltz_w(__lasx_xvslt_wu(__lasx_xvldi(0),
567 sk_bit_cast<__m256i>(x)));
568 return (retv[0] | retv[4]) != 0b0000;
569 }
570#endif
571#if SKVX_USE_SIMD && SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LSX
572 if constexpr (N*sizeof(T) == 16) {
573 v4i32 retv = (v4i32)__lsx_vmskltz_w(__lsx_vslt_wu(__lsx_vldi(0),
574 sk_bit_cast<__m128i>(x)));
575 return retv[0] != 0b0000;
576 }
577#endif
578 return any(x.lo)
579 || any(x.hi);
580}
SIT bool any(const Vec< 1, T > &x)
Definition SkVx.h:530

◆ approx_scale()

SIN Vec< N, uint8_t > skvx::approx_scale ( const Vec< N, uint8_t > &  x,
const Vec< N, uint8_t > &  y 
)

Definition at line 824 of file SkVx.h.

824 {
825 // All of (x*y+x)/256, (x*y+y)/256, and (x*y+255)/256 meet the criteria above.
826 // We happen to have historically picked (x*y+x)/256.
827 auto X = cast<uint16_t>(x),
828 Y = cast<uint16_t>(y);
829 return cast<uint8_t>( (X*Y+X)/256 );
830}
static const SkScalar Y
static const SkScalar X
double y

◆ cast() [1/2]

template<typename D , typename S >
SI Vec< 1, D > skvx::cast ( const Vec< 1, S > &  src)

Definition at line 628 of file SkVx.h.

628{ return (D)src.val; }

◆ cast() [2/2]

template<typename D , int N, typename S >
SI Vec< N, D > skvx::cast ( const Vec< N, S > &  src)

Definition at line 631 of file SkVx.h.

631 {
632#if SKVX_USE_SIMD && defined(__clang__)
633 return to_vec(__builtin_convertvector(to_vext(src), VExt<N,D>));
634#else
635 return join(cast<D>(src.lo), cast<D>(src.hi));
636#endif
637}
SINT Vec< 2 *N, T > join(const Vec< N, T > &lo, const Vec< N, T > &hi)
Definition SkVx.h:242

◆ ceil()

SIN Vec< N, float > skvx::ceil ( const Vec< N, float > &  x)

Definition at line 702 of file SkVx.h.

702{ return map( ceilf, x); }

◆ check_strided_loads() [1/2]

template<int N, typename T >
void skvx::check_strided_loads ( skiatest::Reporter r)

Definition at line 278 of file SkVxTest.cpp.

278 {
279 using Vec = Vec<N,T>;
280 T values[N*4];
281 std::iota(values, values + N*4, 0);
282 Vec a, b, c, d;
283 strided_load2(values, a, b);
284 for (int i = 0; i < N; ++i) {
285 REPORTER_ASSERT(r, a[i] == values[i*2]);
286 REPORTER_ASSERT(r, b[i] == values[i*2 + 1]);
287 }
288 strided_load4(values, a, b, c, d);
289 for (int i = 0; i < N; ++i) {
290 REPORTER_ASSERT(r, a[i] == values[i*4]);
291 REPORTER_ASSERT(r, b[i] == values[i*4 + 1]);
292 REPORTER_ASSERT(r, c[i] == values[i*4 + 2]);
293 REPORTER_ASSERT(r, d[i] == values[i*4 + 3]);
294 }
295}
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
static bool b
struct MyStruct a[10]
SIT void strided_load2(const T *v, Vec< 1, T > &a, Vec< 1, T > &b)
Definition SkVx.h:1112

◆ check_strided_loads() [2/2]

template<typename T >
void skvx::check_strided_loads ( skiatest::Reporter r)

Definition at line 297 of file SkVxTest.cpp.

297 {
298 check_strided_loads<1,T>(r);
299 check_strided_loads<2,T>(r);
300 check_strided_loads<4,T>(r);
301 check_strided_loads<8,T>(r);
302 check_strided_loads<16,T>(r);
303 check_strided_loads<32,T>(r);
304}

◆ cross()

SIT T skvx::cross ( const Vec< 2, T > &  a,
const Vec< 2, T > &  b 
)

Definition at line 982 of file SkVx.h.

982 {
983 auto x = a * shuffle<1,0>(b);
984 return x[0] - x[1];
985}

◆ DEF_TEST() [1/11]

skvx::DEF_TEST ( SkVx  ,
 
)

Definition at line 18 of file SkVxTest.cpp.

18 {
19 static_assert(sizeof(float2) == 8, "");
20 static_assert(sizeof(float4) == 16, "");
21 static_assert(sizeof(float8) == 32, "");
22
23 static_assert(sizeof(byte2) == 2, "");
24 static_assert(sizeof(byte4) == 4, "");
25 static_assert(sizeof(byte8) == 8, "");
26
27 {
28 int4 mask = float4{1,2,3,4} < float4{1,2,4,8};
29 REPORTER_ASSERT(r, mask[0] == int32_t( 0));
30 REPORTER_ASSERT(r, mask[1] == int32_t( 0));
31 REPORTER_ASSERT(r, mask[2] == int32_t(-1));
32 REPORTER_ASSERT(r, mask[3] == int32_t(-1));
33
34 REPORTER_ASSERT(r, any(mask));
35 REPORTER_ASSERT(r, !all(mask));
36 }
37
38 {
39 long4 mask = double4{1,2,3,4} < double4{1,2,4,8};
40 REPORTER_ASSERT(r, mask[0] == int64_t( 0));
41 REPORTER_ASSERT(r, mask[1] == int64_t( 0));
42 REPORTER_ASSERT(r, mask[2] == int64_t(-1));
43 REPORTER_ASSERT(r, mask[3] == int64_t(-1));
44
45 REPORTER_ASSERT(r, any(mask));
46 REPORTER_ASSERT(r, !all(mask));
47 }
48
49 {
50 // Tests that any/all work with non-zero values, not just full bit lanes.
51 REPORTER_ASSERT(r, all(int4{1,2,3,4}));
52 REPORTER_ASSERT(r, !all(int4{1,2,3}));
53 REPORTER_ASSERT(r, any(int4{1,2}));
54 REPORTER_ASSERT(r, !any(int4{}));
55 }
56
57 REPORTER_ASSERT(r, min(float4{1,2,3,4}) == 1);
58 REPORTER_ASSERT(r, max(float4{1,2,3,4}) == 4);
59
60 REPORTER_ASSERT(r, all(int4{1,2,3,4} == int4{1,2,3,4}));
61 REPORTER_ASSERT(r, all(int4{1,2,3} == int4{1,2,3,0}));
62 REPORTER_ASSERT(r, all(int4{1,2} == int4{1,2,0,0}));
63 REPORTER_ASSERT(r, all(int4{1} == int4{1,0,0,0}));
64 REPORTER_ASSERT(r, all(int4(1) == int4{1,1,1,1}));
65 REPORTER_ASSERT(r, all(int4{} == int4{0,0,0,0}));
66 REPORTER_ASSERT(r, all(int4() == int4{0,0,0,0}));
67
68 REPORTER_ASSERT(r, all(int4{1,2,2,1} == min(int4{1,2,3,4}, int4{4,3,2,1})));
69 REPORTER_ASSERT(r, all(int4{4,3,3,4} == max(int4{1,2,3,4}, int4{4,3,2,1})));
70
71 REPORTER_ASSERT(r, all(if_then_else(float4{1,2,3,2} <= float4{2,2,2,2}, float4(42), float4(47))
72 == float4{42,42,47,42}));
73
74 REPORTER_ASSERT(r, all(floor(float4{-1.5f,1.5f,1.0f,-1.0f}) == float4{-2.0f,1.0f,1.0f,-1.0f}));
75 REPORTER_ASSERT(r, all( ceil(float4{-1.5f,1.5f,1.0f,-1.0f}) == float4{-1.0f,2.0f,1.0f,-1.0f}));
76 REPORTER_ASSERT(r, all(trunc(float4{-1.5f,1.5f,1.0f,-1.0f}) == float4{-1.0f,1.0f,1.0f,-1.0f}));
77 REPORTER_ASSERT(r, all(round(float4{-1.5f,1.5f,1.0f,-1.0f}) == float4{-2.0f,2.0f,1.0f,-1.0f}));
78
79
80 REPORTER_ASSERT(r, all(abs(float4{-2,-1,0,1}) == float4{2,1,0,1}));
81
82 // TODO(mtklein): these tests could be made less loose.
83 REPORTER_ASSERT(r, all( sqrt(float4{2,3,4,5}) < float4{2,2,3,3}));
84 REPORTER_ASSERT(r, all( sqrt(float2{2,3}) < float2{2,2}));
85
86 REPORTER_ASSERT(r, all(cast<int>(float4{-1.5f,0.5f,1.0f,1.5f}) == int4{-1,0,1,1}));
87
88 float buf[] = {1,2,3,4,5,6};
89 REPORTER_ASSERT(r, all(float4::Load(buf) == float4{1,2,3,4}));
90 float4{2,3,4,5}.store(buf);
91 REPORTER_ASSERT(r, buf[0] == 2
92 && buf[1] == 3
93 && buf[2] == 4
94 && buf[3] == 5
95 && buf[4] == 5
96 && buf[5] == 6);
97 REPORTER_ASSERT(r, all(float4::Load(buf+0) == float4{2,3,4,5}));
98 REPORTER_ASSERT(r, all(float4::Load(buf+2) == float4{4,5,5,6}));
99
100 REPORTER_ASSERT(r, all(shuffle<2,1,0,3> (float4{1,2,3,4}) == float4{3,2,1,4}));
101 REPORTER_ASSERT(r, all(shuffle<2,1> (float4{1,2,3,4}) == float2{3,2}));
102 REPORTER_ASSERT(r, all(shuffle<3,3,3,3> (float4{1,2,3,4}) == float4{4,4,4,4}));
103 REPORTER_ASSERT(r, all(shuffle<2,1,2,1,2,1,2,1>(float4{1,2,3,4})
104 == float8{3,2,3,2,3,2,3,2}));
105
106 // Test that mixed types can be used where they make sense. Mostly about ergonomics.
107 REPORTER_ASSERT(r, all(float4{1,2,3,4} < 5));
108 REPORTER_ASSERT(r, all( byte4{1,2,3,4} < 5));
109 REPORTER_ASSERT(r, all( int4{1,2,3,4} < 5.0f));
110 float4 five = 5;
111 REPORTER_ASSERT(r, all(five == 5.0f));
112 REPORTER_ASSERT(r, all(five == 5));
113
114 REPORTER_ASSERT(r, all(max(2, min(float4{1,2,3,4}, 3)) == float4{2,2,3,3}));
115
116 for (int x = 0; x < 256; x++)
117 for (int y = 0; y < 256; y++) {
118 uint8_t want = (uint8_t)( 255*(x/255.0 * y/255.0) + 0.5 );
119
120 {
121 uint8_t got = div255(Vec<8, uint16_t>(x) * Vec<8, uint16_t>(y) )[0];
122 REPORTER_ASSERT(r, got == want);
123 }
124
125 {
126 uint8_t got = approx_scale(Vec<8,uint8_t>(x), Vec<8,uint8_t>(y))[0];
127
128 REPORTER_ASSERT(r, got == want-1 ||
129 got == want ||
130 got == want+1);
131 if (x == 0 || y == 0 || x == 255 || y == 255) {
132 REPORTER_ASSERT(r, got == want);
133 }
134 }
135 }
136
137 for (int x = 0; x < 256; x++)
138 for (int y = 0; y < 256; y++) {
139 uint16_t xy = x*y;
140
141 // Make sure to cover implementation cases N=8, N<8, and N>8.
142 REPORTER_ASSERT(r, all(mull(byte2 (x), byte2 (y)) == xy));
143 REPORTER_ASSERT(r, all(mull(byte4 (x), byte4 (y)) == xy));
144 REPORTER_ASSERT(r, all(mull(byte8 (x), byte8 (y)) == xy));
145 REPORTER_ASSERT(r, all(mull(byte16(x), byte16(y)) == xy));
146 }
147
148 {
149 // Intentionally not testing -0, as we don't care if it's 0x0000 or 0x8000.
150 float8 fs = {+0.0f,+0.5f,+1.0f,+2.0f,
151 -4.0f,-0.5f,-1.0f,-2.0f};
152 Vec<8,uint16_t> hs = {0x0000,0x3800,0x3c00,0x4000,
153 0xc400,0xb800,0xbc00,0xc000};
154 REPORTER_ASSERT(r, all( to_half(fs) == hs));
155 REPORTER_ASSERT(r, all(from_half(hs) == fs));
156 }
157}
skvx::float4 float4
static void round(SkPoint *p)
static uint8_t div255(unsigned prod)
skvx::float2 float2
SI T if_then_else(C cond, T t, T e)
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48
SIN Vec< N, float > trunc(const Vec< N, float > &x)
Definition SkVx.h:704
Vec< 8, float > float8
Definition SkVx.h:1147
Vec< 16, uint8_t > byte16
Definition SkVx.h:1156
SIN Vec< N, float > abs(const Vec< N, float > &x)
Definition SkVx.h:707
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition SkVx.h:706
SIN Vec< N, uint16_t > mull(const Vec< N, uint8_t > &x, const Vec< N, uint8_t > &y)
Definition SkVx.h:906
Vec< 4, int32_t > int4
Definition SkVx.h:1159
SIN Vec< N, float > from_half(const Vec< N, uint16_t > &x)
Definition SkVx.h:790
SIN Vec< N, uint16_t > to_half(const Vec< N, float > &x)
Definition SkVx.h:750
Vec< 4, int64_t > long4
Definition SkVx.h:1171
Vec< 4, double > double4
Definition SkVx.h:1150
SIN Vec< N, float > floor(const Vec< N, float > &x)
Definition SkVx.h:703
SIN Vec< N, float > ceil(const Vec< N, float > &x)
Definition SkVx.h:702
SIN Vec< N, uint8_t > approx_scale(const Vec< N, uint8_t > &x, const Vec< N, uint8_t > &y)
Definition SkVx.h:824
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition SkVx.h:109
SKVX_ALWAYS_INLINE void store(void *ptr) const
Definition SkVx.h:112

◆ DEF_TEST() [2/11]

skvx::DEF_TEST ( SkVx_cross_dot  ,
 
)

Definition at line 246 of file SkVxTest.cpp.

246 {
247 REPORTER_ASSERT(r, cross(int2{0,1}, int2{0,1}) == 0);
248 REPORTER_ASSERT(r, cross(int2{1,0}, int2{1,0}) == 0);
249 REPORTER_ASSERT(r, cross(int2{1,1}, int2{1,1}) == 0);
250 REPORTER_ASSERT(r, cross(int2{1,1}, int2{1,-1}) == -2);
251 REPORTER_ASSERT(r, cross(int2{1,1}, int2{-1,1}) == 2);
252
253 REPORTER_ASSERT(r, dot(int2{0,1}, int2{1,0}) == 0);
254 REPORTER_ASSERT(r, dot(int2{1,0}, int2{0,1}) == 0);
255 REPORTER_ASSERT(r, dot(int2{1,1}, int2{1,-1}) == 0);
256 REPORTER_ASSERT(r, dot(int2{1,1}, int2{1,1}) == 2);
257 REPORTER_ASSERT(r, dot(int2{1,1}, int2{-1,-1}) == -2);
258
259 SkRandom rand;
260 for (int i = 0; i < 100; ++i) {
261 float a=rand.nextRangeF(-1,1), b=rand.nextRangeF(-1,1), c=rand.nextRangeF(-1,1),
262 d=rand.nextRangeF(-1,1);
263 constexpr static float kTolerance = 1.f / (1 << 20);
267 dot(float2{a,b}, float2{c,d}), SkPoint::DotProduct({a,b}, {c,d}), kTolerance));
268 }
269
270 auto assertDoublesEqual = [&](double left, double right) {
272 };
273 assertDoublesEqual(cross(double2{1.2, 3.4}, double2{3.4, -1.2}), -13.000000);
274 assertDoublesEqual(cross(double2{12.34, 5.6}, double2{7.8, -9.0}), -154.740000);
275 assertDoublesEqual(cross(double2{12.34, 5.6}, double2{7.8, 9.012345678}), 67.532346);
276}
static constexpr float kTolerance
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:107
float nextRangeF(float min, float max)
Definition SkRandom.h:64
int64_t cross(Point d0, Point d1)
Definition Myers.cpp:55
SINT T dot(const Vec< N, T > &a, const Vec< N, T > &b)
Definition SkVx.h:964
Vec< 2, int32_t > int2
Definition SkVx.h:1158
Vec< 2, double > double2
Definition SkVx.h:1149
static float CrossProduct(const SkVector &a, const SkVector &b)
static float DotProduct(const SkVector &a, const SkVector &b)

◆ DEF_TEST() [3/11]

skvx::DEF_TEST ( SkVx_isfinite  ,
 
)

Definition at line 425 of file SkVxTest.cpp.

425 {
427 REPORTER_ASSERT(r, isfinite(skvx::double4{1.2, 3.4, 5.6, 7.8}));
428 REPORTER_ASSERT(r, isfinite(skvx::float8{8, 7, 6, 5, 4, 3, 2, 1}));
429
431 REPORTER_ASSERT(r, !isfinite(skvx::float2{INFINITY, 10}));
432 REPORTER_ASSERT(r, !isfinite(skvx::float2{NAN, INFINITY}));
433
434 for (int i = 0; i < 4; i++) {
435 auto v = skvx::double4{4, 3, 2, 1};
436 v[i] = INFINITY;
437 REPORTER_ASSERT(r, !isfinite(v), "index %d INFINITY", i);
438 v[i] = NAN;
439 REPORTER_ASSERT(r, !isfinite(v), "index %d NAN", i);
440 }
441
442 for (int i = 0; i < 8; i++) {
443 auto v = skvx::float8{8, 7, 6, 5, 4, 3, 2, 1};
444 v[i] = INFINITY;
445 REPORTER_ASSERT(r, !isfinite(v), "index %d INFINITY", i);
446 v[i] = NAN;
447 REPORTER_ASSERT(r, !isfinite(v), "index %d NAN", i);
448 }
449}
SINT bool isfinite(const Vec< N, T > &v)
Definition SkVx.h:1003

◆ DEF_TEST() [4/11]

skvx::DEF_TEST ( SkVx_length  ,
 
)

Definition at line 366 of file SkVxTest.cpp.

366 {
367 auto assertFloatsEqual = [&](float left, float right) {
369 };
370 auto assertDoublesEqual = [&](double left, double right) {
372 };
373
374 assertFloatsEqual(length(float2{0, 1}), 1.000000f);
375 assertFloatsEqual(length(float2{2, 0}), 2.000000f);
376 assertFloatsEqual(length(float2{3, 4}), 5.000000f);
377 assertFloatsEqual(length(float2{1, 1}), 1.414214f);
378 assertFloatsEqual(length(float2{2.5f, 2.5f}), 3.535534f);
379 assertFloatsEqual(length(float4{1, 2, 3, 4}), 5.477226f);
380
381 assertDoublesEqual(length(double2{2.5, 2.5}), 3.535534);
382 assertDoublesEqual(length(double4{1.5, 2.5, 3.5, 4.5}), 6.403124);
383}
size_t length

◆ DEF_TEST() [5/11]

skvx::DEF_TEST ( SkVx_normalize  ,
 
)

Definition at line 385 of file SkVxTest.cpp.

385 {
386 auto assertFloatsEqual = [&](float left, float right) {
388 };
389 auto assertDoublesEqual = [&](double left, double right) {
391 };
392
393 skvx::float2 twoFloats = normalize(skvx::float2{1.2f, 3.4f});
394 assertFloatsEqual(twoFloats[0], 0.332820f);
395 assertFloatsEqual(twoFloats[1], 0.942990f);
396
397 skvx::double2 twoDoubles = normalize(skvx::double2{2.3, -4.5});
398 assertDoublesEqual(twoDoubles[0], 0.455111);
399 assertDoublesEqual(twoDoubles[1], -0.890435);
400
401 skvx::double4 fourDoubles = normalize(skvx::double4{1.2, 3.4, 5.6, 7.8});
402 assertDoublesEqual(fourDoubles[0], 0.116997);
403 assertDoublesEqual(fourDoubles[1], 0.331490);
404 assertDoublesEqual(fourDoubles[2], 0.545984);
405 assertDoublesEqual(fourDoubles[3], 0.760478);
406}
static void normalize(int n, double *gauss)

◆ DEF_TEST() [6/11]

skvx::DEF_TEST ( SkVx_normalize_infinity_and_nan  ,
 
)

Definition at line 408 of file SkVxTest.cpp.

408 {
409 skvx::float2 zeroLenVec = normalize(skvx::float2{0, 0});
410 REPORTER_ASSERT(r, std::isnan(zeroLenVec[0]), "%f is not nan", zeroLenVec[0]);
411 REPORTER_ASSERT(r, std::isnan(zeroLenVec[1]), "%f is not nan", zeroLenVec[1]);
412 REPORTER_ASSERT(r, !isfinite(zeroLenVec));
413
414 skvx::float2 tooBigVec = normalize(skvx::float2{std::numeric_limits<float>::max(),
415 std::numeric_limits<float>::max()});
416 REPORTER_ASSERT(r, tooBigVec[0] == 0, "%f != 0", tooBigVec[0]);
417 REPORTER_ASSERT(r, tooBigVec[1] == 0, "%f != 0", tooBigVec[1]);
418
419 skvx::double2 tooBigVecD = normalize(skvx::double2{std::numeric_limits<double>::max(),
420 std::numeric_limits<double>::max()});
421 REPORTER_ASSERT(r, tooBigVecD[0] == 0, "%f != 0", tooBigVecD[0]);
422 REPORTER_ASSERT(r, tooBigVecD[1] == 0, "%f != 0", tooBigVecD[1]);
423}

◆ DEF_TEST() [7/11]

skvx::DEF_TEST ( SkVx_saturated_add  ,
 
)

Definition at line 354 of file SkVxTest.cpp.

354 {
355 for (int a = 0; a < (1<<8); a++) {
356 for (int b = 0; b < (1<<8); b++) {
357 int exact = a+b;
358 if (exact > 255) { exact = 255; }
359 if (exact < 0) { exact = 0; }
360
362 }
363 }
364}
SINT std::enable_if_t< std::is_unsigned_v< T >, Vec< N, T > > saturated_add(const Vec< N, T > &x, const Vec< N, T > &y)
Definition SkVx.h:833

◆ DEF_TEST() [8/11]

skvx::DEF_TEST ( SkVx_ScaledDividerU32  ,
 
)

Definition at line 316 of file SkVxTest.cpp.

316 {
317 static constexpr uint32_t kMax = std::numeric_limits<uint32_t>::max();
318
319 auto errorBounds = [&](uint32_t actual, uint32_t expected) {
320 uint32_t lowerLimit = expected == 0 ? 0 : expected - 1,
321 upperLimit = expected == kMax ? kMax : expected + 1;
322 return lowerLimit <= actual && actual <= upperLimit;
323 };
324
325 auto test = [&](uint32_t denom) {
326 // half == 1 so, the max to check is kMax-1
327 ScaledDividerU32 d(denom);
328 uint32_t maxCheck = static_cast<uint32_t>(
329 std::floor((double)(kMax - d.half()) / denom + 0.5));
330 REPORTER_ASSERT(r, errorBounds(d.divide((kMax))[0], maxCheck));
331 for (uint32_t i = 0; i < kMax - d.half(); i += 65535) {
332 uint32_t expected = static_cast<uint32_t>(std::floor((double)i / denom + 0.5));
333 auto actual = d.divide(i + d.half());
334 if (!errorBounds(actual[0], expected)) {
335 SkDebugf("i: %u expected: %u actual: %u\n", i, expected, actual[0]);
336 }
337 // Make sure all the lanes are the same.
338 for (int e = 1; e < 4; e++) {
339 SkASSERT(actual[0] == actual[e]);
340 }
341 }
342 };
343
344 test(2);
345 test(3);
346 test(5);
347 test(7);
348 test(27);
349 test(65'535);
350 test(15'485'863);
351 test(512'927'377);
352}
#define test(name)
#define SkASSERT(cond)
Definition SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1

◆ DEF_TEST() [9/11]

skvx::DEF_TEST ( SkVx_strided_loads  ,
 
)

Definition at line 306 of file SkVxTest.cpp.

306 {
307 check_strided_loads<uint32_t>(r);
308 check_strided_loads<uint16_t>(r);
309 check_strided_loads<uint8_t>(r);
310 check_strided_loads<int32_t>(r);
311 check_strided_loads<int16_t>(r);
312 check_strided_loads<int8_t>(r);
313 check_strided_loads<float>(r);
314}

◆ DEF_TEST() [10/11]

skvx::DEF_TEST ( SkVx_xy  ,
 
)

Definition at line 159 of file SkVxTest.cpp.

159 {
160 float2 f = float2(1,2);
161 REPORTER_ASSERT(r, all(f == float2{1,2}));
162 REPORTER_ASSERT(r, f.x() == 1);
163 REPORTER_ASSERT(r, f.y() == 2);
164 f.y() = 9;
165 REPORTER_ASSERT(r, all(f == float2{1,9}));
166 f.x() = 0;
167 REPORTER_ASSERT(r, all(f == float2(0,9)));
168 f[0] = 8;
169 REPORTER_ASSERT(r, f.x() == 8);
170 f[1] = 6;
171 REPORTER_ASSERT(r, f.y() == 6);
172 REPORTER_ASSERT(r, all(f == float2(8,6)));
173 f = f.yx();
174 REPORTER_ASSERT(r, all(f == float2(6,8)));
175 REPORTER_ASSERT(r, sk_bit_cast<SkPoint>(f) == SkPoint::Make(6,8));
176 SkPoint p;
177 f.store(&p);
178 REPORTER_ASSERT(r, p == SkPoint::Make(6,8));
179 f.yx().store(&p);
180 REPORTER_ASSERT(r, p == SkPoint::Make(8,6));
181 REPORTER_ASSERT(r, all(f.xyxy() == float4(6,8,6,8)));
182 REPORTER_ASSERT(r, all(f.xyxy() == float4(f,f)));
183 REPORTER_ASSERT(r, all(join(f,f) == f.xyxy()));
184 REPORTER_ASSERT(r, all(join(f.yx(),f) == float4(f.y(),f.x(),f)));
185 REPORTER_ASSERT(r, all(join(f.yx(),f) == float4(f.yx(),f.x(),f.y())));
186 REPORTER_ASSERT(r, all(join(f,f.yx()) == float4(f.x(),f.y(),f.yx())));
187 REPORTER_ASSERT(r, all(join(f.yx(),f.yx()) == float4(f.yx(),f.yx())));
188}
static constexpr SkPoint Make(float x, float y)

◆ DEF_TEST() [11/11]

skvx::DEF_TEST ( SkVx_xyzw  ,
 
)

Definition at line 190 of file SkVxTest.cpp.

190 {
191 float4 f = float4{1,2,3,4};
192 REPORTER_ASSERT(r, all(f == float4(1,2,3,4)));
193 REPORTER_ASSERT(r, all(f == float4(1,2,float2(3,4))));
194 REPORTER_ASSERT(r, all(f == float4(float2(1,2),3,4)));
195 REPORTER_ASSERT(r, all(f == float4(float2(1,2),float2(3,4))));
196 f.xy() = float2(9,8);
197 REPORTER_ASSERT(r, all(f == float4(9,8,3,4)));
198 f.zw().x() = 7;
199 f.zw().y() = 6;
200 REPORTER_ASSERT(r, all(f == float4(9,8,7,6)));
201 f.x() = 5;
202 f.y() = 4;
203 f.z() = 3;
204 f.w() = 2;
205 REPORTER_ASSERT(r, all(f == float4(5,4,3,2)));
206 f[0] = 0;
207 REPORTER_ASSERT(r, f.x() == 0);
208 f[1] = 1;
209 REPORTER_ASSERT(r, f.y() == 1);
210 f[2] = 2;
211 REPORTER_ASSERT(r, f.z() == 2);
212 f[3] = 3;
213 REPORTER_ASSERT(r, f.w() == 3);
214 REPORTER_ASSERT(r, all(f.xy() == float2(0,1)));
215 REPORTER_ASSERT(r, all(f.zw() == float2{2,3}));
216 REPORTER_ASSERT(r, all(f == float4(0,1,2,3)));
217 REPORTER_ASSERT(r, all(f.yxwz().lo == shuffle<1,0>(f)));
218 REPORTER_ASSERT(r, all(f.yxwz().hi == shuffle<3,2>(f)));
219 REPORTER_ASSERT(r, all(f.zwxy().lo.lo == f.z()));
220 REPORTER_ASSERT(r, all(f.zwxy().lo.hi == f.w()));
221 REPORTER_ASSERT(r, all(f.zwxy().hi.lo == f.x()));
222 REPORTER_ASSERT(r, all(f.zwxy().hi.hi == f.y()));
223 REPORTER_ASSERT(r, f.yxwz().lo.lo.val == f.y());
224 REPORTER_ASSERT(r, f.yxwz().lo.hi.val == f.x());
225 REPORTER_ASSERT(r, f.yxwz().hi.lo.val == f.w());
226 REPORTER_ASSERT(r, f.yxwz().hi.hi.val == f.z());
227
228 REPORTER_ASSERT(r, all(naive_if_then_else(int2(0,~0),
229 shuffle<3,2>(float4(0,1,2,3)),
230 float4(4,5,6,7).xy()) == float2(4,2)));
231 REPORTER_ASSERT(r, all(if_then_else(int2(0,~0),
232 shuffle<3,2>(float4(0,1,2,3)),
233 float4(4,5,6,7).xy()) == float2(4,2)));
234 REPORTER_ASSERT(r, all(naive_if_then_else(int2(0,~0).xyxy(),
235 float4(0,1,2,3).zwxy(),
236 float4(4,5,6,7)) == float4(4,3,6,1)));
237 REPORTER_ASSERT(r, all(if_then_else(int2(0,~0).xyxy(),
238 float4(0,1,2,3).zwxy(),
239 float4(4,5,6,7)) == float4(4,3,6,1)));
240
241 REPORTER_ASSERT(r, all(pin(float4(0,1,2,3).yxwz(),
242 float2(1).xyxy(),
243 float2(2).xyxy()) == float4(1,1,2,2)));
244}

◆ div255()

SIN Vec< N, uint8_t > skvx::div255 ( const Vec< N, uint16_t > &  x)

Definition at line 818 of file SkVx.h.

818 {
819 return cast<uint8_t>( (x+127)/255 );
820}

◆ dot()

SINT T skvx::dot ( const Vec< N, T > &  a,
const Vec< N, T > &  b 
)

Definition at line 964 of file SkVx.h.

964 {
965 // While dot is a "horizontal" operation like any or all, it needs to remain
966 // in floating point and there aren't really any good SIMD instructions that make it faster.
967 // The constexpr cases remove the for loop in the only cases we realistically call.
968 auto ab = a*b;
969 if constexpr (N == 2) {
970 return ab[0] + ab[1];
971 } else if constexpr (N == 4) {
972 return ab[0] + ab[1] + ab[2] + ab[3];
973 } else {
974 T sum = ab[0];
975 for (int i = 1; i < N; ++i) {
976 sum += ab[i];
977 }
978 return sum;
979 }
980}
Definition ab.py:1

◆ floor()

SIN Vec< N, float > skvx::floor ( const Vec< N, float > &  x)

Definition at line 703 of file SkVx.h.

703{ return map(floorf, x); }

◆ fma()

SIN Vec< N, float > skvx::fma ( const Vec< N, float > &  x,
const Vec< N, float > &  y,
const Vec< N, float > &  z 
)

Definition at line 708 of file SkVx.h.

710 {
711 // I don't understand why Clang's codegen is terrible if we write map(fmaf, x,y,z) directly.
712 auto fn = [](float x, float y, float z) { return fmaf(x,y,z); };
713 return map(fn, x,y,z);
714}

◆ fract()

SIN Vec< N, float > skvx::fract ( const Vec< N, float > &  x)

Definition at line 744 of file SkVx.h.

744{ return x - floor(x); }

◆ from_half()

SIN Vec< N, float > skvx::from_half ( const Vec< N, uint16_t > &  x)

Definition at line 790 of file SkVx.h.

790 {
791 if constexpr (N > 4) {
792 return join(from_half(x.lo),
793 from_half(x.hi));
794 }
795
796#if SKVX_USE_SIMD && defined(__aarch64__)
797 if constexpr (N == 4) {
798 return sk_bit_cast<Vec<N,float>>(vcvt_f32_f16(sk_bit_cast<float16x4_t>(x)));
799 }
800#endif
801
802 Vec<N,int32_t> wide = cast<int32_t>(x),
803 s = wide & 0x8000,
804 em = wide ^ s,
805 inf_or_nan = (em >= (31 << 10)) & (255 << 23), // Expands exponent to fill 8 bits
806 is_norm = em > 0x3ff,
807 // subnormal f16's are 2^-14*0.[m0:9] == 2^-24*[m0:9].0
808 sub = sk_bit_cast<Vec<N,int32_t>>((cast<float>(em) * (1.f/(1<<24)))),
809 norm = ((em<<13) + ((127-15)<<23)), // Shifts mantissa, shifts + re-biases exp
810 finite = (is_norm & norm) | (~is_norm & sub);
811 // If 'x' is f16 +/- infinity, inf_or_nan will be the filled 8-bit exponent but 'norm' will be
812 // all 0s since 'x's mantissa is 0. Thus norm | inf_or_nan becomes f32 infinity. However, if
813 // 'x' is an f16 NaN, some bits of 'norm' will be non-zero, so it stays an f32 NaN after the OR.
814 return sk_bit_cast<Vec<N,float>>((s<<16) | finite | inf_or_nan);
815}
struct MyStruct s

◆ if_then_else() [1/2]

SIT Vec< 1, T > skvx::if_then_else ( const Vec< 1, M< T > > &  cond,
const Vec< 1, T > &  t,
const Vec< 1, T > &  e 
)

Definition at line 479 of file SkVx.h.

479 {
480 // In practice this scalar implementation is unlikely to be used. See next if_then_else().
481 return sk_bit_cast<Vec<1,T>>(( cond & sk_bit_cast<Vec<1, M<T>>>(t)) |
482 (~cond & sk_bit_cast<Vec<1, M<T>>>(e)) );
483}

◆ if_then_else() [2/2]

SINT Vec< N, T > skvx::if_then_else ( const Vec< N, M< T > > &  cond,
const Vec< N, T > &  t,
const Vec< N, T > &  e 
)

Definition at line 484 of file SkVx.h.

484 {
485 // Specializations inline here so they can generalize what types the apply to.
486#if SKVX_USE_SIMD && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2
487 if constexpr (N*sizeof(T) == 32) {
488 return sk_bit_cast<Vec<N,T>>(_mm256_blendv_epi8(sk_bit_cast<__m256i>(e),
489 sk_bit_cast<__m256i>(t),
490 sk_bit_cast<__m256i>(cond)));
491 }
492#endif
493#if SKVX_USE_SIMD && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE41
494 if constexpr (N*sizeof(T) == 16) {
495 return sk_bit_cast<Vec<N,T>>(_mm_blendv_epi8(sk_bit_cast<__m128i>(e),
496 sk_bit_cast<__m128i>(t),
497 sk_bit_cast<__m128i>(cond)));
498 }
499#endif
500#if SKVX_USE_SIMD && defined(SK_ARM_HAS_NEON)
501 if constexpr (N*sizeof(T) == 16) {
502 return sk_bit_cast<Vec<N,T>>(vbslq_u8(sk_bit_cast<uint8x16_t>(cond),
503 sk_bit_cast<uint8x16_t>(t),
504 sk_bit_cast<uint8x16_t>(e)));
505 }
506#endif
507#if SKVX_USE_SIMD && SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LASX
508 if constexpr (N*sizeof(T) == 32) {
509 return sk_bit_cast<Vec<N,T>>(__lasx_xvbitsel_v(sk_bit_cast<__m256i>(e),
510 sk_bit_cast<__m256i>(t),
511 sk_bit_cast<__m256i>(cond)));
512 }
513#endif
514#if SKVX_USE_SIMD && SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LSX
515 if constexpr (N*sizeof(T) == 16) {
516 return sk_bit_cast<Vec<N,T>>(__lsx_vbitsel_v(sk_bit_cast<__m128i>(e),
517 sk_bit_cast<__m128i>(t),
518 sk_bit_cast<__m128i>(cond)));
519 }
520#endif
521 // Recurse for large vectors to try to hit the specializations above.
522 if constexpr (N*sizeof(T) > 16) {
523 return join(if_then_else(cond.lo, t.lo, e.lo),
524 if_then_else(cond.hi, t.hi, e.hi));
525 }
526 // This default can lead to better code than the recursing onto scalars.
527 return naive_if_then_else(cond, t, e);
528}
SINT Vec< N, T > naive_if_then_else(const Vec< N, M< T > > &cond, const Vec< N, T > &t, const Vec< N, T > &e)
Definition SkVx.h:474
Vec< N/2, T > hi
Definition SkVx.h:117
Vec< N/2, T > lo
Definition SkVx.h:117

◆ isfinite()

SINT bool skvx::isfinite ( const Vec< N, T > &  v)

Definition at line 1003 of file SkVx.h.

1003 {
1004 // Multiply all values together with 0. If they were all finite, the output is
1005 // 0 (also finite). If any were not, we'll get nan.
1006 return SkIsFinite(dot(v, Vec<N, T>(0)));
1007}
static bool SkIsFinite(T x, Pack... values)

◆ join()

SINT Vec< 2 *N, T > skvx::join ( const Vec< N, T > &  lo,
const Vec< N, T > &  hi 
)

Definition at line 242 of file SkVx.h.

242 {
243 Vec<2*N,T> v;
244 v.lo = lo;
245 v.hi = hi;
246 return v;
247}

◆ length() [1/2]

SIN double skvx::length ( const Vec< N, double > &  v)

Definition at line 991 of file SkVx.h.

991 {
992 return std::sqrt(dot(v, v));
993}

◆ length() [2/2]

SIN float skvx::length ( const Vec< N, float > &  v)

Definition at line 987 of file SkVx.h.

987 {
988 return std::sqrt(dot(v, v));
989}

◆ lrint() [1/2]

SI Vec< 1, int > skvx::lrint ( const Vec< 1, float > &  x)

Definition at line 716 of file SkVx.h.

716 {
717 return (int)lrintf(x.val);
718}

◆ lrint() [2/2]

SIN Vec< N, int > skvx::lrint ( const Vec< N, float > &  x)

Definition at line 719 of file SkVx.h.

719 {
720#if SKVX_USE_SIMD && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX
721 if constexpr (N == 8) {
722 return sk_bit_cast<Vec<N,int>>(_mm256_cvtps_epi32(sk_bit_cast<__m256>(x)));
723 }
724#endif
725#if SKVX_USE_SIMD && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
726 if constexpr (N == 4) {
727 return sk_bit_cast<Vec<N,int>>(_mm_cvtps_epi32(sk_bit_cast<__m128>(x)));
728 }
729#endif
730#if SKVX_USE_SIMD && SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LASX
731 if constexpr (N == 8) {
732 return sk_bit_cast<Vec<N,int>>(__lasx_xvftint_w_s(sk_bit_cast<__m256>(x)));
733 }
734#endif
735#if SKVX_USE_SIMD && SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LSX
736 if constexpr (N == 4) {
737 return sk_bit_cast<Vec<N,int>>(__lsx_vftint_w_s(sk_bit_cast<__m128>(x)));
738 }
739#endif
740 return join(lrint(x.lo),
741 lrint(x.hi));
742}
SI Vec< 1, int > lrint(const Vec< 1, float > &x)
Definition SkVx.h:716

◆ map() [1/2]

template<typename Fn , int N, typename T , typename... Rest>
auto skvx::map ( Fn &&  fn,
const Vec< N, T > &  first,
const Rest &...  rest 
)

Definition at line 697 of file SkVx.h.

697 {
698 // Derive an {0...N-1} index_sequence from the size of the first arg: N lanes in, N lanes out.
699 return map(std::make_index_sequence<N>{}, fn, first,rest...);
700}

◆ map() [2/2]

template<typename Fn , typename... Args, size_t... I>
SI auto skvx::map ( std::index_sequence< I... >  ,
Fn &&  fn,
const Args &...  args 
) -> skvx::Vec<sizeof...(I), decltype(fn(args[0]...))>

Definition at line 680 of file SkVx.h.

681 {
682 auto lane = [&](size_t i)
683#if defined(__clang__)
684 // CFI, specifically -fsanitize=cfi-icall, seems to give a false positive here,
685 // with errors like "control flow integrity check for type 'float (float)
686 // noexcept' failed during indirect function call... note: sqrtf.cfi_jt defined
687 // here". But we can be quite sure fn is the right type: it's all inferred!
688 // So, stifle CFI in this function.
689 __attribute__((no_sanitize("cfi")))
690#endif
691 { return fn(args[static_cast<int>(i)]...); };
692
693 return { lane(I)... };
694}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
__attribute__((visibility("default"))) int RunBenchmarks(int argc
Definition SkMD5.cpp:134

◆ max() [1/5]

SIT T skvx::max ( const Vec< 1, T > &  x)

Definition at line 641 of file SkVx.h.

641{ return x.val; }

◆ max() [2/5]

SINT T skvx::max ( const Vec< N, T > &  x)

Definition at line 643 of file SkVx.h.

643{ return std::max(max(x.lo), max(x.hi)); }

◆ max() [3/5]

SINT Vec< N, T > skvx::max ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 646 of file SkVx.h.

646{ return naive_if_then_else(x < y, y, x); }

◆ max() [4/5]

SINTU Vec< N, T > skvx::max ( const Vec< N, T > &  x,
y 
)

Definition at line 649 of file SkVx.h.

649{ return max(x, Vec<N,T>(y)); }

◆ max() [5/5]

SINTU Vec< N, T > skvx::max ( x,
const Vec< N, T > &  y 
)

Definition at line 651 of file SkVx.h.

651{ return max(Vec<N,T>(x), y); }

◆ min() [1/5]

SIT T skvx::min ( const Vec< 1, T > &  x)

Definition at line 640 of file SkVx.h.

640{ return x.val; }

◆ min() [2/5]

SINT T skvx::min ( const Vec< N, T > &  x)

Definition at line 642 of file SkVx.h.

642{ return std::min(min(x.lo), min(x.hi)); }

◆ min() [3/5]

SINT Vec< N, T > skvx::min ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 645 of file SkVx.h.

645{ return naive_if_then_else(y < x, y, x); }

◆ min() [4/5]

SINTU Vec< N, T > skvx::min ( const Vec< N, T > &  x,
y 
)

Definition at line 648 of file SkVx.h.

648{ return min(x, Vec<N,T>(y)); }

◆ min() [5/5]

SINTU Vec< N, T > skvx::min ( x,
const Vec< N, T > &  y 
)

Definition at line 650 of file SkVx.h.

650{ return min(Vec<N,T>(x), y); }

◆ mulhi()

SIN Vec< N, uint16_t > skvx::mulhi ( const Vec< N, uint16_t > &  x,
const Vec< N, uint16_t > &  y 
)

Definition at line 938 of file SkVx.h.

939 {
940#if SKVX_USE_SIMD && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
941 // Use _mm_mulhi_epu16 for 8xuint16_t and join or split to get there.
942 if constexpr (N == 8) {
943 return sk_bit_cast<Vec<8,uint16_t>>(_mm_mulhi_epu16(sk_bit_cast<__m128i>(x),
944 sk_bit_cast<__m128i>(y)));
945 } else if constexpr (N < 8) {
946 return mulhi(join(x,x), join(y,y)).lo;
947 } else { // N > 8
948 return join(mulhi(x.lo, y.lo), mulhi(x.hi, y.hi));
949 }
950#elif SKVX_USE_SIMD && SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LSX
951 if constexpr (N == 8) {
952 return sk_bit_cast<Vec<8,uint16_t>>(__lsx_vmuh_hu(sk_bit_cast<__m128i>(x),
953 sk_bit_cast<__m128i>(y)));
954 } else if constexpr (N < 8) {
955 return mulhi(join(x,x), join(y,y)).lo;
956 } else { // N > 8
957 return join(mulhi(x.lo, y.lo), mulhi(x.hi, y.hi));
958 }
959#else
960 return skvx::cast<uint16_t>(mull(x, y) >> 16);
961#endif
962}
SIN Vec< N, uint16_t > mulhi(const Vec< N, uint16_t > &x, const Vec< N, uint16_t > &y)
Definition SkVx.h:938

◆ mull() [1/2]

SIN Vec< N, uint32_t > skvx::mull ( const Vec< N, uint16_t > &  x,
const Vec< N, uint16_t > &  y 
)

Definition at line 922 of file SkVx.h.

923 {
924#if SKVX_USE_SIMD && defined(SK_ARM_HAS_NEON)
925 // NEON can do four u16*u16 -> u32 in one instruction, vmull_u16
926 if constexpr (N == 4) {
927 return to_vec<4,uint32_t>(vmull_u16(to_vext(x), to_vext(y)));
928 } else if constexpr (N < 4) {
929 return mull(join(x,x), join(y,y)).lo;
930 } else { // N > 4
931 return join(mull(x.lo, y.lo), mull(x.hi, y.hi));
932 }
933#else
934 return cast<uint32_t>(x) * cast<uint32_t>(y);
935#endif
936}

◆ mull() [2/2]

SIN Vec< N, uint16_t > skvx::mull ( const Vec< N, uint8_t > &  x,
const Vec< N, uint8_t > &  y 
)

Definition at line 906 of file SkVx.h.

907 {
908#if SKVX_USE_SIMD && defined(SK_ARM_HAS_NEON)
909 // With NEON we can do eight u8*u8 -> u16 in one instruction, vmull_u8 (read, mul-long).
910 if constexpr (N == 8) {
911 return to_vec<8,uint16_t>(vmull_u8(to_vext(x), to_vext(y)));
912 } else if constexpr (N < 8) {
913 return mull(join(x,x), join(y,y)).lo;
914 } else { // N > 8
915 return join(mull(x.lo, y.lo), mull(x.hi, y.hi));
916 }
917#else
918 return cast<uint16_t>(x) * cast<uint16_t>(y);
919#endif
920}

◆ naive_if_then_else()

SINT Vec< N, T > skvx::naive_if_then_else ( const Vec< N, M< T > > &  cond,
const Vec< N, T > &  t,
const Vec< N, T > &  e 
)

Definition at line 474 of file SkVx.h.

474 {
475 return sk_bit_cast<Vec<N,T>>(( cond & sk_bit_cast<Vec<N, M<T>>>(t)) |
476 (~cond & sk_bit_cast<Vec<N, M<T>>>(e)) );
477}

◆ normalize() [1/2]

SIN Vec< N, double > skvx::normalize ( const Vec< N, double > &  v)

Definition at line 999 of file SkVx.h.

999 {
1000 return v / length(v);
1001}

◆ normalize() [2/2]

SIN Vec< N, float > skvx::normalize ( const Vec< N, float > &  v)

Definition at line 995 of file SkVx.h.

995 {
996 return v / length(v);
997}

◆ operator!() [1/2]

SIT Vec< 1, T > skvx::operator! ( const Vec< 1, T > &  x)

Definition at line 344 of file SkVx.h.

344{ return !x.val; }

◆ operator!() [2/2]

SINT Vec< N, T > skvx::operator! ( const Vec< N, T > &  x)

Definition at line 394 of file SkVx.h.

394{ return join(!x.lo, !x.hi); }

◆ operator!=() [1/4]

SIT Vec< 1, M< T > > skvx::operator!= ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 354 of file SkVx.h.

354 {
355 return x.val != y.val ? ~0 : 0;
356 }

◆ operator!=() [2/4]

SINT Vec< N, M< T > > skvx::operator!= ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 404 of file SkVx.h.

404 {
405 return join(x.lo != y.lo, x.hi != y.hi);
406 }

◆ operator!=() [3/4]

SINTU Vec< N, M< T > > skvx::operator!= ( const Vec< N, T > &  x,
y 
)

Definition at line 444 of file SkVx.h.

444{ return x != Vec<N,T>(y); }

◆ operator!=() [4/4]

SINTU Vec< N, M< T > > skvx::operator!= ( x,
const Vec< N, T > &  y 
)

Definition at line 430 of file SkVx.h.

430{ return Vec<N,T>(x) != y; }

◆ operator&() [1/4]

SIT Vec< 1, T > skvx::operator& ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 341 of file SkVx.h.

341{ return x.val & y.val; }

◆ operator&() [2/4]

SINT Vec< N, T > skvx::operator& ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 387 of file SkVx.h.

387 {
388 return join(x.lo & y.lo, x.hi & y.hi);
389 }

◆ operator&() [3/4]

SINTU Vec< N, T > skvx::operator& ( const Vec< N, T > &  x,
y 
)

Definition at line 441 of file SkVx.h.

441{ return x & Vec<N,T>(y); }

◆ operator&() [4/4]

SINTU Vec< N, T > skvx::operator& ( x,
const Vec< N, T > &  y 
)

Definition at line 427 of file SkVx.h.

427{ return Vec<N,T>(x) & y; }

◆ operator&=() [1/2]

SINT Vec< N, T > & skvx::operator&= ( Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 455 of file SkVx.h.

455{ return (x = x & y); }

◆ operator&=() [2/2]

SINTU Vec< N, T > & skvx::operator&= ( Vec< N, T > &  x,
y 
)

Definition at line 463 of file SkVx.h.

463{ return (x = x & Vec<N,T>(y)); }

◆ operator*() [1/4]

SIT Vec< 1, T > skvx::operator* ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 337 of file SkVx.h.

337{ return x.val * y.val; }

◆ operator*() [2/4]

SINT Vec< N, T > skvx::operator* ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 377 of file SkVx.h.

377 {
378 return join(x.lo * y.lo, x.hi * y.hi);
379 }

◆ operator*() [3/4]

SINTU Vec< N, T > skvx::operator* ( const Vec< N, T > &  x,
y 
)

Definition at line 438 of file SkVx.h.

438{ return x * Vec<N,T>(y); }

◆ operator*() [4/4]

SINTU Vec< N, T > skvx::operator* ( x,
const Vec< N, T > &  y 
)

Definition at line 424 of file SkVx.h.

424{ return Vec<N,T>(x) * y; }

◆ operator*=() [1/2]

SINT Vec< N, T > & skvx::operator*= ( Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 452 of file SkVx.h.

452{ return (x = x * y); }

◆ operator*=() [2/2]

SINTU Vec< N, T > & skvx::operator*= ( Vec< N, T > &  x,
y 
)

Definition at line 460 of file SkVx.h.

460{ return (x = x * Vec<N,T>(y)); }

◆ operator+() [1/4]

SIT Vec< 1, T > skvx::operator+ ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 335 of file SkVx.h.

335{ return x.val + y.val; }

◆ operator+() [2/4]

SINT Vec< N, T > skvx::operator+ ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 371 of file SkVx.h.

371 {
372 return join(x.lo + y.lo, x.hi + y.hi);
373 }

◆ operator+() [3/4]

SINTU Vec< N, T > skvx::operator+ ( const Vec< N, T > &  x,
y 
)

Definition at line 436 of file SkVx.h.

436{ return x + Vec<N,T>(y); }

◆ operator+() [4/4]

SINTU Vec< N, T > skvx::operator+ ( x,
const Vec< N, T > &  y 
)

Definition at line 422 of file SkVx.h.

422{ return Vec<N,T>(x) + y; }

◆ operator+=() [1/2]

SINT Vec< N, T > & skvx::operator+= ( Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 450 of file SkVx.h.

450{ return (x = x + y); }

◆ operator+=() [2/2]

SINTU Vec< N, T > & skvx::operator+= ( Vec< N, T > &  x,
y 
)

Definition at line 458 of file SkVx.h.

458{ return (x = x + Vec<N,T>(y)); }

◆ operator-() [1/6]

SIT Vec< 1, T > skvx::operator- ( const Vec< 1, T > &  x)

Definition at line 345 of file SkVx.h.

345{ return -x.val; }

◆ operator-() [2/6]

SIT Vec< 1, T > skvx::operator- ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 336 of file SkVx.h.

336{ return x.val - y.val; }

◆ operator-() [3/6]

SINT Vec< N, T > skvx::operator- ( const Vec< N, T > &  x)

Definition at line 395 of file SkVx.h.

395{ return join(-x.lo, -x.hi); }

◆ operator-() [4/6]

SINT Vec< N, T > skvx::operator- ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 374 of file SkVx.h.

374 {
375 return join(x.lo - y.lo, x.hi - y.hi);
376 }

◆ operator-() [5/6]

SINTU Vec< N, T > skvx::operator- ( const Vec< N, T > &  x,
y 
)

Definition at line 437 of file SkVx.h.

437{ return x - Vec<N,T>(y); }

◆ operator-() [6/6]

SINTU Vec< N, T > skvx::operator- ( x,
const Vec< N, T > &  y 
)

Definition at line 423 of file SkVx.h.

423{ return Vec<N,T>(x) - y; }

◆ operator-=() [1/2]

SINT Vec< N, T > & skvx::operator-= ( Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 451 of file SkVx.h.

451{ return (x = x - y); }

◆ operator-=() [2/2]

SINTU Vec< N, T > & skvx::operator-= ( Vec< N, T > &  x,
y 
)

Definition at line 459 of file SkVx.h.

459{ return (x = x - Vec<N,T>(y)); }

◆ operator/() [1/4]

SIT Vec< 1, T > skvx::operator/ ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 338 of file SkVx.h.

338{ return x.val / y.val; }

◆ operator/() [2/4]

SINT Vec< N, T > skvx::operator/ ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 380 of file SkVx.h.

380 {
381 return join(x.lo / y.lo, x.hi / y.hi);
382 }

◆ operator/() [3/4]

SINTU Vec< N, T > skvx::operator/ ( const Vec< N, T > &  x,
y 
)

Definition at line 439 of file SkVx.h.

439{ return x / Vec<N,T>(y); }

◆ operator/() [4/4]

SINTU Vec< N, T > skvx::operator/ ( x,
const Vec< N, T > &  y 
)

Definition at line 425 of file SkVx.h.

425{ return Vec<N,T>(x) / y; }

◆ operator/=() [1/2]

SINT Vec< N, T > & skvx::operator/= ( Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 453 of file SkVx.h.

453{ return (x = x / y); }

◆ operator/=() [2/2]

SINTU Vec< N, T > & skvx::operator/= ( Vec< N, T > &  x,
y 
)

Definition at line 461 of file SkVx.h.

461{ return (x = x / Vec<N,T>(y)); }

◆ operator<() [1/4]

SIT Vec< 1, M< T > > skvx::operator< ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 363 of file SkVx.h.

363 {
364 return x.val < y.val ? ~0 : 0;
365 }

◆ operator<() [2/4]

SINT Vec< N, M< T > > skvx::operator< ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 413 of file SkVx.h.

413 {
414 return join(x.lo < y.lo, x.hi < y.hi);
415 }

◆ operator<() [3/4]

SINTU Vec< N, M< T > > skvx::operator< ( const Vec< N, T > &  x,
y 
)

Definition at line 447 of file SkVx.h.

447{ return x < Vec<N,T>(y); }

◆ operator<() [4/4]

SINTU Vec< N, M< T > > skvx::operator< ( x,
const Vec< N, T > &  y 
)

Definition at line 433 of file SkVx.h.

433{ return Vec<N,T>(x) < y; }

◆ operator<<() [1/2]

SIT Vec< 1, T > skvx::operator<< ( const Vec< 1, T > &  x,
int  k 
)

Definition at line 348 of file SkVx.h.

348{ return x.val << k; }

◆ operator<<() [2/2]

SINT Vec< N, T > skvx::operator<< ( const Vec< N, T > &  x,
int  k 
)

Definition at line 398 of file SkVx.h.

398{ return join(x.lo << k, x.hi << k); }

◆ operator<<=()

SINT Vec< N, T > & skvx::operator<<= ( Vec< N, T > &  x,
int  bits 
)

Definition at line 466 of file SkVx.h.

466{ return (x = x << bits); }

◆ operator<=() [1/4]

SIT Vec< 1, M< T > > skvx::operator<= ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 357 of file SkVx.h.

357 {
358 return x.val <= y.val ? ~0 : 0;
359 }

◆ operator<=() [2/4]

SINT Vec< N, M< T > > skvx::operator<= ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 407 of file SkVx.h.

407 {
408 return join(x.lo <= y.lo, x.hi <= y.hi);
409 }

◆ operator<=() [3/4]

SINTU Vec< N, M< T > > skvx::operator<= ( const Vec< N, T > &  x,
y 
)

Definition at line 445 of file SkVx.h.

445{ return x <= Vec<N,T>(y); }

◆ operator<=() [4/4]

SINTU Vec< N, M< T > > skvx::operator<= ( x,
const Vec< N, T > &  y 
)

Definition at line 431 of file SkVx.h.

431{ return Vec<N,T>(x) <= y; }

◆ operator==() [1/4]

SIT Vec< 1, M< T > > skvx::operator== ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 351 of file SkVx.h.

351 {
352 return x.val == y.val ? ~0 : 0;
353 }

◆ operator==() [2/4]

SINT Vec< N, M< T > > skvx::operator== ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 401 of file SkVx.h.

401 {
402 return join(x.lo == y.lo, x.hi == y.hi);
403 }

◆ operator==() [3/4]

SINTU Vec< N, M< T > > skvx::operator== ( const Vec< N, T > &  x,
y 
)

Definition at line 443 of file SkVx.h.

443{ return x == Vec<N,T>(y); }

◆ operator==() [4/4]

SINTU Vec< N, M< T > > skvx::operator== ( x,
const Vec< N, T > &  y 
)

Definition at line 429 of file SkVx.h.

429{ return Vec<N,T>(x) == y; }

◆ operator>() [1/4]

SIT Vec< 1, M< T > > skvx::operator> ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 366 of file SkVx.h.

366 {
367 return x.val > y.val ? ~0 : 0;
368 }

◆ operator>() [2/4]

SINT Vec< N, M< T > > skvx::operator> ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 416 of file SkVx.h.

416 {
417 return join(x.lo > y.lo, x.hi > y.hi);
418 }

◆ operator>() [3/4]

SINTU Vec< N, M< T > > skvx::operator> ( const Vec< N, T > &  x,
y 
)

Definition at line 448 of file SkVx.h.

448{ return x > Vec<N,T>(y); }

◆ operator>() [4/4]

SINTU Vec< N, M< T > > skvx::operator> ( x,
const Vec< N, T > &  y 
)

Definition at line 434 of file SkVx.h.

434{ return Vec<N,T>(x) > y; }

◆ operator>=() [1/4]

SIT Vec< 1, M< T > > skvx::operator>= ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 360 of file SkVx.h.

360 {
361 return x.val >= y.val ? ~0 : 0;
362 }

◆ operator>=() [2/4]

SINT Vec< N, M< T > > skvx::operator>= ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 410 of file SkVx.h.

410 {
411 return join(x.lo >= y.lo, x.hi >= y.hi);
412 }

◆ operator>=() [3/4]

SINTU Vec< N, M< T > > skvx::operator>= ( const Vec< N, T > &  x,
y 
)

Definition at line 446 of file SkVx.h.

446{ return x >= Vec<N,T>(y); }

◆ operator>=() [4/4]

SINTU Vec< N, M< T > > skvx::operator>= ( x,
const Vec< N, T > &  y 
)

Definition at line 432 of file SkVx.h.

432{ return Vec<N,T>(x) >= y; }

◆ operator>>() [1/2]

SIT Vec< 1, T > skvx::operator>> ( const Vec< 1, T > &  x,
int  k 
)

Definition at line 349 of file SkVx.h.

349{ return x.val >> k; }

◆ operator>>() [2/2]

SINT Vec< N, T > skvx::operator>> ( const Vec< N, T > &  x,
int  k 
)

Definition at line 399 of file SkVx.h.

399{ return join(x.lo >> k, x.hi >> k); }

◆ operator>>=()

SINT Vec< N, T > & skvx::operator>>= ( Vec< N, T > &  x,
int  bits 
)

Definition at line 467 of file SkVx.h.

467{ return (x = x >> bits); }

◆ operator^() [1/4]

SIT Vec< 1, T > skvx::operator^ ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 340 of file SkVx.h.

340{ return x.val ^ y.val; }

◆ operator^() [2/4]

SINT Vec< N, T > skvx::operator^ ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 384 of file SkVx.h.

384 {
385 return join(x.lo ^ y.lo, x.hi ^ y.hi);
386 }

◆ operator^() [3/4]

SINTU Vec< N, T > skvx::operator^ ( const Vec< N, T > &  x,
y 
)

Definition at line 440 of file SkVx.h.

440{ return x ^ Vec<N,T>(y); }

◆ operator^() [4/4]

SINTU Vec< N, T > skvx::operator^ ( x,
const Vec< N, T > &  y 
)

Definition at line 426 of file SkVx.h.

426{ return Vec<N,T>(x) ^ y; }

◆ operator^=() [1/2]

SINT Vec< N, T > & skvx::operator^= ( Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 454 of file SkVx.h.

454{ return (x = x ^ y); }

◆ operator^=() [2/2]

SINTU Vec< N, T > & skvx::operator^= ( Vec< N, T > &  x,
y 
)

Definition at line 462 of file SkVx.h.

462{ return (x = x ^ Vec<N,T>(y)); }

◆ operator|() [1/4]

SIT Vec< 1, T > skvx::operator| ( const Vec< 1, T > &  x,
const Vec< 1, T > &  y 
)

Definition at line 342 of file SkVx.h.

342{ return x.val | y.val; }

◆ operator|() [2/4]

SINT Vec< N, T > skvx::operator| ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 390 of file SkVx.h.

390 {
391 return join(x.lo | y.lo, x.hi | y.hi);
392 }

◆ operator|() [3/4]

SINTU Vec< N, T > skvx::operator| ( const Vec< N, T > &  x,
y 
)

Definition at line 442 of file SkVx.h.

442{ return x | Vec<N,T>(y); }

◆ operator|() [4/4]

SINTU Vec< N, T > skvx::operator| ( x,
const Vec< N, T > &  y 
)

Definition at line 428 of file SkVx.h.

428{ return Vec<N,T>(x) | y; }

◆ operator|=() [1/2]

SINT Vec< N, T > & skvx::operator|= ( Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 456 of file SkVx.h.

456{ return (x = x | y); }

◆ operator|=() [2/2]

SINTU Vec< N, T > & skvx::operator|= ( Vec< N, T > &  x,
y 
)

Definition at line 464 of file SkVx.h.

464{ return (x = x | Vec<N,T>(y)); }

◆ operator~() [1/2]

SIT Vec< 1, T > skvx::operator~ ( const Vec< 1, T > &  x)

Definition at line 346 of file SkVx.h.

346{ return ~x.val; }

◆ operator~() [2/2]

SINT Vec< N, T > skvx::operator~ ( const Vec< N, T > &  x)

Definition at line 396 of file SkVx.h.

396{ return join(~x.lo, ~x.hi); }

◆ pin()

SINT Vec< N, T > skvx::pin ( const Vec< N, T > &  x,
const Vec< N, T > &  lo,
const Vec< N, T > &  hi 
)

Definition at line 655 of file SkVx.h.

655 {
656 return max(lo, min(x, hi));
657}

◆ round()

SIN Vec< N, float > skvx::round ( const Vec< N, float > &  x)

Definition at line 705 of file SkVx.h.

705{ return map(roundf, x); }

◆ saturated_add()

SINT std::enable_if_t< std::is_unsigned_v< T >, Vec< N, T > > skvx::saturated_add ( const Vec< N, T > &  x,
const Vec< N, T > &  y 
)

Definition at line 833 of file SkVx.h.

834 {
835#if SKVX_USE_SIMD && (SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1 || defined(SK_ARM_HAS_NEON) || \
836 SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LSX)
837 // Both SSE and ARM have 16-lane saturated adds, so use intrinsics for those and recurse down
838 // or join up to take advantage.
839 if constexpr (N == 16 && sizeof(T) == 1) {
840 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
841 return sk_bit_cast<Vec<N,T>>(_mm_adds_epu8(sk_bit_cast<__m128i>(x),
842 sk_bit_cast<__m128i>(y)));
843 #elif SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LSX
844 return sk_bit_cast<Vec<N,T>>(__lsx_vsadd_bu(sk_bit_cast<__m128i>(x),
845 sk_bit_cast<__m128i>(y)));
846 #else // SK_ARM_HAS_NEON
847 return sk_bit_cast<Vec<N,T>>(vqaddq_u8(sk_bit_cast<uint8x16_t>(x),
848 sk_bit_cast<uint8x16_t>(y)));
849 #endif
850 } else if constexpr (N < 16 && sizeof(T) == 1) {
851 return saturated_add(join(x,x), join(y,y)).lo;
852 } else if constexpr (sizeof(T) == 1) {
853 return join(saturated_add(x.lo, y.lo), saturated_add(x.hi, y.hi));
854 }
855#endif
856 // Otherwise saturate manually
857 auto sum = x + y;
858 return if_then_else(sum < x, Vec<N,T>(std::numeric_limits<T>::max()), sum);
859}

◆ shuffle()

template<int... Ix, int N, typename T >
SI Vec< sizeof...(Ix), T > skvx::shuffle ( const Vec< N, T > &  x)

Definition at line 667 of file SkVx.h.

667 {
668#if SKVX_USE_SIMD && defined(__clang__)
669 // TODO: can we just always use { x[Ix]... }?
670 return to_vec<sizeof...(Ix),T>(__builtin_shufflevector(to_vext(x), to_vext(x), Ix...));
671#else
672 return { x[Ix]... };
673#endif
674}

◆ sqrt()

SIN Vec< N, float > skvx::sqrt ( const Vec< N, float > &  x)

Definition at line 706 of file SkVx.h.

706{ return map( sqrtf, x); }

◆ strided_load2() [1/2]

SIT void skvx::strided_load2 ( const T v,
Vec< 1, T > &  a,
Vec< 1, T > &  b 
)

Definition at line 1112 of file SkVx.h.

1112 {
1113 a.val = v[0];
1114 b.val = v[1];
1115}

◆ strided_load2() [2/2]

SINT void skvx::strided_load2 ( const T v,
Vec< N, T > &  a,
Vec< N, T > &  b 
)

Definition at line 1116 of file SkVx.h.

1116 {
1117 strided_load2(v, a.lo, b.lo);
1118 strided_load2(v + 2*(N/2), a.hi, b.hi);
1119}

◆ strided_load4() [1/3]

SI void skvx::strided_load4 ( const float *  v,
Vec< 4, float > &  a,
Vec< 4, float > &  b,
Vec< 4, float > &  c,
Vec< 4, float > &  d 
)

Definition at line 1062 of file SkVx.h.

1066 {
1067 __m128 a_ = _mm_loadu_ps(v);
1068 __m128 b_ = _mm_loadu_ps(v+4);
1069 __m128 c_ = _mm_loadu_ps(v+8);
1070 __m128 d_ = _mm_loadu_ps(v+12);
1071 _MM_TRANSPOSE4_PS(a_, b_, c_, d_);
1072 a = sk_bit_cast<Vec<4,float>>(a_);
1073 b = sk_bit_cast<Vec<4,float>>(b_);
1074 c = sk_bit_cast<Vec<4,float>>(c_);
1075 d = sk_bit_cast<Vec<4,float>>(d_);
1076}

◆ strided_load4() [2/3]

SIT void skvx::strided_load4 ( const T v,
Vec< 1, T > &  a,
Vec< 1, T > &  b,
Vec< 1, T > &  c,
Vec< 1, T > &  d 
)

Definition at line 1013 of file SkVx.h.

1017 {
1018 a.val = v[0];
1019 b.val = v[1];
1020 c.val = v[2];
1021 d.val = v[3];
1022}

◆ strided_load4() [3/3]

SINT void skvx::strided_load4 ( const T v,
Vec< N, T > &  a,
Vec< N, T > &  b,
Vec< N, T > &  c,
Vec< N, T > &  d 
)

Definition at line 1023 of file SkVx.h.

1027 {
1028 strided_load4(v, a.lo, b.lo, c.lo, d.lo);
1029 strided_load4(v + 4*(N/2), a.hi, b.hi, c.hi, d.hi);
1030}
SIT void strided_load4(const T *v, Vec< 1, T > &a, Vec< 1, T > &b, Vec< 1, T > &c, Vec< 1, T > &d)
Definition SkVx.h:1013

◆ to_half()

SIN Vec< N, uint16_t > skvx::to_half ( const Vec< N, float > &  x)

Definition at line 750 of file SkVx.h.

750 {
751 assert(all(x == x)); // No NaNs should reach this function
752
753 // Intrinsics for float->half tend to operate on 4 lanes, and the default implementation has
754 // enough instructions that it's better to split and join on 128 bits groups vs.
755 // recursing for each min/max/shift/etc.
756 if constexpr (N > 4) {
757 return join(to_half(x.lo),
758 to_half(x.hi));
759 }
760
761#if SKVX_USE_SIMD && defined(__aarch64__)
762 if constexpr (N == 4) {
763 return sk_bit_cast<Vec<N,uint16_t>>(vcvt_f16_f32(sk_bit_cast<float32x4_t>(x)));
764
765 }
766#endif
767
768#define I(x) sk_bit_cast<Vec<N,int32_t>>(x)
769#define F(x) sk_bit_cast<Vec<N,float>>(x)
770 Vec<N,int32_t> sem = I(x),
771 s = sem & 0x8000'0000,
772 em = min(sem ^ s, 0x4780'0000), // |x| clamped to f16 infinity
773 // F(em)*8192 increases the exponent by 13, which when added back to em will shift
774 // the mantissa bits 13 to the right. We clamp to 1/2 for subnormal values, which
775 // automatically shifts the mantissa to match 2^-14 expected for a subnorm f16.
776 magic = I(max(F(em) * 8192.f, 0.5f)) & (255 << 23),
777 rounded = I((F(em) + F(magic))), // shift mantissa with automatic round-to-even
778 // Subtract 127 for f32 bias, subtract 13 to undo the *8192, subtract 1 to remove
779 // the implicit leading 1., and add 15 to get the f16 biased exponent.
780 exp = ((magic >> 13) - ((127-15+13+1)<<10)), // shift and re-bias exponent
781 f16 = rounded + exp; // use + if 'rounded' rolled over into first exponent bit
782 return cast<uint16_t>((s>>16) | f16);
783#undef I
784#undef F
785}
static const uint64_t f16[kNumPixels]
#define F(x)
#define I(x)

◆ trunc()

SIN Vec< N, float > skvx::trunc ( const Vec< N, float > &  x)

Definition at line 704 of file SkVx.h.

704{ return map(truncf, x); }