impl SkMulDiv255Round with SkMul16ShiftRound

Inlining shift=8 is trivial for any compiler.
This eliminates the need to unit test the two functions are the same.

Change-Id: Icd181ff11eab73fba26755a9fbecd57260c38bbf
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315887
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Mike Klein 2020-09-09 10:30:55 -05:00 committed by Skia Commit-Bot
parent a0d6dc76f6
commit 215d2b0fa4
2 changed files with 1 additions and 31 deletions

View File

@ -48,10 +48,7 @@ static inline unsigned SkMul16ShiftRound(U16CPU a, U16CPU b, int shift) {
* Only valid if a and b are unsigned and <= 32767.
*/
static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) {
SkASSERT(a <= 32767);
SkASSERT(b <= 32767);
unsigned prod = a*b + 128;
return (prod + (prod >> 8)) >> 8;
return SkMul16ShiftRound(a,b,8);
}
#endif

View File

@ -94,32 +94,6 @@ static void test_floor(skiatest::Reporter* reporter) {
///////////////////////////////////////////////////////////////////////////////
// test that SkMul16ShiftRound and SkMulDiv255Round return the same result
static void test_muldivround(skiatest::Reporter* reporter) {
#if 0
// this "complete" test is too slow, so we test a random sampling of it
for (int a = 0; a <= 32767; ++a) {
for (int b = 0; b <= 32767; ++b) {
unsigned prod0 = SkMul16ShiftRound(a, b, 8);
unsigned prod1 = SkMulDiv255Round(a, b);
SkASSERT(prod0 == prod1);
}
}
#endif
SkRandom rand;
for (int i = 0; i < 10000; ++i) {
unsigned a = rand.nextU() & 0x7FFF;
unsigned b = rand.nextU() & 0x7FFF;
unsigned prod0 = SkMul16ShiftRound(a, b, 8);
unsigned prod1 = SkMulDiv255Round(a, b);
REPORTER_ASSERT(reporter, prod0 == prod1);
}
}
static float float_blend(int src, int dst, float unit) {
return dst + (src - dst) * unit;
}
@ -536,7 +510,6 @@ DEF_TEST(Math, reporter) {
// disable for now
if (false) test_blend31(); // avoid bit rot, suppress warning
test_muldivround(reporter);
test_clz(reporter);
test_ctz(reporter);
}