Xfermode: SSE2 implementation of multiply_modeproc
This patch implements basics for Xfermode SSE optimization. Based on these basics, SSE2 implementation of multiply_modeproc is provided. SSE2 implementation for other modes will come in future. With this patch performance of Xfermode_Multiply will improve about 45%. Here are the data on desktop i7-3770. before: Xfermode_Multiply 8888: cmsecs = 33.30 565: cmsecs = 45.65 after: Xfermode_Multiply 8888: cmsecs = 17.18 565: cmsecs = 24.87 BUG= R=mtklein@google.com Author: qiankun.miao@intel.com Review URL: https://codereview.chromium.org/202903004 git-svn-id: http://skia.googlecode.com/svn/trunk@14006 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
96050eb5a1
commit
25f7455f3a
@ -56,7 +56,7 @@
|
||||
'../src/opts/SkBlurImage_opts_SSE2.cpp',
|
||||
'../src/opts/SkMorphology_opts_SSE2.cpp',
|
||||
'../src/opts/SkUtils_opts_SSE2.cpp',
|
||||
'../src/opts/SkXfermode_opts_none.cpp',
|
||||
'../src/opts/SkXfermode_opts_SSE2.cpp',
|
||||
],
|
||||
}],
|
||||
[ 'skia_arch_type == "arm" and arm_version >= 7', {
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
|
||||
#include "SkXfermode.h"
|
||||
#include "SkXfermode_opts_SSE2.h"
|
||||
#include "SkXfermode_proccoeff.h"
|
||||
#include "SkColorPriv.h"
|
||||
#include "SkMathPriv.h"
|
||||
@ -1993,4 +1994,5 @@ SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode)
|
||||
#if !SK_ARM_NEON_IS_NONE
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkNEONProcCoeffXfermode)
|
||||
#endif
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSSE2ProcCoeffXfermode)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
|
||||
|
@ -914,7 +914,7 @@ void S32_D565_Opaque_SSE2(uint16_t* SK_RESTRICT dst,
|
||||
__m128i b = _mm_packs_epi32(b1, b2);
|
||||
|
||||
// Store 8 16-bit colors in dst.
|
||||
__m128i d_pixel = SkPackRGB16_SSE(r, g, b);
|
||||
__m128i d_pixel = SkPackRGB16_SSE2(r, g, b);
|
||||
_mm_store_si128(d++, d_pixel);
|
||||
count -= 8;
|
||||
}
|
||||
@ -983,54 +983,54 @@ void S32A_D565_Opaque_SSE2(uint16_t* SK_RESTRICT dst,
|
||||
__m128i dst_pixel = _mm_load_si128(d);
|
||||
|
||||
// Extract A from src.
|
||||
__m128i sa1 = _mm_slli_epi32(src_pixel1,(24 - SK_A32_SHIFT));
|
||||
__m128i sa1 = _mm_slli_epi32(src_pixel1, (24 - SK_A32_SHIFT));
|
||||
sa1 = _mm_srli_epi32(sa1, 24);
|
||||
__m128i sa2 = _mm_slli_epi32(src_pixel2,(24 - SK_A32_SHIFT));
|
||||
__m128i sa2 = _mm_slli_epi32(src_pixel2, (24 - SK_A32_SHIFT));
|
||||
sa2 = _mm_srli_epi32(sa2, 24);
|
||||
__m128i sa = _mm_packs_epi32(sa1, sa2);
|
||||
|
||||
// Extract R from src.
|
||||
__m128i sr1 = _mm_slli_epi32(src_pixel1,(24 - SK_R32_SHIFT));
|
||||
__m128i sr1 = _mm_slli_epi32(src_pixel1, (24 - SK_R32_SHIFT));
|
||||
sr1 = _mm_srli_epi32(sr1, 24);
|
||||
__m128i sr2 = _mm_slli_epi32(src_pixel2,(24 - SK_R32_SHIFT));
|
||||
__m128i sr2 = _mm_slli_epi32(src_pixel2, (24 - SK_R32_SHIFT));
|
||||
sr2 = _mm_srli_epi32(sr2, 24);
|
||||
__m128i sr = _mm_packs_epi32(sr1, sr2);
|
||||
|
||||
// Extract G from src.
|
||||
__m128i sg1 = _mm_slli_epi32(src_pixel1,(24 - SK_G32_SHIFT));
|
||||
__m128i sg1 = _mm_slli_epi32(src_pixel1, (24 - SK_G32_SHIFT));
|
||||
sg1 = _mm_srli_epi32(sg1, 24);
|
||||
__m128i sg2 = _mm_slli_epi32(src_pixel2,(24 - SK_G32_SHIFT));
|
||||
__m128i sg2 = _mm_slli_epi32(src_pixel2, (24 - SK_G32_SHIFT));
|
||||
sg2 = _mm_srli_epi32(sg2, 24);
|
||||
__m128i sg = _mm_packs_epi32(sg1, sg2);
|
||||
|
||||
// Extract B from src.
|
||||
__m128i sb1 = _mm_slli_epi32(src_pixel1,(24 - SK_B32_SHIFT));
|
||||
__m128i sb1 = _mm_slli_epi32(src_pixel1, (24 - SK_B32_SHIFT));
|
||||
sb1 = _mm_srli_epi32(sb1, 24);
|
||||
__m128i sb2 = _mm_slli_epi32(src_pixel2,(24 - SK_B32_SHIFT));
|
||||
__m128i sb2 = _mm_slli_epi32(src_pixel2, (24 - SK_B32_SHIFT));
|
||||
sb2 = _mm_srli_epi32(sb2, 24);
|
||||
__m128i sb = _mm_packs_epi32(sb1, sb2);
|
||||
|
||||
// Extract R G B from dst.
|
||||
__m128i dr = _mm_srli_epi16(dst_pixel,SK_R16_SHIFT);
|
||||
__m128i dr = _mm_srli_epi16(dst_pixel, SK_R16_SHIFT);
|
||||
dr = _mm_and_si128(dr, r16_mask);
|
||||
__m128i dg = _mm_srli_epi16(dst_pixel,SK_G16_SHIFT);
|
||||
__m128i dg = _mm_srli_epi16(dst_pixel, SK_G16_SHIFT);
|
||||
dg = _mm_and_si128(dg, g16_mask);
|
||||
__m128i db = _mm_srli_epi16(dst_pixel,SK_B16_SHIFT);
|
||||
__m128i db = _mm_srli_epi16(dst_pixel, SK_B16_SHIFT);
|
||||
db = _mm_and_si128(db, b16_mask);
|
||||
|
||||
__m128i isa = _mm_sub_epi16(var255, sa); // 255 -sa
|
||||
|
||||
// Calculate R G B of result.
|
||||
// Original algorithm is in SkSrcOver32To16().
|
||||
dr = _mm_add_epi16(sr, SkMul16ShiftRound_SSE(dr, isa, SK_R16_BITS));
|
||||
dr = _mm_add_epi16(sr, SkMul16ShiftRound_SSE2(dr, isa, SK_R16_BITS));
|
||||
dr = _mm_srli_epi16(dr, 8 - SK_R16_BITS);
|
||||
dg = _mm_add_epi16(sg, SkMul16ShiftRound_SSE(dg, isa, SK_G16_BITS));
|
||||
dg = _mm_add_epi16(sg, SkMul16ShiftRound_SSE2(dg, isa, SK_G16_BITS));
|
||||
dg = _mm_srli_epi16(dg, 8 - SK_G16_BITS);
|
||||
db = _mm_add_epi16(sb, SkMul16ShiftRound_SSE(db, isa, SK_B16_BITS));
|
||||
db = _mm_add_epi16(sb, SkMul16ShiftRound_SSE2(db, isa, SK_B16_BITS));
|
||||
db = _mm_srli_epi16(db, 8 - SK_B16_BITS);
|
||||
|
||||
// Pack R G B into 16-bit color.
|
||||
__m128i d_pixel = SkPackRGB16_SSE(dr, dg, db);
|
||||
__m128i d_pixel = SkPackRGB16_SSE2(dr, dg, db);
|
||||
|
||||
// Store 8 16-bit colors in dst.
|
||||
_mm_store_si128(d++, d_pixel);
|
||||
@ -1143,7 +1143,7 @@ void S32_D565_Opaque_Dither_SSE2(uint16_t* SK_RESTRICT dst,
|
||||
sb = _mm_srli_epi16(sb, SK_B32_BITS - SK_B16_BITS);
|
||||
|
||||
// Pack and store 16-bit dst pixel.
|
||||
__m128i d_pixel = SkPackRGB16_SSE(sr, sg, sb);
|
||||
__m128i d_pixel = SkPackRGB16_SSE2(sr, sg, sb);
|
||||
_mm_store_si128(d++, d_pixel);
|
||||
|
||||
count -= 8;
|
||||
@ -1242,9 +1242,9 @@ void S32A_D565_Opaque_Dither_SSE2(uint16_t* SK_RESTRICT dst,
|
||||
__m128i dst_pixel = _mm_load_si128(d);
|
||||
|
||||
// Extract A from src.
|
||||
__m128i sa1 = _mm_slli_epi32(src_pixel1,(24 - SK_A32_SHIFT));
|
||||
__m128i sa1 = _mm_slli_epi32(src_pixel1, (24 - SK_A32_SHIFT));
|
||||
sa1 = _mm_srli_epi32(sa1, 24);
|
||||
__m128i sa2 = _mm_slli_epi32(src_pixel2,(24 - SK_A32_SHIFT));
|
||||
__m128i sa2 = _mm_slli_epi32(src_pixel2, (24 - SK_A32_SHIFT));
|
||||
sa2 = _mm_srli_epi32(sa2, 24);
|
||||
__m128i sa = _mm_packs_epi32(sa1, sa2);
|
||||
|
||||
@ -1323,7 +1323,7 @@ void S32A_D565_Opaque_Dither_SSE2(uint16_t* SK_RESTRICT dst,
|
||||
db = _mm_srli_epi16(db, 5);
|
||||
|
||||
// Package and store dst pixel.
|
||||
__m128i d_pixel = SkPackRGB16_SSE(dr, dg, db);
|
||||
__m128i d_pixel = SkPackRGB16_SSE2(dr, dg, db);
|
||||
_mm_store_si128(d++, d_pixel);
|
||||
|
||||
count -= 8;
|
||||
|
@ -10,7 +10,38 @@
|
||||
|
||||
#include <emmintrin.h>
|
||||
|
||||
static inline __m128i SkMul16ShiftRound_SSE(__m128i a, __m128i b, int shift) {
|
||||
// See #define SkAlphaMulAlpha(a, b) SkMulDiv255Round(a, b) in SkXfermode.cpp.
|
||||
static inline __m128i SkAlphaMulAlpha_SSE2(__m128i a, __m128i b) {
|
||||
__m128i prod = _mm_mullo_epi16(a, b);
|
||||
prod = _mm_add_epi32(prod, _mm_set1_epi32(128));
|
||||
prod = _mm_add_epi32(prod, _mm_srli_epi32(prod, 8));
|
||||
prod = _mm_srli_epi32(prod, 8);
|
||||
|
||||
return prod;
|
||||
}
|
||||
|
||||
static inline __m128i SkGetPackedA32_SSE2(__m128i src) {
|
||||
__m128i a = _mm_slli_epi32(src, (24 - SK_A32_SHIFT));
|
||||
return _mm_srli_epi32(a, 24);
|
||||
}
|
||||
|
||||
static inline __m128i SkGetPackedR32_SSE2(__m128i src) {
|
||||
__m128i r = _mm_slli_epi32(src, (24 - SK_R32_SHIFT));
|
||||
return _mm_srli_epi32(r, 24);
|
||||
}
|
||||
|
||||
static inline __m128i SkGetPackedG32_SSE2(__m128i src) {
|
||||
__m128i g = _mm_slli_epi32(src, (24 - SK_G32_SHIFT));
|
||||
return _mm_srli_epi32(g, 24);
|
||||
}
|
||||
|
||||
static inline __m128i SkGetPackedB32_SSE2(__m128i src) {
|
||||
__m128i b = _mm_slli_epi32(src, (24 - SK_B32_SHIFT));
|
||||
return _mm_srli_epi32(b, 24);
|
||||
}
|
||||
|
||||
static inline __m128i SkMul16ShiftRound_SSE2(__m128i a,
|
||||
__m128i b, int shift) {
|
||||
__m128i prod = _mm_mullo_epi16(a, b);
|
||||
prod = _mm_add_epi16(prod, _mm_set1_epi16(1 << (shift - 1)));
|
||||
prod = _mm_add_epi16(prod, _mm_srli_epi16(prod, shift));
|
||||
@ -19,7 +50,7 @@ static inline __m128i SkMul16ShiftRound_SSE(__m128i a, __m128i b, int shift) {
|
||||
return prod;
|
||||
}
|
||||
|
||||
static inline __m128i SkPackRGB16_SSE(__m128i r, __m128i g, __m128i b) {
|
||||
static inline __m128i SkPackRGB16_SSE2(__m128i r, __m128i g, __m128i b) {
|
||||
r = _mm_slli_epi16(r, SK_R16_SHIFT);
|
||||
g = _mm_slli_epi16(g, SK_G16_SHIFT);
|
||||
b = _mm_slli_epi16(b, SK_B16_SHIFT);
|
||||
@ -28,4 +59,86 @@ static inline __m128i SkPackRGB16_SSE(__m128i r, __m128i g, __m128i b) {
|
||||
return _mm_or_si128(c, b);
|
||||
}
|
||||
|
||||
#endif//SkColor_opts_SSE2_DEFINED
|
||||
static inline __m128i SkPackARGB32_SSE2(__m128i a, __m128i r,
|
||||
__m128i g, __m128i b) {
|
||||
a = _mm_slli_epi32(a, SK_A32_SHIFT);
|
||||
r = _mm_slli_epi32(r, SK_R32_SHIFT);
|
||||
g = _mm_slli_epi32(g, SK_G32_SHIFT);
|
||||
b = _mm_slli_epi32(b, SK_B32_SHIFT);
|
||||
|
||||
__m128i c = _mm_or_si128(a, r);
|
||||
c = _mm_or_si128(c, g);
|
||||
return _mm_or_si128(c, b);
|
||||
}
|
||||
|
||||
static inline __m128i SkPacked16ToR32_SSE2(__m128i src) {
|
||||
__m128i r = _mm_srli_epi32(src, SK_R16_SHIFT);
|
||||
r = _mm_and_si128(r, _mm_set1_epi32(SK_R16_MASK));
|
||||
r = _mm_or_si128(_mm_slli_epi32(r, (8 - SK_R16_BITS)),
|
||||
_mm_srli_epi32(r, (2 * SK_R16_BITS - 8)));
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline __m128i SkPacked16ToG32_SSE2(__m128i src) {
|
||||
__m128i g = _mm_srli_epi32(src, SK_G16_SHIFT);
|
||||
g = _mm_and_si128(g, _mm_set1_epi32(SK_G16_MASK));
|
||||
g = _mm_or_si128(_mm_slli_epi32(g, (8 - SK_G16_BITS)),
|
||||
_mm_srli_epi32(g, (2 * SK_G16_BITS - 8)));
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
static inline __m128i SkPacked16ToB32_SSE2(__m128i src) {
|
||||
__m128i b = _mm_srli_epi32(src, SK_B16_SHIFT);
|
||||
b = _mm_and_si128(b, _mm_set1_epi32(SK_B16_MASK));
|
||||
b = _mm_or_si128(_mm_slli_epi32(b, (8 - SK_B16_BITS)),
|
||||
_mm_srli_epi32(b, (2 * SK_B16_BITS - 8)));
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
static inline __m128i SkPixel16ToPixel32_SSE2(__m128i src) {
|
||||
__m128i r = SkPacked16ToR32_SSE2(src);
|
||||
__m128i g = SkPacked16ToG32_SSE2(src);
|
||||
__m128i b = SkPacked16ToB32_SSE2(src);
|
||||
|
||||
return SkPackARGB32_SSE2(_mm_set1_epi32(0xFF), r, g, b);
|
||||
}
|
||||
|
||||
static inline __m128i SkPixel32ToPixel16_ToU16_SSE2(__m128i src_pixel1,
|
||||
__m128i src_pixel2) {
|
||||
// Calculate result r.
|
||||
__m128i r1 = _mm_srli_epi32(src_pixel1,
|
||||
SK_R32_SHIFT + (8 - SK_R16_BITS));
|
||||
r1 = _mm_and_si128(r1, _mm_set1_epi32(SK_R16_MASK));
|
||||
__m128i r2 = _mm_srli_epi32(src_pixel2,
|
||||
SK_R32_SHIFT + (8 - SK_R16_BITS));
|
||||
r2 = _mm_and_si128(r2, _mm_set1_epi32(SK_R16_MASK));
|
||||
__m128i r = _mm_packs_epi32(r1, r2);
|
||||
|
||||
// Calculate result g.
|
||||
__m128i g1 = _mm_srli_epi32(src_pixel1,
|
||||
SK_G32_SHIFT + (8 - SK_G16_BITS));
|
||||
g1 = _mm_and_si128(g1, _mm_set1_epi32(SK_G16_MASK));
|
||||
__m128i g2 = _mm_srli_epi32(src_pixel2,
|
||||
SK_G32_SHIFT + (8 - SK_G16_BITS));
|
||||
g2 = _mm_and_si128(g2, _mm_set1_epi32(SK_G16_MASK));
|
||||
__m128i g = _mm_packs_epi32(g1, g2);
|
||||
|
||||
// Calculate result b.
|
||||
__m128i b1 = _mm_srli_epi32(src_pixel1,
|
||||
SK_B32_SHIFT + (8 - SK_B16_BITS));
|
||||
b1 = _mm_and_si128(b1, _mm_set1_epi32(SK_B16_MASK));
|
||||
__m128i b2 = _mm_srli_epi32(src_pixel2,
|
||||
SK_B32_SHIFT + (8 - SK_B16_BITS));
|
||||
b2 = _mm_and_si128(b2, _mm_set1_epi32(SK_B16_MASK));
|
||||
__m128i b = _mm_packs_epi32(b1, b2);
|
||||
|
||||
// Store 8 16-bit colors in dst.
|
||||
__m128i d_pixel = SkPackRGB16_SSE2(r, g, b);
|
||||
|
||||
return d_pixel;
|
||||
}
|
||||
|
||||
#endif // SkColor_opts_SSE2_DEFINED
|
||||
|
266
src/opts/SkXfermode_opts_SSE2.cpp
Normal file
266
src/opts/SkXfermode_opts_SSE2.cpp
Normal file
@ -0,0 +1,266 @@
|
||||
#include "SkColorPriv.h"
|
||||
#include "SkColor_opts_SSE2.h"
|
||||
#include "SkMathPriv.h"
|
||||
#include "SkXfermode.h"
|
||||
#include "SkXfermode_opts_SSE2.h"
|
||||
#include "SkXfermode_proccoeff.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 4 pixels SSE2 version functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static inline __m128i SkDiv255Round_SSE2(__m128i prod) {
|
||||
prod = _mm_add_epi32(prod, _mm_set1_epi32(128)); // prod += 128;
|
||||
prod = _mm_add_epi32(prod, _mm_srli_epi32(prod, 8)); // prod + (prod >> 8)
|
||||
prod = _mm_srli_epi32(prod, 8); // >> 8
|
||||
|
||||
return prod;
|
||||
}
|
||||
|
||||
static inline __m128i clamp_div255round_SSE2(__m128i prod) {
|
||||
// test if > 0
|
||||
__m128i cmp1 = _mm_cmpgt_epi32(prod, _mm_setzero_si128());
|
||||
// test if < 255*255
|
||||
__m128i cmp2 = _mm_cmplt_epi32(prod, _mm_set1_epi32(255*255));
|
||||
|
||||
__m128i ret = _mm_setzero_si128();
|
||||
|
||||
// if value >= 255*255, value = 255
|
||||
ret = _mm_andnot_si128(cmp2, _mm_set1_epi32(255));
|
||||
|
||||
__m128i div = SkDiv255Round_SSE2(prod);
|
||||
|
||||
// test if > 0 && < 255*255
|
||||
__m128i cmp = _mm_and_si128(cmp1, cmp2);
|
||||
|
||||
ret = _mm_or_si128(_mm_and_si128(cmp, div), _mm_andnot_si128(cmp, ret));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline __m128i srcover_byte_SSE2(__m128i a, __m128i b) {
|
||||
// a + b - SkAlphaMulAlpha(a, b);
|
||||
return _mm_sub_epi32(_mm_add_epi32(a, b), SkAlphaMulAlpha_SSE2(a, b));
|
||||
|
||||
}
|
||||
|
||||
static inline __m128i blendfunc_multiply_byte_SSE2(__m128i sc, __m128i dc,
|
||||
__m128i sa, __m128i da) {
|
||||
// sc * (255 - da)
|
||||
__m128i ret1 = _mm_sub_epi32(_mm_set1_epi32(255), da);
|
||||
ret1 = _mm_mullo_epi16(sc, ret1);
|
||||
|
||||
// dc * (255 - sa)
|
||||
__m128i ret2 = _mm_sub_epi32(_mm_set1_epi32(255), sa);
|
||||
ret2 = _mm_mullo_epi16(dc, ret2);
|
||||
|
||||
// sc * dc
|
||||
__m128i ret3 = _mm_mullo_epi16(sc, dc);
|
||||
|
||||
__m128i ret = _mm_add_epi32(ret1, ret2);
|
||||
ret = _mm_add_epi32(ret, ret3);
|
||||
|
||||
return clamp_div255round_SSE2(ret);
|
||||
}
|
||||
|
||||
static __m128i multiply_modeproc_SSE2(__m128i src, __m128i dst) {
|
||||
__m128i sa = SkGetPackedA32_SSE2(src);
|
||||
__m128i da = SkGetPackedA32_SSE2(dst);
|
||||
__m128i a = srcover_byte_SSE2(sa, da);
|
||||
|
||||
__m128i sr = SkGetPackedR32_SSE2(src);
|
||||
__m128i dr = SkGetPackedR32_SSE2(dst);
|
||||
__m128i r = blendfunc_multiply_byte_SSE2(sr, dr, sa, da);
|
||||
|
||||
__m128i sg = SkGetPackedG32_SSE2(src);
|
||||
__m128i dg = SkGetPackedG32_SSE2(dst);
|
||||
__m128i g = blendfunc_multiply_byte_SSE2(sg, dg, sa, da);
|
||||
|
||||
|
||||
__m128i sb = SkGetPackedB32_SSE2(src);
|
||||
__m128i db = SkGetPackedB32_SSE2(dst);
|
||||
__m128i b = blendfunc_multiply_byte_SSE2(sb, db, sa, da);
|
||||
|
||||
return SkPackARGB32_SSE2(a, r, g, b);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern SkXfermodeProcSIMD gSSE2XfermodeProcs[];
|
||||
|
||||
SkSSE2ProcCoeffXfermode::SkSSE2ProcCoeffXfermode(SkReadBuffer& buffer)
|
||||
: INHERITED(buffer) {
|
||||
fProcSIMD = gSSE2XfermodeProcs[this->getMode()];
|
||||
}
|
||||
|
||||
void SkSSE2ProcCoeffXfermode::xfer32(SkPMColor dst[], const SkPMColor src[],
|
||||
int count, const SkAlpha aa[]) const {
|
||||
SkASSERT(dst && src && count >= 0);
|
||||
|
||||
SkXfermodeProc proc = this->getProc();
|
||||
SkXfermodeProcSIMD procSIMD = fProcSIMD;
|
||||
SkASSERT(procSIMD != NULL);
|
||||
|
||||
if (NULL == aa) {
|
||||
if (count >= 4) {
|
||||
while (((size_t)dst & 0x0F) != 0) {
|
||||
*dst = proc(*src, *dst);
|
||||
dst++;
|
||||
src++;
|
||||
count--;
|
||||
}
|
||||
|
||||
const __m128i* s = reinterpret_cast<const __m128i*>(src);
|
||||
__m128i* d = reinterpret_cast<__m128i*>(dst);
|
||||
|
||||
while (count >= 4) {
|
||||
__m128i src_pixel = _mm_loadu_si128(s++);
|
||||
__m128i dst_pixel = _mm_load_si128(d);
|
||||
|
||||
dst_pixel = procSIMD(src_pixel, dst_pixel);
|
||||
_mm_store_si128(d++, dst_pixel);
|
||||
count -= 4;
|
||||
}
|
||||
|
||||
src = reinterpret_cast<const SkPMColor*>(s);
|
||||
dst = reinterpret_cast<SkPMColor*>(d);
|
||||
}
|
||||
|
||||
for (int i = count - 1; i >= 0; --i) {
|
||||
*dst = proc(*src, *dst);
|
||||
dst++;
|
||||
src++;
|
||||
}
|
||||
} else {
|
||||
for (int i = count - 1; i >= 0; --i) {
|
||||
unsigned a = aa[i];
|
||||
if (0 != a) {
|
||||
SkPMColor dstC = dst[i];
|
||||
SkPMColor C = proc(src[i], dstC);
|
||||
if (a != 0xFF) {
|
||||
C = SkFourByteInterp(C, dstC, a);
|
||||
}
|
||||
dst[i] = C;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SkSSE2ProcCoeffXfermode::xfer16(uint16_t* SK_RESTRICT dst,
|
||||
const SkPMColor* SK_RESTRICT src, int count,
|
||||
const SkAlpha* SK_RESTRICT aa) const {
|
||||
SkASSERT(dst && src && count >= 0);
|
||||
|
||||
SkXfermodeProc proc = this->getProc();
|
||||
SkXfermodeProcSIMD procSIMD = fProcSIMD;
|
||||
SkASSERT(procSIMD != NULL);
|
||||
|
||||
if (NULL == aa) {
|
||||
if (count >= 8) {
|
||||
while (((size_t)dst & 0x0F) != 0) {
|
||||
SkPMColor dstC = SkPixel16ToPixel32(*dst);
|
||||
*dst = SkPixel32ToPixel16_ToU16(proc(*src, dstC));
|
||||
dst++;
|
||||
src++;
|
||||
count--;
|
||||
}
|
||||
|
||||
const __m128i* s = reinterpret_cast<const __m128i*>(src);
|
||||
__m128i* d = reinterpret_cast<__m128i*>(dst);
|
||||
|
||||
while (count >= 8) {
|
||||
__m128i src_pixel1 = _mm_loadu_si128(s++);
|
||||
__m128i src_pixel2 = _mm_loadu_si128(s++);
|
||||
__m128i dst_pixel = _mm_load_si128(d);
|
||||
|
||||
__m128i dst_pixel1 = _mm_unpacklo_epi16(dst_pixel, _mm_setzero_si128());
|
||||
__m128i dst_pixel2 = _mm_unpackhi_epi16(dst_pixel, _mm_setzero_si128());
|
||||
|
||||
__m128i dstC1 = SkPixel16ToPixel32_SSE2(dst_pixel1);
|
||||
__m128i dstC2 = SkPixel16ToPixel32_SSE2(dst_pixel2);
|
||||
|
||||
dst_pixel1 = procSIMD(src_pixel1, dstC1);
|
||||
dst_pixel2 = procSIMD(src_pixel2, dstC2);
|
||||
dst_pixel = SkPixel32ToPixel16_ToU16_SSE2(dst_pixel1, dst_pixel2);
|
||||
|
||||
_mm_store_si128(d++, dst_pixel);
|
||||
count -= 8;
|
||||
}
|
||||
|
||||
src = reinterpret_cast<const SkPMColor*>(s);
|
||||
dst = reinterpret_cast<uint16_t*>(d);
|
||||
}
|
||||
|
||||
for (int i = count - 1; i >= 0; --i) {
|
||||
SkPMColor dstC = SkPixel16ToPixel32(*dst);
|
||||
*dst = SkPixel32ToPixel16_ToU16(proc(*src, dstC));
|
||||
dst++;
|
||||
src++;
|
||||
}
|
||||
} else {
|
||||
for (int i = count - 1; i >= 0; --i) {
|
||||
unsigned a = aa[i];
|
||||
if (0 != a) {
|
||||
SkPMColor dstC = SkPixel16ToPixel32(dst[i]);
|
||||
SkPMColor C = proc(src[i], dstC);
|
||||
if (0xFF != a) {
|
||||
C = SkFourByteInterp(C, dstC, a);
|
||||
}
|
||||
dst[i] = SkPixel32ToPixel16_ToU16(C);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef SK_IGNORE_TO_STRING
|
||||
void SkSSE2ProcCoeffXfermode::toString(SkString* str) const {
|
||||
this->INHERITED::toString(str);
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 4 pixels modeprocs with SSE2
|
||||
SkXfermodeProcSIMD gSSE2XfermodeProcs[] = {
|
||||
NULL, // kClear_Mode
|
||||
NULL, // kSrc_Mode
|
||||
NULL, // kDst_Mode
|
||||
NULL, // kSrcOver_Mode
|
||||
NULL, // kDstOver_Mode
|
||||
NULL, // kSrcIn_Mode
|
||||
NULL, // kDstIn_Mode
|
||||
NULL, // kSrcOut_Mode
|
||||
NULL, // kDstOut_Mode
|
||||
NULL, // kSrcATop_Mode
|
||||
NULL, // kDstATop_Mode
|
||||
NULL, // kXor_Mode
|
||||
NULL, // kPlus_Mode
|
||||
NULL, // kModulate_Mode
|
||||
NULL, // kScreen_Mode
|
||||
|
||||
NULL, // kOverlay_Mode
|
||||
NULL, // kDarken_Mode
|
||||
NULL, // kLighten_Mode
|
||||
NULL, // kColorDodge_Mode
|
||||
NULL, // kColorBurn_Mode
|
||||
NULL, // kHardLight_Mode
|
||||
NULL, // kSoftLight_Mode
|
||||
NULL, // kDifference_Mode
|
||||
NULL, // kExclusion_Mode
|
||||
multiply_modeproc_SSE2,
|
||||
|
||||
NULL, // kHue_Mode
|
||||
NULL, // kSaturation_Mode
|
||||
NULL, // kColor_Mode
|
||||
NULL, // kLuminosity_Mode
|
||||
};
|
||||
|
||||
SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl_SSE2(const ProcCoeff& rec,
|
||||
SkXfermode::Mode mode) {
|
||||
SkXfermodeProcSIMD procSIMD = gSSE2XfermodeProcs[mode];
|
||||
|
||||
if (procSIMD != NULL) {
|
||||
return SkNEW_ARGS(SkSSE2ProcCoeffXfermode, (rec, mode, procSIMD));
|
||||
}
|
||||
return NULL;
|
||||
}
|
32
src/opts/SkXfermode_opts_SSE2.h
Normal file
32
src/opts/SkXfermode_opts_SSE2.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef SkXfermode_opts_SSE2_DEFINED
|
||||
#define SkXfermode_opts_SSE2_DEFINED
|
||||
|
||||
#include "SkXfermode_proccoeff.h"
|
||||
|
||||
typedef __m128i (*SkXfermodeProcSIMD)(__m128i src, __m128i dst);
|
||||
|
||||
class SkSSE2ProcCoeffXfermode : public SkProcCoeffXfermode {
|
||||
public:
|
||||
SkSSE2ProcCoeffXfermode(const ProcCoeff& rec, SkXfermode::Mode mode,
|
||||
SkXfermodeProcSIMD procSIMD)
|
||||
: INHERITED(rec, mode), fProcSIMD(procSIMD) {}
|
||||
|
||||
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
|
||||
const SkAlpha aa[]) const SK_OVERRIDE;
|
||||
virtual void xfer16(uint16_t* SK_RESTRICT dst, const SkPMColor* SK_RESTRICT src,
|
||||
int count, const SkAlpha* SK_RESTRICT aa) const SK_OVERRIDE;
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSSE2ProcCoeffXfermode)
|
||||
|
||||
private:
|
||||
SkSSE2ProcCoeffXfermode(SkReadBuffer& buffer);
|
||||
|
||||
SkXfermodeProcSIMD fProcSIMD;
|
||||
typedef SkProcCoeffXfermode INHERITED;
|
||||
};
|
||||
|
||||
SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl_SSE2(const ProcCoeff& rec,
|
||||
SkXfermode::Mode mode);
|
||||
|
||||
#endif // SkXfermode_opts_SSE2_DEFINED
|
@ -17,6 +17,8 @@
|
||||
#include "SkUtils.h"
|
||||
#include "SkMorphology_opts.h"
|
||||
#include "SkMorphology_opts_SSE2.h"
|
||||
#include "SkXfermode.h"
|
||||
#include "SkXfermode_proccoeff.h"
|
||||
|
||||
#include "SkRTConf.h"
|
||||
|
||||
@ -307,3 +309,32 @@ SkBlitRow::ColorRectProc PlatformColorRectProcFactory() {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl_SSE2(const ProcCoeff& rec,
|
||||
SkXfermode::Mode mode);
|
||||
|
||||
SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl(const ProcCoeff& rec,
|
||||
SkXfermode::Mode mode);
|
||||
|
||||
SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl(const ProcCoeff& rec,
|
||||
SkXfermode::Mode mode) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkProcCoeffXfermode* SkPlatformXfermodeFactory(const ProcCoeff& rec,
|
||||
SkXfermode::Mode mode);
|
||||
|
||||
SkProcCoeffXfermode* SkPlatformXfermodeFactory(const ProcCoeff& rec,
|
||||
SkXfermode::Mode mode) {
|
||||
if (cachedHasSSE2()) {
|
||||
return SkPlatformXfermodeFactory_impl_SSE2(rec, mode);
|
||||
} else {
|
||||
return SkPlatformXfermodeFactory_impl(rec, mode);
|
||||
}
|
||||
}
|
||||
|
||||
SkXfermodeProc SkPlatformXfermodeProcFactory(SkXfermode::Mode mode);
|
||||
|
||||
SkXfermodeProc SkPlatformXfermodeProcFactory(SkXfermode::Mode mode) {
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user