tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

arm.h (4971B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /* compile-time and runtime tests for whether to use SSE instructions */
      6 
      7 #ifndef mozilla_arm_h_
      8 #define mozilla_arm_h_
      9 
     10 // for definition of MFBT_DATA
     11 #include "mozilla/Types.h"
     12 
     13 /* This is patterned after SSE.h, but provides ARMv5E, ARMv6, and NEON
     14   detection. For reasons similar to the SSE code, code using NEON (even just
     15   in inline asm) needs to be in a separate compilation unit from the regular
     16   code, because it requires an ".fpu neon" directive which can't be undone.
     17   ARMv5E and ARMv6 code may also require an .arch directive, since by default
     18   the assembler refuses to generate code for opcodes outside of its current
     19   .arch setting.
     20 
     21   TODO: Add Thumb, Thumb2, VFP, iwMMX, etc. detection, if we need it. */
     22 
     23 #if defined(__GNUC__) && defined(__arm__)
     24 
     25 #  define MOZILLA_ARM_ARCH 3
     26 
     27 #  if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
     28      defined(_ARM_ARCH_4)
     29 #    undef MOZILLA_ARM_ARCH
     30 #    define MOZILLA_ARM_ARCH 4
     31 #  endif
     32 
     33 #  if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) ||   \
     34      defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || \
     35      defined(__ARM_ARCH_5TEJ__) || defined(_ARM_ARCH_5)
     36 #    undef MOZILLA_ARM_ARCH
     37 #    define MOZILLA_ARM_ARCH 5
     38 #  endif
     39 
     40 #  if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) ||    \
     41      defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) ||   \
     42      defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) || \
     43      defined(__ARM_ARCH_6M__) || defined(_ARM_ARCH_6)
     44 #    undef MOZILLA_ARM_ARCH
     45 #    define MOZILLA_ARM_ARCH 6
     46 #  endif
     47 
     48 #  if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) ||  \
     49      defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || \
     50      defined(__ARM_ARCH_7EM__) || defined(_ARM_ARCH_7)
     51 #    undef MOZILLA_ARM_ARCH
     52 #    define MOZILLA_ARM_ARCH 7
     53 #  endif
     54 
     55 #  ifdef __GNUC__
     56 #    define MOZILLA_MAY_SUPPORT_EDSP 1
     57 
     58 #    if defined(HAVE_ARM_SIMD)
     59 #      define MOZILLA_MAY_SUPPORT_ARMV6 1
     60 #    endif
     61 
     62 #    if defined(HAVE_ARM_NEON)
     63 #      define MOZILLA_MAY_SUPPORT_NEON 1
     64 #    endif
     65 
     66 #    if defined(HAVE_ARM_SIMD)
     67 #      define MOZILLA_MAY_SUPPORT_ARMV7 1
     68 #    endif
     69 #  endif
     70 
     71 // Currently we only have CPU detection for Linux via /proc/cpuinfo
     72 #  if defined(__linux__) || defined(ANDROID)
     73 #    define MOZILLA_ARM_HAVE_CPUID_DETECTION 1
     74 #  endif
     75 
     76 #endif
     77 
     78 // When using -mfpu=neon on arm gcc, or using default on aarch64,
     79 // the compiler generates neon instructions.
     80 #if defined(__ARM_NEON)
     81 #  define MOZILLA_PRESUME_NEON 1
     82 #endif
     83 
     84 #if defined(__ARM_FEATURE_CRYPTO)
     85 #  define MOZILLA_PRESUME_ARM_AES 1
     86 #endif
     87 
     88 namespace mozilla {
     89 
     90 namespace arm_private {
     91 #if defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
     92 #  if !defined(MOZILLA_PRESUME_EDSP)
     93 extern bool MFBT_DATA edsp_enabled;
     94 #  endif
     95 #  if !defined(MOZILLA_PRESUME_ARMV6)
     96 extern bool MFBT_DATA armv6_enabled;
     97 #  endif
     98 #  if !defined(MOZILLA_PRESUME_ARMV7)
     99 extern bool MFBT_DATA armv7_enabled;
    100 #  endif
    101 #  if !defined(MOZILLA_PRESUME_NEON)
    102 extern bool MFBT_DATA neon_enabled;
    103 #  endif
    104 #  if !defined(MOZILLA_PRESUME_ARM_AES)
    105 extern bool MFBT_DATA aes_enabled;
    106 #  endif
    107 #endif
    108 }  // namespace arm_private
    109 
    110 #if defined(MOZILLA_PRESUME_EDSP)
    111 #  define MOZILLA_MAY_SUPPORT_EDSP 1
    112 inline bool supports_edsp() { return true; }
    113 #elif defined(MOZILLA_MAY_SUPPORT_EDSP) && \
    114    defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
    115 inline bool supports_edsp() { return arm_private::edsp_enabled; }
    116 #else
    117 inline bool supports_edsp() { return false; }
    118 #endif
    119 
    120 #if defined(MOZILLA_PRESUME_ARMV6)
    121 #  define MOZILLA_MAY_SUPPORT_ARMV6 1
    122 inline bool supports_armv6() { return true; }
    123 #elif defined(MOZILLA_MAY_SUPPORT_ARMV6) && \
    124    defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
    125 inline bool supports_armv6() { return arm_private::armv6_enabled; }
    126 #else
    127 inline bool supports_armv6() { return false; }
    128 #endif
    129 
    130 #if defined(MOZILLA_PRESUME_ARMV7)
    131 #  define MOZILLA_MAY_SUPPORT_ARMV7 1
    132 inline bool supports_armv7() { return true; }
    133 #elif defined(MOZILLA_MAY_SUPPORT_ARMV7) && \
    134    defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
    135 inline bool supports_armv7() { return arm_private::armv7_enabled; }
    136 #else
    137 inline bool supports_armv7() { return false; }
    138 #endif
    139 
    140 #if defined(MOZILLA_PRESUME_NEON)
    141 #  define MOZILLA_MAY_SUPPORT_NEON 1
    142 inline bool supports_neon() { return true; }
    143 #elif defined(MOZILLA_MAY_SUPPORT_NEON) && \
    144    defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
    145 inline bool supports_neon() { return arm_private::neon_enabled; }
    146 #else
    147 inline bool supports_neon() { return false; }
    148 #endif
    149 #if defined(MOZILLA_PRESUME_ARM_AES)
    150 inline bool supports_arm_aes() { return true; }
    151 #elif defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
    152 inline bool supports_arm_aes() { return arm_private::aes_enabled; }
    153 #else
    154 inline bool supports_arm_aes() { return false; }
    155 #endif
    156 
    157 }  // namespace mozilla
    158 
    159 #endif /* !defined(mozilla_arm_h_) */