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

Side by Side Diff: include/core/SkFloatingPoint.h

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 2006 The Android Open Source Project 3 * Copyright 2006 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 #ifndef SkFloatingPoint_DEFINED 10 #ifndef SkFloatingPoint_DEFINED
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 #define sk_float_ceil2int(x) (int)sk_float_ceil(x) 89 #define sk_float_ceil2int(x) (int)sk_float_ceil(x)
90 #endif 90 #endif
91 91
92 extern const uint32_t gIEEENotANumber; 92 extern const uint32_t gIEEENotANumber;
93 extern const uint32_t gIEEEInfinity; 93 extern const uint32_t gIEEEInfinity;
94 extern const uint32_t gIEEENegativeInfinity; 94 extern const uint32_t gIEEENegativeInfinity;
95 95
96 #define SK_FloatNaN (*SkTCast<const float*>(&gIEEENotANumber)) 96 #define SK_FloatNaN (*SkTCast<const float*>(&gIEEENotANumber))
97 #define SK_FloatInfinity (*SkTCast<const float*>(&gIEEEInfinity)) 97 #define SK_FloatInfinity (*SkTCast<const float*>(&gIEEEInfinity))
98 #define SK_FloatNegativeInfinity (*SkTCast<const float*>(&gIEEENegativeInfini ty)) 98 #define SK_FloatNegativeInfinity (*SkTCast<const float*>(&gIEEENegativeInfini ty))
99
100 #ifdef __SSE__
101 #include <xmmintrin.h>
99 #endif 102 #endif
103
104 // Fast, approximate inverse square root.
105 // Compare to name-brand "1.0f / sk_float_sqrt(x)".
106 inline float sk_float_rsqrt(float x) {
reed1 2013/11/07 22:28:44 static ...
107 // We want all this inlined, so we'll inline SIMD and just take the hit when we don't know we've got
108 // it at compile time. This is going to be too fast to productively hide behind a function pointer.
109 #ifdef __SSE__
110 float result;
111 _mm_store_ss(&result, _mm_rsqrt_ss(_mm_set_ss(x)));
112 return result;
113 #else
114 // TODO(mtklein): NEON
115 float xhalf = 0.5f*x;
116 int i = *SkTCast<int*>(&x);
117 i = 0x5f3759df - (i>>1);
118 x = *SkTCast<float*>(&i);
119 x = x*(1.5f-xhalf*x*x);
120 // x = x*(1.5f-xhalf*x*x); // this line takes err from 10^-3 to 10^-6, but at what cost!?!?
121 return x;
122 #endif
123 }
124
125 #endif
OLDNEW
« no previous file with comments | « bench/MathBench.cpp ('k') | src/core/SkPoint.cpp » ('j') | src/core/SkPoint.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698