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

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: 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
« expectations/gm/ignored-tests.txt ('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 adding these 2 prefetches
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 } else {
35 return vld1_u8((uint8_t*)src);
36 }
37 }
38
39 /**
40 * Helper function to store the low 8-bits from a 16x8 NEON register to 2 rows
41 */
42 template<BlurDirection dstDirection>
43 inline void store_2_pixels(uint16x8_t result16x8, SkPMColor* dst, int dstStride) {
44 if (dstDirection == kX) {
45 uint32x2_t temp = vreinterpret_u32_u8(vmovn_u16(result16x8));
46 vst1_lane_u32(dst, temp, 0);
47 vst1_lane_u32(dst + dstStride, temp, 1);
48 } else {
49 uint8x8_t temp = vmovn_u16(result16x8);
50 vst1_u8((uint8_t*)dst, temp);
51 }
52 }
53
54 /**
55 * fast path for kernel size less than 128
56 */
57 template<BlurDirection srcDirection, BlurDirection dstDirection>
58 void SkDoubleRowBoxBlur_NEON(const SkPMColor** src, int srcStride, SkPMColor** d st, int kernelSize,
59 int leftOffset, int rightOffset, int width, int* height)
60 {
61 const int rightBorder = SkMin32(rightOffset + 1, width);
62 const int srcStrideX = srcDirection == kX ? 1 : srcStride;
63 const int dstStrideX = dstDirection == kX ? 1 : *height;
64 const int srcStrideY = srcDirection == kX ? srcStride : 1;
65 const int dstStrideY = dstDirection == kX ? width : 1;
66 const uint16x8_t scale = vdupq_n_u16((1 << 15) / kernelSize);
67
68 for (; *height >= 2; *height -= 2) {
69 uint16x8_t sum = vdupq_n_u16(0);
70 const SkPMColor* p = *src;
71 for (int i = 0; i < rightBorder; i++) {
72 sum = vaddw_u8(sum,
73 load_2_pixels<srcDirection>(p, srcStride));
74 p += srcStrideX;
75 }
76
77 const SkPMColor* sptr = *src;
78 SkPMColor* dptr = *dst;
79 for (int x = 0; x < width; x++) {
80 // val = (sum * scale * 2 + 0x8000) >> 16
81 uint16x8_t resultPixels = vreinterpretq_u16_s16(vqrdmulhq_s16(
82 vreinterpretq_s16_u16(sum), vreinterpretq_s16_u16(scale)));
83 store_2_pixels<dstDirection>(resultPixels, dptr, width);
84
85 if (x >= leftOffset) {
86 sum = vsubw_u8(sum,
87 load_2_pixels<srcDirection>(sptr - leftOffset * srcStrideX, srcStride));
88 }
89 if (x + rightOffset + 1 < width) {
90 sum = vaddw_u8(sum,
91 load_2_pixels<srcDirection>(sptr + (rightOffset + 1) * srcSt rideX, srcStride));
92 }
93 sptr += srcStrideX;
94 dptr += dstStrideX;
95 }
96 *src += srcStrideY * 2;
97 *dst += dstStrideY * 2;
98 }
99 }
100
101
102 /**
23 * Helper function to spread the components of a 32-bit integer into the 103 * 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. 104 * lower 8 bits of each 16-bit element of a NEON register.
25 */ 105 */
26 106
27 static inline uint16x4_t expand(uint32_t a) { 107 static inline uint16x4_t expand(uint32_t a) {
28 // ( ARGB ) -> ( ARGB ARGB ) -> ( A R G B A R G B ) 108 // ( ARGB ) -> ( ARGB ARGB ) -> ( A R G B A R G B )
29 uint8x8_t v8 = vreinterpret_u8_u32(vdup_n_u32(a)); 109 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 ) 110 // ( 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)); 111 return vget_low_u16(vmovl_u8(v8));
32 } 112 }
33 113
34 template<BlurDirection srcDirection, BlurDirection dstDirection> 114 template<BlurDirection srcDirection, BlurDirection dstDirection>
35 void SkBoxBlur_NEON(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize, 115 void SkBoxBlur_NEON(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize,
36 int leftOffset, int rightOffset, int width, int height) 116 int leftOffset, int rightOffset, int width, int height)
37 { 117 {
38 const int rightBorder = SkMin32(rightOffset + 1, width); 118 const int rightBorder = SkMin32(rightOffset + 1, width);
39 const int srcStrideX = srcDirection == kX ? 1 : srcStride; 119 const int srcStrideX = srcDirection == kX ? 1 : srcStride;
40 const int dstStrideX = dstDirection == kX ? 1 : height; 120 const int dstStrideX = dstDirection == kX ? 1 : height;
41 const int srcStrideY = srcDirection == kX ? srcStride : 1; 121 const int srcStrideY = srcDirection == kX ? srcStride : 1;
42 const int dstStrideY = dstDirection == kX ? width : 1; 122 const int dstStrideY = dstDirection == kX ? width : 1;
43 const uint32x4_t scale = vdupq_n_u32((1 << 24) / kernelSize); 123 const uint32x4_t scale = vdupq_n_u32((1 << 24) / kernelSize);
44 const uint32x4_t half = vdupq_n_u32(1 << 23); 124 const uint32x4_t half = vdupq_n_u32(1 << 23);
45 for (int y = 0; y < height; ++y) { 125
126 if (kernelSize < 128)
127 {
128 SkDoubleRowBoxBlur_NEON<srcDirection, dstDirection>(&src, srcStride, &ds t, kernelSize,
129 leftOffset, rightOffset, width, &height);
130 }
131
132 for (; height > 0; height--) {
46 uint32x4_t sum = vdupq_n_u32(0); 133 uint32x4_t sum = vdupq_n_u32(0);
47 const SkPMColor* p = src; 134 const SkPMColor* p = src;
48 for (int i = 0; i < rightBorder; ++i) { 135 for (int i = 0; i < rightBorder; ++i) {
49 sum = vaddw_u16(sum, expand(*p)); 136 sum = vaddw_u16(sum, expand(*p));
50 p += srcStrideX; 137 p += srcStrideX;
51 } 138 }
52 139
53 const SkPMColor* sptr = src; 140 const SkPMColor* sptr = src;
54 SkPMColor* dptr = dst; 141 SkPMColor* dptr = dst;
55 for (int x = 0; x < width; ++x) { 142 for (int x = 0; x < width; ++x) {
(...skipping 14 matching lines...) Expand all
70 157
71 if (x >= leftOffset) { 158 if (x >= leftOffset) {
72 const SkPMColor* l = sptr - leftOffset * srcStrideX; 159 const SkPMColor* l = sptr - leftOffset * srcStrideX;
73 sum = vsubw_u16(sum, expand(*l)); 160 sum = vsubw_u16(sum, expand(*l));
74 } 161 }
75 if (x + rightOffset + 1 < width) { 162 if (x + rightOffset + 1 < width) {
76 const SkPMColor* r = sptr + (rightOffset + 1) * srcStrideX; 163 const SkPMColor* r = sptr + (rightOffset + 1) * srcStrideX;
77 sum = vaddw_u16(sum, expand(*r)); 164 sum = vaddw_u16(sum, expand(*r));
78 } 165 }
79 sptr += srcStrideX; 166 sptr += srcStrideX;
80 if (srcDirection == kY) { 167 if (srcDirection == kX) {
81 SK_PREFETCH(sptr + (rightOffset + 1) * srcStrideX); 168 SK_PREFETCH(sptr + (rightOffset + 16) * srcStrideX);
82 } 169 }
83 dptr += dstStrideX; 170 dptr += dstStrideX;
84 } 171 }
85 src += srcStrideY; 172 src += srcStrideY;
86 dst += dstStrideY; 173 dst += dstStrideY;
87 } 174 }
88 } 175 }
89 176
90 } // namespace 177 } // namespace
91 178
92 bool SkBoxBlurGetPlatformProcs_NEON(SkBoxBlurProc* boxBlurX, 179 bool SkBoxBlurGetPlatformProcs_NEON(SkBoxBlurProc* boxBlurX,
93 SkBoxBlurProc* boxBlurY, 180 SkBoxBlurProc* boxBlurY,
94 SkBoxBlurProc* boxBlurXY, 181 SkBoxBlurProc* boxBlurXY,
95 SkBoxBlurProc* boxBlurYX) { 182 SkBoxBlurProc* boxBlurYX) {
96 *boxBlurX = SkBoxBlur_NEON<kX, kX>; 183 *boxBlurX = SkBoxBlur_NEON<kX, kX>;
97 *boxBlurY = SkBoxBlur_NEON<kY, kY>; 184 *boxBlurY = SkBoxBlur_NEON<kY, kY>;
98 *boxBlurXY = SkBoxBlur_NEON<kX, kY>; 185 *boxBlurXY = SkBoxBlur_NEON<kX, kY>;
99 *boxBlurYX = SkBoxBlur_NEON<kY, kX>; 186 *boxBlurYX = SkBoxBlur_NEON<kY, kX>;
100 return true; 187 return true;
101 } 188 }
OLDNEW
« expectations/gm/ignored-tests.txt ('K') | « gm/imageblur.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698