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

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

Issue 1264893002: Runtime CPU detection for rsqrt(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « src/core/SkOpts.h ('k') | src/opts/SkOpts_neon.cpp » ('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 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkOnce.h" 8 #include "SkOnce.h"
9 #include "SkOpts.h" 9 #include "SkOpts.h"
10 10
11 #if defined(SK_CPU_X86) 11 #if defined(SK_CPU_X86)
12 #if defined(SK_BUILD_FOR_WIN32) 12 #if defined(SK_BUILD_FOR_WIN32)
13 #include <intrin.h> 13 #include <intrin.h>
14 static void cpuid(uint32_t abcd[4]) { __cpuid((int*)abcd, 1); } 14 static void cpuid(uint32_t abcd[4]) { __cpuid((int*)abcd, 1); }
15 #else 15 #else
16 #include <cpuid.h> 16 #include <cpuid.h>
17 static void cpuid(uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, abc d+2, abcd+3); } 17 static void cpuid(uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, abc d+2, abcd+3); }
18 #endif 18 #endif
19 #elif !defined(SK_ARM_HAS_NEON) && defined(SK_CPU_ARM32) && defined(SK_BUILD_FOR _ANDROID) 19 #elif !defined(SK_ARM_HAS_NEON) && defined(SK_CPU_ARM32) && defined(SK_BUILD_FOR _ANDROID)
20 #include <cpu-features.h> 20 #include <cpu-features.h>
21 #endif 21 #endif
22 22
23 static float rsqrt_portable(float x) {
24 // Get initial estimate.
25 int i = *SkTCast<int*>(&x);
26 i = 0x5F1FFFF9 - (i>>1);
27 float estimate = *SkTCast<float*>(&i);
28
29 // One step of Newton's method to refine.
30 const float estimate_sq = estimate*estimate;
31 estimate *= 0.703952253f*(2.38924456f-x*estimate_sq);
32 return estimate;
33 }
34
23 namespace SkOpts { 35 namespace SkOpts {
24 // (Define default function pointer values here...) 36 // Define default function pointer values here...
37 decltype(rsqrt) rsqrt = rsqrt_portable;
25 38
26 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. 39 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp.
27 void Init_sse2(); 40 void Init_sse2();
28 void Init_ssse3(); 41 void Init_ssse3();
29 void Init_sse41(); 42 void Init_sse41();
30 void Init_neon(); 43 void Init_neon();
31 //TODO: _dsp2, _armv7, _armv8, _x86, _x86_64, _sse42, _avx, avx2, ... ? 44 //TODO: _dsp2, _armv7, _armv8, _x86, _x86_64, _sse42, _avx, avx2, ... ?
32 45
33 static void init() { 46 static void init() {
34 #if defined(SK_CPU_X86) 47 #if defined(SK_CPU_X86)
(...skipping 11 matching lines...) Expand all
46 59
47 SK_DECLARE_STATIC_ONCE(gInitOnce); 60 SK_DECLARE_STATIC_ONCE(gInitOnce);
48 void Init() { SkOnce(&gInitOnce, init); } 61 void Init() { SkOnce(&gInitOnce, init); }
49 62
50 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 63 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
51 static struct AutoInit { 64 static struct AutoInit {
52 AutoInit() { Init(); } 65 AutoInit() { Init(); }
53 } gAutoInit; 66 } gAutoInit;
54 #endif 67 #endif
55 } 68 }
OLDNEW
« no previous file with comments | « src/core/SkOpts.h ('k') | src/opts/SkOpts_neon.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698