mozglue/build/arm.h

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:32e694b876bc
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
56 # ifdef __GNUC__
57 # define MOZILLA_MAY_SUPPORT_EDSP 1
58
59 # if defined(HAVE_ARM_SIMD)
60 # define MOZILLA_MAY_SUPPORT_ARMV6 1
61 # endif
62
63 # if defined(HAVE_ARM_NEON)
64 # define MOZILLA_MAY_SUPPORT_NEON 1
65 # endif
66
67 # if defined(HAVE_ARM_SIMD)
68 # define MOZILLA_MAY_SUPPORT_ARMV7 1
69 # endif
70 # endif
71
72 // When using -mfpu=neon, gcc generates neon instructions.
73
74 # if defined(__ARM_NEON__)
75 # define MOZILLA_PRESUME_NEON 1
76 # endif
77
78 // Currently we only have CPU detection for Linux via /proc/cpuinfo
79 # if defined(__linux__) || defined(ANDROID)
80 # define MOZILLA_ARM_HAVE_CPUID_DETECTION 1
81 # endif
82
83 #elif defined(_MSC_VER) && defined(_M_ARM)
84
85 # define MOZILLA_ARM_HAVE_CPUID_DETECTION 1
86 // _M_ARM on MSVC has current cpu architecture.
87 # define MOZILLA_ARM_ARCH _M_ARM
88
89 // MSVC only allows external asm for ARM, so we don't have to rely on
90 // compiler support.
91 # define MOZILLA_MAY_SUPPORT_EDSP 1
92 # if defined(HAVE_ARM_SIMD)
93 # define MOZILLA_MAY_SUPPORT_ARMV6 1
94 # define MOZILLA_MAY_SUPPORT_ARMV7 1
95 # endif
96 # if defined(HAVE_ARM_NEON)
97 # define MOZILLA_MAY_SUPPORT_NEON 1
98 # endif
99
100 #endif
101
102 namespace mozilla {
103
104 namespace arm_private {
105 #if defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
106 #if !defined(MOZILLA_PRESUME_EDSP)
107 extern bool MFBT_DATA edsp_enabled;
108 #endif
109 #if !defined(MOZILLA_PRESUME_ARMV6)
110 extern bool MFBT_DATA armv6_enabled;
111 #endif
112 #if !defined(MOZILLA_PRESUME_ARMV7)
113 extern bool MFBT_DATA armv7_enabled;
114 #endif
115 #if !defined(MOZILLA_PRESUME_NEON)
116 extern bool MFBT_DATA neon_enabled;
117 #endif
118 #endif
119 }
120
121 #if defined(MOZILLA_PRESUME_EDSP)
122 # define MOZILLA_MAY_SUPPORT_EDSP 1
123 inline bool supports_edsp() { return true; }
124 #elif defined(MOZILLA_MAY_SUPPORT_EDSP) \
125 && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
126 inline bool supports_edsp() { return arm_private::edsp_enabled; }
127 #else
128 inline bool supports_edsp() { return false; }
129 #endif
130
131 #if defined(MOZILLA_PRESUME_ARMV6)
132 # define MOZILLA_MAY_SUPPORT_ARMV6 1
133 inline bool supports_armv6() { return true; }
134 #elif defined(MOZILLA_MAY_SUPPORT_ARMV6) \
135 && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
136 inline bool supports_armv6() { return arm_private::armv6_enabled; }
137 #else
138 inline bool supports_armv6() { return false; }
139 #endif
140
141 #if defined(MOZILLA_PRESUME_ARMV7)
142 # define MOZILLA_MAY_SUPPORT_ARMV7 1
143 inline bool supports_armv7() { return true; }
144 #elif defined(MOZILLA_MAY_SUPPORT_ARMV7) \
145 && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
146 inline bool supports_armv7() { return arm_private::armv7_enabled; }
147 #else
148 inline bool supports_armv7() { return false; }
149 #endif
150
151 #if defined(MOZILLA_PRESUME_NEON)
152 # define MOZILLA_MAY_SUPPORT_NEON 1
153 inline bool supports_neon() { return true; }
154 #elif defined(MOZILLA_MAY_SUPPORT_NEON) \
155 && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
156 inline bool supports_neon() { return arm_private::neon_enabled; }
157 #else
158 inline bool supports_neon() { return false; }
159 #endif
160
161 }
162
163 #endif /* !defined(mozilla_arm_h_) */

mercurial