aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/opts
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-05-06 13:22:02 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-05-06 13:22:02 -0700
commite0cab96599764f7611de015f558a6b22162c3eda (patch)
treef08d1532ab8414bccaccfe7b298ee22c65a9927a /src/opts
parent0ce02c3ac1ff412b14c275eaf918acd88b3f0774 (diff)
Really use SSE4 (and SSSE3) in SkBlurImage_SSE4
We don't seem to be making good use of the available instruction set. SSE4.1 gives us an easy way to unpack a pixel into an __m128i, and SSSE3 gave us an easy way to do the reverse. This should be bit-perfect and about a 10% speedup. BUG=skia: Review URL: https://codereview.chromium.org/1123263003
Diffstat (limited to 'src/opts')
-rw-r--r--src/opts/SkBlurImage_opts_SSE4.cpp37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/opts/SkBlurImage_opts_SSE4.cpp b/src/opts/SkBlurImage_opts_SSE4.cpp
index 81748af7b2..1359d04f1d 100644
--- a/src/opts/SkBlurImage_opts_SSE4.cpp
+++ b/src/opts/SkBlurImage_opts_SSE4.cpp
@@ -27,16 +27,11 @@ enum BlurDirection {
* lower 8 bits of each 32-bit element of an SSE register.
*/
inline __m128i expand(int a) {
- const __m128i zero = _mm_setzero_si128();
-
- // 0 0 0 0 0 0 0 0 0 0 0 0 A R G B
- __m128i result = _mm_cvtsi32_si128(a);
-
- // 0 0 0 0 0 0 0 0 0 A 0 R 0 G 0 B
- result = _mm_unpacklo_epi8(result, zero);
-
- // 0 0 0 A 0 0 0 R 0 0 0 G 0 0 0 B
- return _mm_unpacklo_epi16(result, zero);
+ // ARGB -> 0000 0000 0000 ARGB
+ __m128i widened = _mm_cvtsi32_si128(a);
+ // SSE4.1 has xxxx xxxx xxxx ARGB -> 000A 000R 000G 000B as a one-stop-shop instruction.
+ // It can even work from memory, so a smart compiler probably merges in the _mm_cvtsi32_si128().
+ return _mm_cvtepu8_epi32(widened);
}
template<BlurDirection srcDirection, BlurDirection dstDirection>
@@ -50,9 +45,8 @@ void SkBoxBlur_SSE4(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker
const int dstStrideY = dstDirection == kX ? width : 1;
const __m128i scale = _mm_set1_epi32((1 << 24) / kernelSize);
const __m128i half = _mm_set1_epi32(1 << 23);
- const __m128i zero = _mm_setzero_si128();
for (int y = 0; y < height; ++y) {
- __m128i sum = zero;
+ __m128i sum = _mm_setzero_si128();
const SkPMColor* p = src;
for (int i = 0; i < rightBorder; ++i) {
sum = _mm_add_epi32(sum, expand(*p));
@@ -62,20 +56,20 @@ void SkBoxBlur_SSE4(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker
const SkPMColor* sptr = src;
SkColor* dptr = dst;
for (int x = 0; x < width; ++x) {
- __m128i result = _mm_mullo_epi32(sum, scale);
+ // TODO(mtklein): We are working in 8.24 here. Drop to 8.8 when the kernel is narrow?
- // sumA*scale+.5 sumB*scale+.5 sumG*scale+.5 sumB*scale+.5
+ // Multiply each component by scale (i.e. divide by kernel size) and add half to round.
+ __m128i result = _mm_mullo_epi32(sum, scale);
result = _mm_add_epi32(result, half);
- // 0 0 0 A 0 0 0 R 0 0 0 G 0 0 0 B
- result = _mm_srli_epi32(result, 24);
-
- // 0 0 0 0 0 0 0 0 0 A 0 R 0 G 0 B
- result = _mm_packs_epi32(result, zero);
+ // Now pack the top byte of each 32-bit lane back down into one 32-bit color.
+ // Axxx Rxxx Gxxx Bxxx -> xxxx xxxx xxxx ARGB
+ const char _ = 0; // Don't care what ends up in these bytes. Happens to be byte 0.
+ result = _mm_shuffle_epi8(result, _mm_set_epi8(_,_,_,_, _,_,_,_, _,_,_,_, 15,11,7,3));
- // 0 0 0 0 0 0 0 0 0 0 0 0 A R G B
- result = _mm_packus_epi16(result, zero);
*dptr = _mm_cvtsi128_si32(result);
+
+ // TODO(mtklein): experiment with breaking this loop into 3 parts
if (x >= leftOffset) {
SkColor l = *(sptr - leftOffset * srcStrideX);
sum = _mm_sub_epi32(sum, expand(l));
@@ -86,6 +80,7 @@ void SkBoxBlur_SSE4(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker
}
sptr += srcStrideX;
if (srcDirection == kY) {
+ // TODO(mtklein): experiment with moving this prefetch forward
_mm_prefetch(reinterpret_cast<const char*>(sptr + (rightOffset + 1) * srcStrideX),
_MM_HINT_T0);
}