Bug 1869043 add a main thread record of track audio outputs r=padenot
[gecko.git] / build / moz.configure / arm.configure
blob5d26f4d73239182a0b139db3e739cbe3e3152957
1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 @depends(target.os)
9 def arm_option_defaults(os):
10     if os == "Android":
11         arch = "armv7-a"
12         thumb = "yes"
13         fpu = "neon"
14         float_abi = "softfp"
15     else:
16         arch = thumb = fpu = float_abi = "toolchain-default"
17     return namespace(
18         arch=arch,
19         thumb=thumb,
20         fpu=fpu,
21         float_abi=float_abi,
22     )
25 # Note: '{...|}' in the help of all options with a non-constant default to
26 # make the lint happy. The first arm is always going to be used, because a
27 # default is always returned. The lint is fooled by this file being
28 # conditional. If it weren't conditional, the lint wouldn't ask for '{|}' to
29 # be there.
30 option(
31     "--with-arch",
32     nargs=1,
33     default=arm_option_defaults.arch,
34     help="{Use specific CPU features (-march=type). Resets thumb, fpu, "
35     "float-abi, etc. defaults when set|}",
39 @depends("--with-arch")
40 def arch_option(value):
41     if value:
42         if value[0] != "toolchain-default":
43             return ["-march={}".format(value[0])]
44     return []
47 option(
48     "--with-thumb",
49     choices=("yes", "no", "toolchain-default"),
50     default=arm_option_defaults.thumb,
51     nargs="?",
52     help="{Use Thumb instruction set (-mthumb)|}",
56 def normalize_arm_option(value):
57     if value:
58         if len(value):
59             if value[0] == "yes":
60                 return True
61             elif value[0] == "no":
62                 return False
63             else:
64                 return value[0]
65         return True
66     return False
69 @depends("--with-thumb")
70 def thumb_option(value):
71     value = normalize_arm_option(value)
72     if value is True:
73         return ["-mthumb"]
74     if value is False:
75         return ["-marm"]
76     return []
79 option(
80     "--with-thumb-interwork",
81     choices=("yes", "no", "toolchain-default"),
82     default="toolchain-default",
83     nargs="?",
84     help="Use Thumb/ARM instuctions interwork (-mthumb-interwork)",
88 @depends("--with-thumb-interwork")
89 def thumb_interwork_option(value):
90     value = normalize_arm_option(value)
91     if value is True:
92         return ["-mthumb-interwork"]
93     if value is False:
94         return ["-mno-thumb-interwork"]
95     return []
98 option(
99     "--with-fpu",
100     nargs=1,
101     default=arm_option_defaults.fpu,
102     help="{Use specific FPU type (-mfpu=type)|}",
106 @depends("--with-fpu")
107 def fpu_option(value):
108     if value:
109         if value[0] != "toolchain-default":
110             return ["-mfpu={}".format(value[0])]
111     return []
114 option(
115     "--with-float-abi",
116     nargs=1,
117     default=arm_option_defaults.float_abi,
118     help="{Use specific arm float ABI (-mfloat-abi=type)|}",
122 @depends("--with-float-abi")
123 def float_abi_option(value):
124     if value:
125         if value[0] != "toolchain-default":
126             return ["-mfloat-abi={}".format(value[0])]
127     return []
130 option(
131     "--with-soft-float",
132     choices=("yes", "no", "toolchain-default"),
133     default="toolchain-default",
134     nargs="?",
135     help="Use soft float library (-msoft-float)",
139 @depends("--with-soft-float")
140 def soft_float_option(value):
141     value = normalize_arm_option(value)
142     if value is True:
143         return ["-msoft-float"]
144     if value is False:
145         return ["-mno-soft-float"]
146     return []
149 check_and_add_flag(
150     "-mno-unaligned-access", when=depends(target.os)(lambda os: os == "Android")
154 # The set of flags that clang understands
155 @depends(
156     arch_option,
157     thumb_option,
158     fpu_option,
159     float_abi_option,
160     soft_float_option,
162 def all_clang_arm_flags(arch, thumb, fpu, float_abi, soft_float):
163     return arch + thumb + fpu + float_abi + soft_float
166 # All the flags the compiler understands. When the compiler is clang, this
167 # still includes unsupported flags, but we live it to configure to fail
168 # during a compiler check. These checks aren't available for clang as used
169 # by bindgen, so we keep the separate set of flags for clang for bindgen.
170 @depends(all_clang_arm_flags, thumb_interwork_option)
171 def all_arm_flags(flags, interwork):
172     return flags + interwork
175 add_old_configure_assignment("_ARM_FLAGS", all_arm_flags)
176 add_old_configure_assignment("_THUMB_FLAGS", thumb_option)
179 @depends(configure_cache, c_compiler, all_arm_flags)
180 @checking("ARM version support in compiler", lambda x: x.arm_arch)
181 @imports(_from="textwrap", _import="dedent")
182 def arm_target(configure_cache, compiler, all_arm_flags):
183     # We're going to preprocess the following source to figure out some details
184     # about the arm target options we have enabled.
185     source = dedent(
186         """\
187         %ARM_ARCH __ARM_ARCH
188         #if __thumb2__
189         %THUMB2 yes
190         #else
191         %THUMB2 no
192         #endif
193         // Confusingly, the __SOFTFP__ preprocessor variable indicates the
194         // "softfloat" ABI, not the "softfp" ABI.
195         #if __SOFTFP__
196         %FLOAT_ABI soft
197         #elif __ARM_PCS_VFP
198         %FLOAT_ABI hard
199         #else
200         %FLOAT_ABI softfp
201         #endif
202         // There is more subtlety to it than this preprocessor test, but MOZ_FPU doesn't
203         // need to be too fine-grained.
204         #if __ARM_NEON
205         %FPU neon
206         #elif __ARM_VFPV2__ || __ARM_FP == 12
207         %FPU vfpv2
208         #elif __ARM_VFPV3__
209         %FPU vfpv3
210         #elif __ARM_VFPV4__ || __ARM_FP == 14
211         %FPU vfpv4
212         #elif __ARM_FPV5__
213         %FPU fp-armv8
214         #endif
215     """
216     )
217     result = try_invoke_compiler(
218         configure_cache,
219         [compiler.compiler] + compiler.flags,
220         compiler.language,
221         source,
222         ["-E"] + all_arm_flags,
223         wrapper=compiler.wrapper,
224     )
225     # Metadata emitted by preprocessors such as GCC with LANG=ja_JP.utf-8 may
226     # have non-ASCII characters. Treat the output as bytearray.
227     data = {"fpu": None}  # fpu may not get a value from the preprocessor.
228     for line in result.splitlines():
229         if line.startswith("%"):
230             k, _, v = line.partition(" ")
231             k = k.lstrip("%").lower()
232             if k == "arm_arch":
233                 data[k] = int(v)
234             else:
235                 data[k] = {
236                     "yes": True,
237                     "no": False,
238                 }.get(v, v)
239             log.debug("%s = %s", k, data[k])
241     return namespace(**data)
244 @depends(arm_target.arm_arch, when=depends(target.os)(lambda os: os == "Android"))
245 def armv7(arch):
246     if arch < 7:
247         die("Android/armv6 and earlier are not supported")
250 set_config("MOZ_THUMB2", True, when=arm_target.thumb2)
251 set_define("MOZ_THUMB2", True, when=arm_target.thumb2)
254 have_arm_simd = c_compiler.try_compile(
255     body='asm("uqadd8 r1, r1, r2");', check_msg="for ARM SIMD support in compiler"
258 set_config("HAVE_ARM_SIMD", have_arm_simd)
259 set_define("HAVE_ARM_SIMD", have_arm_simd)
261 have_arm_neon = c_compiler.try_compile(
262     body='asm(".fpu neon\\n vadd.i8 d0, d0, d0");',
263     check_msg="for ARM NEON support in compiler",
266 set_config("HAVE_ARM_NEON", have_arm_neon)
267 set_define("HAVE_ARM_NEON", have_arm_neon)
270 # We don't need to build NEON support if we're targetting a non-NEON device.
271 # This matches media/webrtc/trunk/webrtc/build/common.gypi.
272 @depends(arm_target.arm_arch, when=have_arm_neon)
273 def build_arm_neon(arm_arch):
274     return arm_arch >= 7
277 set_config("BUILD_ARM_NEON", True, when=build_arm_neon)
278 set_define("BUILD_ARM_NEON", True, when=build_arm_neon)
281 set_config("ARM_ARCH", depends(arm_target.arm_arch)(lambda x: str(x)))
282 set_config("MOZ_FPU", arm_target.fpu)
285 @depends(arm_target)
286 def neon_flags(arm_target):
287     # Building with -mfpu=neon requires either the "softfp" or the
288     # "hardfp" ABI. Depending on the compiler's default target, and the
289     # CFLAGS, the default ABI might be neither, in which case it is the
290     # "softfloat" ABI.
291     # The "softfloat" ABI is binary-compatible with the "softfp" ABI, so
292     # we can safely mix code built with both ABIs. So, if we detect
293     # that compiling uses the "softfloat" ABI, force the use of the
294     # "softfp" ABI instead.
295     flags = ["-mfpu=neon"]
296     if arm_target.float_abi == "soft":
297         flags.append("-mfloat-abi=softfp")
298     if arm_target.arm_arch < 7:
299         # clang needs to be forced to at least armv7 for -mfpu=neon to do
300         # something.
301         flags.append("-march=armv7-a")
302     return tuple(flags)
305 set_config("NEON_FLAGS", neon_flags)