aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-18 19:11:30 +0000
committerGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-18 19:11:30 +0000
commit25a11e48e54b0d3895a69228090f1455131db987 (patch)
tree06c0bf040087d1d044924c17c408a0a52f15f0f8
parent114cfbd10ec2d91aa60fcc60a795c45d5b8345ae (diff)
Add bench to test float to fixed conversion
R=reed@google.com Review URL: https://codereview.chromium.org/19773006 git-svn-id: http://skia.googlecode.com/svn/trunk@10155 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--bench/MathBench.cpp44
-rw-r--r--include/core/SkFixed.h2
-rw-r--r--src/core/SkCordic.cpp12
3 files changed, 51 insertions, 7 deletions
diff --git a/bench/MathBench.cpp b/bench/MathBench.cpp
index 1fc5705be8..32a89d64ef 100644
--- a/bench/MathBench.cpp
+++ b/bench/MathBench.cpp
@@ -480,6 +480,48 @@ private:
///////////////////////////////////////////////////////////////////////////////
+class FixedMathBench : public SkBenchmark {
+ enum {
+ N = SkBENCHLOOP(1000),
+ NN = SkBENCHLOOP(1000),
+ };
+ float fData[N];
+ SkFixed fResult[N];
+public:
+
+ FixedMathBench(void* param) : INHERITED(param) {
+ SkRandom rand;
+ for (int i = 0; i < N; ++i) {
+ fData[i] = rand.nextSScalar1();
+ }
+
+ fIsRendering = false;
+ }
+
+protected:
+ virtual void onDraw(SkCanvas*) {
+ for (int j = 0; j < NN; ++j) {
+ for (int i = 0; i < N - 4; ++i) {
+ fResult[i] = SkFloatToFixed(fData[i]);
+ }
+ }
+
+ SkPaint paint;
+ if (paint.getAlpha() == 0) {
+ SkDebugf("%d\n", fResult[0]);
+ }
+ }
+
+ virtual const char* onGetName() {
+ return "float_to_fixed";
+ }
+
+private:
+ typedef SkBenchmark INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
DEF_BENCH( return new NoOpMathBench(p); )
DEF_BENCH( return new SlowISqrtMathBench(p); )
DEF_BENCH( return new FastISqrtMathBench(p); )
@@ -501,3 +543,5 @@ DEF_BENCH( return new CLZBench(p, false); )
DEF_BENCH( return new CLZBench(p, true); )
DEF_BENCH( return new NormalizeBench(p); )
+
+DEF_BENCH( return new FixedMathBench(p); )
diff --git a/include/core/SkFixed.h b/include/core/SkFixed.h
index ba2479a538..abeeccce10 100644
--- a/include/core/SkFixed.h
+++ b/include/core/SkFixed.h
@@ -192,7 +192,7 @@ inline bool SkFixedNearlyZero(SkFixed x, SkFixed tolerance = SK_FixedNearlyZero)
#if defined(SK_CPU_ARM) && !defined(__thumb__)
/* This guy does not handle NaN or other obscurities, but is faster than
- than (int)(x*65536) when we only have software floats
+ than (int)(x*65536)
*/
inline SkFixed SkFloatToFixed_arm(float x)
{
diff --git a/src/core/SkCordic.cpp b/src/core/SkCordic.cpp
index 00dd76ebb5..3adc92faa1 100644
--- a/src/core/SkCordic.cpp
+++ b/src/core/SkCordic.cpp
@@ -203,7 +203,7 @@ void SkCordic_UnitTest()
float val;
for (float angle = -720; angle < 720; angle += 30) {
float radian = angle * 3.1415925358f / 180.0f;
- SkFixed f_angle = (int) (radian * 65536.0f);
+ SkFixed f_angle = SkFloatToFixed(radian);
// sincos
float sine = sinf(radian);
float cosine = cosf(radian);
@@ -226,7 +226,7 @@ void SkCordic_UnitTest()
SkDebugf("tan error : angle = %g ; tan = %g ; cordic = %g\n", angle, _tan, tan2);
}
for (val = -1; val <= 1; val += .1f) {
- SkFixed f_val = (int) (val * 65536.0f);
+ SkFixed f_val = SkFloatToFixed(val);
// asin
float arcsine = asinf(val);
SkFixed f_arcsine = SkCordicASin(f_val);
@@ -240,7 +240,7 @@ void SkCordic_UnitTest()
#else
val = .5; {
#endif
- SkFixed f_val = (int) (val * 65536.0f);
+ SkFixed f_val = SkFloatToFixed(val);
// acos
float arccos = acosf(val);
SkFixed f_arccos = SkCordicACos(f_val);
@@ -257,8 +257,8 @@ void SkCordic_UnitTest()
val = 0; {
float val2 = -1000; {
#endif
- SkFixed f_val = (int) (val * 65536.0f);
- SkFixed f_val2 = (int) (val2 * 65536.0f);
+ SkFixed f_val = SkFloatToFixed(val);
+ SkFixed f_val2 = SkFloatToFixed(val2);
float arctan = atan2f(val, val2);
SkFixed f_arctan = SkCordicATan2(f_val, f_val2);
float arctan2 = (float) f_arctan / 65536.0f;
@@ -273,7 +273,7 @@ void SkCordic_UnitTest()
#else
val = .5; {
#endif
- SkFixed f_val = (int) (val * 65536.0f);
+ SkFixed f_val = SkFloatToFixed(val);
// acos
float log = logf(val);
SkFixed f_log = SkCordicLog(f_val);