| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
| 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 #ifndef SkUtilsArm_DEFINED | 8 #ifndef SkUtilsArm_DEFINED |
| 9 #define SkUtilsArm_DEFINED | 9 #define SkUtilsArm_DEFINED |
| 10 | 10 |
| 11 #include "SkCpu.h" |
| 11 #include "SkUtils.h" | 12 #include "SkUtils.h" |
| 12 | 13 |
| 13 // Define SK_ARM_NEON_MODE to one of the following values | 14 // Define SK_ARM_NEON_MODE to one of the following values |
| 14 // corresponding respectively to: | 15 // corresponding respectively to: |
| 15 // - No ARM Neon support at all (not targetting ARMv7-A, or don't have NEON) | 16 // - No ARM Neon support at all (not targetting ARMv7-A, or don't have NEON) |
| 16 // - Full ARM Neon support (i.e. assume the CPU always supports it) | 17 // - Full ARM Neon support (i.e. assume the CPU always supports it) |
| 17 // - Optional ARM Neon support (i.e. probe CPU at runtime) | 18 // - Optional ARM Neon support (i.e. probe CPU at runtime) |
| 18 // | 19 // |
| 19 #define SK_ARM_NEON_MODE_NONE 0 | 20 #define SK_ARM_NEON_MODE_NONE 0 |
| 20 #define SK_ARM_NEON_MODE_ALWAYS 1 | 21 #define SK_ARM_NEON_MODE_ALWAYS 1 |
| 21 #define SK_ARM_NEON_MODE_DYNAMIC 2 | 22 #define SK_ARM_NEON_MODE_DYNAMIC 2 |
| 22 | 23 |
| 23 #if defined(SK_ARM_HAS_OPTIONAL_NEON) | 24 #if defined(SK_ARM_HAS_OPTIONAL_NEON) |
| 24 # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_DYNAMIC | 25 # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_DYNAMIC |
| 25 #elif defined(SK_ARM_HAS_NEON) | 26 #elif defined(SK_ARM_HAS_NEON) |
| 26 # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_ALWAYS | 27 # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_ALWAYS |
| 27 #else | 28 #else |
| 28 # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_NONE | 29 # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_NONE |
| 29 #endif | 30 #endif |
| 30 | 31 |
| 31 // Convenience test macros, always defined as 0 or 1 | 32 // Convenience test macros, always defined as 0 or 1 |
| 32 #define SK_ARM_NEON_IS_NONE (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_NONE) | 33 #define SK_ARM_NEON_IS_NONE (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_NONE) |
| 33 #define SK_ARM_NEON_IS_ALWAYS (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_ALWAYS) | 34 #define SK_ARM_NEON_IS_ALWAYS (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_ALWAYS) |
| 34 #define SK_ARM_NEON_IS_DYNAMIC (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_DYNAMIC) | 35 #define SK_ARM_NEON_IS_DYNAMIC (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_DYNAMIC) |
| 35 | 36 |
| 36 // The sk_cpu_arm_has_neon() function returns true iff the target device | 37 // The sk_cpu_arm_has_neon() function returns true iff the target device |
| 37 // is ARMv7-A and supports Neon instructions. In DYNAMIC mode, this actually | 38 // is ARMv7-A and supports Neon instructions. In DYNAMIC mode, this actually |
| 38 // probes the CPU at runtime (and caches the result). | 39 // probes the CPU at runtime (and caches the result). |
| 39 | 40 |
| 41 static inline bool sk_cpu_arm_has_neon(void) { |
| 40 #if SK_ARM_NEON_IS_NONE | 42 #if SK_ARM_NEON_IS_NONE |
| 41 static inline bool sk_cpu_arm_has_neon(void) { | |
| 42 return false; | 43 return false; |
| 44 #else |
| 45 return SkCpu::Supports(SkCpu::NEON); |
| 46 #endif |
| 43 } | 47 } |
| 44 #elif SK_ARM_NEON_IS_ALWAYS | |
| 45 static inline bool sk_cpu_arm_has_neon(void) { | |
| 46 return true; | |
| 47 } | |
| 48 #else // SK_ARM_NEON_IS_DYNAMIC | |
| 49 | |
| 50 extern bool sk_cpu_arm_has_neon(void) SK_PURE_FUNC; | |
| 51 #endif | |
| 52 | 48 |
| 53 // Use SK_ARM_NEON_WRAP(symbol) to map 'symbol' to a NEON-specific symbol | 49 // Use SK_ARM_NEON_WRAP(symbol) to map 'symbol' to a NEON-specific symbol |
| 54 // when applicable. This will transform 'symbol' differently depending on | 50 // when applicable. This will transform 'symbol' differently depending on |
| 55 // the current NEON configuration, i.e.: | 51 // the current NEON configuration, i.e.: |
| 56 // | 52 // |
| 57 // NONE -> 'symbol' | 53 // NONE -> 'symbol' |
| 58 // ALWAYS -> 'symbol_neon' | 54 // ALWAYS -> 'symbol_neon' |
| 59 // DYNAMIC -> 'symbol' or 'symbol_neon' depending on runtime check. | 55 // DYNAMIC -> 'symbol' or 'symbol_neon' depending on runtime check. |
| 60 // | 56 // |
| 61 // The goal is to simplify user code, for example: | 57 // The goal is to simplify user code, for example: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 77 // | 73 // |
| 78 #if SK_ARM_NEON_IS_NONE | 74 #if SK_ARM_NEON_IS_NONE |
| 79 # define SK_ARM_NEON_WRAP(x) (x) | 75 # define SK_ARM_NEON_WRAP(x) (x) |
| 80 #elif SK_ARM_NEON_IS_ALWAYS | 76 #elif SK_ARM_NEON_IS_ALWAYS |
| 81 # define SK_ARM_NEON_WRAP(x) (x ## _neon) | 77 # define SK_ARM_NEON_WRAP(x) (x ## _neon) |
| 82 #elif SK_ARM_NEON_IS_DYNAMIC | 78 #elif SK_ARM_NEON_IS_DYNAMIC |
| 83 # define SK_ARM_NEON_WRAP(x) (sk_cpu_arm_has_neon() ? x ## _neon : x) | 79 # define SK_ARM_NEON_WRAP(x) (sk_cpu_arm_has_neon() ? x ## _neon : x) |
| 84 #endif | 80 #endif |
| 85 | 81 |
| 86 #endif // SkUtilsArm_DEFINED | 82 #endif // SkUtilsArm_DEFINED |
| OLD | NEW |