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

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

Issue 1264543006: Port SkXfermode opts to SkOpts.h (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 4 months 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
« no previous file with comments | « gyp/opts.gypi ('k') | include/private/SkOpts.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #define SkFloatingPoint_DEFINED 11 #define SkFloatingPoint_DEFINED
12 12
13 #include "SkTypes.h" 13 #include "SkTypes.h"
14 #include "../private/SkOpts.h"
15 14
16 #include <math.h> 15 #include <math.h>
17 #include <float.h> 16 #include <float.h>
18 17
19 // For _POSIX_VERSION 18 // For _POSIX_VERSION
20 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) 19 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
21 #include <unistd.h> 20 #include <unistd.h>
22 #endif 21 #endif
23 22
24 #include "SkFloatBits.h" 23 #include "SkFloatBits.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 #define sk_double_ceil2int(x) (int)ceil(x) 120 #define sk_double_ceil2int(x) (int)ceil(x)
122 121
123 extern const uint32_t gIEEENotANumber; 122 extern const uint32_t gIEEENotANumber;
124 extern const uint32_t gIEEEInfinity; 123 extern const uint32_t gIEEEInfinity;
125 extern const uint32_t gIEEENegativeInfinity; 124 extern const uint32_t gIEEENegativeInfinity;
126 125
127 #define SK_FloatNaN (*SkTCast<const float*>(&gIEEENotANumber)) 126 #define SK_FloatNaN (*SkTCast<const float*>(&gIEEENotANumber))
128 #define SK_FloatInfinity (*SkTCast<const float*>(&gIEEEInfinity)) 127 #define SK_FloatInfinity (*SkTCast<const float*>(&gIEEEInfinity))
129 #define SK_FloatNegativeInfinity (*SkTCast<const float*>(&gIEEENegativeInfini ty)) 128 #define SK_FloatNegativeInfinity (*SkTCast<const float*>(&gIEEENegativeInfini ty))
130 129
130 // We forward declare this to break an #include cycle.
131 // (SkScalar -> SkFloatingPoint -> SkOpts.h -> SkXfermode -> SkColor -> SkScalar )
132 namespace SkOpts { extern float (*rsqrt)(float); }
133
131 // Fast, approximate inverse square root. 134 // Fast, approximate inverse square root.
132 // Compare to name-brand "1.0f / sk_float_sqrt(x)". Should be around 10x faster on SSE, 2x on NEON. 135 // Compare to name-brand "1.0f / sk_float_sqrt(x)". Should be around 10x faster on SSE, 2x on NEON.
133 static inline float sk_float_rsqrt(const float x) { 136 static inline float sk_float_rsqrt(const float x) {
134 // We want all this inlined, so we'll inline SIMD and just take the hit when we don't know we've got 137 // We want all this inlined, so we'll inline SIMD and just take the hit when we don't know we've got
135 // it at compile time. This is going to be too fast to productively hide behind a function pointer. 138 // it at compile time. This is going to be too fast to productively hide behind a function pointer.
136 // 139 //
137 // We do one step of Newton's method to refine the estimates in the NEON and nul l paths. No 140 // We do one step of Newton's method to refine the estimates in the NEON and nul l paths. No
138 // refinement is faster, but very innacurate. Two steps is more accurate, but s lower than 1/sqrt. 141 // refinement is faster, but very innacurate. Two steps is more accurate, but s lower than 1/sqrt.
139 // 142 //
140 // Optimized constants in the null path courtesy of http://rrrola.wz.cz/inv_sqrt .html 143 // Optimized constants in the null path courtesy of http://rrrola.wz.cz/inv_sqrt .html
141 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1 144 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
142 return _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ss(x))); 145 return _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ss(x)));
143 #elif defined(SK_ARM_HAS_NEON) 146 #elif defined(SK_ARM_HAS_NEON)
144 // Get initial estimate. 147 // Get initial estimate.
145 const float32x2_t xx = vdup_n_f32(x); // Clever readers will note we're doi ng everything 2x. 148 const float32x2_t xx = vdup_n_f32(x); // Clever readers will note we're doi ng everything 2x.
146 float32x2_t estimate = vrsqrte_f32(xx); 149 float32x2_t estimate = vrsqrte_f32(xx);
147 150
148 // One step of Newton's method to refine. 151 // One step of Newton's method to refine.
149 const float32x2_t estimate_sq = vmul_f32(estimate, estimate); 152 const float32x2_t estimate_sq = vmul_f32(estimate, estimate);
150 estimate = vmul_f32(estimate, vrsqrts_f32(xx, estimate_sq)); 153 estimate = vmul_f32(estimate, vrsqrts_f32(xx, estimate_sq));
151 return vget_lane_f32(estimate, 0); // 1 will work fine too; the answer's in both places. 154 return vget_lane_f32(estimate, 0); // 1 will work fine too; the answer's in both places.
152 #else 155 #else
153 // Perhaps runtime-detected NEON, or a portable fallback. 156 // Perhaps runtime-detected NEON, or a portable fallback.
154 return SkOpts::rsqrt(x); 157 return SkOpts::rsqrt(x);
155 #endif 158 #endif
156 } 159 }
157 160
158 #endif 161 #endif
OLDNEW
« no previous file with comments | « gyp/opts.gypi ('k') | include/private/SkOpts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698