Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Unified Diff: src/opts/SkNx_sse.h

Issue 1685773002: Sk4f: add floor() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add a bench Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/opts/SkNx_neon.h ('k') | tests/SkNxTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/opts/SkNx_sse.h
diff --git a/src/opts/SkNx_sse.h b/src/opts/SkNx_sse.h
index 889253b9d8cfff1fbb56266863386190db3fec14..def7ba17191d9225f195bace7422a6d584c561a5 100644
--- a/src/opts/SkNx_sse.h
+++ b/src/opts/SkNx_sse.h
@@ -13,6 +13,17 @@
#define SKNX_IS_FAST
+// SSE 4.1 has _mm_floor_ps to floor 4 floats. We emulate it:
+// - round by adding (1<<23) with our sign, then subtracting it;
+// - if that rounded value is bigger than our input, subtract 1.
+static inline __m128 sse2_mm_floor_ps(__m128 v) {
+ __m128 sign = _mm_and_ps(v, _mm_set1_ps(-0.0f));
+ __m128 bias = _mm_or_ps(sign, _mm_set1_ps(1<<23));
+ __m128 rounded = _mm_sub_ps(_mm_add_ps(v, bias), bias);
+ __m128 too_big = _mm_cmpgt_ps(rounded, v);
+ return _mm_sub_ps(rounded, _mm_and_ps(too_big, _mm_set1_ps(1.0f)));
+}
+
template <>
class SkNx<2, float> {
public:
@@ -92,6 +103,7 @@ public:
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 floor() const { return sse2_mm_floor_ps(fVec); }
SkNx sqrt () const { return _mm_sqrt_ps (fVec); }
SkNx rsqrt0() const { return _mm_rsqrt_ps(fVec); }
« no previous file with comments | « src/opts/SkNx_neon.h ('k') | tests/SkNxTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698