Chromium Code Reviews| 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 "SkTypes.h" |
| 12 #include "SkUtils.h" | |
| 13 | 12 |
| 14 // Define SK_ARM_NEON_MODE to one of the following values | 13 #if defined(SK_ARM_HAS_NEON) |
| 15 // corresponding respectively to: | 14 #define SK_ARM_NEON_WRAP(x) (x ## _neon) |
| 16 // - No ARM Neon support at all (not targetting ARMv7-A, or don't have NEON) | |
| 17 // - Full ARM Neon support (i.e. assume the CPU always supports it) | |
| 18 // - Optional ARM Neon support (i.e. probe CPU at runtime) | |
| 19 // | |
| 20 #define SK_ARM_NEON_MODE_NONE 0 | |
| 21 #define SK_ARM_NEON_MODE_ALWAYS 1 | |
| 22 #define SK_ARM_NEON_MODE_DYNAMIC 2 | |
| 23 | |
| 24 #if defined(SK_ARM_HAS_OPTIONAL_NEON) | |
| 25 # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_DYNAMIC | |
| 26 #elif defined(SK_ARM_HAS_NEON) | |
| 27 # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_ALWAYS | |
| 28 #else | 15 #else |
| 29 # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_NONE | 16 #define SK_ARM_NEON_WRAP(x) (x) |
|
djsollen
2016/05/05 17:55:08
can we remove this wrapper now as well?
mtklein_C
2016/05/05 17:57:33
There are still a few files where this chooses bet
| |
| 30 #endif | |
| 31 | |
| 32 // Convenience test macros, always defined as 0 or 1 | |
| 33 #define SK_ARM_NEON_IS_NONE (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_NONE) | |
| 34 #define SK_ARM_NEON_IS_ALWAYS (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_ALWAYS) | |
| 35 #define SK_ARM_NEON_IS_DYNAMIC (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_DYNAMIC) | |
| 36 | |
| 37 // The sk_cpu_arm_has_neon() function returns true iff the target device | |
| 38 // is ARMv7-A and supports Neon instructions. In DYNAMIC mode, this actually | |
| 39 // probes the CPU at runtime (and caches the result). | |
| 40 | |
| 41 static inline bool sk_cpu_arm_has_neon(void) { | |
| 42 #if SK_ARM_NEON_IS_NONE | |
| 43 return false; | |
| 44 #else | |
| 45 return SkCpu::Supports(SkCpu::NEON); | |
| 46 #endif | |
| 47 } | |
| 48 | |
| 49 // Use SK_ARM_NEON_WRAP(symbol) to map 'symbol' to a NEON-specific symbol | |
| 50 // when applicable. This will transform 'symbol' differently depending on | |
| 51 // the current NEON configuration, i.e.: | |
| 52 // | |
| 53 // NONE -> 'symbol' | |
| 54 // ALWAYS -> 'symbol_neon' | |
| 55 // DYNAMIC -> 'symbol' or 'symbol_neon' depending on runtime check. | |
| 56 // | |
| 57 // The goal is to simplify user code, for example: | |
| 58 // | |
| 59 // return SK_ARM_NEON_WRAP(do_something)(params); | |
| 60 // | |
| 61 // Replaces the equivalent: | |
| 62 // | |
| 63 // #if SK_ARM_NEON_IS_NONE | |
| 64 // return do_something(params); | |
| 65 // #elif SK_ARM_NEON_IS_ALWAYS | |
| 66 // return do_something_neon(params); | |
| 67 // #elif SK_ARM_NEON_IS_DYNAMIC | |
| 68 // if (sk_cpu_arm_has_neon()) | |
| 69 // return do_something_neon(params); | |
| 70 // else | |
| 71 // return do_something(params); | |
| 72 // #endif | |
| 73 // | |
| 74 #if SK_ARM_NEON_IS_NONE | |
| 75 # define SK_ARM_NEON_WRAP(x) (x) | |
| 76 #elif SK_ARM_NEON_IS_ALWAYS | |
| 77 # define SK_ARM_NEON_WRAP(x) (x ## _neon) | |
| 78 #elif SK_ARM_NEON_IS_DYNAMIC | |
| 79 # define SK_ARM_NEON_WRAP(x) (sk_cpu_arm_has_neon() ? x ## _neon : x) | |
| 80 #endif | 17 #endif |
| 81 | 18 |
| 82 #endif // SkUtilsArm_DEFINED | 19 #endif // SkUtilsArm_DEFINED |
| OLD | NEW |