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_neon.cpp

Issue 99933004: Implement a NEON version of the RGBA gaussian blur. This shows a 9-15% speedup on Nexus-10. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Moar vector comments Created 7 years 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
« no previous file with comments | « gyp/opts.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h"
12 #include "SkRect.h"
13
14 #include <arm_neon.h>
15
16 namespace {
17
18 enum BlurDirection {
19 kX, kY
20 };
21
22 /**
23 * Helper function to spread the components of a 32-bit integer into the
24 * lower 8 bits of each 32-bit element of a NEON register.
25 */
26
27 inline uint32x4_t expand(uint32_t a) {
28 // ( ARGB ) -> ( ARGB ARGB ) -> ( A R G B A R G B )
29 uint8x8_t v8 = vreinterpret_u8_u32(vdup_n_u32(a));
30 // ( A R G B A R G B ) -> ( 0A 0R 0G 0B 0A 0R 0G 0B ) -> ( 0A 0R 0G 0B )
31 const uint16x4_t v16 = vget_low_u16(vmovl_u8(v8));
32 // ( 0A 0R 0G 0B ) -> ( 000A 000R 000G 000B )
33 return vmovl_u16(v16);
34 }
35
36 template<BlurDirection srcDirection, BlurDirection dstDirection>
37 void SkBoxBlur_NEON(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize,
38 int leftOffset, int rightOffset, int width, int height)
39 {
40 const int rightBorder = SkMin32(rightOffset + 1, width);
41 const int srcStrideX = srcDirection == kX ? 1 : srcStride;
42 const int dstStrideX = dstDirection == kX ? 1 : height;
43 const int srcStrideY = srcDirection == kX ? srcStride : 1;
44 const int dstStrideY = dstDirection == kX ? width : 1;
45 const uint32x4_t scale = vdupq_n_u32((1 << 24) / kernelSize);
46 const uint32x4_t half = vdupq_n_u32(1 << 23);
47 for (int y = 0; y < height; ++y) {
48 uint32x4_t sum = vdupq_n_u32(0);
49 const SkPMColor* p = src;
50 for (int i = 0; i < rightBorder; ++i) {
51 sum = vaddq_u32(sum, expand(*p));
52 p += srcStrideX;
53 }
54
55 const SkPMColor* sptr = src;
56 SkPMColor* dptr = dst;
57 for (int x = 0; x < width; ++x) {
58 // ( half+sumA*scale half+sumR*scale half+sumG*scale half+sumB*scale )
59 uint32x4_t result = vmlaq_u32(half, sum, scale);
60
61 // Shift down to lower 8 bits of each element.
62 // ( AAAA RRRR GGGG BBBB ) -> ( 000A 000R 000G 000B )
63 result = vshrq_n_u32(result, 24);
64
65 // ( 000A 000R 000G 000B ) -> ( 0A 0R 0G 0B )
66 uint16x4_t result16 = vqmovn_u32(result);
67
68 // ( 0A 0R 0G 0B ) -> ( 0A 0R 0G 0B 0A 0R 0G 0B ) -> ( A R G B A R G B )
69 uint8x8_t result8 = vqmovn_u16(vcombine_u16(result16, result16));
70
71 // ( A R G B A R G B ) -> ( ARGB ARGB ) -> ( ARGB )
72 // Store low 32 bits to destination.
73 vst1_lane_u32(dptr, vreinterpret_u32_u8(result8), 0);
74 if (x >= leftOffset) {
75 const SkPMColor* l = sptr - leftOffset * srcStrideX;
76 sum = vsubq_u32(sum, expand(*l));
77 }
78 if (x + rightOffset + 1 < width) {
79 const SkPMColor* r = sptr + (rightOffset + 1) * srcStrideX;
80 sum = vaddq_u32(sum, expand(*r));
81 }
82 sptr += srcStrideX;
83 if (srcDirection == kY) {
84 SK_PREFETCH(sptr + (rightOffset + 1) * srcStrideX);
85 }
86 dptr += dstStrideX;
87 }
88 src += srcStrideY;
89 dst += dstStrideY;
90 }
91 }
92
93 } // namespace
94
95 bool SkBoxBlurGetPlatformProcs(SkBoxBlurProc* boxBlurX,
96 SkBoxBlurProc* boxBlurY,
97 SkBoxBlurProc* boxBlurXY,
98 SkBoxBlurProc* boxBlurYX) {
99 *boxBlurX = SkBoxBlur_NEON<kX, kX>;
100 *boxBlurY = SkBoxBlur_NEON<kY, kY>;
101 *boxBlurXY = SkBoxBlur_NEON<kX, kY>;
102 *boxBlurYX = SkBoxBlur_NEON<kY, kX>;
103 return true;
104 }
OLDNEW
« no previous file with comments | « gyp/opts.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698