add SkNx::abs(), for now only implemented for Sk4f

There's no reason we couldn't implement this for all ints and floats;
just don't want to land unused code.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1590843003
CQ_EXTRA_TRYBOTS=client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot

Review URL: https://codereview.chromium.org/1590843003
This commit is contained in:
mtklein 2016-01-15 12:16:40 -08:00 committed by Commit bot
parent 98eb3d3776
commit c33065a93a
4 changed files with 16 additions and 0 deletions

View File

@ -74,6 +74,8 @@ public:
return SkNx(SkNx<N/2, T>::Max(a.fLo, b.fLo), SkNx<N/2, T>::Max(a.fHi, b.fHi));
}
SkNx abs() const { return SkNx(fLo.abs(), fHi.abs()); }
SkNx sqrt() const { return SkNx(fLo.sqrt(), fHi.sqrt()); }
// Generally, increasing precision, increasing cost.
SkNx rsqrt0() const { return SkNx(fLo.rsqrt0(), fHi.rsqrt0()); }
@ -134,6 +136,8 @@ public:
static SkNx Min(const SkNx& a, const SkNx& b) { return SkNx(SkTMin(a.fVal, b.fVal)); }
static SkNx Max(const SkNx& a, const SkNx& b) { return SkNx(SkTMax(a.fVal, b.fVal)); }
SkNx abs() const { return SkTAbs(fVal); }
SkNx sqrt () const { return SkNx(Sqrt(fVal)); }
SkNx rsqrt0() const { return this->sqrt().invert(); }
SkNx rsqrt1() const { return this->rsqrt0(); }

View File

@ -187,6 +187,8 @@ public:
static SkNx Min(const SkNx& l, const SkNx& r) { return vminq_f32(l.fVec, r.fVec); }
static SkNx Max(const SkNx& l, const SkNx& r) { return vmaxq_f32(l.fVec, r.fVec); }
SkNx abs() const { return vabsq_f32(fVec); }
SkNx rsqrt0() const { return vrsqrteq_f32(fVec); }
SkNx rsqrt1() const {
float32x4_t est0 = this->rsqrt0().fVec;

View File

@ -176,6 +176,8 @@ public:
static SkNx Min(const SkNx& l, const SkNx& r) { return _mm_min_ps(l.fVec, r.fVec); }
static SkNx Max(const SkNx& l, const SkNx& r) { return _mm_max_ps(l.fVec, r.fVec); }
SkNx abs() const { return _mm_andnot_ps(_mm_set1_ps(-0.0f), fVec); }
SkNx sqrt() const { return _mm_sqrt_ps (fVec); }
SkNx rsqrt0() const { return _mm_rsqrt_ps(fVec); }
SkNx rsqrt1() const { return this->rsqrt0(); }

View File

@ -216,3 +216,11 @@ DEF_TEST(SkNx_cast, r) {
REPORTER_ASSERT(r, is.kth<2>() == 0);
REPORTER_ASSERT(r, is.kth<3>() == 1);
}
DEF_TEST(SkNx_abs, r) {
auto fs = Sk4f(0.0f, -0.0f, 2.0f, -4.0f).abs();
REPORTER_ASSERT(r, fs.kth<0>() == 0.0f);
REPORTER_ASSERT(r, fs.kth<1>() == 0.0f);
REPORTER_ASSERT(r, fs.kth<2>() == 2.0f);
REPORTER_ASSERT(r, fs.kth<3>() == 4.0f);
}