trim some fat from SSE2 fixed point alpha code

- extract alpha from a pixel: 5 1-cycle ops to 4 1-cycle ops
  - load alphas: drop 4 unnecessary ops

Should be no pixel diffs.

BUG=skia:
CQ_EXTRA_TRYBOTS=client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot

Review URL: https://codereview.chromium.org/1447273004
This commit is contained in:
mtklein 2015-11-17 12:05:57 -08:00 committed by Commit bot
parent 32d6b87616
commit f769c1f80e
2 changed files with 14 additions and 14 deletions

View File

@ -63,18 +63,17 @@ inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const {
#else #else
inline Sk4px Sk4px::alphas() const { inline Sk4px Sk4px::alphas() const {
static_assert(SK_A32_SHIFT == 24, "Intel's always little-endian."); static_assert(SK_A32_SHIFT == 24, "Intel's always little-endian.");
__m128i as = _mm_srli_epi32(this->fVec, 24); // ___3 ___2 ___1 ___0 // We exploit that A >= rgb for any premul pixel.
as = _mm_or_si128(as, _mm_slli_si128(as, 1)); // __33 __22 __11 __00 __m128i as = fVec; // 3xxx 2xxx 1xxx 0xxx
as = _mm_or_si128(as, _mm_slli_si128(as, 2)); // 3333 2222 1111 0000 as = _mm_max_epu8(as, _mm_srli_epi32(as, 8)); // 33xx 22xx 11xx 00xx
as = _mm_max_epu8(as, _mm_srli_epi32(as, 16)); // 3333 2222 1111 0000
return Sk16b(as); return Sk16b(as);
} }
inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) {
__m128i as = _mm_cvtsi32_si128(*(const uint32_t*)a); // ____ ____ ____ 3210 __m128i as = _mm_cvtsi32_si128(*(const uint32_t*)a); // ____ ____ ____ 3210
as = _mm_unpacklo_epi8 (as, _mm_setzero_si128()); // ____ ____ _3_2 _1_0 as = _mm_unpacklo_epi8 (as, as); // ____ ____ 3322 1100
as = _mm_unpacklo_epi16(as, _mm_setzero_si128()); // ___3 ___2 ___1 ___0 as = _mm_unpacklo_epi16(as, as); // 3333 2222 1111 0000
as = _mm_or_si128(as, _mm_slli_si128(as, 1)); // __33 __22 __11 __00
as = _mm_or_si128(as, _mm_slli_si128(as, 2)); // 3333 2222 1111 0000
return Sk16b(as); return Sk16b(as);
} }
#endif #endif

View File

@ -61,10 +61,9 @@ struct SkPx {
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
return _mm_shuffle_epi8(as, _mm_set_epi8(3,3,3,3, 2,2,2,2, 1,1,1,1, 0,0,0,0)); return _mm_shuffle_epi8(as, _mm_set_epi8(3,3,3,3, 2,2,2,2, 1,1,1,1, 0,0,0,0));
#else #else
as = _mm_unpacklo_epi8 (as, _mm_setzero_si128()); // ____ ____ _3_2 _1_0 as = _mm_unpacklo_epi8 (as, as); // ____ ____ 3322 1100
as = _mm_unpacklo_epi16(as, _mm_setzero_si128()); // ___3 ___2 ___1 ___0 as = _mm_unpacklo_epi16(as, as); // 3333 2222 1111 0000
as = _mm_or_si128(as, _mm_slli_si128(as, 1)); // __33 __22 __11 __00 return as;
return _mm_or_si128(as, _mm_slli_si128(as, 2)); // 3333 2222 1111 0000
#endif #endif
} }
static Alpha Load(const uint8_t* a, int n) { static Alpha Load(const uint8_t* a, int n) {
@ -108,9 +107,11 @@ struct SkPx {
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
return _mm_shuffle_epi8(fVec, _mm_set_epi8(15,15,15,15, 11,11,11,11, 7,7,7,7, 3,3,3,3)); return _mm_shuffle_epi8(fVec, _mm_set_epi8(15,15,15,15, 11,11,11,11, 7,7,7,7, 3,3,3,3));
#else #else
__m128i as = _mm_srli_epi32(fVec, 24); // ___3 ___2 ___1 ___0 // We exploit that A >= rgb for any premul pixel.
as = _mm_or_si128(as, _mm_slli_si128(as, 1)); // __33 __22 __11 __00 __m128i as = fVec; // 3xxx 2xxx 1xxx 0xxx
return _mm_or_si128(as, _mm_slli_si128(as, 2)); // 3333 2222 1111 0000 as = _mm_max_epu8(as, _mm_srli_epi32(as, 8)); // 33xx 22xx 11xx 00xx
as = _mm_max_epu8(as, _mm_srli_epi32(as, 16)); // 3333 2222 1111 0000
return as;
#endif #endif
} }