mtklein | 8317a18 | 2015-07-30 07:30:16 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkOnce.h" |
| 9 | #include "SkOpts.h" |
| 10 | |
| 11 | #if defined(SK_CPU_X86) |
| 12 | #if defined(SK_BUILD_FOR_WIN32) |
| 13 | #include <intrin.h> |
| 14 | static void cpuid(uint32_t abcd[4]) { __cpuid((int*)abcd, 1); } |
| 15 | #else |
| 16 | #include <cpuid.h> |
| 17 | static void cpuid(uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, abcd+2, abcd+3); } |
| 18 | #endif |
| 19 | #elif !defined(SK_ARM_HAS_NEON) && defined(SK_CPU_ARM32) && defined(SK_BUILD_FOR_ANDROID) |
| 20 | #include <cpu-features.h> |
| 21 | #endif |
| 22 | |
| 23 | namespace SkOpts { |
| 24 | // (Define default function pointer values here...) |
| 25 | |
| 26 | // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. |
| 27 | void Init_sse2(); |
| 28 | void Init_ssse3(); |
| 29 | void Init_sse41(); |
| 30 | void Init_neon(); |
| 31 | //TODO: _dsp2, _armv7, _armv8, _x86, _x86_64, _sse42, _avx, avx2, ... ? |
| 32 | |
| 33 | static void init() { |
| 34 | #if defined(SK_CPU_X86) |
| 35 | uint32_t abcd[] = {0,0,0,0}; |
| 36 | cpuid(abcd); |
| 37 | if (abcd[3] & (1<<26)) { Init_sse2(); } |
| 38 | if (abcd[2] & (1<< 9)) { Init_ssse3(); } |
| 39 | if (abcd[2] & (1<<19)) { Init_sse41(); } |
| 40 | #elif defined(SK_ARM_HAS_NEON) |
| 41 | Init_neon(); |
| 42 | #elif defined(SK_CPU_ARM32) && defined(SK_BUILD_FOR_ANDROID) |
| 43 | if (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) { Init_neon(); } |
| 44 | #endif |
| 45 | } |
| 46 | |
| 47 | SK_DECLARE_STATIC_ONCE(gInitOnce); |
| 48 | void Init() { SkOnce(&gInitOnce, init); } |
| 49 | |
| 50 | #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 51 | static struct AutoInit { |
| 52 | AutoInit() { Init(); } |
| 53 | } gAutoInit; |
| 54 | #endif |
| 55 | } |