Make gMask_00FF00FF a constant
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 12 May 2014 15:38:00 +0000 (15:38 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 12 May 2014 15:38:00 +0000 (15:38 +0000)
This is to optimize SkAlphaMulQ() in PIC mode. With the visibility=default
symbol the constant is not known at compile time (and is not a constant), but
instead is fetched through a double indirection through GOT. The function is
quite hot on one of the chromium benchmarks:
rasterize_and_record_micro.key_silk_cases.

This change replaces the symbol with a compile-time constant. As a bonus the
variable is not exported from the dynamic library, i. e. a cleaner library
interface.

See specific performance improvements on Android here:
  http://goo.gl/iMuTDt

R=skyostil@chromium.org, tomhudson@chromium.org, mtklein@google.com, reed@google.com, tomhudson@google.com

Author: pasko@chromium.org

Review URL: https://codereview.chromium.org/270473003

git-svn-id: http://skia.googlecode.com/svn/trunk@14696 2bbb7eff-a529-9590-31e7-b0007b416f81

include/core/SkColorPriv.h
src/core/SkBitmapProcState_filter.h
src/core/SkBlitMask_D32.cpp
src/core/SkBlitter.cpp
src/opts/SkColor_opts_SSE2.h

index d5571df..8fd1e57 100644 (file)
@@ -524,10 +524,8 @@ SkPMColor SkPremultiplyARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
     return SkPackARGB32(a, r, g, b);
 }
 
-SK_API extern const uint32_t gMask_00FF00FF;
-
 static inline uint32_t SkAlphaMulQ(uint32_t c, unsigned scale) {
-    uint32_t mask = gMask_00FF00FF;
+    uint32_t mask = 0xFF00FF;
 
     uint32_t rb = ((c & mask) * scale) >> 8;
     uint32_t ag = ((c >> 8) & mask) * scale;
@@ -787,8 +785,6 @@ static inline SkPMColor16 SkPackARGB4444(unsigned a, unsigned r,
                          (g << SK_G4444_SHIFT) | (b << SK_B4444_SHIFT));
 }
 
-extern const uint16_t gMask_0F0F;
-
 static inline U16CPU SkAlphaMulQ4(U16CPU c, unsigned scale) {
     SkASSERT(scale <= 16);
 
index 1260665..99f40ec 100644 (file)
@@ -26,7 +26,7 @@ static inline void Filter_32_opaque(unsigned x, unsigned y,
     SkASSERT((unsigned)y <= 0xF);
 
     int xy = x * y;
-    static const uint32_t mask = gMask_00FF00FF; //0xFF00FF;
+    const uint32_t mask = 0xFF00FF;
 
     int scale = 256 - 16*y - 16*x + xy;
     uint32_t lo = (a00 & mask) * scale;
@@ -56,7 +56,7 @@ static inline void Filter_32_alpha(unsigned x, unsigned y,
     SkASSERT(alphaScale <= 256);
 
     int xy = x * y;
-    static const uint32_t mask = gMask_00FF00FF; //0xFF00FF;
+    const uint32_t mask = 0xFF00FF;
 
     int scale = 256 - 16*y - 16*x + xy;
     uint32_t lo = (a00 & mask) * scale;
@@ -86,7 +86,7 @@ static inline void Filter_32_opaque(unsigned t,
                                     SkPMColor* dstColor) {
     SkASSERT((unsigned)t <= 0xF);
 
-    static const uint32_t mask = gMask_00FF00FF; //0x00FF00FF;
+    const uint32_t mask = 0xFF00FF;
 
     int scale = 256 - 16*t;
     uint32_t lo = (color0 & mask) * scale;
@@ -108,7 +108,7 @@ static inline void Filter_32_alpha(unsigned t,
     SkASSERT((unsigned)t <= 0xF);
     SkASSERT(alphaScale <= 256);
 
-    static const uint32_t mask = gMask_00FF00FF; //0x00FF00FF;
+    const uint32_t mask = 0xFF00FF;
 
     int scale = 256 - 16*t;
     uint32_t lo = (color0 & mask) * scale;
index 1f16d77..008386c 100644 (file)
@@ -353,9 +353,6 @@ static void A8_RowProc_Blend(SkPMColor* SK_RESTRICT dst,
 static void A8_RowProc_Opaque(SkPMColor* SK_RESTRICT dst,
                               const uint8_t* SK_RESTRICT mask,
                               const SkPMColor* SK_RESTRICT src, int count) {
-#if 0 // suppress warning
-    const uint32_t rbmask = gMask_00FF00FF;
-#endif
     for (int i = 0; i < count; ++i) {
         int m = mask[i];
         if (m) {
index 81e46c5..a86881a 100644 (file)
@@ -993,11 +993,6 @@ SkBlitter* SkBlitter::Choose(const SkBitmap& device,
 
 ///////////////////////////////////////////////////////////////////////////////
 
-const uint16_t gMask_0F0F = 0xF0F;
-const uint32_t gMask_00FF00FF = 0xFF00FF;
-
-///////////////////////////////////////////////////////////////////////////////
-
 class SkTransparentShaderContext : public SkShader::Context {
 public:
     SkTransparentShaderContext(const SkShader& shader, const SkShader::ContextRec& rec)
index b06fe1a..7e61d52 100644 (file)
@@ -42,7 +42,7 @@ static inline __m128i SkAlphaMulAlpha_SSE2(const __m128i& a,
 
 // Portable version SkAlphaMulQ is in SkColorPriv.h.
 static inline __m128i SkAlphaMulQ_SSE2(const __m128i& c, const __m128i& scale) {
-    __m128i mask = _mm_set1_epi32(gMask_00FF00FF);
+    __m128i mask = _mm_set1_epi32(0xFF00FF);
     __m128i s = _mm_or_si128(_mm_slli_epi32(scale, 16), scale);
 
     // uint32_t rb = ((c & mask) * scale) >> 8