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

Side by Side Diff: src/opts/SkBlurImage_opts_SSE2.cpp

Issue 61643011: SSE2 implementation of RGBA box blurs. This yields ~2X perf improvement on (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Add a reinterpret_cast to please MSC. Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 enum BlurDirection {
mtklein 2013/11/08 18:42:34 namespace {} around the enum and template?
Stephen White 2013/11/08 20:20:49 Done.
17 kX, kY
18 };
19
20 template<BlurDirection srcDirection, BlurDirection dstDirection>
21 void SkBoxBlur_SSE2(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize,
22 int leftOffset, int rightOffset, int width, int height)
mtklein 2013/11/08 18:42:34 funky indent
Stephen White 2013/11/08 20:20:49 Fixed.
23 {
24 int rightBorder = SkMin32(rightOffset + 1, width);
mtklein 2013/11/08 18:42:34 in the interest of readability, can you sprinkle c
Stephen White 2013/11/08 20:20:49 I usually find it's just noise, but ok. Done.
25 int srcStrideX = srcDirection == kX ? 1 : srcStride;
26 int dstStrideX = dstDirection == kX ? 1 : height;
27 int srcStrideY = srcDirection == kX ? srcStride : 1;
28 int dstStrideY = dstDirection == kX ? width : 1;
29 __m128i scale = _mm_set1_epi32((1 << 24) / kernelSize);
mtklein 2013/11/08 18:42:34 If I'm thinking right, this is the limiting factor
Stephen White 2013/11/08 20:20:49 There is no integer divide in SSE2. You're right
mtklein 2013/11/08 20:37:35 Duh. SGTM
30 __m128i half = _mm_set1_epi32(1 << 23);
31 __m128i zero = _mm_setzero_si128();
32 for (int y = 0; y < height; ++y) {
33 __m128i sum = zero;
34 const SkPMColor* p = src;
35 for (int i = 0; i < rightBorder; ++i) {
36 __m128i expanded = _mm_cvtsi32_si128(*p);
37 expanded = _mm_unpacklo_epi8(expanded, zero);
mtklein 2013/11/08 18:42:34 Can you narrate a little for folks who don't speak
Stephen White 2013/11/08 20:20:49 Done.
38 expanded = _mm_unpacklo_epi16(expanded, zero);
39 sum = _mm_add_epi32(sum, expanded);
40 p += srcStrideX;
41 }
42
43 const SkPMColor* sptr = src;
44 SkColor* dptr = dst;
45 for (int x = 0; x < width; ++x) {
46 __m128i tmp1 = _mm_mul_epu32(sum, scale);
mtklein 2013/11/08 18:42:34 So, I'd following along right there with you if th
Stephen White 2013/11/08 20:20:49 Those 7 instructions are an unfortunate side-effec
47 __m128i tmp2 = _mm_mul_epu32(_mm_srli_si128(sum, 4),
48 _mm_srli_si128(scale, 4));
49 __m128i result = _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUF FLE(0,0,2,0)),
50 _mm_shuffle_epi32(tmp2, _MM_SHUF FLE(0,0,2,0)));
51 result = _mm_add_epi32(result, half);
52 result = _mm_srli_epi32(result, 24);
53 result = _mm_packs_epi32(result, zero);
mtklein 2013/11/08 18:42:34 These two lines are // 000A 000R 000G 000B -> 0000
Stephen White 2013/11/08 20:20:49 Yep, comment added.
54 result = _mm_packus_epi16(result, zero);
55 *dptr = _mm_cvtsi128_si32(result);
56 if (x >= leftOffset) {
57 SkColor l = *(sptr - leftOffset * srcStrideX);
58 __m128i expanded = _mm_cvtsi32_si128(l);
59 expanded = _mm_unpacklo_epi8(expanded, zero);
60 expanded = _mm_unpacklo_epi16(expanded, zero);
61 sum = _mm_sub_epi32(sum, expanded);
62 }
63 if (x + rightOffset + 1 < width) {
64 SkColor r = *(sptr + (rightOffset + 1) * srcStrideX);
65 __m128i expanded = _mm_cvtsi32_si128(r);
66 expanded = _mm_unpacklo_epi8(expanded, zero);
67 expanded = _mm_unpacklo_epi16(expanded, zero);
68 sum = _mm_add_epi32(sum, expanded);
69 }
70 sptr += srcStrideX;
71 if (srcDirection == kY) {
72 _mm_prefetch(reinterpret_cast<const char*>(sptr + (rightOffset + 1) * srcStrideX), _MM_HINT_T0);
mtklein 2013/11/08 18:42:34 linebreak after the ,?
Stephen White 2013/11/08 20:20:49 Done.
73 }
74 dptr += dstStrideX;
75 }
76 src += srcStrideY;
77 dst += dstStrideY;
78 }
79 }
80
81 bool SkBoxBlurGetPlatformProcs_SSE2(SkBoxBlurProc* boxBlurX,
82 SkBoxBlurProc* boxBlurY,
83 SkBoxBlurProc* boxBlurXY) {
84 *boxBlurX = SkBoxBlur_SSE2<kX, kX>;
85 *boxBlurY = SkBoxBlur_SSE2<kY, kY>;
86 *boxBlurXY = SkBoxBlur_SSE2<kX, kY>;
87 return true;
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698