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

Side by Side Diff: src/core/SkPoint.cpp

Issue 60083014: Add sk_float_rsqrt with SSE + NEON fast paths. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: reup Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2008 The Android Open Source Project 3 * Copyright 2008 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkPoint.h" 10 #include "SkPoint.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 * doubles, which is much slower (3x in a desktop test) but will not overflow. 156 * doubles, which is much slower (3x in a desktop test) but will not overflow.
157 */ 157 */
158 bool SkPoint::setLength(float x, float y, float length) { 158 bool SkPoint::setLength(float x, float y, float length) {
159 float mag2; 159 float mag2;
160 if (isLengthNearlyZero(x, y, &mag2)) { 160 if (isLengthNearlyZero(x, y, &mag2)) {
161 return false; 161 return false;
162 } 162 }
163 163
164 float scale; 164 float scale;
165 if (SkScalarIsFinite(mag2)) { 165 if (SkScalarIsFinite(mag2)) {
166 scale = length / sk_float_sqrt(mag2); 166 scale = length * sk_float_rsqrt(mag2);
reed1 2013/11/07 22:28:44 not prepared to land this, until we know more abou
167 } else { 167 } else {
168 // our mag2 step overflowed to infinity, so use doubles instead. 168 // our mag2 step overflowed to infinity, so use doubles instead.
169 // much slower, but needed when x or y are very large, other wise we 169 // much slower, but needed when x or y are very large, other wise we
170 // divide by inf. and return (0,0) vector. 170 // divide by inf. and return (0,0) vector.
171 double xx = x; 171 double xx = x;
172 double yy = y; 172 double yy = y;
173 scale = (float)(length / sqrt(xx * xx + yy * yy)); 173 scale = (float)(length / sqrt(xx * xx + yy * yy));
174 } 174 }
175 fX = x * scale; 175 fX = x * scale;
176 fY = y * scale; 176 fY = y * scale;
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 508
509 if (uDotV <= 0) { 509 if (uDotV <= 0) {
510 return v.lengthSqd(); 510 return v.lengthSqd();
511 } else if (uDotV > uLengthSqd) { 511 } else if (uDotV > uLengthSqd) {
512 return b.distanceToSqd(*this); 512 return b.distanceToSqd(*this);
513 } else { 513 } else {
514 SkScalar det = u.cross(v); 514 SkScalar det = u.cross(v);
515 return SkScalarMulDiv(det, det, uLengthSqd); 515 return SkScalarMulDiv(det, det, uLengthSqd);
516 } 516 }
517 } 517 }
OLDNEW
« include/core/SkFloatingPoint.h ('K') | « include/core/SkFloatingPoint.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698