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

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

Issue 105893003: NEON fast path for box blur (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: remove useless prefetch. 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
« gm/imageblur.cpp ('K') | « gm/imageblur.cpp ('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
1 /* 1 /*
2 * Copyright 2013 The Android Open Source Project 2 * Copyright 2013 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkBlurImage_opts.h" 11 #include "SkBlurImage_opts.h"
12 #include "SkRect.h" 12 #include "SkRect.h"
13 13
14 #include <arm_neon.h> 14 #include <arm_neon.h>
15 15
16 namespace { 16 namespace {
17 17
18 enum BlurDirection { 18 enum BlurDirection {
19 kX, kY 19 kX, kY
20 }; 20 };
21 21
22 /** 22 /**
23 * Helper function to load 2 pixels from diffent rows to a 8x8 NEON register
24 * and also pre-load pixels for future read
25 */
26 template<BlurDirection srcDirection>
27 inline uint8x8_t load_2_pixels(const SkPMColor* src, int srcStride) {
28 if (srcDirection == kX) {
29 uint32x2_t temp = vdup_n_u32(0);
30 // 10% faster by add these 2 prefetches
Stephen White 2013/12/19 15:27:03 Nit: add -> adding
zheng.xu 2013/12/20 04:29:54 Done.
31 SK_PREFETCH(src + 16);
32 SK_PREFETCH(src + srcStride + 16);
33 return vreinterpret_u8_u32(vld1_lane_u32(src + srcStride, vld1_lane_u32( src, temp, 0), 1));
34 }
35 }
36
37 /**
38 * Helper function to store the low 8-bits from a 16x8 NEON register to 2 rows
39 */
40 template<BlurDirection dstDirection>
41 inline void store_2_pixels(uint16x8_t result16x8, SkPMColor* dst, int dstStride) {
42 if (dstDirection == kX) {
43 uint32x2_t temp = vreinterpret_u32_u8(vmovn_u16(result16x8));
44 vst1_lane_u32(dst, temp, 0);
45 vst1_lane_u32(dst + dstStride, temp, 1);
46 } else {
47 uint8x8_t temp = vmovn_u16(result16x8);
48 vst1_u8((uint8_t*)dst, temp);
49 }
50 }
51
52 /**
53 * fast path for kernel size less than 128
54 */
55 template<BlurDirection srcDirection, BlurDirection dstDirection>
56 void SkDoubleRowBoxBlur_NEON(const SkPMColor** src, int srcStride, SkPMColor** d st, int kernelSize,
57 int leftOffset, int rightOffset, int width, int* height)
58 {
59 const int rightBorder = SkMin32(rightOffset + 1, width);
60 const int srcStrideX = srcDirection == kX ? 1 : srcStride;
61 const int dstStrideX = dstDirection == kX ? 1 : *height;
62 const int srcStrideY = srcDirection == kX ? srcStride : 1;
63 const int dstStrideY = dstDirection == kX ? width : 1;
64 const uint16x8_t scale = vdupq_n_u16((1 << 15) / kernelSize);
65
66 for (; *height >= 2; *height -= 2) {
67 uint16x8_t sum = vdupq_n_u16(0);
68 const SkPMColor* p = *src;
69 for (int i = 0; i < rightBorder; i++) {
70 sum = vaddw_u8(sum,
71 load_2_pixels<srcDirection>(p, srcStride));
72 p += srcStrideX;
73 }
74
75 const SkPMColor* sptr = *src;
76 SkPMColor* dptr = *dst;
77 for (int x = 0; x < width; x++) {
78 // val = (sum * scale * 2 + 0x8000) >> 16
79 uint16x8_t resultPixels = vreinterpretq_u16_s16(vqrdmulhq_s16(
80 vreinterpretq_s16_u16(sum), vreinterpretq_s16_u16(scale)));
81 store_2_pixels<dstDirection>(resultPixels, dptr, width);
82
83 if (x >= leftOffset) {
84 sum = vsubw_u8(sum,
85 load_2_pixels<srcDirection>(sptr - leftOffset * srcStrideX, srcStride));
86 }
87 if (x + rightOffset + 1 < width) {
88 sum = vaddw_u8(sum,
89 load_2_pixels<srcDirection>(sptr + (rightOffset + 1) * srcSt rideX, srcStride));
90 }
91 sptr += srcStrideX;
92 dptr += dstStrideX;
93 }
94 *src += srcStrideY * 2;
95 *dst += dstStrideY * 2;
96 }
97 }
98
99
100 /**
23 * Helper function to spread the components of a 32-bit integer into the 101 * Helper function to spread the components of a 32-bit integer into the
24 * lower 8 bits of each 16-bit element of a NEON register. 102 * lower 8 bits of each 16-bit element of a NEON register.
25 */ 103 */
26 104
27 static inline uint16x4_t expand(uint32_t a) { 105 static inline uint16x4_t expand(uint32_t a) {
28 // ( ARGB ) -> ( ARGB ARGB ) -> ( A R G B A R G B ) 106 // ( ARGB ) -> ( ARGB ARGB ) -> ( A R G B A R G B )
29 uint8x8_t v8 = vreinterpret_u8_u32(vdup_n_u32(a)); 107 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 ) 108 // ( A R G B A R G B ) -> ( 0A 0R 0G 0B 0A 0R 0G 0B ) -> ( 0A 0R 0G 0B )
31 return vget_low_u16(vmovl_u8(v8)); 109 return vget_low_u16(vmovl_u8(v8));
32 } 110 }
33 111
34 template<BlurDirection srcDirection, BlurDirection dstDirection> 112 template<BlurDirection srcDirection, BlurDirection dstDirection>
35 void SkBoxBlur_NEON(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize, 113 void SkBoxBlur_NEON(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize,
36 int leftOffset, int rightOffset, int width, int height) 114 int leftOffset, int rightOffset, int width, int height)
37 { 115 {
38 const int rightBorder = SkMin32(rightOffset + 1, width); 116 const int rightBorder = SkMin32(rightOffset + 1, width);
39 const int srcStrideX = srcDirection == kX ? 1 : srcStride; 117 const int srcStrideX = srcDirection == kX ? 1 : srcStride;
40 const int dstStrideX = dstDirection == kX ? 1 : height; 118 const int dstStrideX = dstDirection == kX ? 1 : height;
41 const int srcStrideY = srcDirection == kX ? srcStride : 1; 119 const int srcStrideY = srcDirection == kX ? srcStride : 1;
42 const int dstStrideY = dstDirection == kX ? width : 1; 120 const int dstStrideY = dstDirection == kX ? width : 1;
43 const uint32x4_t scale = vdupq_n_u32((1 << 24) / kernelSize); 121 const uint32x4_t scale = vdupq_n_u32((1 << 24) / kernelSize);
44 const uint32x4_t half = vdupq_n_u32(1 << 23); 122 const uint32x4_t half = vdupq_n_u32(1 << 23);
45 for (int y = 0; y < height; ++y) { 123
124 if (kernelSize < 128)
125 {
126 SkDoubleRowBoxBlur_NEON<srcDirection, dstDirection>(&src, srcStride, &ds t, kernelSize,
127 leftOffset, rightOffset, width, &height);
128 }
129
130 for (; height > 0; height--) {
46 uint32x4_t sum = vdupq_n_u32(0); 131 uint32x4_t sum = vdupq_n_u32(0);
47 const SkPMColor* p = src; 132 const SkPMColor* p = src;
48 for (int i = 0; i < rightBorder; ++i) { 133 for (int i = 0; i < rightBorder; ++i) {
49 sum = vaddw_u16(sum, expand(*p)); 134 sum = vaddw_u16(sum, expand(*p));
50 p += srcStrideX; 135 p += srcStrideX;
51 } 136 }
52 137
53 const SkPMColor* sptr = src; 138 const SkPMColor* sptr = src;
54 SkPMColor* dptr = dst; 139 SkPMColor* dptr = dst;
55 for (int x = 0; x < width; ++x) { 140 for (int x = 0; x < width; ++x) {
(...skipping 14 matching lines...) Expand all
70 155
71 if (x >= leftOffset) { 156 if (x >= leftOffset) {
72 const SkPMColor* l = sptr - leftOffset * srcStrideX; 157 const SkPMColor* l = sptr - leftOffset * srcStrideX;
73 sum = vsubw_u16(sum, expand(*l)); 158 sum = vsubw_u16(sum, expand(*l));
74 } 159 }
75 if (x + rightOffset + 1 < width) { 160 if (x + rightOffset + 1 < width) {
76 const SkPMColor* r = sptr + (rightOffset + 1) * srcStrideX; 161 const SkPMColor* r = sptr + (rightOffset + 1) * srcStrideX;
77 sum = vaddw_u16(sum, expand(*r)); 162 sum = vaddw_u16(sum, expand(*r));
78 } 163 }
79 sptr += srcStrideX; 164 sptr += srcStrideX;
80 if (srcDirection == kY) { 165 if (srcDirection == kX) {
81 SK_PREFETCH(sptr + (rightOffset + 1) * srcStrideX); 166 SK_PREFETCH(sptr + (rightOffset + 16) * srcStrideX);
82 } 167 }
83 dptr += dstStrideX; 168 dptr += dstStrideX;
84 } 169 }
85 src += srcStrideY; 170 src += srcStrideY;
86 dst += dstStrideY; 171 dst += dstStrideY;
87 } 172 }
88 } 173 }
89 174
90 } // namespace 175 } // namespace
91 176
92 bool SkBoxBlurGetPlatformProcs_NEON(SkBoxBlurProc* boxBlurX, 177 bool SkBoxBlurGetPlatformProcs_NEON(SkBoxBlurProc* boxBlurX,
93 SkBoxBlurProc* boxBlurY, 178 SkBoxBlurProc* boxBlurY,
94 SkBoxBlurProc* boxBlurXY, 179 SkBoxBlurProc* boxBlurXY,
95 SkBoxBlurProc* boxBlurYX) { 180 SkBoxBlurProc* boxBlurYX) {
96 *boxBlurX = SkBoxBlur_NEON<kX, kX>; 181 *boxBlurX = SkBoxBlur_NEON<kX, kX>;
97 *boxBlurY = SkBoxBlur_NEON<kY, kY>; 182 *boxBlurY = SkBoxBlur_NEON<kY, kY>;
98 *boxBlurXY = SkBoxBlur_NEON<kX, kY>; 183 *boxBlurXY = SkBoxBlur_NEON<kX, kY>;
99 *boxBlurYX = SkBoxBlur_NEON<kY, kX>; 184 *boxBlurYX = SkBoxBlur_NEON<kY, kX>;
100 return true; 185 return true;
101 } 186 }
OLDNEW
« gm/imageblur.cpp ('K') | « gm/imageblur.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698