De-proc Color32

Also strips SK_SUPPORT_LEGACY_COLOR32_MATH,
which is no longer needed.

Seems handy to have SkTypes include the relevant intrinsics when
we know we've got them, but I'm not married to it.

Locally this looks like a pointlessly small perf win, but I'm mostly
keen to get all the code together.

BUG=skia:

Committed: https://skia.googlesource.com/skia/+/376e9bc206b69d9190f38dfebb132a8769bbd72b

Committed: https://skia.googlesource.com/skia/+/d65dc0cedd5b50dd407b6ff8fdc39123f11511cc

CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-Mips-Debug-Android-Trybot

Review URL: https://codereview.chromium.org/1104183004
This commit is contained in:
mtklein 2015-04-27 15:11:01 -07:00 committed by Commit bot
parent 641c3ff7c6
commit 95cc012cca
14 changed files with 99 additions and 203 deletions

View File

@ -64,20 +64,12 @@ public:
static Proc32 Factory32(unsigned flags32);
/** Function pointer that blends a single color with a row of 32-bit colors
onto a 32-bit destination
*/
typedef void (*ColorProc)(SkPMColor dst[], const SkPMColor src[], int count, SkPMColor color);
/** Blend a single color onto a row of S32 pixels, writing the result
into a row of D32 pixels. src and dst may be the same memory, but
if they are not, they may not overlap.
*/
static void Color32(SkPMColor dst[], const SkPMColor src[], int count, SkPMColor color);
//! Public entry-point to return a blit function ptr
static ColorProc ColorProcFactory();
/** These static functions are called by the Factory and Factory32
functions, and should return either NULL, or a
platform-specific function-ptr to be used in place of the
@ -85,7 +77,6 @@ public:
*/
static Proc32 PlatformProcs32(unsigned flags);
static ColorProc PlatformColorProc();
static Proc16 PlatformFactory565(unsigned flags);
static ColorProc16 PlatformColorFactory565(unsigned flags);

View File

@ -14,6 +14,12 @@
#include <stdint.h>
#include <sys/types.h>
#if defined(SK_ARM_HAS_NEON)
#include <arm_neon.h>
#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
#include <immintrin.h>
#endif
/** \file SkTypes.h
*/

View File

@ -131,37 +131,99 @@ SkBlitRow::Proc32 SkBlitRow::Factory32(unsigned flags) {
return proc;
}
SkBlitRow::Proc32 SkBlitRow::ColorProcFactory() {
SkBlitRow::ColorProc proc = PlatformColorProc();
if (NULL == proc) {
proc = Color32;
}
SkASSERT(proc);
return proc;
}
#define SK_SUPPORT_LEGACY_COLOR32_MATHx
// Color32 and its SIMD specializations use the blend_256_round_alt algorithm
// from tests/BlendTest.cpp. It's not quite perfect, but it's never wrong in the
// interesting edge cases, and it's quite a bit faster than blend_perfect.
// Color32 uses the blend_256_round_alt algorithm from tests/BlendTest.cpp.
// It's not quite perfect, but it's never wrong in the interesting edge cases,
// and it's quite a bit faster than blend_perfect.
//
// blend_256_round_alt is our currently blessed algorithm. Please use it or an analogous one.
void SkBlitRow::Color32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src,
int count, SkPMColor color) {
void SkBlitRow::Color32(SkPMColor dst[], const SkPMColor src[], int count, SkPMColor color) {
switch (SkGetPackedA32(color)) {
case 0: memmove(dst, src, count * sizeof(SkPMColor)); return;
case 255: sk_memset32(dst, color, count); return;
}
unsigned invA = 255 - SkGetPackedA32(color);
#ifdef SK_SUPPORT_LEGACY_COLOR32_MATH // blend_256_plus1_trunc, busted
unsigned round = 0;
#else // blend_256_round_alt, good
invA += invA >> 7;
SkASSERT(invA < 256); // We've already handled alpha == 0 above.
#if defined(SK_ARM_HAS_NEON)
uint16x8_t colorHigh = vshll_n_u8((uint8x8_t)vdup_n_u32(color), 8);
uint16x8_t colorAndRound = vaddq_u16(colorHigh, vdupq_n_u16(128));
uint8x8_t invA8 = vdup_n_u8(invA);
// Does the core work of blending color onto 4 pixels, returning the resulting 4 pixels.
auto kernel = [&](const uint32x4_t& src4) -> uint32x4_t {
uint16x8_t lo = vmull_u8(vget_low_u8( (uint8x16_t)src4), invA8),
hi = vmull_u8(vget_high_u8((uint8x16_t)src4), invA8);
return (uint32x4_t)
vcombine_u8(vaddhn_u16(colorAndRound, lo), vaddhn_u16(colorAndRound, hi));
};
while (count >= 8) {
uint32x4_t dst0 = kernel(vld1q_u32(src+0)),
dst4 = kernel(vld1q_u32(src+4));
vst1q_u32(dst+0, dst0);
vst1q_u32(dst+4, dst4);
src += 8;
dst += 8;
count -= 8;
}
if (count >= 4) {
vst1q_u32(dst, kernel(vld1q_u32(src)));
src += 4;
dst += 4;
count -= 4;
}
if (count >= 2) {
uint32x2_t src2 = vld1_u32(src);
vst1_u32(dst, vget_low_u32(kernel(vcombine_u32(src2, src2))));
src += 2;
dst += 2;
count -= 2;
}
if (count >= 1) {
vst1q_lane_u32(dst, kernel(vdupq_n_u32(*src)), 0);
}
#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
__m128i colorHigh = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_set1_epi32(color));
__m128i colorAndRound = _mm_add_epi16(colorHigh, _mm_set1_epi16(128));
__m128i invA16 = _mm_set1_epi16(invA);
// Does the core work of blending color onto 4 pixels, returning the resulting 4 pixels.
auto kernel = [&](const __m128i& src4) -> __m128i {
__m128i lo = _mm_mullo_epi16(invA16, _mm_unpacklo_epi8(src4, _mm_setzero_si128())),
hi = _mm_mullo_epi16(invA16, _mm_unpackhi_epi8(src4, _mm_setzero_si128()));
return _mm_packus_epi16(_mm_srli_epi16(_mm_add_epi16(colorAndRound, lo), 8),
_mm_srli_epi16(_mm_add_epi16(colorAndRound, hi), 8));
};
while (count >= 8) {
__m128i dst0 = kernel(_mm_loadu_si128((const __m128i*)(src+0))),
dst4 = kernel(_mm_loadu_si128((const __m128i*)(src+4)));
_mm_storeu_si128((__m128i*)(dst+0), dst0);
_mm_storeu_si128((__m128i*)(dst+4), dst4);
src += 8;
dst += 8;
count -= 8;
}
if (count >= 4) {
_mm_storeu_si128((__m128i*)dst, kernel(_mm_loadu_si128((const __m128i*)src)));
src += 4;
dst += 4;
count -= 4;
}
if (count >= 2) {
_mm_storel_epi64((__m128i*)dst, kernel(_mm_loadl_epi64((const __m128i*)src)));
src += 2;
dst += 2;
count -= 2;
}
if (count >= 1) {
*dst = _mm_cvtsi128_si32(kernel(_mm_cvtsi32_si128(*src)));
}
#else // Neither NEON nor SSE2.
unsigned round = (128 << 16) + (128 << 0);
#endif
while (count --> 0) {
// Our math is 16-bit, so we can do a little bit of SIMD in 32-bit registers.
@ -172,5 +234,6 @@ void SkBlitRow::Color32(SkPMColor* SK_RESTRICT dst,
src++;
dst++;
}
#endif
}

View File

@ -52,7 +52,6 @@ SkARGB32_Blitter::SkARGB32_Blitter(const SkBitmap& device, const SkPaint& paint)
fSrcB = SkAlphaMul(SkColorGetB(color), scale);
fPMColor = SkPackARGB32(fSrcA, fSrcR, fSrcG, fSrcB);
fColor32Proc = SkBlitRow::ColorProcFactory();
}
const SkBitmap* SkARGB32_Blitter::justAnOpaqueColor(uint32_t* value) {
@ -72,7 +71,7 @@ void SkARGB32_Blitter::blitH(int x, int y, int width) {
SkASSERT(x >= 0 && y >= 0 && x + width <= fDevice.width());
uint32_t* device = fDevice.getAddr32(x, y);
fColor32Proc(device, device, width, fPMColor);
SkBlitRow::Color32(device, device, width, fPMColor);
}
void SkARGB32_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
@ -97,7 +96,7 @@ void SkARGB32_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
sk_memset32(device, color, count);
} else {
uint32_t sc = SkAlphaMulQ(color, SkAlpha255To256(aa));
fColor32Proc(device, device, count, sc);
SkBlitRow::Color32(device, device, count, sc);
}
}
runs += count;
@ -109,7 +108,7 @@ void SkARGB32_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
void SkARGB32_Blitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) {
uint32_t* device = fDevice.getAddr32(x, y);
SkDEBUGCODE((void)fDevice.getAddr32(x + 1, y);)
device[0] = SkBlendARGB32(fPMColor, device[0], a0);
device[1] = SkBlendARGB32(fPMColor, device[1], a1);
}
@ -117,7 +116,7 @@ void SkARGB32_Blitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) {
void SkARGB32_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) {
uint32_t* device = fDevice.getAddr32(x, y);
SkDEBUGCODE((void)fDevice.getAddr32(x, y + 1);)
device[0] = SkBlendARGB32(fPMColor, device[0], a0);
device = (uint32_t*)((char*)device + fDevice.rowBytes());
device[0] = SkBlendARGB32(fPMColor, device[0], a1);
@ -248,7 +247,7 @@ void SkARGB32_Blitter::blitRect(int x, int y, int width, int height) {
size_t rowBytes = fDevice.rowBytes();
while (--height >= 0) {
fColor32Proc(device, device, width, color);
SkBlitRow::Color32(device, device, width, color);
device = (uint32_t*)((char*)device + rowBytes);
}
}
@ -301,7 +300,7 @@ void SkARGB32_Black_Blitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) {
void SkARGB32_Black_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) {
uint32_t* device = fDevice.getAddr32(x, y);
SkDEBUGCODE((void)fDevice.getAddr32(x, y + 1);)
device[0] = (a0 << SK_A32_SHIFT) + SkAlphaMulQ(device[0], 256 - a0);
device = (uint32_t*)((char*)device + fDevice.rowBytes());
device[0] = (a1 << SK_A32_SHIFT) + SkAlphaMulQ(device[0], 256 - a1);

View File

@ -126,7 +126,6 @@ public:
protected:
SkColor fColor;
SkPMColor fPMColor;
SkBlitRow::ColorProc fColor32Proc;
private:
unsigned fSrcA, fSrcR, fSrcG, fSrcB;

View File

@ -40,7 +40,7 @@ uint32_t SkModeColorFilter::getFlags() const {
void SkModeColorFilter::filterSpan(const SkPMColor shader[], int count, SkPMColor result[]) const {
SkPMColor color = fPMColor;
SkXfermodeProc proc = fProc;
for (int i = 0; i < count; i++) {
result[i] = proc(color, shader[i]);
}
@ -394,19 +394,13 @@ private:
class SrcOver_SkModeColorFilter : public SkModeColorFilter {
public:
SrcOver_SkModeColorFilter(SkColor color)
: INHERITED(color, SkXfermode::kSrcOver_Mode) {
fColor32Proc = SkBlitRow::ColorProcFactory();
}
SrcOver_SkModeColorFilter(SkColor color) : INHERITED(color, SkXfermode::kSrcOver_Mode) { }
void filterSpan(const SkPMColor shader[], int count, SkPMColor result[]) const override {
fColor32Proc(result, shader, count, this->getPMColor());
SkBlitRow::Color32(result, shader, count, this->getPMColor());
}
private:
SkBlitRow::ColorProc fColor32Proc;
typedef SkModeColorFilter INHERITED;
};

View File

@ -232,71 +232,6 @@ void S32A_Blend_BlitRow32_SSE2(SkPMColor* SK_RESTRICT dst,
}
}
#define SK_SUPPORT_LEGACY_COLOR32_MATHx
/* SSE2 version of Color32()
* portable version is in core/SkBlitRow_D32.cpp
*/
// Color32 and its SIMD specializations use the blend_256_round_alt algorithm
// from tests/BlendTest.cpp. It's not quite perfect, but it's never wrong in the
// interesting edge cases, and it's quite a bit faster than blend_perfect.
//
// blend_256_round_alt is our currently blessed algorithm. Please use it or an analogous one.
void Color32_SSE2(SkPMColor dst[], const SkPMColor src[], int count, SkPMColor color) {
switch (SkGetPackedA32(color)) {
case 0: memmove(dst, src, count * sizeof(SkPMColor)); return;
case 255: sk_memset32(dst, color, count); return;
}
__m128i colorHigh = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_set1_epi32(color));
#ifdef SK_SUPPORT_LEGACY_COLOR32_MATH // blend_256_plus1_trunc, busted
__m128i colorAndRound = colorHigh;
#else // blend_256_round_alt, good
__m128i colorAndRound = _mm_add_epi16(colorHigh, _mm_set1_epi16(128));
#endif
unsigned invA = 255 - SkGetPackedA32(color);
#ifdef SK_SUPPORT_LEGACY_COLOR32_MATH // blend_256_plus1_trunc, busted
__m128i invA16 = _mm_set1_epi16(invA);
#else // blend_256_round_alt, good
SkASSERT(invA + (invA >> 7) < 256); // We should still fit in the low byte here.
__m128i invA16 = _mm_set1_epi16(invA + (invA >> 7));
#endif
// Does the core work of blending color onto 4 pixels, returning the resulting 4 pixels.
auto kernel = [&](const __m128i& src4) -> __m128i {
__m128i lo = _mm_mullo_epi16(invA16, _mm_unpacklo_epi8(src4, _mm_setzero_si128())),
hi = _mm_mullo_epi16(invA16, _mm_unpackhi_epi8(src4, _mm_setzero_si128()));
return _mm_packus_epi16(_mm_srli_epi16(_mm_add_epi16(colorAndRound, lo), 8),
_mm_srli_epi16(_mm_add_epi16(colorAndRound, hi), 8));
};
while (count >= 8) {
__m128i dst0 = kernel(_mm_loadu_si128((const __m128i*)(src+0))),
dst4 = kernel(_mm_loadu_si128((const __m128i*)(src+4)));
_mm_storeu_si128((__m128i*)(dst+0), dst0);
_mm_storeu_si128((__m128i*)(dst+4), dst4);
src += 8;
dst += 8;
count -= 8;
}
if (count >= 4) {
_mm_storeu_si128((__m128i*)dst, kernel(_mm_loadu_si128((const __m128i*)src)));
src += 4;
dst += 4;
count -= 4;
}
if (count >= 2) {
_mm_storel_epi64((__m128i*)dst, kernel(_mm_loadl_epi64((const __m128i*)src)));
src += 2;
dst += 2;
count -= 2;
}
if (count >= 1) {
*dst = _mm_cvtsi128_si32(kernel(_mm_cvtsi32_si128(*src)));
}
}
void Color32A_D565_SSE2(uint16_t dst[], SkPMColor src, int count, int x, int y) {
SkASSERT(count > 0);

View File

@ -22,8 +22,6 @@ void S32A_Blend_BlitRow32_SSE2(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src,
int count, U8CPU alpha);
void Color32_SSE2(SkPMColor dst[], const SkPMColor src[], int count,
SkPMColor color);
void Color32A_D565_SSE2(uint16_t dst[], SkPMColor src, int count, int x,
int y);

View File

@ -390,9 +390,3 @@ SkBlitRow::Proc32 SkBlitRow::PlatformProcs32(unsigned flags) {
return SK_ARM_NEON_WRAP(sk_blitrow_platform_32_procs_arm)[flags];
}
///////////////////////////////////////////////////////////////////////////////
#define Color32_arm NULL
SkBlitRow::ColorProc SkBlitRow::PlatformColorProc() {
return SK_ARM_NEON_WRAP(Color32_arm);
}

View File

@ -1679,69 +1679,6 @@ void S32_D565_Opaque_Dither_neon(uint16_t* SK_RESTRICT dst,
}
}
#define SK_SUPPORT_LEGACY_COLOR32_MATHx
// Color32 and its SIMD specializations use the blend_256_round_alt algorithm
// from tests/BlendTest.cpp. It's not quite perfect, but it's never wrong in the
// interesting edge cases, and it's quite a bit faster than blend_perfect.
//
// blend_256_round_alt is our currently blessed algorithm. Please use it or an analogous one.
void Color32_arm_neon(SkPMColor* dst, const SkPMColor* src, int count, SkPMColor color) {
switch (SkGetPackedA32(color)) {
case 0: memmove(dst, src, count * sizeof(SkPMColor)); return;
case 255: sk_memset32(dst, color, count); return;
}
uint16x8_t colorHigh = vshll_n_u8((uint8x8_t)vdup_n_u32(color), 8);
#ifdef SK_SUPPORT_LEGACY_COLOR32_MATH // blend_256_plus1_trunc, busted
uint16x8_t colorAndRound = colorHigh;
#else // blend_256_round_alt, good
uint16x8_t colorAndRound = vaddq_u16(colorHigh, vdupq_n_u16(128));
#endif
unsigned invA = 255 - SkGetPackedA32(color);
#ifdef SK_SUPPORT_LEGACY_COLOR32_MATH // blend_256_plus1_trunc, busted
uint8x8_t invA8 = vdup_n_u8(invA);
#else // blend_256_round_alt, good
SkASSERT(invA + (invA >> 7) < 256); // This next part only works if alpha is not 0.
uint8x8_t invA8 = vdup_n_u8(invA + (invA >> 7));
#endif
// Does the core work of blending color onto 4 pixels, returning the resulting 4 pixels.
auto kernel = [&](const uint32x4_t& src4) -> uint32x4_t {
uint16x8_t lo = vmull_u8(vget_low_u8( (uint8x16_t)src4), invA8),
hi = vmull_u8(vget_high_u8((uint8x16_t)src4), invA8);
return (uint32x4_t)
vcombine_u8(vaddhn_u16(colorAndRound, lo), vaddhn_u16(colorAndRound, hi));
};
while (count >= 8) {
uint32x4_t dst0 = kernel(vld1q_u32(src+0)),
dst4 = kernel(vld1q_u32(src+4));
vst1q_u32(dst+0, dst0);
vst1q_u32(dst+4, dst4);
src += 8;
dst += 8;
count -= 8;
}
if (count >= 4) {
vst1q_u32(dst, kernel(vld1q_u32(src)));
src += 4;
dst += 4;
count -= 4;
}
if (count >= 2) {
uint32x2_t src2 = vld1_u32(src);
vst1_u32(dst, vget_low_u32(kernel(vcombine_u32(src2, src2))));
src += 2;
dst += 2;
count -= 2;
}
if (count >= 1) {
vst1q_lane_u32(dst, kernel(vdupq_n_u32(*src)), 0);
}
}
///////////////////////////////////////////////////////////////////////////////
const SkBlitRow::Proc16 sk_blitrow_platform_565_procs_arm_neon[] = {

View File

@ -13,7 +13,4 @@ extern const SkBlitRow::Proc16 sk_blitrow_platform_565_procs_arm_neon[];
extern const SkBlitRow::ColorProc16 sk_blitrow_platform_565_colorprocs_arm_neon[];
extern const SkBlitRow::Proc32 sk_blitrow_platform_32_procs_arm_neon[];
extern void Color32_arm_neon(SkPMColor* dst, const SkPMColor* src, int count,
SkPMColor color);
#endif

View File

@ -953,7 +953,3 @@ SkBlitRow::ColorProc16 SkBlitRow::PlatformColorFactory565(unsigned flags) {
SkBlitRow::Proc32 SkBlitRow::PlatformProcs32(unsigned flags) {
return platform_32_procs_mips_dsp[flags];
}
SkBlitRow::ColorProc SkBlitRow::PlatformColorProc() {
return NULL;
}

View File

@ -20,8 +20,3 @@ SkBlitRow::ColorProc16 SkBlitRow::PlatformColorFactory565(unsigned flags) {
SkBlitRow::Proc32 SkBlitRow::PlatformProcs32(unsigned flags) {
return NULL;
}
SkBlitRow::ColorProc SkBlitRow::PlatformColorProc() {
return NULL;
}

View File

@ -258,14 +258,6 @@ SkBlitRow::Proc32 SkBlitRow::PlatformProcs32(unsigned flags) {
}
}
SkBlitRow::ColorProc SkBlitRow::PlatformColorProc() {
if (supports_simd(SK_CPU_SSE_LEVEL_SSE2)) {
return Color32_SSE2;
} else {
return NULL;
}
}
////////////////////////////////////////////////////////////////////////////////
SkBlitMask::ColorProc SkBlitMask::PlatformColorProcs(SkColorType dstCT,