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

Unified Diff: src/opts/SkColor_opts_SSE2.h

Issue 755573002: Cleanup with SkAlphaMulQ_SSE2() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix performance regression Created 6 years, 1 month 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/SkBlitRow_opts_SSE2.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/opts/SkColor_opts_SSE2.h
diff --git a/src/opts/SkColor_opts_SSE2.h b/src/opts/SkColor_opts_SSE2.h
index 741d1ab77732cdfb41c1a8f8a4aa2f8ca426484b..c1e41f02aee100b266ffea14957d863092177b39 100644
--- a/src/opts/SkColor_opts_SSE2.h
+++ b/src/opts/SkColor_opts_SSE2.h
@@ -42,24 +42,42 @@ static inline __m128i SkAlphaMulAlpha_SSE2(const __m128i& a,
return prod;
}
+static const __m128i rb_mask = _mm_set1_epi32(0x00FF00FF);
+static const __m128i ag_mask = _mm_set1_epi32(0xFF00FF00);
+
// Portable version SkAlphaMulQ is in SkColorPriv.h.
static inline __m128i SkAlphaMulQ_SSE2(const __m128i& c, const __m128i& scale) {
- __m128i mask = _mm_set1_epi32(0xFF00FF);
__m128i s = _mm_or_si128(_mm_slli_epi32(scale, 16), scale);
// uint32_t rb = ((c & mask) * scale) >> 8
- __m128i rb = _mm_and_si128(mask, c);
+ __m128i rb = _mm_and_si128(rb_mask, c);
rb = _mm_mullo_epi16(rb, s);
rb = _mm_srli_epi16(rb, 8);
// uint32_t ag = ((c >> 8) & mask) * scale
__m128i ag = _mm_srli_epi16(c, 8);
- ASSERT_EQ(ag, _mm_and_si128(mask, ag)); // ag = _mm_srli_epi16(c, 8) did this for us.
+ ASSERT_EQ(ag, _mm_and_si128(rb_mask, ag)); // ag = _mm_srli_epi16(c, 8) did this for us.
ag = _mm_mullo_epi16(ag, s);
// (rb & mask) | (ag & ~mask)
- ASSERT_EQ(rb, _mm_and_si128(mask, rb)); // rb = _mm_srli_epi16(rb, 8) did this for us.
- ag = _mm_andnot_si128(mask, ag);
+ ASSERT_EQ(rb, _mm_and_si128(rb_mask, rb)); // rb = _mm_srli_epi16(rb, 8) did this for us.
+ ag = _mm_and_si128(ag_mask, ag);
+ return _mm_or_si128(rb, ag);
+}
+
+// Fast path for SkAlphaMulQ_SSE2 with a constant scale factor.
+static inline __m128i SkAlphaMulQ_SSE2(const __m128i& c, const unsigned scale) {
+ __m128i s = _mm_set1_epi16(scale << 8); // Move scale factor to upper byte of word.
+
+ // With mulhi, red and blue values are already in the right place and
+ // don't need to be divided by 256.
+ __m128i rb = _mm_and_si128(rb_mask, c);
+ rb = _mm_mulhi_epu16(rb, s);
+
+ __m128i ag = _mm_and_si128(ag_mask, c);
+ ag = _mm_mulhi_epu16(ag, s); // Alpha and green values are in the higher byte of each word.
+ ag = _mm_and_si128(ag_mask, ag);
+
return _mm_or_si128(rb, ag);
}
« no previous file with comments | « src/opts/SkBlitRow_opts_SSE2.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698