2015-07-13 13:18:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2011-10-10 14:19:40 +00:00
|
|
|
#include "SkColorPriv.h"
|
2011-08-29 17:49:23 +00:00
|
|
|
#include "SkMatrix.h"
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "SkPaint.h"
|
2011-08-29 17:49:23 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
2012-05-30 12:26:52 +00:00
|
|
|
static float sk_fsel(float pred, float result_ge, float result_lt) {
|
|
|
|
return pred >= 0 ? result_ge : result_lt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float fast_floor(float x) {
|
2012-05-30 14:08:57 +00:00
|
|
|
// float big = sk_fsel(x, 0x1.0p+23, -0x1.0p+23);
|
|
|
|
float big = sk_fsel(x, (float)(1 << 23), -(float)(1 << 23));
|
2012-05-30 12:26:52 +00:00
|
|
|
return (x + big) - big;
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class MathBench : public Benchmark {
|
2011-08-29 17:49:23 +00:00
|
|
|
enum {
|
|
|
|
kBuffer = 100,
|
|
|
|
};
|
|
|
|
SkString fName;
|
|
|
|
float fSrc[kBuffer], fDst[kBuffer];
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
MathBench(const char name[]) {
|
2011-08-29 17:49:23 +00:00
|
|
|
fName.printf("math_%s", name);
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2011-08-29 17:49:23 +00:00
|
|
|
for (int i = 0; i < kBuffer; ++i) {
|
|
|
|
fSrc[i] = rand.nextSScalar1();
|
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
2012-09-13 15:50:24 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2011-08-29 17:49:23 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 18:09:54 +00:00
|
|
|
virtual void performTest(float* SK_RESTRICT dst,
|
|
|
|
const float* SK_RESTRICT src,
|
2012-04-16 15:50:18 +00:00
|
|
|
int count) = 0;
|
2011-08-29 17:49:23 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual int mulLoopCount() const { return 1; }
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2011-08-29 17:49:23 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
int n = loops * this->mulLoopCount();
|
2011-08-29 17:49:23 +00:00
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
this->performTest(fDst, fSrc, kBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2011-08-29 17:49:23 +00:00
|
|
|
};
|
|
|
|
|
2011-10-10 14:19:40 +00:00
|
|
|
class MathBenchU32 : public MathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
MathBenchU32(const char name[]) : INHERITED(name) {}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2011-10-10 14:19:40 +00:00
|
|
|
protected:
|
2012-08-23 18:09:54 +00:00
|
|
|
virtual void performITest(uint32_t* SK_RESTRICT dst,
|
|
|
|
const uint32_t* SK_RESTRICT src,
|
2012-04-16 15:50:18 +00:00
|
|
|
int count) = 0;
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int count) override {
|
2011-10-10 14:19:40 +00:00
|
|
|
uint32_t* d = SkTCast<uint32_t*>(dst);
|
|
|
|
const uint32_t* s = SkTCast<const uint32_t*>(src);
|
|
|
|
this->performITest(d, s, count);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef MathBench INHERITED;
|
|
|
|
};
|
2011-08-29 17:49:23 +00:00
|
|
|
|
2011-10-10 14:19:40 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-08-29 17:49:23 +00:00
|
|
|
|
|
|
|
class NoOpMathBench : public MathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
NoOpMathBench() : INHERITED("noOp") {}
|
2011-08-29 17:49:23 +00:00
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int count) override {
|
2011-08-29 17:49:23 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
dst[i] = src[i] + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef MathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2013-11-08 20:14:16 +00:00
|
|
|
class SkRSqrtMathBench : public MathBench {
|
|
|
|
public:
|
|
|
|
SkRSqrtMathBench() : INHERITED("sk_float_rsqrt") {}
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int count) override {
|
2013-11-08 20:14:16 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
dst[i] = sk_float_rsqrt(src[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef MathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-12 12:02:28 +00:00
|
|
|
class SlowISqrtMathBench : public MathBench {
|
2011-08-29 17:49:23 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
SlowISqrtMathBench() : INHERITED("slowIsqrt") {}
|
2011-08-29 17:49:23 +00:00
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int count) override {
|
2013-08-12 12:02:28 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
dst[i] = 1.0f / sk_float_sqrt(src[i]);
|
2011-08-29 17:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-12 12:02:28 +00:00
|
|
|
private:
|
|
|
|
typedef MathBench INHERITED;
|
|
|
|
};
|
2011-08-29 17:49:23 +00:00
|
|
|
|
2013-08-12 12:02:28 +00:00
|
|
|
static inline float SkFastInvSqrt(float x) {
|
|
|
|
float xhalf = 0.5f*x;
|
|
|
|
int i = *SkTCast<int*>(&x);
|
|
|
|
i = 0x5f3759df - (i>>1);
|
|
|
|
x = *SkTCast<float*>(&i);
|
|
|
|
x = x*(1.5f-xhalf*x*x);
|
|
|
|
// x = x*(1.5f-xhalf*x*x); // this line takes err from 10^-3 to 10^-6
|
|
|
|
return x;
|
|
|
|
}
|
2011-08-29 17:49:23 +00:00
|
|
|
|
2013-08-12 12:02:28 +00:00
|
|
|
class FastISqrtMathBench : public MathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
FastISqrtMathBench() : INHERITED("fastIsqrt") {}
|
2013-08-12 12:02:28 +00:00
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int count) override {
|
2013-08-12 12:02:28 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
dst[i] = SkFastInvSqrt(src[i]);
|
2011-08-29 17:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2013-08-12 12:02:28 +00:00
|
|
|
typedef MathBench INHERITED;
|
2011-08-29 17:49:23 +00:00
|
|
|
};
|
|
|
|
|
2011-10-10 14:19:40 +00:00
|
|
|
static inline uint32_t QMul64(uint32_t value, U8CPU alpha) {
|
|
|
|
SkASSERT((uint8_t)alpha == alpha);
|
|
|
|
const uint32_t mask = 0xFF00FF;
|
|
|
|
|
|
|
|
uint64_t tmp = value;
|
|
|
|
tmp = (tmp & mask) | ((tmp & ~mask) << 24);
|
|
|
|
tmp *= alpha;
|
2012-06-06 12:11:45 +00:00
|
|
|
return (uint32_t) (((tmp >> 8) & mask) | ((tmp >> 32) & ~mask));
|
2011-10-10 14:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class QMul64Bench : public MathBenchU32 {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
QMul64Bench() : INHERITED("qmul64") {}
|
2011-10-10 14:19:40 +00:00
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performITest(uint32_t* SK_RESTRICT dst,
|
|
|
|
const uint32_t* SK_RESTRICT src,
|
|
|
|
int count) override {
|
2011-10-10 14:19:40 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
dst[i] = QMul64(src[i], (uint8_t)i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef MathBenchU32 INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class QMul32Bench : public MathBenchU32 {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
QMul32Bench() : INHERITED("qmul32") {}
|
2011-10-10 14:19:40 +00:00
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performITest(uint32_t* SK_RESTRICT dst,
|
|
|
|
const uint32_t* SK_RESTRICT src,
|
|
|
|
int count) override {
|
2011-10-10 14:19:40 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
dst[i] = SkAlphaMulQ(src[i], (uint8_t)i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef MathBenchU32 INHERITED;
|
|
|
|
};
|
|
|
|
|
2011-08-29 17:49:23 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-12-05 21:53:22 +00:00
|
|
|
static bool isFinite_int(float x) {
|
|
|
|
uint32_t bits = SkFloat2Bits(x); // need unsigned for our shifts
|
|
|
|
int exponent = bits << 1 >> 24;
|
|
|
|
return exponent != 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isFinite_float(float x) {
|
2012-04-16 15:50:18 +00:00
|
|
|
return SkToBool(sk_float_isfinite(x));
|
2011-12-05 21:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isFinite_mulzero(float x) {
|
|
|
|
float y = x * 0;
|
|
|
|
return y == y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isfinite_and_int(const float data[4]) {
|
|
|
|
return isFinite_int(data[0]) && isFinite_int(data[1]) && isFinite_int(data[2]) && isFinite_int(data[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isfinite_and_float(const float data[4]) {
|
|
|
|
return isFinite_float(data[0]) && isFinite_float(data[1]) && isFinite_float(data[2]) && isFinite_float(data[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isfinite_and_mulzero(const float data[4]) {
|
|
|
|
return isFinite_mulzero(data[0]) && isFinite_mulzero(data[1]) && isFinite_mulzero(data[2]) && isFinite_mulzero(data[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define mulzeroadd(data) (data[0]*0 + data[1]*0 + data[2]*0 + data[3]*0)
|
|
|
|
|
|
|
|
static bool isfinite_plus_int(const float data[4]) {
|
|
|
|
return isFinite_int(mulzeroadd(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isfinite_plus_float(const float data[4]) {
|
2011-12-06 20:18:05 +00:00
|
|
|
return !sk_float_isnan(mulzeroadd(data));
|
2011-12-05 21:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isfinite_plus_mulzero(const float data[4]) {
|
|
|
|
float x = mulzeroadd(data);
|
|
|
|
return x == x;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef bool (*IsFiniteProc)(const float[]);
|
|
|
|
|
|
|
|
#define MAKEREC(name) { name, #name }
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
IsFiniteProc fProc;
|
|
|
|
const char* fName;
|
|
|
|
} gRec[] = {
|
|
|
|
MAKEREC(isfinite_and_int),
|
|
|
|
MAKEREC(isfinite_and_float),
|
|
|
|
MAKEREC(isfinite_and_mulzero),
|
|
|
|
MAKEREC(isfinite_plus_int),
|
|
|
|
MAKEREC(isfinite_plus_float),
|
|
|
|
MAKEREC(isfinite_plus_mulzero),
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef MAKEREC
|
|
|
|
|
2011-12-06 18:56:37 +00:00
|
|
|
static bool isFinite(const SkRect& r) {
|
|
|
|
// x * 0 will be NaN iff x is infinity or NaN.
|
|
|
|
// a + b will be NaN iff either a or b is NaN.
|
|
|
|
float value = r.fLeft * 0 + r.fTop * 0 + r.fRight * 0 + r.fBottom * 0;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-12-06 18:56:37 +00:00
|
|
|
// value is either NaN or it is finite (zero).
|
|
|
|
// value==value will be true iff value is not NaN
|
|
|
|
return value == value;
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class IsFiniteBench : public Benchmark {
|
2011-12-05 21:53:22 +00:00
|
|
|
enum {
|
2013-09-10 19:23:38 +00:00
|
|
|
N = 1000,
|
2011-12-05 21:53:22 +00:00
|
|
|
};
|
|
|
|
float fData[N];
|
|
|
|
public:
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
IsFiniteBench(int index) {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2011-12-05 21:53:22 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
fData[i] = rand.nextSScalar1();
|
|
|
|
}
|
2011-12-06 18:56:37 +00:00
|
|
|
|
|
|
|
if (index < 0) {
|
2015-08-27 14:41:13 +00:00
|
|
|
fProc = nullptr;
|
2011-12-06 18:56:37 +00:00
|
|
|
fName = "isfinite_rect";
|
|
|
|
} else {
|
|
|
|
fProc = gRec[index].fProc;
|
|
|
|
fName = gRec[index].fName;
|
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2011-12-05 21:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2011-12-05 21:53:22 +00:00
|
|
|
IsFiniteProc proc = fProc;
|
|
|
|
const float* data = fData;
|
2011-12-06 18:56:37 +00:00
|
|
|
// do this so the compiler won't throw away the function call
|
|
|
|
int counter = 0;
|
|
|
|
|
|
|
|
if (proc) {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int j = 0; j < loops; ++j) {
|
2011-12-06 18:56:37 +00:00
|
|
|
for (int i = 0; i < N - 4; ++i) {
|
|
|
|
counter += proc(&data[i]);
|
|
|
|
}
|
2011-12-05 21:53:22 +00:00
|
|
|
}
|
2011-12-06 18:56:37 +00:00
|
|
|
} else {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int j = 0; j < loops; ++j) {
|
2011-12-06 18:56:37 +00:00
|
|
|
for (int i = 0; i < N - 4; ++i) {
|
|
|
|
const SkRect* r = reinterpret_cast<const SkRect*>(&data[i]);
|
2012-06-06 12:11:45 +00:00
|
|
|
if (false) { // avoid bit rot, suppress warning
|
|
|
|
isFinite(*r);
|
|
|
|
}
|
2011-12-06 18:56:37 +00:00
|
|
|
counter += r->isFinite();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-12-06 18:56:37 +00:00
|
|
|
SkPaint paint;
|
|
|
|
if (paint.getAlpha() == 0) {
|
|
|
|
SkDebugf("%d\n", counter);
|
2011-12-05 21:53:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2011-12-05 21:53:22 +00:00
|
|
|
return fName;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-12-05 21:53:22 +00:00
|
|
|
private:
|
|
|
|
IsFiniteProc fProc;
|
|
|
|
const char* fName;
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2011-12-05 21:53:22 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class FloorBench : public Benchmark {
|
2012-05-30 12:26:52 +00:00
|
|
|
enum {
|
2013-09-10 19:23:38 +00:00
|
|
|
ARRAY = 1000,
|
2012-05-30 12:26:52 +00:00
|
|
|
};
|
|
|
|
float fData[ARRAY];
|
|
|
|
bool fFast;
|
|
|
|
public:
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
FloorBench(bool fast) : fFast(fast) {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-30 12:26:52 +00:00
|
|
|
for (int i = 0; i < ARRAY; ++i) {
|
|
|
|
fData[i] = rand.nextSScalar1();
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-30 12:26:52 +00:00
|
|
|
if (fast) {
|
|
|
|
fName = "floor_fast";
|
|
|
|
} else {
|
|
|
|
fName = "floor_std";
|
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2012-05-30 12:26:52 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-30 12:26:52 +00:00
|
|
|
virtual void process(float) {}
|
|
|
|
|
|
|
|
protected:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-05-30 12:26:52 +00:00
|
|
|
float accum = 0;
|
|
|
|
const float* data = fData;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-30 12:26:52 +00:00
|
|
|
if (fFast) {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int j = 0; j < loops; ++j) {
|
2012-05-30 12:26:52 +00:00
|
|
|
for (int i = 0; i < ARRAY; ++i) {
|
|
|
|
accum += fast_floor(data[i]);
|
|
|
|
}
|
|
|
|
this->process(accum);
|
|
|
|
}
|
|
|
|
} else {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int j = 0; j < loops; ++j) {
|
2012-05-30 12:26:52 +00:00
|
|
|
for (int i = 0; i < ARRAY; ++i) {
|
|
|
|
accum += sk_float_floor(data[i]);
|
|
|
|
}
|
|
|
|
this->process(accum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2012-05-30 12:26:52 +00:00
|
|
|
return fName;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-30 12:26:52 +00:00
|
|
|
private:
|
|
|
|
const char* fName;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-30 12:26:52 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class CLZBench : public Benchmark {
|
2013-04-29 13:55:11 +00:00
|
|
|
enum {
|
2013-09-10 19:23:38 +00:00
|
|
|
ARRAY = 1000,
|
2013-04-29 13:55:11 +00:00
|
|
|
};
|
|
|
|
uint32_t fData[ARRAY];
|
|
|
|
bool fUsePortable;
|
|
|
|
|
2013-04-30 07:01:03 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
CLZBench(bool usePortable) : fUsePortable(usePortable) {
|
2013-04-29 13:55:11 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-04-29 13:55:11 +00:00
|
|
|
for (int i = 0; i < ARRAY; ++i) {
|
|
|
|
fData[i] = rand.nextU();
|
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-29 13:55:11 +00:00
|
|
|
if (fUsePortable) {
|
|
|
|
fName = "clz_portable";
|
|
|
|
} else {
|
|
|
|
fName = "clz_intrinsic";
|
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2013-04-29 13:55:11 +00:00
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-29 13:55:11 +00:00
|
|
|
// just so the compiler doesn't remove our loops
|
|
|
|
virtual void process(int) {}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-29 13:55:11 +00:00
|
|
|
protected:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-04-29 13:55:11 +00:00
|
|
|
int accum = 0;
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-29 13:55:11 +00:00
|
|
|
if (fUsePortable) {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int j = 0; j < loops; ++j) {
|
2013-04-29 13:55:11 +00:00
|
|
|
for (int i = 0; i < ARRAY; ++i) {
|
|
|
|
accum += SkCLZ_portable(fData[i]);
|
|
|
|
}
|
|
|
|
this->process(accum);
|
|
|
|
}
|
|
|
|
} else {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int j = 0; j < loops; ++j) {
|
2013-04-29 13:55:11 +00:00
|
|
|
for (int i = 0; i < ARRAY; ++i) {
|
|
|
|
accum += SkCLZ(fData[i]);
|
|
|
|
}
|
|
|
|
this->process(accum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-29 13:55:11 +00:00
|
|
|
return fName;
|
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-29 13:55:11 +00:00
|
|
|
private:
|
|
|
|
const char* fName;
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-04-29 13:55:11 +00:00
|
|
|
};
|
|
|
|
|
2011-12-05 21:53:22 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class NormalizeBench : public Benchmark {
|
2013-05-03 12:56:39 +00:00
|
|
|
enum {
|
2013-09-10 19:23:38 +00:00
|
|
|
ARRAY =1000,
|
2013-05-03 12:56:39 +00:00
|
|
|
};
|
|
|
|
SkVector fVec[ARRAY];
|
2013-05-04 07:01:15 +00:00
|
|
|
|
2013-05-03 12:56:39 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
NormalizeBench() {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-05-03 12:56:39 +00:00
|
|
|
for (int i = 0; i < ARRAY; ++i) {
|
|
|
|
fVec[i].set(rand.nextSScalar1(), rand.nextSScalar1());
|
|
|
|
}
|
2013-05-04 07:01:15 +00:00
|
|
|
|
2013-05-03 12:56:39 +00:00
|
|
|
fName = "point_normalize";
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2013-05-03 12:56:39 +00:00
|
|
|
}
|
2013-05-04 07:01:15 +00:00
|
|
|
|
2013-05-03 12:56:39 +00:00
|
|
|
// just so the compiler doesn't remove our loops
|
|
|
|
virtual void process(int) {}
|
2013-05-04 07:01:15 +00:00
|
|
|
|
2013-05-03 12:56:39 +00:00
|
|
|
protected:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-05-03 12:56:39 +00:00
|
|
|
int accum = 0;
|
2013-05-04 07:01:15 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int j = 0; j < loops; ++j) {
|
2013-05-03 12:56:39 +00:00
|
|
|
for (int i = 0; i < ARRAY; ++i) {
|
|
|
|
accum += fVec[i].normalize();
|
|
|
|
}
|
|
|
|
this->process(accum);
|
|
|
|
}
|
|
|
|
}
|
2013-05-04 07:01:15 +00:00
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2013-05-03 12:56:39 +00:00
|
|
|
return fName;
|
|
|
|
}
|
2013-05-04 07:01:15 +00:00
|
|
|
|
2013-05-03 12:56:39 +00:00
|
|
|
private:
|
|
|
|
const char* fName;
|
2013-05-04 07:01:15 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-05-03 12:56:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class FixedMathBench : public Benchmark {
|
2013-07-18 19:11:30 +00:00
|
|
|
enum {
|
2013-09-10 19:23:38 +00:00
|
|
|
N = 1000,
|
2013-07-18 19:11:30 +00:00
|
|
|
};
|
|
|
|
float fData[N];
|
|
|
|
SkFixed fResult[N];
|
|
|
|
public:
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
FixedMathBench() {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
fData[i] = rand.nextSScalar1();
|
2013-07-18 19:11:30 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2013-07-18 19:11:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int j = 0; j < loops; ++j) {
|
2013-07-18 19:11:30 +00:00
|
|
|
for (int i = 0; i < N - 4; ++i) {
|
|
|
|
fResult[i] = SkFloatToFixed(fData[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
if (paint.getAlpha() == 0) {
|
|
|
|
SkDebugf("%d\n", fResult[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2013-07-18 19:11:30 +00:00
|
|
|
return "float_to_fixed";
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-07-18 19:11:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-26 19:22:54 +00:00
|
|
|
template <typename T>
|
2014-06-19 19:32:29 +00:00
|
|
|
class DivModBench : public Benchmark {
|
2013-09-27 13:39:14 +00:00
|
|
|
SkString fName;
|
2013-09-26 19:22:54 +00:00
|
|
|
public:
|
2013-09-27 13:39:14 +00:00
|
|
|
explicit DivModBench(const char* name) {
|
|
|
|
fName.printf("divmod_%s", name);
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2013-09-26 19:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2013-09-27 13:39:14 +00:00
|
|
|
return fName.c_str();
|
2013-09-26 19:22:54 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-09-26 19:22:54 +00:00
|
|
|
volatile T a = 0, b = 0;
|
|
|
|
T div = 0, mod = 0;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-09-26 19:22:54 +00:00
|
|
|
if ((T)i == 0) continue; // Small T will wrap around.
|
|
|
|
SkTDivMod((T)(i+1), (T)i, &div, &mod);
|
|
|
|
a ^= div;
|
|
|
|
b ^= mod;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DEF_BENCH(return new DivModBench<uint8_t>("uint8_t"))
|
|
|
|
DEF_BENCH(return new DivModBench<uint16_t>("uint16_t"))
|
|
|
|
DEF_BENCH(return new DivModBench<uint32_t>("uint32_t"))
|
|
|
|
DEF_BENCH(return new DivModBench<uint64_t>("uint64_t"))
|
|
|
|
|
|
|
|
DEF_BENCH(return new DivModBench<int8_t>("int8_t"))
|
|
|
|
DEF_BENCH(return new DivModBench<int16_t>("int16_t"))
|
|
|
|
DEF_BENCH(return new DivModBench<int32_t>("int32_t"))
|
|
|
|
DEF_BENCH(return new DivModBench<int64_t>("int64_t"))
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new NoOpMathBench(); )
|
2013-11-08 20:14:16 +00:00
|
|
|
DEF_BENCH( return new SkRSqrtMathBench(); )
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new SlowISqrtMathBench(); )
|
|
|
|
DEF_BENCH( return new FastISqrtMathBench(); )
|
|
|
|
DEF_BENCH( return new QMul64Bench(); )
|
|
|
|
DEF_BENCH( return new QMul32Bench(); )
|
2013-04-29 13:48:34 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new IsFiniteBench(-1); )
|
|
|
|
DEF_BENCH( return new IsFiniteBench(0); )
|
|
|
|
DEF_BENCH( return new IsFiniteBench(1); )
|
|
|
|
DEF_BENCH( return new IsFiniteBench(2); )
|
|
|
|
DEF_BENCH( return new IsFiniteBench(3); )
|
|
|
|
DEF_BENCH( return new IsFiniteBench(4); )
|
|
|
|
DEF_BENCH( return new IsFiniteBench(5); )
|
2013-04-29 13:48:34 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new FloorBench(false); )
|
|
|
|
DEF_BENCH( return new FloorBench(true); )
|
2013-04-29 13:48:34 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new CLZBench(false); )
|
|
|
|
DEF_BENCH( return new CLZBench(true); )
|
2013-05-03 12:56:39 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new NormalizeBench(); )
|
2013-07-18 19:11:30 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new FixedMathBench(); )
|