replace SkFixedDiv impl with native 64bit math

BUG=skia:
TBR=

Review URL: https://codereview.chromium.org/1022543003
This commit is contained in:
reed 2015-03-18 19:04:43 -07:00 committed by Commit bot
parent 1a5041e446
commit 7c44ca926b
2 changed files with 48 additions and 1 deletions

View File

@ -545,6 +545,50 @@ private:
///////////////////////////////////////////////////////////////////////////////
class DivBitsBench : public Benchmark {
protected:
enum {
N = 1000
};
volatile int32_t fSrc[N], fDst[N];
public:
DivBitsBench() {
SkRandom rand;
for (int i = 0; i < N; ++i) {
fSrc[i] = rand.nextU();
}
}
protected:
virtual void onDraw(const int loops, SkCanvas*) {
for (int j = 0; j < loops; ++j) {
for (int i = 0; i < N - 4; ++i) {
fDst[i] = SkDivBits(fSrc[i], fSrc[i] >> 3, 16);
}
}
}
virtual const char* onGetName() {
return "divbits";
}
};
DEF_BENCH( return new DivBitsBench; )
class FixedDivBench : public DivBitsBench {
protected:
virtual void onDraw(const int loops, SkCanvas*) {
for (int j = 0; j < loops; ++j) {
for (int i = 0; i < N - 4; ++i) {
fDst[i] = SkFixedDiv(fSrc[i], fSrc[i] >> 3);
}
}
}
virtual const char* onGetName() {
return "fixeddiv";
}
};
DEF_BENCH( return new FixedDivBench; )
///////////////////////////////////////////////////////////////////////////////
template <typename T>
class DivModBench : public Benchmark {
SkString fName;

View File

@ -78,7 +78,10 @@ typedef int32_t SkFixed;
#define SkFixedAbs(x) SkAbs32(x)
#define SkFixedAve(a, b) (((a) + (b)) >> 1)
#define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16)
static inline int32_t SkFixedDiv(int32_t numer, int32_t denom) {
int64_t tmp = ((int64_t)numer << 16) / denom;
return (int32_t)tmp;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Now look for ASM overrides for our portable versions (should consider putting this in its own file)