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

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

Issue 366593004: Add SSE4 version of BlurImage optimizations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Trying to set mac-flags to sse4 Created 6 years, 5 months 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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 The Android Open Source Project 2 * Copyright 2014 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 #include <emmintrin.h>
9 #include "SkBitmap.h" 8 #include "SkBitmap.h"
10 #include "SkBlurImage_opts_SSE2.h" 9 #include "SkBlurImage_opts_SSE4.h"
11 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
12 #include "SkRect.h" 11 #include "SkRect.h"
13 12
13 /* With the exception of the Android framework we always build the SSE4 function s
14 * and enable the caller to determine SSE4 support. However, for the Android fr amework,
15 * if the device does not support SSE4x then the compiler will not supply the re quired
16 * -msse4* option needed to build this file, so instead we provide a stub implem entation.
17 */
18 #if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) || SK_CPU_SSE_LEVEL >= SK_CPU_SSE_L EVEL_SSE41
19
20 #include <smmintrin.h>
21
14 namespace { 22 namespace {
15 enum BlurDirection { 23 enum BlurDirection {
16 kX, kY 24 kX, kY
17 }; 25 };
18 26
19 /* Helper function to spread the components of a 32-bit integer into the 27 /* Helper function to spread the components of a 32-bit integer into the
20 * lower 8 bits of each 32-bit element of an SSE register. 28 * lower 8 bits of each 32-bit element of an SSE register.
21 */ 29 */
22 inline __m128i expand(int a) { 30 inline __m128i expand(int a) {
23 const __m128i zero = _mm_setzero_si128(); 31 const __m128i zero = _mm_setzero_si128();
24 32
25 // 0 0 0 0 0 0 0 0 0 0 0 0 A R G B 33 // 0 0 0 0 0 0 0 0 0 0 0 0 A R G B
26 __m128i result = _mm_cvtsi32_si128(a); 34 __m128i result = _mm_cvtsi32_si128(a);
27 35
28 // 0 0 0 0 0 0 0 0 0 A 0 R 0 G 0 B 36 // 0 0 0 0 0 0 0 0 0 A 0 R 0 G 0 B
29 result = _mm_unpacklo_epi8(result, zero); 37 result = _mm_unpacklo_epi8(result, zero);
30 38
31 // 0 0 0 A 0 0 0 R 0 0 0 G 0 0 0 B 39 // 0 0 0 A 0 0 0 R 0 0 0 G 0 0 0 B
32 return _mm_unpacklo_epi16(result, zero); 40 return _mm_unpacklo_epi16(result, zero);
33 } 41 }
34 42
35 template<BlurDirection srcDirection, BlurDirection dstDirection> 43 template<BlurDirection srcDirection, BlurDirection dstDirection>
36 void SkBoxBlur_SSE2(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize, 44 void SkBoxBlur_SSE4(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize,
37 int leftOffset, int rightOffset, int width, int height) 45 int leftOffset, int rightOffset, int width, int height)
38 { 46 {
39 const int rightBorder = SkMin32(rightOffset + 1, width); 47 const int rightBorder = SkMin32(rightOffset + 1, width);
40 const int srcStrideX = srcDirection == kX ? 1 : srcStride; 48 const int srcStrideX = srcDirection == kX ? 1 : srcStride;
41 const int dstStrideX = dstDirection == kX ? 1 : height; 49 const int dstStrideX = dstDirection == kX ? 1 : height;
42 const int srcStrideY = srcDirection == kX ? srcStride : 1; 50 const int srcStrideY = srcDirection == kX ? srcStride : 1;
43 const int dstStrideY = dstDirection == kX ? width : 1; 51 const int dstStrideY = dstDirection == kX ? width : 1;
44 const __m128i scale = _mm_set1_epi32((1 << 24) / kernelSize); 52 const __m128i scale = _mm_set1_epi32((1 << 24) / kernelSize);
45 const __m128i half = _mm_set1_epi32(1 << 23); 53 const __m128i half = _mm_set1_epi32(1 << 23);
46 const __m128i zero = _mm_setzero_si128(); 54 const __m128i zero = _mm_setzero_si128();
47 for (int y = 0; y < height; ++y) { 55 for (int y = 0; y < height; ++y) {
48 __m128i sum = zero; 56 __m128i sum = zero;
49 const SkPMColor* p = src; 57 const SkPMColor* p = src;
50 for (int i = 0; i < rightBorder; ++i) { 58 for (int i = 0; i < rightBorder; ++i) {
51 sum = _mm_add_epi32(sum, expand(*p)); 59 sum = _mm_add_epi32(sum, expand(*p));
52 p += srcStrideX; 60 p += srcStrideX;
53 } 61 }
54 62
55 const SkPMColor* sptr = src; 63 const SkPMColor* sptr = src;
56 SkColor* dptr = dst; 64 SkColor* dptr = dst;
57 for (int x = 0; x < width; ++x) { 65 for (int x = 0; x < width; ++x) {
58 #if 0
59 // In SSE4.1, this would be
60 __m128i result = _mm_mullo_epi32(sum, scale); 66 __m128i result = _mm_mullo_epi32(sum, scale);
61 #else 67
62 // But SSE2 has no PMULLUD, so we must do AG and RB separately.
63 __m128i tmp1 = _mm_mul_epu32(sum, scale);
64 __m128i tmp2 = _mm_mul_epu32(_mm_srli_si128(sum, 4),
65 _mm_srli_si128(scale, 4));
66 __m128i result = _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUF FLE(0,0,2,0)),
67 _mm_shuffle_epi32(tmp2, _MM_SHUF FLE(0,0,2,0)));
68 #endif
69 // sumA*scale+.5 sumB*scale+.5 sumG*scale+.5 sumB*scale+.5 68 // sumA*scale+.5 sumB*scale+.5 sumG*scale+.5 sumB*scale+.5
70 result = _mm_add_epi32(result, half); 69 result = _mm_add_epi32(result, half);
71 70
72 // 0 0 0 A 0 0 0 R 0 0 0 G 0 0 0 B 71 // 0 0 0 A 0 0 0 R 0 0 0 G 0 0 0 B
73 result = _mm_srli_epi32(result, 24); 72 result = _mm_srli_epi32(result, 24);
74 73
75 // 0 0 0 0 0 0 0 0 0 A 0 R 0 G 0 B 74 // 0 0 0 0 0 0 0 0 0 A 0 R 0 G 0 B
76 result = _mm_packs_epi32(result, zero); 75 result = _mm_packs_epi32(result, zero);
77 76
78 // 0 0 0 0 0 0 0 0 0 0 0 0 A R G B 77 // 0 0 0 0 0 0 0 0 0 0 0 0 A R G B
(...skipping 14 matching lines...) Expand all
93 } 92 }
94 dptr += dstStrideX; 93 dptr += dstStrideX;
95 } 94 }
96 src += srcStrideY; 95 src += srcStrideY;
97 dst += dstStrideY; 96 dst += dstStrideY;
98 } 97 }
99 } 98 }
100 99
101 } // namespace 100 } // namespace
102 101
103 bool SkBoxBlurGetPlatformProcs_SSE2(SkBoxBlurProc* boxBlurX, 102 bool SkBoxBlurGetPlatformProcs_SSE4(SkBoxBlurProc* boxBlurX,
104 SkBoxBlurProc* boxBlurY, 103 SkBoxBlurProc* boxBlurY,
105 SkBoxBlurProc* boxBlurXY, 104 SkBoxBlurProc* boxBlurXY,
106 SkBoxBlurProc* boxBlurYX) { 105 SkBoxBlurProc* boxBlurYX) {
107 *boxBlurX = SkBoxBlur_SSE2<kX, kX>; 106 *boxBlurX = SkBoxBlur_SSE4<kX, kX>;
108 *boxBlurY = SkBoxBlur_SSE2<kY, kY>; 107 *boxBlurY = SkBoxBlur_SSE4<kY, kY>;
109 *boxBlurXY = SkBoxBlur_SSE2<kX, kY>; 108 *boxBlurXY = SkBoxBlur_SSE4<kX, kY>;
110 *boxBlurYX = SkBoxBlur_SSE2<kY, kX>; 109 *boxBlurYX = SkBoxBlur_SSE4<kY, kX>;
111 return true; 110 return true;
112 } 111 }
112
113 #else // !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) || SK_CPU_SSE_LEVEL >= SK_CPU_ SSE_LEVEL_SSE41
114
115 bool SkBoxBlurGetPlatformProcs_SSE4(SkBoxBlurProc* boxBlurX,
116 SkBoxBlurProc* boxBlurY,
117 SkBoxBlurProc* boxBlurXY,
118 SkBoxBlurProc* boxBlurYX) {
119 sk_throw();
120 }
121
122
123 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698