Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 The Android Open Source Project | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 | |
| 9 #include "SkBitmap.h" | |
| 10 #include "SkColorPriv.h" | |
| 11 #include "SkBlurImage_opts_SSE2.h" | |
| 12 #include "SkRect.h" | |
| 13 | |
| 14 #include <emmintrin.h> | |
| 15 | |
| 16 template<SkBlurDirection srcDirection, SkBlurDirection dstDirection> | |
| 17 void SkBoxBlur_SSE2(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize, | |
| 18 int leftOffset, int rightOffset, int width, int height) | |
| 19 { | |
| 20 int rightBorder = SkMin32(rightOffset + 1, width); | |
| 21 int srcStrideX = srcDirection == kX_BlurDirection ? 1 : srcStride; | |
| 22 int dstStrideX = dstDirection == kX_BlurDirection ? 1 : height; | |
| 23 int srcStrideY = srcDirection == kX_BlurDirection ? srcStride : 1; | |
| 24 int dstStrideY = dstDirection == kX_BlurDirection ? width : 1; | |
| 25 __m128i scale = _mm_set1_epi32((1 << 24) / kernelSize); | |
| 26 __m128i half = _mm_set1_epi32(1 << 23); | |
| 27 __m128i zero = _mm_setzero_si128(); | |
| 28 for (int y = 0; y < height; ++y) { | |
| 29 __m128i sum = zero; | |
| 30 const SkPMColor* p = src; | |
| 31 for (int i = 0; i < rightBorder; ++i) { | |
| 32 __m128i expanded = _mm_cvtsi32_si128(*p); | |
| 33 expanded = _mm_unpacklo_epi8(expanded, zero); | |
| 34 expanded = _mm_unpacklo_epi16(expanded, zero); | |
| 35 sum = _mm_add_epi32(sum, expanded); | |
| 36 p += srcStrideX; | |
| 37 } | |
| 38 | |
| 39 const SkPMColor* sptr = src; | |
| 40 SkColor* dptr = dst; | |
| 41 for (int x = 0; x < width; ++x) { | |
| 42 __m128i tmp1 = _mm_mul_epu32(sum, scale); | |
| 43 __m128i tmp2 = _mm_mul_epu32(_mm_srli_si128(sum, 4), | |
| 44 _mm_srli_si128(scale, 4)); | |
| 45 __m128i result = _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUF FLE(0,0,2,0)), | |
| 46 _mm_shuffle_epi32(tmp2, _MM_SHUF FLE(0,0,2,0))); | |
| 47 result = _mm_add_epi32(result, half); | |
| 48 result = _mm_srli_epi32(result, 24); | |
| 49 result = _mm_packs_epi32(result, zero); | |
| 50 result = _mm_packus_epi16(result, zero); | |
| 51 *dptr = _mm_cvtsi128_si32(result); | |
| 52 if (x >= leftOffset) { | |
| 53 SkColor l = *(sptr - leftOffset * srcStrideX); | |
| 54 __m128i expanded = _mm_cvtsi32_si128(l); | |
| 55 expanded = _mm_unpacklo_epi8(expanded, zero); | |
| 56 expanded = _mm_unpacklo_epi16(expanded, zero); | |
| 57 sum = _mm_sub_epi32(sum, expanded); | |
| 58 } | |
| 59 if (x + rightOffset + 1 < width) { | |
| 60 SkColor r = *(sptr + (rightOffset + 1) * srcStrideX); | |
| 61 __m128i expanded = _mm_cvtsi32_si128(r); | |
| 62 expanded = _mm_unpacklo_epi8(expanded, zero); | |
| 63 expanded = _mm_unpacklo_epi16(expanded, zero); | |
| 64 sum = _mm_add_epi32(sum, expanded); | |
| 65 } | |
| 66 sptr += srcStrideX; | |
| 67 if (srcDirection == kY_BlurDirection) { | |
| 68 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
| |
| 69 } | |
| 70 dptr += dstStrideX; | |
| 71 } | |
| 72 src += srcStrideY; | |
| 73 dst += dstStrideY; | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 template void SkBoxBlur_SSE2<kX_BlurDirection, kX_BlurDirection>( | |
| 78 const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize, | |
| 79 int leftOffset, int rightOffset, int width, int height); | |
| 80 | |
| 81 template void SkBoxBlur_SSE2<kX_BlurDirection, kY_BlurDirection>( | |
| 82 const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize, | |
| 83 int leftOffset, int rightOffset, int width, int height); | |
| 84 | |
| 85 template void SkBoxBlur_SSE2<kY_BlurDirection, kX_BlurDirection>( | |
| 86 const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize, | |
| 87 int leftOffset, int rightOffset, int width, int height); | |
| 88 | |
| 89 template void SkBoxBlur_SSE2<kY_BlurDirection, kY_BlurDirection>( | |
| 90 const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize, | |
| 91 int leftOffset, int rightOffset, int width, int height); | |
| OLD | NEW |