1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is arm.h
15 : *
16 : * The Initial Developer of the Original Code is the Mozilla Foundation.
17 : * Portions created by the Initial Developer are Copyright (C) 2011
18 : * the Initial Developer. All Rights Reserved.
19 : *
20 : * Contributor(s):
21 : * Timothy B. Terriberry <tterriberry@mozilla.com>
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either the GNU General Public License Version 2 or later (the "GPL"), or
25 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 : * in which case the provisions of the GPL or the LGPL are applicable instead
27 : * of those above. If you wish to allow use of your version of this file only
28 : * under the terms of either the GPL or the LGPL, and not to allow others to
29 : * use your version of this file under the terms of the MPL, indicate your
30 : * decision by deleting the provisions above and replace them with the notice
31 : * and other provisions required by the GPL or the LGPL. If you do not delete
32 : * the provisions above, a recipient may use your version of this file under
33 : * the terms of any one of the MPL, the GPL or the LGPL.
34 : *
35 : * ***** END LICENSE BLOCK ***** */
36 :
37 : /* compile-time and runtime tests for whether to use SSE instructions */
38 :
39 : #ifndef mozilla_arm_h_
40 : #define mozilla_arm_h_
41 :
42 : // for definition of NS_COM_GLUE
43 : #include "nscore.h"
44 :
45 : /* This is patterned after SSE.h, but provides ARMv5E, ARMv6, and NEON
46 : detection. For reasons similar to the SSE code, code using NEON (even just
47 : in inline asm) needs to be in a separate compilation unit from the regular
48 : code, because it requires an ".fpu neon" directive which can't be undone.
49 : ARMv5E and ARMv6 code may also require an .arch directive, since by default
50 : the assembler refuses to generate code for opcodes outside of its current
51 : .arch setting.
52 :
53 : TODO: Add Thumb, Thumb2, VFP, iwMMX, etc. detection, if we need it. */
54 :
55 : #if defined(__GNUC__) && defined(__arm__)
56 :
57 : # define MOZILLA_ARM_ARCH 3
58 :
59 : # if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) \
60 : || defined(_ARM_ARCH_4)
61 : # undef MOZILLA_ARM_ARCH
62 : # define MOZILLA_ARM_ARCH 4
63 : # endif
64 :
65 : # if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
66 : || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
67 : || defined(__ARM_ARCH_5TEJ__) || defined(_ARM_ARCH_5)
68 : # undef MOZILLA_ARM_ARCH
69 : # define MOZILLA_ARM_ARCH 5
70 : # endif
71 :
72 : # if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
73 : || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
74 : || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \
75 : || defined(__ARM_ARCH_6M__) || defined(_ARM_ARCH_6)
76 : # undef MOZILLA_ARM_ARCH
77 : # define MOZILLA_ARM_ARCH 6
78 : # endif
79 :
80 : # if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
81 : || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
82 : || defined(__ARM_ARCH_7EM__) || defined(_ARM_ARCH_7)
83 : # undef MOZILLA_ARM_ARCH
84 : # define MOZILLA_ARM_ARCH 7
85 : # endif
86 :
87 :
88 : # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
89 : # define MOZILLA_MAY_SUPPORT_EDSP 1
90 : # endif
91 :
92 : # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
93 : # if defined(HAVE_ARM_SIMD)
94 : # define MOZILLA_MAY_SUPPORT_ARMV6 1
95 : # endif
96 : # endif
97 :
98 : // Technically 4.2.x only works in the CodeSourcery releases, but I don't
99 : // know how to detect those separately from mainline gcc (which got support
100 : // in 4.3). The Maemo version 5 SDK shipped with the CodeSourcery 4.2.1
101 : // release, which we need to work.
102 : # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
103 : # if defined(HAVE_ARM_NEON)
104 : # define MOZILLA_MAY_SUPPORT_NEON 1
105 : # endif
106 : # endif
107 :
108 : // Currently we only have CPU detection for Linux via /proc/cpuinfo
109 : # if defined(__linux__) || defined(ANDROID)
110 : # define MOZILLA_ARM_HAVE_CPUID_DETECTION 1
111 : # endif
112 :
113 : #elif defined(_MSC_VER) && defined(_M_ARM)
114 :
115 : # define MOZILLA_ARM_HAVE_CPUID_DETECTION 1
116 : // I don't know how to do arch detection at compile time for MSVC, so assume
117 : // the worst for now.
118 : # define MOZILLA_ARM_ARCH 3
119 :
120 : // MSVC only allows external asm for ARM, so we don't have to rely on
121 : // compiler support.
122 : # define MOZILLA_MAY_SUPPORT_EDSP 1
123 : # if defined(HAVE_ARM_SIMD)
124 : # define MOZILLA_MAY_SUPPORT_ARMV6 1
125 : # endif
126 : # if defined(HAVE_ARM_NEON)
127 : # define MOZILLA_MAY_SUPPORT_NEON 1
128 : # endif
129 :
130 : #endif
131 :
132 : namespace mozilla {
133 :
134 : namespace arm_private {
135 : #if defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
136 : #if !defined(MOZILLA_PRESUME_EDSP)
137 : extern bool NS_COM_GLUE edsp_enabled;
138 : #endif
139 : #if !defined(MOZILLA_PRESUME_ARMV6)
140 : extern bool NS_COM_GLUE armv6_enabled;
141 : #endif
142 : #if !defined(MOZILLA_PRESUME_NEON)
143 : extern bool NS_COM_GLUE neon_enabled;
144 : #endif
145 : #endif
146 : }
147 :
148 : #if defined(MOZILLA_PRESUME_EDSP)
149 : # define MOZILLA_MAY_SUPPORT_EDSP 1
150 : inline bool supports_edsp() { return true; }
151 : #elif defined(MOZILLA_MAY_SUPPORT_EDSP) \
152 : && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
153 : inline bool supports_edsp() { return arm_private::edsp_enabled; }
154 : #else
155 230 : inline bool supports_edsp() { return false; }
156 : #endif
157 :
158 : #if defined(MOZILLA_PRESUME_ARMV6)
159 : # define MOZILLA_MAY_SUPPORT_ARMV6 1
160 : inline bool supports_armv6() { return true; }
161 : #elif defined(MOZILLA_MAY_SUPPORT_ARMV6) \
162 : && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
163 : inline bool supports_armv6() { return arm_private::armv6_enabled; }
164 : #else
165 230 : inline bool supports_armv6() { return false; }
166 : #endif
167 :
168 : #if defined(MOZILLA_PRESUME_NEON)
169 : # define MOZILLA_MAY_SUPPORT_NEON 1
170 : inline bool supports_neon() { return true; }
171 : #elif defined(MOZILLA_MAY_SUPPORT_NEON) \
172 : && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
173 : inline bool supports_neon() { return arm_private::neon_enabled; }
174 : #else
175 230 : inline bool supports_neon() { return false; }
176 : #endif
177 :
178 : }
179 :
180 : #endif /* !defined(mozilla_arm_h_) */
|