Index: src/opts/SkBlurImage_opts_SSE2.cpp |
diff --git a/src/opts/SkBlurImage_opts_SSE2.cpp b/src/opts/SkBlurImage_opts_SSE2.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3a4c2ff00b0aef63a989ff84df657f739cffded5 |
--- /dev/null |
+++ b/src/opts/SkBlurImage_opts_SSE2.cpp |
@@ -0,0 +1,91 @@ |
+/* |
+ * Copyright 2013 The Android Open Source Project |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+ |
+#include "SkBitmap.h" |
+#include "SkColorPriv.h" |
+#include "SkBlurImage_opts_SSE2.h" |
+#include "SkRect.h" |
+ |
+#include <emmintrin.h> |
+ |
+template<SkBlurDirection srcDirection, SkBlurDirection dstDirection> |
+void SkBoxBlur_SSE2(const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize, |
+ int leftOffset, int rightOffset, int width, int height) |
+{ |
+ int rightBorder = SkMin32(rightOffset + 1, width); |
+ int srcStrideX = srcDirection == kX_BlurDirection ? 1 : srcStride; |
+ int dstStrideX = dstDirection == kX_BlurDirection ? 1 : height; |
+ int srcStrideY = srcDirection == kX_BlurDirection ? srcStride : 1; |
+ int dstStrideY = dstDirection == kX_BlurDirection ? width : 1; |
+ __m128i scale = _mm_set1_epi32((1 << 24) / kernelSize); |
+ __m128i half = _mm_set1_epi32(1 << 23); |
+ __m128i zero = _mm_setzero_si128(); |
+ for (int y = 0; y < height; ++y) { |
+ __m128i sum = zero; |
+ const SkPMColor* p = src; |
+ for (int i = 0; i < rightBorder; ++i) { |
+ __m128i expanded = _mm_cvtsi32_si128(*p); |
+ expanded = _mm_unpacklo_epi8(expanded, zero); |
+ expanded = _mm_unpacklo_epi16(expanded, zero); |
+ sum = _mm_add_epi32(sum, expanded); |
+ p += srcStrideX; |
+ } |
+ |
+ const SkPMColor* sptr = src; |
+ SkColor* dptr = dst; |
+ for (int x = 0; x < width; ++x) { |
+ __m128i tmp1 = _mm_mul_epu32(sum, scale); |
+ __m128i tmp2 = _mm_mul_epu32(_mm_srli_si128(sum, 4), |
+ _mm_srli_si128(scale, 4)); |
+ __m128i result = _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUFFLE(0,0,2,0)), |
+ _mm_shuffle_epi32(tmp2, _MM_SHUFFLE(0,0,2,0))); |
+ result = _mm_add_epi32(result, half); |
+ result = _mm_srli_epi32(result, 24); |
+ result = _mm_packs_epi32(result, zero); |
+ result = _mm_packus_epi16(result, zero); |
+ *dptr = _mm_cvtsi128_si32(result); |
+ if (x >= leftOffset) { |
+ SkColor l = *(sptr - leftOffset * srcStrideX); |
+ __m128i expanded = _mm_cvtsi32_si128(l); |
+ expanded = _mm_unpacklo_epi8(expanded, zero); |
+ expanded = _mm_unpacklo_epi16(expanded, zero); |
+ sum = _mm_sub_epi32(sum, expanded); |
+ } |
+ if (x + rightOffset + 1 < width) { |
+ SkColor r = *(sptr + (rightOffset + 1) * srcStrideX); |
+ __m128i expanded = _mm_cvtsi32_si128(r); |
+ expanded = _mm_unpacklo_epi8(expanded, zero); |
+ expanded = _mm_unpacklo_epi16(expanded, zero); |
+ sum = _mm_add_epi32(sum, expanded); |
+ } |
+ sptr += srcStrideX; |
+ if (srcDirection == kY_BlurDirection) { |
+ SK_PREFETCH(sptr + (rightOffset + 1) * srcStrideX); |
mtklein
2013/11/08 02:11:03
This reminds me, >=xmmintrin.h has _mm_prefetch, s
Stephen White
2013/11/08 15:47:47
Cool! Done. (I think it's better to do it explicit
mtklein
2013/11/08 18:42:33
Right. I was thinking rather the other way, that
|
+ } |
+ dptr += dstStrideX; |
+ } |
+ src += srcStrideY; |
+ dst += dstStrideY; |
+ } |
+} |
+ |
+template void SkBoxBlur_SSE2<kX_BlurDirection, kX_BlurDirection>( |
+ const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize, |
+ int leftOffset, int rightOffset, int width, int height); |
+ |
+template void SkBoxBlur_SSE2<kX_BlurDirection, kY_BlurDirection>( |
+ const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize, |
+ int leftOffset, int rightOffset, int width, int height); |
+ |
+template void SkBoxBlur_SSE2<kY_BlurDirection, kX_BlurDirection>( |
+ const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize, |
+ int leftOffset, int rightOffset, int width, int height); |
+ |
+template void SkBoxBlur_SSE2<kY_BlurDirection, kY_BlurDirection>( |
+ const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize, |
+ int leftOffset, int rightOffset, int width, int height); |