mozglue/build/arm.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial