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/. */
5 /* compile-time and runtime tests for whether to use SSE instructions */
10 // for definition of NS_COM_GLUE
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
21 TODO: Add Thumb, Thumb2, VFP, iwMMX, etc. detection, if we need it. */
23 #if defined(__GNUC__) && defined(__arm__)
25 # define MOZILLA_ARM_ARCH 3
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
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
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
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
56 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
57 # define MOZILLA_MAY_SUPPORT_EDSP 1
60 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
61 # if defined(HAVE_ARM_SIMD)
62 # define MOZILLA_MAY_SUPPORT_ARMV6 1
66 // Technically 4.2.x only works in the CodeSourcery releases, but I don't
67 // know how to detect those separately from mainline gcc (which got support
68 // in 4.3). The Maemo version 5 SDK shipped with the CodeSourcery 4.2.1
69 // release, which we need to work.
70 # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
71 # if defined(HAVE_ARM_NEON)
72 # define MOZILLA_MAY_SUPPORT_NEON 1
76 // ARMv7 support was merged in gcc 4.3.
77 # if __GNUC__> 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
78 # if defined(HAVE_ARM_SIMD)
79 # define MOZILLA_MAY_SUPPORT_ARMV7 1
83 // When using -mfpu=neon, gcc generates neon instructions.
85 # if defined(__ARM_NEON__)
86 # define MOZILLA_PRESUME_NEON 1
89 // Currently we only have CPU detection for Linux via /proc/cpuinfo
90 # if defined(__linux__) || defined(ANDROID)
91 # define MOZILLA_ARM_HAVE_CPUID_DETECTION 1
94 #elif defined(_MSC_VER) && defined(_M_ARM)
96 # define MOZILLA_ARM_HAVE_CPUID_DETECTION 1
97 // _M_ARM on MSVC has current cpu architecture.
98 # define MOZILLA_ARM_ARCH _M_ARM
100 // MSVC only allows external asm for ARM, so we don't have to rely on
102 # define MOZILLA_MAY_SUPPORT_EDSP 1
103 # if defined(HAVE_ARM_SIMD)
104 # define MOZILLA_MAY_SUPPORT_ARMV6 1
105 # define MOZILLA_MAY_SUPPORT_ARMV7 1
107 # if defined(HAVE_ARM_NEON)
108 # define MOZILLA_MAY_SUPPORT_NEON 1
115 namespace arm_private
{
116 #if defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
117 #if !defined(MOZILLA_PRESUME_EDSP)
118 extern bool NS_COM_GLUE edsp_enabled
;
120 #if !defined(MOZILLA_PRESUME_ARMV6)
121 extern bool NS_COM_GLUE armv6_enabled
;
123 #if !defined(MOZILLA_PRESUME_ARMV7)
124 extern bool NS_COM_GLUE armv7_enabled
;
126 #if !defined(MOZILLA_PRESUME_NEON)
127 extern bool NS_COM_GLUE neon_enabled
;
132 #if defined(MOZILLA_PRESUME_EDSP)
133 # define MOZILLA_MAY_SUPPORT_EDSP 1
134 inline bool supports_edsp() { return true; }
135 #elif defined(MOZILLA_MAY_SUPPORT_EDSP) \
136 && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
137 inline bool supports_edsp() { return arm_private::edsp_enabled
; }
139 inline bool supports_edsp() { return false; }
142 #if defined(MOZILLA_PRESUME_ARMV6)
143 # define MOZILLA_MAY_SUPPORT_ARMV6 1
144 inline bool supports_armv6() { return true; }
145 #elif defined(MOZILLA_MAY_SUPPORT_ARMV6) \
146 && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
147 inline bool supports_armv6() { return arm_private::armv6_enabled
; }
149 inline bool supports_armv6() { return false; }
152 #if defined(MOZILLA_PRESUME_ARMV7)
153 # define MOZILLA_MAY_SUPPORT_ARMV7 1
154 inline bool supports_armv7() { return true; }
155 #elif defined(MOZILLA_MAY_SUPPORT_ARMV7) \
156 && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
157 inline bool supports_armv7() { return arm_private::armv7_enabled
; }
159 inline bool supports_armv7() { return false; }
162 #if defined(MOZILLA_PRESUME_NEON)
163 # define MOZILLA_MAY_SUPPORT_NEON 1
164 inline bool supports_neon() { return true; }
165 #elif defined(MOZILLA_MAY_SUPPORT_NEON) \
166 && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
167 inline bool supports_neon() { return arm_private::neon_enabled
; }
169 inline bool supports_neon() { return false; }
174 #endif /* !defined(mozilla_arm_h_) */