aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2016-01-15 12:16:40 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-01-15 12:16:40 -0800
commitc33065a93ad0874672c4c66b9711aa0b3ef7b7e7 (patch)
tree835aab7ff1fd1c67dbe2d12c6914c37ce69846ad
parent98eb3d3776ba64099a19c92ab7aac4f2e323d857 (diff)
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
-rw-r--r--src/core/SkNx.h4
-rw-r--r--src/opts/SkNx_neon.h2
-rw-r--r--src/opts/SkNx_sse.h2
-rw-r--r--tests/SkNxTest.cpp8
4 files changed, 16 insertions, 0 deletions
diff --git a/src/core/SkNx.h b/src/core/SkNx.h
index 684a31dcef..2bbd495ce5 100644
--- a/src/core/SkNx.h
+++ b/src/core/SkNx.h
@@ -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(); }
diff --git a/src/opts/SkNx_neon.h b/src/opts/SkNx_neon.h
index 0955cb2b5b..c04f4d5f91 100644
--- a/src/opts/SkNx_neon.h
+++ b/src/opts/SkNx_neon.h
@@ -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;
diff --git a/src/opts/SkNx_sse.h b/src/opts/SkNx_sse.h
index b3f5091406..c6163b6a80 100644
--- a/src/opts/SkNx_sse.h
+++ b/src/opts/SkNx_sse.h
@@ -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(); }
diff --git a/tests/SkNxTest.cpp b/tests/SkNxTest.cpp
index 754e9800b1..fcd113d44d 100644
--- a/tests/SkNxTest.cpp
+++ b/tests/SkNxTest.cpp
@@ -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);
+}