The compiler can generate smulbb perfectly well nowadays.

BUG=skia:4117

Review URL: https://codereview.chromium.org/1273203002
This commit is contained in:
mtklein 2015-08-07 08:48:12 -07:00 committed by Commit bot
parent ca1f07eb5f
commit 3848427d88
7 changed files with 23 additions and 60 deletions

View File

@ -193,7 +193,7 @@ static inline unsigned Sk255To256(U8CPU value) {
/** Multiplify value by 0..256, and shift the result down 8
(i.e. return (value * alpha256) >> 8)
*/
#define SkAlphaMul(value, alpha256) (SkMulS16(value, alpha256) >> 8)
#define SkAlphaMul(value, alpha256) (((value) * (alpha256)) >> 8)
// The caller may want negative values, so keep all params signed (int)
// so we don't accidentally slip into unsigned math and lose the sign
@ -213,7 +213,7 @@ static inline int SkAlphaBlend255(S16CPU src, S16CPU dst, U8CPU alpha) {
SkASSERT((int16_t)dst == dst);
SkASSERT((uint8_t)alpha == alpha);
int prod = SkMulS16(src - dst, alpha) + 128;
int prod = (src - dst) * alpha + 128;
prod = (prod + (prod >> 8)) >> 8;
return dst + prod;
}

View File

@ -156,34 +156,6 @@ template <typename T> inline bool SkIsPow2(T value) {
///////////////////////////////////////////////////////////////////////////////
/**
* SkMulS16(a, b) multiplies a * b, but requires that a and b are both int16_t.
* With this requirement, we can generate faster instructions on some
* architectures.
*/
#ifdef SK_ARM_HAS_EDSP
static inline int32_t SkMulS16(S16CPU x, S16CPU y) {
SkASSERT((int16_t)x == x);
SkASSERT((int16_t)y == y);
int32_t product;
asm("smulbb %0, %1, %2 \n"
: "=r"(product)
: "r"(x), "r"(y)
);
return product;
}
#else
#ifdef SK_DEBUG
static inline int32_t SkMulS16(S16CPU x, S16CPU y) {
SkASSERT((int16_t)x == x);
SkASSERT((int16_t)y == y);
return x * y;
}
#else
#define SkMulS16(x, y) ((x) * (y))
#endif
#endif
/**
* Return a*b/((1 << shift) - 1), rounding any fractional bits.
* Only valid if a and b are unsigned and <= 32767 and shift is > 0 and <= 8
@ -192,7 +164,7 @@ static inline unsigned SkMul16ShiftRound(U16CPU a, U16CPU b, int shift) {
SkASSERT(a <= 32767);
SkASSERT(b <= 32767);
SkASSERT(shift > 0 && shift <= 8);
unsigned prod = SkMulS16(a, b) + (1 << (shift - 1));
unsigned prod = a*b + (1 << (shift - 1));
return (prod + (prod >> shift)) >> shift;
}
@ -203,7 +175,7 @@ static inline unsigned SkMul16ShiftRound(U16CPU a, U16CPU b, int shift) {
static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) {
SkASSERT(a <= 32767);
SkASSERT(b <= 32767);
unsigned prod = SkMulS16(a, b) + 128;
unsigned prod = a*b + 128;
return (prod + (prod >> 8)) >> 8;
}

View File

@ -172,12 +172,6 @@
#else
#define SK_ARM_ARCH 3
#endif
#if defined(__thumb2__) && (SK_ARM_ARCH >= 6) \
|| !defined(__thumb__) && ((SK_ARM_ARCH > 5) || defined(__ARM_ARCH_5E__) \
|| defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__))
#define SK_ARM_HAS_EDSP
#endif
#endif
#endif

View File

@ -57,7 +57,7 @@ static inline unsigned SkClampUMax(unsigned value, unsigned max) {
static inline U8CPU SkMulDiv255Trunc(U8CPU a, U8CPU b) {
SkASSERT((uint8_t)a == a);
SkASSERT((uint8_t)b == b);
unsigned prod = SkMulS16(a, b) + 1;
unsigned prod = a*b + 1;
return (prod + (prod >> 8)) >> 8;
}
@ -67,7 +67,7 @@ static inline U8CPU SkMulDiv255Trunc(U8CPU a, U8CPU b) {
static inline U8CPU SkMulDiv255Ceiling(U8CPU a, U8CPU b) {
SkASSERT((uint8_t)a == a);
SkASSERT((uint8_t)b == b);
unsigned prod = SkMulS16(a, b) + 255;
unsigned prod = a*b + 255;
return (prod + (prod >> 8)) >> 8;
}

View File

@ -34,7 +34,7 @@
static inline int SmallDot6Scale(int value, int dot6) {
SkASSERT((int16_t)value == value);
SkASSERT((unsigned)dot6 <= 64);
return SkMulS16(value, dot6) >> 6;
return (value * dot6) >> 6;
}
//#define TEST_GAMMA

View File

@ -714,9 +714,9 @@ void S32A_D565_Blend_neon(uint16_t* SK_RESTRICT dst,
if (sc) {
uint16_t dc = *dst;
unsigned dst_scale = 255 - SkMulDiv255Round(SkGetPackedA32(sc), alpha);
unsigned dr = SkMulS16(SkPacked32ToR16(sc), alpha) + SkMulS16(SkGetPackedR16(dc), dst_scale);
unsigned dg = SkMulS16(SkPacked32ToG16(sc), alpha) + SkMulS16(SkGetPackedG16(dc), dst_scale);
unsigned db = SkMulS16(SkPacked32ToB16(sc), alpha) + SkMulS16(SkGetPackedB16(dc), dst_scale);
unsigned dr = (SkPacked32ToR16(sc) * alpha) + (SkGetPackedR16(dc) * dst_scale);
unsigned dg = (SkPacked32ToG16(sc) * alpha) + (SkGetPackedG16(dc) * dst_scale);
unsigned db = (SkPacked32ToB16(sc) * alpha) + (SkGetPackedB16(dc) * dst_scale);
*dst = SkPackRGB16(SkDiv255Round(dr), SkDiv255Round(dg), SkDiv255Round(db));
}
dst += 1;

View File

@ -753,12 +753,9 @@ static void S32A_D565_Blend_mips_dsp(uint16_t* SK_RESTRICT dst,
if (sc) {
uint16_t dc = *dst;
unsigned dst_scale = 255 - SkMulDiv255Round(SkGetPackedA32(sc), alpha);
unsigned dr = SkMulS16(SkPacked32ToR16(sc), alpha) +
SkMulS16(SkGetPackedR16(dc), dst_scale);
unsigned dg = SkMulS16(SkPacked32ToG16(sc), alpha) +
SkMulS16(SkGetPackedG16(dc), dst_scale);
unsigned db = SkMulS16(SkPacked32ToB16(sc), alpha) +
SkMulS16(SkGetPackedB16(dc), dst_scale);
unsigned dr = (SkPacked32ToR16(sc) * alpha) + (SkGetPackedR16(dc) * dst_scale);
unsigned dg = (SkPacked32ToG16(sc) * alpha) + (SkGetPackedG16(dc) * dst_scale);
unsigned db = (SkPacked32ToB16(sc) * alpha) + (SkGetPackedB16(dc) * dst_scale);
*dst = SkPackRGB16(SkDiv255Round(dr), SkDiv255Round(dg), SkDiv255Round(db));
}
dst += 1;