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/.
9 def arm_option_defaults(os):
16 arch = thumb = fpu = float_abi = "toolchain-default"
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
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):
42 if value[0] != "toolchain-default":
43 return ["-march={}".format(value[0])]
49 choices=("yes", "no", "toolchain-default"),
50 default=arm_option_defaults.thumb,
52 help="{Use Thumb instruction set (-mthumb)|}",
56 def normalize_arm_option(value):
61 elif value[0] == "no":
69 @depends("--with-thumb")
70 def thumb_option(value):
71 value = normalize_arm_option(value)
80 "--with-thumb-interwork",
81 choices=("yes", "no", "toolchain-default"),
82 default="toolchain-default",
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)
92 return ["-mthumb-interwork"]
94 return ["-mno-thumb-interwork"]
101 default=arm_option_defaults.fpu,
102 help="{Use specific FPU type (-mfpu=type)|}",
106 @depends("--with-fpu")
107 def fpu_option(value):
109 if value[0] != "toolchain-default":
110 return ["-mfpu={}".format(value[0])]
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):
125 if value[0] != "toolchain-default":
126 return ["-mfloat-abi={}".format(value[0])]
132 choices=("yes", "no", "toolchain-default"),
133 default="toolchain-default",
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)
143 return ["-msoft-float"]
145 return ["-mno-soft-float"]
150 "-mno-unaligned-access", when=depends(target.os)(lambda os: os == "Android")
154 # The set of flags that clang understands
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 @depends(configure_cache, c_compiler, all_arm_flags)
176 @checking("ARM version support in compiler", lambda x: x.arm_arch)
177 @imports(_from="textwrap", _import="dedent")
178 def arm_target(configure_cache, compiler, all_arm_flags):
179 # We're going to preprocess the following source to figure out some details
180 # about the arm target options we have enabled.
189 // Confusingly, the __SOFTFP__ preprocessor variable indicates the
190 // "softfloat" ABI, not the "softfp" ABI.
198 // There is more subtlety to it than this preprocessor test, but MOZ_FPU doesn't
199 // need to be too fine-grained.
202 #elif __ARM_VFPV2__ || __ARM_FP == 12
206 #elif __ARM_VFPV4__ || __ARM_FP == 14
213 result = try_invoke_compiler(
215 [compiler.compiler] + compiler.flags,
218 ["-E"] + all_arm_flags,
219 wrapper=compiler.wrapper,
221 # Metadata emitted by preprocessors such as GCC with LANG=ja_JP.utf-8 may
222 # have non-ASCII characters. Treat the output as bytearray.
223 data = {"fpu": None} # fpu may not get a value from the preprocessor.
224 for line in result.splitlines():
225 if line.startswith("%"):
226 k, _, v = line.partition(" ")
227 k = k.lstrip("%").lower()
235 log.debug("%s = %s", k, data[k])
237 return namespace(**data)
240 @depends(arm_target.arm_arch, when=depends(target.os)(lambda os: os == "Android"))
243 die("Android/armv6 and earlier are not supported")
246 set_config("MOZ_THUMB2", True, when=arm_target.thumb2)
247 set_define("MOZ_THUMB2", True, when=arm_target.thumb2)
250 have_arm_simd = c_compiler.try_compile(
251 body='asm("uqadd8 r1, r1, r2");', check_msg="for ARM SIMD support in compiler"
254 set_config("HAVE_ARM_SIMD", have_arm_simd)
255 set_define("HAVE_ARM_SIMD", have_arm_simd)
257 have_arm_neon = c_compiler.try_compile(
258 body='asm(".fpu neon\\n vadd.i8 d0, d0, d0");',
259 check_msg="for ARM NEON support in compiler",
262 set_config("HAVE_ARM_NEON", have_arm_neon)
263 set_define("HAVE_ARM_NEON", have_arm_neon)
266 # We don't need to build NEON support if we're targetting a non-NEON device.
267 # This matches media/webrtc/trunk/webrtc/build/common.gypi.
268 @depends(arm_target.arm_arch, when=have_arm_neon)
269 def build_arm_neon(arm_arch):
273 set_config("BUILD_ARM_NEON", True, when=build_arm_neon)
274 set_define("BUILD_ARM_NEON", True, when=build_arm_neon)
277 set_config("ARM_ARCH", depends(arm_target.arm_arch)(lambda x: str(x)))
278 set_config("MOZ_FPU", arm_target.fpu)
282 def neon_flags(arm_target):
283 # Building with -mfpu=neon requires either the "softfp" or the
284 # "hardfp" ABI. Depending on the compiler's default target, and the
285 # CFLAGS, the default ABI might be neither, in which case it is the
287 # The "softfloat" ABI is binary-compatible with the "softfp" ABI, so
288 # we can safely mix code built with both ABIs. So, if we detect
289 # that compiling uses the "softfloat" ABI, force the use of the
290 # "softfp" ABI instead.
291 flags = ["-mfpu=neon"]
292 if arm_target.float_abi == "soft":
293 flags.append("-mfloat-abi=softfp")
294 if arm_target.arm_arch < 7:
295 # clang needs to be forced to at least armv7 for -mfpu=neon to do
297 flags.append("-march=armv7-a")
301 set_config("NEON_FLAGS", neon_flags)