gfx/skia/trunk/src/core/SkUtilsArm.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkUtilsArm.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2012 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +#ifndef SkUtilsArm_DEFINED
    1.13 +#define SkUtilsArm_DEFINED
    1.14 +
    1.15 +#include "SkUtils.h"
    1.16 +
    1.17 +// Define SK_ARM_NEON_MODE to one of the following values
    1.18 +// corresponding respectively to:
    1.19 +// - No ARM Neon support at all  (not targetting ARMv7-A, or don't have NEON)
    1.20 +// - Full ARM Neon support (i.e. assume the CPU always supports it)
    1.21 +// - Optional ARM Neon support (i.e. probe CPU at runtime)
    1.22 +//
    1.23 +#define SK_ARM_NEON_MODE_NONE     0
    1.24 +#define SK_ARM_NEON_MODE_ALWAYS   1
    1.25 +#define SK_ARM_NEON_MODE_DYNAMIC  2
    1.26 +
    1.27 +#if defined(SK_CPU_ARM) && defined(__ARM_HAVE_OPTIONAL_NEON_SUPPORT)
    1.28 +#  define SK_ARM_NEON_MODE  SK_ARM_NEON_MODE_DYNAMIC
    1.29 +#elif defined(SK_CPU_ARM) && defined(__ARM_HAVE_NEON)
    1.30 +#  define SK_ARM_NEON_MODE  SK_ARM_NEON_MODE_ALWAYS
    1.31 +#else
    1.32 +#  define SK_ARM_NEON_MODE  SK_ARM_NEON_MODE_NONE
    1.33 +#endif
    1.34 +
    1.35 +// Convenience test macros, always defined as 0 or 1
    1.36 +#define SK_ARM_NEON_IS_NONE    (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_NONE)
    1.37 +#define SK_ARM_NEON_IS_ALWAYS  (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_ALWAYS)
    1.38 +#define SK_ARM_NEON_IS_DYNAMIC (SK_ARM_NEON_MODE == SK_ARM_NEON_MODE_DYNAMIC)
    1.39 +
    1.40 +// The sk_cpu_arm_has_neon() function returns true iff the target device
    1.41 +// is ARMv7-A and supports Neon instructions. In DYNAMIC mode, this actually
    1.42 +// probes the CPU at runtime (and caches the result).
    1.43 +
    1.44 +#if SK_ARM_NEON_IS_NONE
    1.45 +static inline bool sk_cpu_arm_has_neon(void) {
    1.46 +    return false;
    1.47 +}
    1.48 +#elif SK_ARM_NEON_IS_ALWAYS
    1.49 +static inline bool sk_cpu_arm_has_neon(void) {
    1.50 +    return true;
    1.51 +}
    1.52 +#else // SK_ARM_NEON_IS_DYNAMIC
    1.53 +
    1.54 +extern bool sk_cpu_arm_has_neon(void) SK_PURE_FUNC;
    1.55 +#endif
    1.56 +
    1.57 +// Use SK_ARM_NEON_WRAP(symbol) to map 'symbol' to a NEON-specific symbol
    1.58 +// when applicable. This will transform 'symbol' differently depending on
    1.59 +// the current NEON configuration, i.e.:
    1.60 +//
    1.61 +//    NONE           -> 'symbol'
    1.62 +//    ALWAYS         -> 'symbol_neon'
    1.63 +//    DYNAMIC        -> 'symbol' or 'symbol_neon' depending on runtime check.
    1.64 +//
    1.65 +// The goal is to simplify user code, for example:
    1.66 +//
    1.67 +//      return SK_ARM_NEON_WRAP(do_something)(params);
    1.68 +//
    1.69 +// Replaces the equivalent:
    1.70 +//
    1.71 +//     #if SK_ARM_NEON_IS_NONE
    1.72 +//       return do_something(params);
    1.73 +//     #elif SK_ARM_NEON_IS_ALWAYS
    1.74 +//       return do_something_neon(params);
    1.75 +//     #elif SK_ARM_NEON_IS_DYNAMIC
    1.76 +//       if (sk_cpu_arm_has_neon())
    1.77 +//         return do_something_neon(params);
    1.78 +//       else
    1.79 +//         return do_something(params);
    1.80 +//     #endif
    1.81 +//
    1.82 +#if SK_ARM_NEON_IS_NONE
    1.83 +#  define SK_ARM_NEON_WRAP(x)   (x)
    1.84 +#elif SK_ARM_NEON_IS_ALWAYS
    1.85 +#  define SK_ARM_NEON_WRAP(x)   (x ## _neon)
    1.86 +#elif SK_ARM_NEON_IS_DYNAMIC
    1.87 +#  define SK_ARM_NEON_WRAP(x)   (sk_cpu_arm_has_neon() ? x ## _neon : x)
    1.88 +#endif
    1.89 +
    1.90 +#endif // SkUtilsArm_DEFINED

mercurial