Bug 1578501 [wpt PR 18803] - WebKit export of https://bugs.webkit.org/show_bug.cgi...
[gecko.git] / build / moz.configure / arm.configure
blob5819df78cf727d701a627e0fb3d3483ec0bf3ea0
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/.
7 @depends(target.os, '--help')
8 def arm_option_defaults(os, _):
9     if os == 'Android':
10         arch = 'armv7-a'
11         thumb = 'yes'
12         fpu = 'neon'
13         float_abi = 'softfp'
14     else:
15         arch = thumb = fpu = float_abi = 'toolchain-default'
16     return namespace(
17         arch=arch,
18         thumb=thumb,
19         fpu=fpu,
20         float_abi=float_abi,
21     )
24 # Note: '{...|}' in the help of all options with a non-constant default to
25 # make the lint happy. The first arm is always going to be used, because a
26 # default is always returned. The lint is fooled by this file being
27 # conditional. If it weren't conditional, the lint wouldn't ask for '{|}' to
28 # be there.
29 js_option('--with-arch', nargs=1,
30           default=arm_option_defaults.arch,
31           help='{Use specific CPU features (-march=type). Resets thumb, fpu, '
32                'float-abi, etc. defaults when set|}')
35 @depends('--with-arch')
36 def arch_option(value):
37     if value:
38         if value[0] != 'toolchain-default':
39             return ['-march={}'.format(value[0])]
40     return []
43 js_option('--with-thumb', choices=('yes', 'no', 'toolchain-default'),
44           default=arm_option_defaults.thumb,
45           nargs='?', help='{Use Thumb instruction set (-mthumb)|}')
48 def normalize_arm_option(value):
49     if value:
50         if len(value):
51             if value[0] == 'yes':
52                 return True
53             elif value[0] == 'no':
54                 return False
55             else:
56                 return value[0]
57         return True
58     return False
60 @depends('--with-thumb')
61 def thumb_option(value):
62     value = normalize_arm_option(value)
63     if value is True:
64         return ['-mthumb']
65     if value is False:
66         return ['-marm']
67     return []
70 js_option('--with-thumb-interwork', choices=('yes', 'no', 'toolchain-default'),
71           default='toolchain-default',
72           nargs='?', help='Use Thumb/ARM instuctions interwork (-mthumb-interwork)')
75 @depends('--with-thumb-interwork')
76 def thumb_interwork_option(value):
77     value = normalize_arm_option(value)
78     if value is True:
79         return ['-mthumb-interwork']
80     if value is False:
81         return ['-mno-thumb-interwork']
82     return []
85 js_option('--with-fpu', nargs=1,
86           default=arm_option_defaults.fpu,
87           help='{Use specific FPU type (-mfpu=type)|}')
90 @depends('--with-fpu')
91 def fpu_option(value):
92     if value:
93         if value[0] != 'toolchain-default':
94             return ['-mfpu={}'.format(value[0])]
95     return []
98 js_option('--with-float-abi', nargs=1,
99           default=arm_option_defaults.float_abi,
100           help='{Use specific arm float ABI (-mfloat-abi=type)|}')
103 @depends('--with-float-abi')
104 def float_abi_option(value):
105     if value:
106         if value[0] != 'toolchain-default':
107             return ['-mfloat-abi={}'.format(value[0])]
108     return []
111 js_option('--with-soft-float', choices=('yes', 'no', 'toolchain-default'),
112           default='toolchain-default',
113           nargs='?', help='Use soft float library (-msoft-float)')
116 @depends('--with-soft-float')
117 def soft_float_option(value):
118     value = normalize_arm_option(value)
119     if value is True:
120         return ['-msoft-float']
121     if value is False:
122         return ['-mno-soft-float']
123     return []
126 check_and_add_gcc_flag('-mno-unaligned-access',
127                        when=depends(target.os)(lambda os: os == 'Android'))
130 @depends(arch_option, thumb_option, thumb_interwork_option, fpu_option,
131          float_abi_option, soft_float_option)
132 def all_flags(arch, thumb, interwork, fpu, float_abi, soft_float):
133     return arch + thumb + interwork + fpu + float_abi + soft_float
136 add_old_configure_assignment('_ARM_FLAGS', all_flags)
137 add_old_configure_assignment('_THUMB_FLAGS', thumb_option)
140 @depends(c_compiler, all_flags)
141 @checking('ARM version support in compiler', lambda x: x.arm_arch)
142 @imports(_from='textwrap', _import='dedent')
143 def arm_target(compiler, all_flags):
144     # We're going to preprocess the following source to figure out some details
145     # about the arm target options we have enabled.
146     source = dedent('''\
147         %ARM_ARCH __ARM_ARCH
148         #if __thumb2__
149         %THUMB2 yes
150         #else
151         %THUMB2 no
152         #endif
153         // Confusingly, the __SOFTFP__ preprocessor variable indicates the
154         // "softfloat" ABI, not the "softfp" ABI.
155         #if __SOFTFP__
156         %FLOAT_ABI soft
157         #elif __ARM_PCS_VFP
158         %FLOAT_ABI hard
159         #else
160         %FLOAT_ABI softfp
161         #endif
162         // There is more subtlety to it than this preprocessor test, but MOZ_FPU doesn't
163         // need to be too fine-grained.
164         #if __ARM_NEON
165         %FPU neon
166         #elif __ARM_VFPV2__ || __ARM_FP == 12
167         %FPU vfpv2
168         #elif __ARM_VFPV3__
169         %FPU vfpv3
170         #elif __ARM_VFPV4__ || __ARM_FP == 14
171         %FPU vfpv4
172         #elif __ARM_FPV5__
173         %FPU fp-armv8
174         #endif
175     ''')
176     result = try_invoke_compiler(
177         compiler.wrapper + [compiler.compiler] + compiler.flags,
178         compiler.language,
179         source,
180         ['-E'] + all_flags,
181     )
182     # Metadata emitted by preprocessors such as GCC with LANG=ja_JP.utf-8 may
183     # have non-ASCII characters. Treat the output as bytearray.
184     data = {'fpu': None}  # fpu may not get a value from the preprocessor.
185     for line in result.splitlines():
186         if line.startswith(b'%'):
187             k, _, v = line.partition(' ')
188             k = k.lstrip('%').lower()
189             if k == 'arm_arch':
190                 data[k] = int(v)
191             else:
192                 data[k] = {
193                     'yes': True,
194                     'no': False,
195                 }.get(v, v)
196             log.debug('%s = %s', k, data[k])
198     return namespace(**data)
201 @depends(arm_target.arm_arch, when=depends(target.os)(lambda os: os == 'Android'))
202 def armv7(arch):
203     if arch < 7:
204         die('Android/armv6 and earlier are not supported')
207 set_config('MOZ_THUMB2', True, when=arm_target.thumb2)
208 set_define('MOZ_THUMB2', True, when=arm_target.thumb2)
209 add_old_configure_assignment('MOZ_THUMB2', True, when=arm_target.thumb2)
212 have_arm_simd = c_compiler.try_compile(body='asm("uqadd8 r1, r1, r2");',
213                                        check_msg='for ARM SIMD support in compiler')
215 set_config('HAVE_ARM_SIMD', have_arm_simd)
216 set_define('HAVE_ARM_SIMD', have_arm_simd)
218 have_arm_neon = c_compiler.try_compile(body='asm(".fpu neon\\n vadd.i8 d0, d0, d0");',
219                                        check_msg='for ARM NEON support in compiler')
221 set_config('HAVE_ARM_NEON', have_arm_neon)
222 set_define('HAVE_ARM_NEON', have_arm_neon)
225 # We don't need to build NEON support if we're targetting a non-NEON device.
226 # This matches media/webrtc/trunk/webrtc/build/common.gypi.
227 @depends(arm_target.arm_arch, when=have_arm_neon)
228 def build_arm_neon(arm_arch):
229     return arm_arch >= 7
232 set_config('BUILD_ARM_NEON', build_arm_neon)
233 set_define('BUILD_ARM_NEON', build_arm_neon)
236 set_config('ARM_ARCH', depends(arm_target.arm_arch)(lambda x: str(x)))
237 add_old_configure_assignment('ARM_ARCH', depends(arm_target.arm_arch)(lambda x: str(x)))
238 set_config('MOZ_FPU', arm_target.fpu)
241 @depends(arm_target.float_abi)
242 def neon_flags(float_abi):
243     # Building with -mfpu=neon requires either the "softfp" or the
244     # "hardfp" ABI. Depending on the compiler's default target, and the
245     # CFLAGS, the default ABI might be neither, in which case it is the
246     # "softfloat" ABI.
247     # The "softfloat" ABI is binary-compatible with the "softfp" ABI, so
248     # we can safely mix code built with both ABIs. So, if we detect
249     # that compiling uses the "softfloat" ABI, force the use of the
250     # "softfp" ABI instead.
251     flags = ['-mfpu=neon']
252     if float_abi == 'soft':
253         flags.append('-mfloat-abi=softfp')
254     return tuple(flags)
257 set_config('NEON_FLAGS', neon_flags)