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

Unified Diff: src/opts/SkNx_sse.h

Issue 1682953002: Sk4f: floor() via int32_t roundtrip. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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') | no next file » | 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 def7ba17191d9225f195bace7422a6d584c561a5..7d00ddf9ba4722ef7ff1306e266f40099824cb18 100644
--- a/src/opts/SkNx_sse.h
+++ b/src/opts/SkNx_sse.h
@@ -14,14 +14,13 @@
#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.
+// - roundtrip through integers via truncation
+// - subtract 1 if that's too big (possible for negative values).
+// This restricts the domain of our inputs to a maximum somehwere around 2^31. Seems plenty big.
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)));
+ __m128 roundtrip = _mm_cvtepi32_ps(_mm_cvttps_epi32(v));
+ __m128 too_big = _mm_cmpgt_ps(roundtrip, v);
+ return _mm_sub_ps(roundtrip, _mm_and_ps(too_big, _mm_set1_ps(1.0f)));
}
template <>
« no previous file with comments | « src/opts/SkNx_neon.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698