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, "--help")
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"]
149 check_and_add_gcc_flag(
150 "-mno-unaligned-access", when=depends(target.os)(lambda os: os == "Android")
157 thumb_interwork_option,
162 def all_flags(arch, thumb, interwork, fpu, float_abi, soft_float):
163 return arch + thumb + interwork + fpu + float_abi + soft_float
166 add_old_configure_assignment("_ARM_FLAGS", all_flags)
167 add_old_configure_assignment("_THUMB_FLAGS", thumb_option)
170 @depends(c_compiler, all_flags)
171 @checking("ARM version support in compiler", lambda x: x.arm_arch)
172 @imports(_from="textwrap", _import="dedent")
173 def arm_target(compiler, all_flags):
174 # We're going to preprocess the following source to figure out some details
175 # about the arm target options we have enabled.
184 // Confusingly, the __SOFTFP__ preprocessor variable indicates the
185 // "softfloat" ABI, not the "softfp" ABI.
193 // There is more subtlety to it than this preprocessor test, but MOZ_FPU doesn't
194 // need to be too fine-grained.
197 #elif __ARM_VFPV2__ || __ARM_FP == 12
201 #elif __ARM_VFPV4__ || __ARM_FP == 14
208 result = try_invoke_compiler(
209 compiler.wrapper + [compiler.compiler] + compiler.flags,
214 # Metadata emitted by preprocessors such as GCC with LANG=ja_JP.utf-8 may
215 # have non-ASCII characters. Treat the output as bytearray.
216 data = {"fpu": None} # fpu may not get a value from the preprocessor.
217 for line in result.splitlines():
218 if line.startswith("%"):
219 k, _, v = line.partition(" ")
220 k = k.lstrip("%").lower()
228 log.debug("%s = %s", k, data[k])
230 return namespace(**data)
233 @depends(arm_target.arm_arch, when=depends(target.os)(lambda os: os == "Android"))
236 die("Android/armv6 and earlier are not supported")
239 set_config("MOZ_THUMB2", True, when=arm_target.thumb2)
240 set_define("MOZ_THUMB2", True, when=arm_target.thumb2)
241 add_old_configure_assignment("MOZ_THUMB2", True, when=arm_target.thumb2)
244 have_arm_simd = c_compiler.try_compile(
245 body='asm("uqadd8 r1, r1, r2");', check_msg="for ARM SIMD support in compiler"
248 set_config("HAVE_ARM_SIMD", have_arm_simd)
249 set_define("HAVE_ARM_SIMD", have_arm_simd)
251 have_arm_neon = c_compiler.try_compile(
252 body='asm(".fpu neon\\n vadd.i8 d0, d0, d0");',
253 check_msg="for ARM NEON support in compiler",
256 set_config("HAVE_ARM_NEON", have_arm_neon)
257 set_define("HAVE_ARM_NEON", have_arm_neon)
260 # We don't need to build NEON support if we're targetting a non-NEON device.
261 # This matches media/webrtc/trunk/webrtc/build/common.gypi.
262 @depends(arm_target.arm_arch, when=have_arm_neon)
263 def build_arm_neon(arm_arch):
267 set_config("BUILD_ARM_NEON", build_arm_neon)
268 set_define("BUILD_ARM_NEON", build_arm_neon)
271 set_config("ARM_ARCH", depends(arm_target.arm_arch)(lambda x: str(x)))
272 add_old_configure_assignment("ARM_ARCH", depends(arm_target.arm_arch)(lambda x: str(x)))
273 set_config("MOZ_FPU", arm_target.fpu)
276 @depends(arm_target.float_abi)
277 def neon_flags(float_abi):
278 # Building with -mfpu=neon requires either the "softfp" or the
279 # "hardfp" ABI. Depending on the compiler's default target, and the
280 # CFLAGS, the default ABI might be neither, in which case it is the
282 # The "softfloat" ABI is binary-compatible with the "softfp" ABI, so
283 # we can safely mix code built with both ABIs. So, if we detect
284 # that compiling uses the "softfloat" ABI, force the use of the
285 # "softfp" ABI instead.
286 flags = ["-mfpu=neon"]
287 if float_abi == "soft":
288 flags.append("-mfloat-abi=softfp")
292 set_config("NEON_FLAGS", neon_flags)