Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Issue 21755002: Experiments on calculating reciprocal of square root (Closed)

Created:
7 years, 4 months ago by Yang Gu
Modified:
7 years, 4 months ago
CC:
skia-review_googlegroups.com
Visibility:
Public.

Description

Experiments on calculating reciprocal of square root BUG= Committed: http://code.google.com/p/skia/source/detail?r=10671

Patch Set 1 #

Patch Set 2 : Change existing benchmark code #

Patch Set 3 : Better calculate reciprocal of square root #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+54 lines, -31 lines) Patch
M bench/MathBench.cpp View 1 2 2 chunks +45 lines, -31 lines 0 comments Download
M include/core/SkMath.h View 1 2 1 chunk +9 lines, -0 lines 2 comments Download

Messages

Total messages: 17 (0 generated)
Yang Gu
Reciprocal of square root is often calculated here and there in the code, and we ...
7 years, 4 months ago (2013-08-02 08:28:47 UTC) #1
reed1
I'm not sure how important this is for Skia drawing operations. That said, have you ...
7 years, 4 months ago (2013-08-02 13:53:42 UTC) #2
tomhudson
https://code.google.com/p/skia/issues/detail?id=885 We've always seen "slow" inverse sqrt as faster than the "fast" variant in the ...
7 years, 4 months ago (2013-08-02 14:20:09 UTC) #3
Yang Gu
Glad to know you already put this in your radar. I inlined the two new ...
7 years, 4 months ago (2013-08-05 10:12:23 UTC) #4
Yang Gu
Invite Tom to review
7 years, 4 months ago (2013-08-08 04:53:33 UTC) #5
tomhudson
Let's try to figure out why this is giving different results than our pre-existing inverse ...
7 years, 4 months ago (2013-08-08 10:17:59 UTC) #6
Yang Gu
As I wrote a new benchmark, and tested data against it, so the difference of ...
7 years, 4 months ago (2013-08-09 06:15:15 UTC) #7
tomhudson
It sounds like a large chunk of the difference is that your new code and ...
7 years, 4 months ago (2013-08-09 09:48:58 UTC) #8
Yang Gu
According to my test last time, intrinsic solution is on par with fastinv solution, so ...
7 years, 4 months ago (2013-08-12 05:20:33 UTC) #9
tomhudson
lgtm
7 years, 4 months ago (2013-08-12 08:30:14 UTC) #10
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://skia-tree-status.appspot.com/cq/yang.gu@intel.com/21755002/18001
7 years, 4 months ago (2013-08-12 08:30:19 UTC) #11
commit-bot: I haz the power
Change committed as 10671
7 years, 4 months ago (2013-08-12 08:37:53 UTC) #12
reed1
https://codereview.chromium.org/21755002/diff/18001/include/core/SkMath.h File include/core/SkMath.h (right): https://codereview.chromium.org/21755002/diff/18001/include/core/SkMath.h#newcode176 include/core/SkMath.h:176: static inline float SkFloatInvSqrt(float x) { Need dox for ...
7 years, 4 months ago (2013-08-12 14:05:54 UTC) #13
Yang Gu
https://codereview.chromium.org/21755002/diff/18001/include/core/SkMath.h File include/core/SkMath.h (right): https://codereview.chromium.org/21755002/diff/18001/include/core/SkMath.h#newcode176 include/core/SkMath.h:176: static inline float SkFloatInvSqrt(float x) { On 2013/08/12 14:05:54, ...
7 years, 4 months ago (2013-08-13 03:33:31 UTC) #14
reed1
Since there is no caller in skia, I think we should move this into the ...
7 years, 4 months ago (2013-08-13 12:37:02 UTC) #15
tomhudson
On 2013/08/13 03:33:31, Yang Gu wrote: > > 2. Why is this public right now? ...
7 years, 4 months ago (2013-08-13 21:39:25 UTC) #16
Yang Gu
7 years, 4 months ago (2013-08-14 03:17:08 UTC) #17
Message was sent while issue was closed.
My argue is that even if we find the real Android workloads, we may also
question its generality. Actually the merged patch just moved code from
MathBench to core (I only renamed and reformatted it). I'm OK to add comments to
it, but I really don't know its original source. I think we can point it to code
of Quake 3, which is the origin of this algorithm. 
For me, this patch is reasonable as the calculation of reciprocal square root
happens at many places of Skia. So my plan is: 1) Have an API in core (the
merged patch). 2) Replace original calculations in Skia with this new API. 
I definitely need your green light for step 1, so that I may continue to work on
step 2. Below is a list (maybe not complete) I plan to work at step 2:

experimental/Intersection/SkAntiEdge.cpp
    double dist = fabs(numer) / sqrt(denom);

experimental/Intersection/LineParameters.h
    double normal = sqrt(normalSquared());
    double reciprocal = 1 / normal;

experimental/Intersection/ConvexHull_Test.cpp
    double length = sqrt(dx * dx + dy * dy);
    double invLength = 1 / length;

experimental/Intersection/CubicUtilities.cpp
    double theta = acos(R / sqrt(Q3));

experimental/Intersection/DataTypes.h
    const double FLT_EPSILON_SQRT = sqrt(FLT_EPSILON);
    const double FLT_EPSILON_INVERSE = 1 / FLT_EPSILON;

experimental/Intersection/CubicToQuadratics.cpp
    double dist = sqrt(dx * dx + dy * dy);
    double tDiv3 = precision / (adjust * dist);

experimental/AndroidPathRenderer/AndroidPathRenderer.cpp
    float scaleX = sk_float_sqrt(m00 * m00 + m01 * m01);
    float scaleY = sk_float_sqrt(m10 * m10 + m11 * m11);
    inverseScaleX = (scaleX != 0) ? (1.0f / scaleX) : 1.0f;
    inverseScaleY = (scaleY != 0) ? (1.0f / scaleY) : 1.0f;

samplecode/SampleAARects.cpp
    canvas->translate(SkFloatToScalar(20.0f / sqrtf(2.f)), SkFloatToScalar(20.0f
/ sqrtf(2.f)));

src/effects/SkEmbossMaskFilter.cpp
    mag = SkScalarSqrt(mag);
    for (int i = 0; i < 3; i++) {
        v[i] = SkScalarDiv(v[i], mag);
    }

src/views/SkTouchGesture.cpp
    double dist0 = sqrt(dx*dx + dy*dy);
    double scale = dist1 / dist0;

src/pathops/SkPathOpsCubic.cpp
    double theta = acos(R / sqrt(Q3));

src/pathops/SkLineParameters.h
    double normal = sqrt(normalSquared());
    double reciprocal = 1 / normal;

src/pathops/SkPathOpsTypes.h
    const double FLT_EPSILON_SQRT = sqrt(FLT_EPSILON);
    const double FLT_EPSILON_INVERSE = 1 / FLT_EPSILON;

src/utils/SkMatrix44.cpp
    double scale = 1 / sqrt(len2);

src/utils/SkCamera.cpp
    float mag = sk_float_sqrt(fX*fX + fY*fY + fZ*fZ);
    float scale = 1.0f / mag;

src/animator/SkAnimateActive.cpp
    SkScalar originalDistance = SkScalarSqrt(originalSum);
    SkScalar workingDistance = SkScalarSqrt(workingSum);
    existing->fState[index].fDuration = (SkMSec)
SkScalarMulDiv(fState[index].fDuration,
        workingDistance, originalDistance);

src/core/SkGeometry.cpp
    SkScalar root = SkScalarSqrt(tmp2[1].fZ);
    dst[0].fW = tmp2[0].fZ / root;
    dst[1].fW = tmp2[2].fZ / root;


src/core/SkBitmapProcState.cpp
    SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd));

src/core/SkStrokerPriv.cpp
    sinHalfAngle = SkScalarSqrt(SkScalarHalf(SK_Scalar1 + dotProd));
    mid.setLength(SkScalarDiv(radius, sinHalfAngle));

src/core/SkPoint.cpp
    mag = sk_float_sqrt(mag2);
    scale = 1 / mag;

Powered by Google App Engine
This is Rietveld 408576698