aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-24 13:53:23 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-24 13:53:23 +0000
commit7866228f06e402d37f8fcab70a688e1f34c1d27b (patch)
treedf1b1281f4da1a2cf35fd4793bf34386393c62aa
parent060ef18d5c02029eade04961f4cf62068d72a68e (diff)
optimizations for D16 using SSE2 skia_bench -config 565 -match bitmap_8888_scale_filter -forceFilter 1 -repeat 30 The result I got on Android platform was below: w/o this optimization routine: D/skia ( 1868): running bench [640 480] bitmap_8888_scale_filter D/skia ( 1868): 565: cmsecs = 286.50 w/ with optimization: D/skia ( 1463): running bench [640 480] bitmap_8888_scale_filter D/skia ( 1463): 565: cmsecs = 186.80 The net gain is 34.80%. git-svn-id: http://skia.googlecode.com/svn/trunk@4729 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--bench/BitmapBench.cpp2
-rw-r--r--src/core/SkBitmapProcState.h2
-rw-r--r--src/opts/SkBitmapProcState_opts_SSE2.cpp133
-rw-r--r--src/opts/SkBitmapProcState_opts_SSE2.h3
-rw-r--r--src/opts/opts_check_SSE2.cpp4
5 files changed, 143 insertions, 1 deletions
diff --git a/bench/BitmapBench.cpp b/bench/BitmapBench.cpp
index 51dd47a94a..40a733d35a 100644
--- a/bench/BitmapBench.cpp
+++ b/bench/BitmapBench.cpp
@@ -251,7 +251,7 @@ static SkBenchmark* Fact6(void* p) { return new BitmapBench(p, true, SkBitmap::k
static SkBenchmark* Fact7(void* p) { return new BitmapBench(p, true, SkBitmap::kARGB_8888_Config, true, true); }
static SkBenchmark* Fact8(void* p) { return new BitmapBench(p, true, SkBitmap::kARGB_8888_Config, true, false); }
-// scale filter -> S32_opaque_D32_filter_DX_{SSE2,SSSE3}
+// scale filter -> S32_opaque_D32_filter_DX_{SSE2,SSSE3} and Fact9 is also for S32_D16_filter_DX_SSE2
static SkBenchmark* Fact9(void* p) { return new FilterBitmapBench(p, false, SkBitmap::kARGB_8888_Config, false, false, -1, -1, true, false, true); }
static SkBenchmark* Fact10(void* p) { return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, false, false, -1, -1, true, false, true); }
static SkBenchmark* Fact11(void* p) { return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, true, true, -1, -1, true, false, true); }
diff --git a/src/core/SkBitmapProcState.h b/src/core/SkBitmapProcState.h
index dc56138db0..e9951c801e 100644
--- a/src/core/SkBitmapProcState.h
+++ b/src/core/SkBitmapProcState.h
@@ -186,5 +186,7 @@ void ClampX_ClampY_filter_affine(const SkBitmapProcState& s,
uint32_t xy[], int count, int x, int y);
void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s,
uint32_t xy[], int count, int x, int y);
+void S32_D16_filter_DX(const SkBitmapProcState& s,
+ const uint32_t* xy, int count, uint16_t* colors);
#endif
diff --git a/src/opts/SkBitmapProcState_opts_SSE2.cpp b/src/opts/SkBitmapProcState_opts_SSE2.cpp
index 5cb432535d..4ec4ba87dc 100644
--- a/src/opts/SkBitmapProcState_opts_SSE2.cpp
+++ b/src/opts/SkBitmapProcState_opts_SSE2.cpp
@@ -632,3 +632,136 @@ void ClampX_ClampY_nofilter_affine_SSE2(const SkBitmapProcState& s,
fy += dy;
}
}
+
+/* SSE version of S32_D16_filter_DX_SSE2
+ * Definition is in section of "D16 functions for SRC == 8888" in SkBitmapProcState.cpp
+ * It combines S32_opaque_D32_filter_DX_SSE2 and SkPixel32ToPixel16
+ */
+void S32_D16_filter_DX_SSE2(const SkBitmapProcState& s,
+ const uint32_t* xy,
+ int count, uint16_t* colors) {
+ SkASSERT(count > 0 && colors != NULL);
+ SkASSERT(s.fDoFilter);
+ SkASSERT(s.fBitmap->config() == SkBitmap::kARGB_8888_Config);
+ SkASSERT(s.fBitmap->isOpaque());
+
+ SkPMColor dstColor, tmpColor;
+ const char* srcAddr = static_cast<const char*>(s.fBitmap->getPixels());
+ unsigned rb = s.fBitmap->rowBytes();
+ uint32_t XY = *xy++;
+ unsigned y0 = XY >> 14;
+ const uint32_t* row0 = reinterpret_cast<const uint32_t*>(srcAddr + (y0 >> 4) * rb);
+ const uint32_t* row1 = reinterpret_cast<const uint32_t*>(srcAddr + (XY & 0x3FFF) * rb);
+ unsigned subY = y0 & 0xF;
+
+ // ( 0, 0, 0, 0, 0, 0, 0, 16)
+ __m128i sixteen = _mm_cvtsi32_si128(16);
+
+ // ( 0, 0, 0, 0, 16, 16, 16, 16)
+ sixteen = _mm_shufflelo_epi16(sixteen, 0);
+
+ // ( 0, 0, 0, 0, 0, 0, 0, y)
+ __m128i allY = _mm_cvtsi32_si128(subY);
+
+ // ( 0, 0, 0, 0, y, y, y, y)
+ allY = _mm_shufflelo_epi16(allY, 0);
+
+ // ( 0, 0, 0, 0, 16-y, 16-y, 16-y, 16-y)
+ __m128i negY = _mm_sub_epi16(sixteen, allY);
+
+ // (16-y, 16-y, 16-y, 16-y, y, y, y, y)
+ allY = _mm_unpacklo_epi64(allY, negY);
+
+ // (16, 16, 16, 16, 16, 16, 16, 16 )
+ sixteen = _mm_shuffle_epi32(sixteen, 0);
+
+ // ( 0, 0, 0, 0, 0, 0, 0, 0)
+ __m128i zero = _mm_setzero_si128();
+
+ __m128i _m_shift_5 = _mm_set1_epi32((1<<5)-1);
+ __m128i _m_shift_6 = _mm_set1_epi32((1<<6)-1);
+ do {
+ uint32_t XX = *xy++; // x0:14 | 4 | x1:14
+ unsigned x0 = XX >> 18;
+ unsigned x1 = XX & 0x3FFF;
+
+ // (0, 0, 0, 0, 0, 0, 0, x)
+ __m128i allX = _mm_cvtsi32_si128((XX >> 14) & 0x0F);
+
+ // (0, 0, 0, 0, x, x, x, x)
+ allX = _mm_shufflelo_epi16(allX, 0);
+
+ // (x, x, x, x, x, x, x, x)
+ allX = _mm_shuffle_epi32(allX, 0);
+
+ // (16-x, 16-x, 16-x, 16-x, 16-x, 16-x, 16-x)
+ __m128i negX = _mm_sub_epi16(sixteen, allX);
+
+ // Load 4 samples (pixels).
+ __m128i a00 = _mm_cvtsi32_si128(row0[x0]);
+ __m128i a01 = _mm_cvtsi32_si128(row0[x1]);
+ __m128i a10 = _mm_cvtsi32_si128(row1[x0]);
+ __m128i a11 = _mm_cvtsi32_si128(row1[x1]);
+
+ // (0, 0, a00, a10)
+ __m128i a00a10 = _mm_unpacklo_epi32(a10, a00);
+
+ // Expand to 16 bits per component.
+ a00a10 = _mm_unpacklo_epi8(a00a10, zero);
+
+ // ((a00 * (16-y)), (a10 * y)).
+ a00a10 = _mm_mullo_epi16(a00a10, allY);
+
+ // (a00 * (16-y) * (16-x), a10 * y * (16-x)).
+ a00a10 = _mm_mullo_epi16(a00a10, negX);
+
+ // (0, 0, a01, a10)
+ __m128i a01a11 = _mm_unpacklo_epi32(a11, a01);
+
+ // Expand to 16 bits per component.
+ a01a11 = _mm_unpacklo_epi8(a01a11, zero);
+
+ // (a01 * (16-y)), (a11 * y)
+ a01a11 = _mm_mullo_epi16(a01a11, allY);
+
+ // (a01 * (16-y) * x), (a11 * y * x)
+ a01a11 = _mm_mullo_epi16(a01a11, allX);
+
+ // (a00*w00 + a01*w01, a10*w10 + a11*w11)
+ __m128i sum = _mm_add_epi16(a00a10, a01a11);
+
+ // (DC, a00*w00 + a01*w01)
+ __m128i shifted = _mm_shuffle_epi32(sum, 0xEE);
+
+ // (DC, a00*w00 + a01*w01 + a10*w10 + a11*w11)
+ sum = _mm_add_epi16(sum, shifted);
+
+ // Divide each 16 bit component by 256.
+ sum = _mm_srli_epi16(sum, 8);
+
+ // Pack lower 4 16 bit values of sum into lower 4 bytes.
+ sum = _mm_packus_epi16(sum, zero);
+
+ // Extract low int and store.
+ dstColor = _mm_cvtsi128_si32(sum);
+
+ //*colors++ = SkPixel32ToPixel16(dstColor);
+ // below is much faster than the above. It's tested for Android benchmark--Softweg
+ __m128i _m_temp1 = _mm_set1_epi32(dstColor);
+ __m128i _m_temp2 = _mm_srli_epi32(_m_temp1, 3);
+
+ unsigned int r32 = _mm_cvtsi128_si32(_m_temp2);
+ unsigned r = (r32 & ((1<<5) -1)) << 11;
+
+ _m_temp2 = _mm_srli_epi32(_m_temp2, 7);
+ unsigned int g32 = _mm_cvtsi128_si32(_m_temp2);
+ unsigned g = (g32 & ((1<<6) -1)) << 5;
+
+ _m_temp2 = _mm_srli_epi32(_m_temp2, 9);
+ unsigned int b32 = _mm_cvtsi128_si32(_m_temp2);
+ unsigned b = (b32 & ((1<<5) -1));
+
+ *colors++ = r | g | b;
+
+ } while (--count > 0);
+}
diff --git a/src/opts/SkBitmapProcState_opts_SSE2.h b/src/opts/SkBitmapProcState_opts_SSE2.h
index 3fdf69691f..46e35a0f96 100644
--- a/src/opts/SkBitmapProcState_opts_SSE2.h
+++ b/src/opts/SkBitmapProcState_opts_SSE2.h
@@ -25,3 +25,6 @@ void ClampX_ClampY_filter_affine_SSE2(const SkBitmapProcState& s,
uint32_t xy[], int count, int x, int y);
void ClampX_ClampY_nofilter_affine_SSE2(const SkBitmapProcState& s,
uint32_t xy[], int count, int x, int y);
+void S32_D16_filter_DX_SSE2(const SkBitmapProcState& s,
+ const uint32_t* xy,
+ int count, uint16_t* colors);
diff --git a/src/opts/opts_check_SSE2.cpp b/src/opts/opts_check_SSE2.cpp
index 711ee33e63..1a704b8057 100644
--- a/src/opts/opts_check_SSE2.cpp
+++ b/src/opts/opts_check_SSE2.cpp
@@ -124,6 +124,10 @@ void SkBitmapProcState::platformProcs() {
} else if (fSampleProc32 == S32_alpha_D32_filter_DX) {
fSampleProc32 = S32_alpha_D32_filter_DX_SSE2;
}
+
+ if (fSampleProc16 == S32_D16_filter_DX) {
+ fSampleProc16 = S32_D16_filter_DX_SSE2;
+ }
}
if (cachedHasSSSE3() || cachedHasSSE2()) {