Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2012 The Android Open Source Project |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | #ifndef SkUtilsArm_DEFINED |
michael@0 | 10 | #define SkUtilsArm_DEFINED |
michael@0 | 11 | |
michael@0 | 12 | #include "SkUtils.h" |
michael@0 | 13 | |
michael@0 | 14 | // Define SK_ARM_NEON_MODE to one of the following values |
michael@0 | 15 | // corresponding respectively to: |
michael@0 | 16 | // - No ARM Neon support at all (not targetting ARMv7-A, or don't have NEON) |
michael@0 | 17 | // - Full ARM Neon support (i.e. assume the CPU always supports it) |
michael@0 | 18 | // - Optional ARM Neon support (i.e. probe CPU at runtime) |
michael@0 | 19 | // |
michael@0 | 20 | #define SK_ARM_NEON_MODE_NONE 0 |
michael@0 | 21 | #define SK_ARM_NEON_MODE_ALWAYS 1 |
michael@0 | 22 | #define SK_ARM_NEON_MODE_DYNAMIC 2 |
michael@0 | 23 | |
michael@0 | 24 | #if defined(SK_CPU_ARM) && defined(__ARM_HAVE_OPTIONAL_NEON_SUPPORT) |
michael@0 | 25 | # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_DYNAMIC |
michael@0 | 26 | #elif defined(SK_CPU_ARM) && defined(__ARM_HAVE_NEON) |
michael@0 | 27 | # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_ALWAYS |
michael@0 | 28 | #else |
michael@0 | 29 | # define SK_ARM_NEON_MODE SK_ARM_NEON_MODE_NONE |
michael@0 | 30 | #endif |
michael@0 | 31 | |
michael@0 | 32 | // Convenience test macros, always defined as 0 or 1 |
michael@0 | 33 | #define SK_ARM_NEON_IS_NONE (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_NONE) |
michael@0 | 34 | #define SK_ARM_NEON_IS_ALWAYS (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_ALWAYS) |
michael@0 | 35 | #define SK_ARM_NEON_IS_DYNAMIC (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_DYNAMIC) |
michael@0 | 36 | |
michael@0 | 37 | // The sk_cpu_arm_has_neon() function returns true iff the target device |
michael@0 | 38 | // is ARMv7-A and supports Neon instructions. In DYNAMIC mode, this actually |
michael@0 | 39 | // probes the CPU at runtime (and caches the result). |
michael@0 | 40 | |
michael@0 | 41 | #if SK_ARM_NEON_IS_NONE |
michael@0 | 42 | static inline bool sk_cpu_arm_has_neon(void) { |
michael@0 | 43 | return false; |
michael@0 | 44 | } |
michael@0 | 45 | #elif SK_ARM_NEON_IS_ALWAYS |
michael@0 | 46 | static inline bool sk_cpu_arm_has_neon(void) { |
michael@0 | 47 | return true; |
michael@0 | 48 | } |
michael@0 | 49 | #else // SK_ARM_NEON_IS_DYNAMIC |
michael@0 | 50 | |
michael@0 | 51 | extern bool sk_cpu_arm_has_neon(void) SK_PURE_FUNC; |
michael@0 | 52 | #endif |
michael@0 | 53 | |
michael@0 | 54 | // Use SK_ARM_NEON_WRAP(symbol) to map 'symbol' to a NEON-specific symbol |
michael@0 | 55 | // when applicable. This will transform 'symbol' differently depending on |
michael@0 | 56 | // the current NEON configuration, i.e.: |
michael@0 | 57 | // |
michael@0 | 58 | // NONE -> 'symbol' |
michael@0 | 59 | // ALWAYS -> 'symbol_neon' |
michael@0 | 60 | // DYNAMIC -> 'symbol' or 'symbol_neon' depending on runtime check. |
michael@0 | 61 | // |
michael@0 | 62 | // The goal is to simplify user code, for example: |
michael@0 | 63 | // |
michael@0 | 64 | // return SK_ARM_NEON_WRAP(do_something)(params); |
michael@0 | 65 | // |
michael@0 | 66 | // Replaces the equivalent: |
michael@0 | 67 | // |
michael@0 | 68 | // #if SK_ARM_NEON_IS_NONE |
michael@0 | 69 | // return do_something(params); |
michael@0 | 70 | // #elif SK_ARM_NEON_IS_ALWAYS |
michael@0 | 71 | // return do_something_neon(params); |
michael@0 | 72 | // #elif SK_ARM_NEON_IS_DYNAMIC |
michael@0 | 73 | // if (sk_cpu_arm_has_neon()) |
michael@0 | 74 | // return do_something_neon(params); |
michael@0 | 75 | // else |
michael@0 | 76 | // return do_something(params); |
michael@0 | 77 | // #endif |
michael@0 | 78 | // |
michael@0 | 79 | #if SK_ARM_NEON_IS_NONE |
michael@0 | 80 | # define SK_ARM_NEON_WRAP(x) (x) |
michael@0 | 81 | #elif SK_ARM_NEON_IS_ALWAYS |
michael@0 | 82 | # define SK_ARM_NEON_WRAP(x) (x ## _neon) |
michael@0 | 83 | #elif SK_ARM_NEON_IS_DYNAMIC |
michael@0 | 84 | # define SK_ARM_NEON_WRAP(x) (sk_cpu_arm_has_neon() ? x ## _neon : x) |
michael@0 | 85 | #endif |
michael@0 | 86 | |
michael@0 | 87 | #endif // SkUtilsArm_DEFINED |