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

Unified Diff: src/opts/SkPMFloat_sse.h

Issue 1201343004: Convert SkPMFloat to [0,1] range and prune its API. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 6 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/SkPMFloat_none.h ('k') | tests/PMFloatTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/opts/SkPMFloat_sse.h
diff --git a/src/opts/SkPMFloat_sse.h b/src/opts/SkPMFloat_sse.h
new file mode 100644
index 0000000000000000000000000000000000000000..802b17ba0cc6e38b7ced3f4f45f0bcda1544929a
--- /dev/null
+++ b/src/opts/SkPMFloat_sse.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+namespace { // See SkPMFloat.h
+
+inline SkPMFloat::SkPMFloat(SkPMColor c) {
+ SkPMColorAssert(c);
+#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
+ const int _ = 255; // Zero these bytes.
+ __m128i fix8 = _mm_cvtsi32_si128((int)c),
+ fix8_32 = _mm_shuffle_epi8(fix8, _mm_setr_epi8(0,_,_,_, 1,_,_,_, 2,_,_,_, 3,_,_,_));
+#else
+ __m128i fix8 = _mm_cvtsi32_si128((int)c),
+ fix8_16 = _mm_unpacklo_epi8 (fix8, _mm_setzero_si128()),
+ fix8_32 = _mm_unpacklo_epi16(fix8_16, _mm_setzero_si128());
+#endif
+ fVec = _mm_mul_ps(_mm_cvtepi32_ps(fix8_32), _mm_set1_ps(1.0f / 255));
+ SkASSERT(this->isValid());
+}
+
+inline SkPMColor SkPMFloat::round() const {
+ // We don't use _mm_cvtps_epi32, because we want precise control over how 0.5 rounds (up).
+ __m128 scaled = _mm_mul_ps(_mm_set1_ps(255), fVec);
+ __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), scaled)),
+ fix8_16 = _mm_packus_epi16(fix8_32, fix8_32),
+ fix8 = _mm_packus_epi16(fix8_16, fix8_16);
+ SkPMColor c = _mm_cvtsi128_si32(fix8);
+ SkPMColorAssert(c);
+ return c;
+}
+
+} // namespace
« no previous file with comments | « src/opts/SkPMFloat_none.h ('k') | tests/PMFloatTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698