19 static_assert(
sizeof(
float2) == 8,
"");
20 static_assert(
sizeof(
float4) == 16,
"");
21 static_assert(
sizeof(
float8) == 32,
"");
23 static_assert(
sizeof(
byte2) == 2,
"");
24 static_assert(
sizeof(
byte4) == 4,
"");
25 static_assert(
sizeof(
byte8) == 8,
"");
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})));
88 float buf[] = {1,2,3,4,5,6};
100 REPORTER_ASSERT(r,
all(shuffle<2,1,0,3> (
float4{1,2,3,4}) ==
float4{3,2,1,4}));
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}));
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 );
131 if (
x == 0 ||
y == 0 ||
x == 255 ||
y == 255) {
137 for (
int x = 0;
x < 256;
x++)
138 for (
int y = 0;
y < 256;
y++) {
150 float8 fs = {+0.0f,+0.5f,+1.0f,+2.0f,
151 -4.0f,-0.5f,-1.0f,-2.0f};
153 0xc400,0xb800,0xbc00,0xc000};
229 shuffle<3,2>(
float4(0,1,2,3)),
232 shuffle<3,2>(
float4(0,1,2,3)),
260 for (
int i = 0;
i < 100; ++
i) {
263 constexpr static float kTolerance = 1.f / (1 << 20);
270 auto assertDoublesEqual = [&](
double left,
double right) {
284 for (
int i = 0;
i <
N; ++
i) {
289 for (
int i = 0;
i <
N; ++
i) {
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);
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);
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;
325 auto test = [&](uint32_t denom) {
328 uint32_t maxCheck =
static_cast<uint32_t
>(
329 std::floor((
double)(kMax -
d.half()) / denom + 0.5));
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]);
338 for (
int e = 1;
e < 4;
e++) {
355 for (
int a = 0;
a < (1<<8);
a++) {
356 for (
int b = 0;
b < (1<<8);
b++) {
358 if (exact > 255) { exact = 255; }
359 if (exact < 0) { exact = 0; }
367 auto assertFloatsEqual = [&](
float left,
float right) {
370 auto assertDoublesEqual = [&](
double left,
double right) {
378 assertFloatsEqual(
length(
float2{2.5f, 2.5f}), 3.535534f);
379 assertFloatsEqual(
length(
float4{1, 2, 3, 4}), 5.477226f);
382 assertDoublesEqual(
length(
double4{1.5, 2.5, 3.5, 4.5}), 6.403124);
386 auto assertFloatsEqual = [&](
float left,
float right) {
389 auto assertDoublesEqual = [&](
double left,
double right) {
394 assertFloatsEqual(twoFloats[0], 0.332820f);
395 assertFloatsEqual(twoFloats[1], 0.942990f);
398 assertDoublesEqual(twoDoubles[0], 0.455111);
399 assertDoublesEqual(twoDoubles[1], -0.890435);
402 assertDoublesEqual(fourDoubles[0], 0.116997);
403 assertDoublesEqual(fourDoubles[1], 0.331490);
404 assertDoublesEqual(fourDoubles[2], 0.545984);
405 assertDoublesEqual(fourDoubles[3], 0.760478);
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]);
434 for (
int i = 0;
i < 4;
i++) {
442 for (
int i = 0;
i < 8;
i++) {
static constexpr float kTolerance
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
#define REPORTER_ASSERT(r, cond,...)
float nextRangeF(float min, float max)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
static float max(float r, float g, float b)
SINT bool isfinite(const Vec< N, T > &v)
SIN Vec< N, float > trunc(const Vec< N, float > &x)
SINT T dot(const Vec< N, T > &a, const Vec< N, T > &b)
SIT Vec< 1, T > if_then_else(const Vec< 1, M< T > > &cond, const Vec< 1, T > &t, const Vec< 1, T > &e)
Vec< 16, uint8_t > byte16
SINT Vec< N, T > naive_if_then_else(const Vec< N, M< T > > &cond, const Vec< N, T > &t, const Vec< N, T > &e)
SIN Vec< N, float > round(const Vec< N, float > &x)
SIT void strided_load4(const T *v, Vec< 1, T > &a, Vec< 1, T > &b, Vec< 1, T > &c, Vec< 1, T > &d)
SIN Vec< N, float > abs(const Vec< N, float > &x)
SIT void strided_load2(const T *v, Vec< 1, T > &a, Vec< 1, T > &b)
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
SIN Vec< N, float > normalize(const Vec< N, float > &v)
SINT Vec< 2 *N, T > join(const Vec< N, T > &lo, const Vec< N, T > &hi)
SIN Vec< N, uint16_t > mull(const Vec< N, uint8_t > &x, const Vec< N, uint8_t > &y)
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, uint16_t > to_half(const Vec< N, float > &x)
SIT bool all(const Vec< 1, T > &x)
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)
SIT T max(const Vec< 1, T > &x)
SIT T min(const Vec< 1, T > &x)
void check_strided_loads(skiatest::Reporter *r)
SIN Vec< N, float > floor(const Vec< N, float > &x)
SIT bool any(const Vec< 1, T > &x)
SIN Vec< N, float > ceil(const Vec< N, float > &x)
SIN float length(const Vec< N, float > &v)
SIN Vec< N, uint8_t > approx_scale(const Vec< N, uint8_t > &x, const Vec< N, uint8_t > &y)
SIT T cross(const Vec< 2, T > &a, const Vec< 2, T > &b)
SINT Vec< N, T > pin(const Vec< N, T > &x, const Vec< N, T > &lo, const Vec< N, T > &hi)
static float CrossProduct(const SkVector &a, const SkVector &b)
static float DotProduct(const SkVector &a, const SkVector &b)
static constexpr SkPoint Make(float x, float y)
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
SKVX_ALWAYS_INLINE void store(void *ptr) const