From: robertphillips@google.com Date: Mon, 12 Aug 2013 12:02:28 +0000 (+0000) Subject: Revert of r10671 (Experiments on calculating reciprocal of square root) due to bots... X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~11309 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=36bb270c1e05020d7f8df3bf244309fb44a9fff3;p=platform%2Fupstream%2FlibSkiaSharp.git Revert of r10671 (Experiments on calculating reciprocal of square root) due to bots failures: Win7: http://108.170.217.252:10117/builders/Build-Win7-VS2010-x86-Debug/builds/715/steps/BuildMost/logs/stdio Win8: http://108.170.217.252:10117/builders/Build-Win8-VS2012-x86-Debug/builds/383/steps/BuildMost/logs/stdio Mac10.6: http://108.170.217.252:10117/builders/Build-Mac10.6-GCC-x86-Debug/builds/1259/steps/BuildMost/logs/stdio git-svn-id: http://skia.googlecode.com/svn/trunk@10672 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/bench/MathBench.cpp b/bench/MathBench.cpp index c2b600c..32a89d6 100644 --- a/bench/MathBench.cpp +++ b/bench/MathBench.cpp @@ -93,58 +93,44 @@ private: typedef MathBench INHERITED; }; -class InvSqrtBench : public SkBenchmark { - enum { - ARRAY = SkBENCHLOOP(1000), - LOOP = SkBENCHLOOP(5000), - }; - float fData[ARRAY]; - const char *type; - +class SlowISqrtMathBench : public MathBench { public: - InvSqrtBench(void* param, const char *type) - : INHERITED(param) - , type(type) { - } - - // just so the compiler doesn't remove our loops - virtual void process(int) {} - + SlowISqrtMathBench(void* param) : INHERITED(param, "slowIsqrt") {} protected: - virtual void onPreDraw() SK_OVERRIDE { - SkRandom rand; - for (int i = 0; i < ARRAY; ++i) { - fData[i] = rand.nextRangeF(0, 10000); + virtual void performTest(float* SK_RESTRICT dst, + const float* SK_RESTRICT src, + int count) { + for (int i = 0; i < count; ++i) { + dst[i] = 1.0f / sk_float_sqrt(src[i]); } - - fIsRendering = false; } +private: + typedef MathBench INHERITED; +}; - virtual void onDraw(SkCanvas*) { - float accum = 0; +static inline float SkFastInvSqrt(float x) { + float xhalf = 0.5f*x; + int i = *SkTCast(&x); + i = 0x5f3759df - (i>>1); + x = *SkTCast(&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; +} - if (strcmp(type, "float_slow") == 0) { - for (int j = 0; j < LOOP; ++j) - for (int i = 0; i < ARRAY; ++i) - accum += 1.0f / sk_float_sqrt(fData[i]); - } else if (strcmp(type, "float_fast") == 0) { - for (int j = 0; j < LOOP; ++j) - for (int i = 0; i < ARRAY; ++i) - accum += SkFloatInvSqrt(fData[i]); +class FastISqrtMathBench : public MathBench { +public: + FastISqrtMathBench(void* param) : INHERITED(param, "fastIsqrt") {} +protected: + virtual void performTest(float* SK_RESTRICT dst, + const float* SK_RESTRICT src, + int count) { + for (int i = 0; i < count; ++i) { + dst[i] = SkFastInvSqrt(src[i]); } - - this->process(accum); - } - - virtual const char* onGetName() { - fName.printf("math_inv_sqrt"); - fName.appendf("_%s", type); - return fName.c_str(); } - private: - SkString fName; - typedef SkBenchmark INHERITED; + typedef MathBench INHERITED; }; static inline uint32_t QMul64(uint32_t value, U8CPU alpha) { @@ -537,8 +523,8 @@ private: /////////////////////////////////////////////////////////////////////////////// DEF_BENCH( return new NoOpMathBench(p); ) -DEF_BENCH( return new InvSqrtBench(p, "float_slow"); ) -DEF_BENCH( return new InvSqrtBench(p, "float_fast"); ) +DEF_BENCH( return new SlowISqrtMathBench(p); ) +DEF_BENCH( return new FastISqrtMathBench(p); ) DEF_BENCH( return new QMul64Bench(p); ) DEF_BENCH( return new QMul32Bench(p); ) diff --git a/include/core/SkMath.h b/include/core/SkMath.h index 66df00f..078c8fc 100644 --- a/include/core/SkMath.h +++ b/include/core/SkMath.h @@ -173,13 +173,4 @@ static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { return (prod + (prod >> 8)) >> 8; } -static inline float SkFloatInvSqrt(float x) { - float xhalf = 0.5f * x; - int i = *SkTCast(&x); - i = 0x5f3759df - (i >> 1); - x = *SkTCast(&i); - x = x * (1.5f - xhalf * x * x); - return x; -} - #endif