]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.cpu.mk
Makefile.inc1 release bsd.own.mk: Introduce and use TAR_CMD
[FreeBSD/FreeBSD.git] / share / mk / bsd.cpu.mk
1 # $FreeBSD$
2
3 # Set default CPU compile flags and baseline CPUTYPE for each arch.  The
4 # compile flags must support the minimum CPU type for each architecture but
5 # may tune support for more advanced processors.
6
7 .if !defined(CPUTYPE) || empty(CPUTYPE)
8 _CPUCFLAGS =
9 . if ${MACHINE_CPUARCH} == "aarch64"
10 MACHINE_CPU = arm64
11 . elif ${MACHINE_CPUARCH} == "amd64"
12 MACHINE_CPU = amd64 sse2 sse mmx
13 . elif ${MACHINE_CPUARCH} == "arm"
14 MACHINE_CPU = arm
15 . elif ${MACHINE_CPUARCH} == "i386"
16 MACHINE_CPU = i486
17 . elif ${MACHINE_CPUARCH} == "powerpc"
18 MACHINE_CPU = aim
19 . elif ${MACHINE_CPUARCH} == "riscv"
20 MACHINE_CPU = riscv
21 . endif
22 .else
23
24 # Handle aliases (not documented in make.conf to avoid user confusion
25 # between e.g. i586 and pentium)
26
27 . if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
28 .  if ${CPUTYPE} == "barcelona"
29 CPUTYPE = amdfam10
30 .  elif ${CPUTYPE} == "skx"
31 CPUTYPE = skylake-avx512
32 .  elif ${CPUTYPE} == "core-avx2"
33 CPUTYPE = haswell
34 .  elif ${CPUTYPE} == "core-avx-i"
35 CPUTYPE = ivybridge
36 .  elif ${CPUTYPE} == "corei7-avx"
37 CPUTYPE = sandybridge
38 .  elif ${CPUTYPE} == "corei7"
39 CPUTYPE = nehalem
40 .  elif ${CPUTYPE} == "slm"
41 CPUTYPE = silvermont
42 .  elif ${CPUTYPE} == "atom"
43 CPUTYPE = bonnell
44 .  elif ${CPUTYPE} == "core"
45 CPUTYPE = prescott
46 .  endif
47 .  if ${MACHINE_CPUARCH} == "amd64"
48 .   if ${CPUTYPE} == "prescott"
49 CPUTYPE = nocona
50 .   endif
51 .  else
52 .   if ${CPUTYPE} == "k7"
53 CPUTYPE = athlon
54 .   elif ${CPUTYPE} == "p4"
55 CPUTYPE = pentium4
56 .   elif ${CPUTYPE} == "p4m"
57 CPUTYPE = pentium4m
58 .   elif ${CPUTYPE} == "p3"
59 CPUTYPE = pentium3
60 .   elif ${CPUTYPE} == "p3m"
61 CPUTYPE = pentium3m
62 .   elif ${CPUTYPE} == "p-m"
63 CPUTYPE = pentium-m
64 .   elif ${CPUTYPE} == "p2"
65 CPUTYPE = pentium2
66 .   elif ${CPUTYPE} == "i686"
67 CPUTYPE = pentiumpro
68 .   elif ${CPUTYPE} == "i586/mmx"
69 CPUTYPE = pentium-mmx
70 .   elif ${CPUTYPE} == "i586"
71 CPUTYPE = pentium
72 .   endif
73 .  endif
74 . endif
75
76 ###############################################################################
77 # Logic to set up correct gcc optimization flag.  This must be included
78 # after /etc/make.conf so it can react to the local value of CPUTYPE
79 # defined therein.  Consult:
80 #       http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
81 #       http://gcc.gnu.org/onlinedocs/gcc/RS-6000-and-PowerPC-Options.html
82 #       http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html
83 #       http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html
84
85 . if ${MACHINE_CPUARCH} == "i386"
86 .  if ${CPUTYPE} == "crusoe"
87 _CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0
88 .  elif ${CPUTYPE} == "k5"
89 _CPUCFLAGS = -march=pentium
90 .  elif ${CPUTYPE} == "c7"
91 _CPUCFLAGS = -march=c3-2
92 .  else
93 _CPUCFLAGS = -march=${CPUTYPE}
94 .  endif
95 . elif ${MACHINE_CPUARCH} == "amd64"
96 _CPUCFLAGS = -march=${CPUTYPE}
97 . elif ${MACHINE_CPUARCH} == "arm"
98 .  if ${CPUTYPE} == "xscale"
99 #XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself
100 #_CPUCFLAGS = -mcpu=xscale
101 _CPUCFLAGS = -march=armv5te -D__XSCALE__
102 .  elif ${CPUTYPE:M*soft*} != ""
103 _CPUCFLAGS = -mfloat-abi=softfp
104 .  elif ${CPUTYPE} == "cortexa"
105 _CPUCFLAGS = -march=armv7 -mfpu=vfp
106 .  elif ${CPUTYPE:Marmv[4567]*} != ""
107 # Handle all the armvX types that FreeBSD runs:
108 #       armv4, armv4t, armv5, armv5te, armv6, armv6t2, armv7, armv7-a, armv7ve
109 # they require -march=. All the others require -mcpu=.
110 _CPUCFLAGS = -march=${CPUTYPE}
111 .  else
112 # Common values for FreeBSD
113 # arm: (any arm v4 or v5 processor you are targeting)
114 #       arm920t, arm926ej-s, marvell-pj4, fa526, fa626,
115 #       fa606te, fa626te, fa726te
116 # armv6:
117 #       arm1176jzf-s
118 # armv7: generic-armv7-a, cortex-a5, cortex-a7, cortex-a8, cortex-a9,
119 #       cortex-a12, cortex-a15, cortex-a17
120 #       cortex-a53, cortex-a57, cortex-a72,
121 #       exynos-m1
122 _CPUCFLAGS = -mcpu=${CPUTYPE}
123 . endif
124 . elif ${MACHINE_ARCH} == "powerpc"
125 .  if ${CPUTYPE} == "e500"
126 _CPUCFLAGS = -Wa,-me500 -msoft-float
127 .  else
128 _CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64
129 .  endif
130 . elif ${MACHINE_ARCH:Mpowerpc64*} != ""
131 _CPUCFLAGS = -mcpu=${CPUTYPE}
132 . elif ${MACHINE_CPUARCH} == "aarch64"
133 .  if ${CPUTYPE:Marmv*} != ""
134 # Use -march when the CPU type is an architecture value, e.g. armv8.1-a
135 _CPUCFLAGS = -march=${CPUTYPE}
136 .  else
137 # Otherwise assume we have a CPU type
138 _CPUCFLAGS = -mcpu=${CPUTYPE}
139 .  endif
140 . endif
141
142 # Set up the list of CPU features based on the CPU type.  This is an
143 # unordered list to make it easy for client makefiles to test for the
144 # presence of a CPU feature.
145
146 ########## i386
147 . if ${MACHINE_CPUARCH} == "i386"
148 .  if ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \
149     ${CPUTYPE} == "znver1"
150 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
151 .  elif ${CPUTYPE} == "bdver4"
152 MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
153 .  elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
154     ${CPUTYPE} == "bdver1"
155 MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
156 .  elif ${CPUTYPE} == "btver2"
157 MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
158 .  elif ${CPUTYPE} == "btver1"
159 MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
160 .  elif ${CPUTYPE} == "amdfam10"
161 MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586
162 .  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3"
163 MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586
164 .  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
165     ${CPUTYPE} == "athlon-fx"
166 MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586
167 .  elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
168     ${CPUTYPE} == "athlon-4"
169 MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586
170 .  elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird"
171 MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586
172 .  elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode"
173 MACHINE_CPU = 3dnow mmx k6 k5 i586
174 .  elif ${CPUTYPE} == "k6"
175 MACHINE_CPU = mmx k6 k5 i586
176 .  elif ${CPUTYPE} == "k5"
177 MACHINE_CPU = k5 i586
178 .  elif ${CPUTYPE} == "sapphirerapids" || ${CPUTYPE} == "tigerlake" || \
179     ${CPUTYPE} == "cooperlake" || ${CPUTYPE} == "cascadelake" || \
180     ${CPUTYPE} == "icelake-server" || ${CPUTYPE} == "icelake-client" || \
181     ${CPUTYPE} == "cannonlake" || ${CPUTYPE} == "knm" || \
182     ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl" || \
183     ${CPUTYPE} == "x86-64-v4"
184 MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
185 .  elif ${CPUTYPE} == "alderlake" || ${CPUTYPE} == "skylake" || \
186     ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" || \
187     ${CPUTYPE} == "x86-64-v3"
188 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
189 .  elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
190 MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
191 .  elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \
192     ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \
193     ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \
194     ${CPUTYPE} == "x86-64-v2"
195 MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
196 .  elif ${CPUTYPE} == "penryn"
197 MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586
198 .  elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
199 MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586
200 .  elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott"
201 MACHINE_CPU = sse3 sse2 sse i686 mmx i586
202 .  elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \
203     ${CPUTYPE} == "pentium-m" || ${CPUTYPE} == "x86-64"
204 MACHINE_CPU = sse2 sse i686 mmx i586
205 .  elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m"
206 MACHINE_CPU = sse i686 mmx i586
207 .  elif ${CPUTYPE} == "pentium2"
208 MACHINE_CPU = i686 mmx i586
209 .  elif ${CPUTYPE} == "pentiumpro"
210 MACHINE_CPU = i686 i586
211 .  elif ${CPUTYPE} == "pentium-mmx"
212 MACHINE_CPU = mmx i586
213 .  elif ${CPUTYPE} == "pentium"
214 MACHINE_CPU = i586
215 .  elif ${CPUTYPE} == "c7"
216 MACHINE_CPU = sse3 sse2 sse i686 mmx i586
217 .  elif ${CPUTYPE} == "c3-2"
218 MACHINE_CPU = sse i686 mmx i586
219 .  elif ${CPUTYPE} == "c3"
220 MACHINE_CPU = 3dnow mmx i586
221 .  elif ${CPUTYPE} == "winchip2"
222 MACHINE_CPU = 3dnow mmx
223 .  elif ${CPUTYPE} == "winchip-c6"
224 MACHINE_CPU = mmx
225 .  endif
226 MACHINE_CPU += i486
227 ########## amd64
228 . elif ${MACHINE_CPUARCH} == "amd64"
229 .  if ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \
230     ${CPUTYPE} == "znver1"
231 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3
232 .  elif ${CPUTYPE} == "bdver4"
233 MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3
234 .  elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
235     ${CPUTYPE} == "bdver1"
236 MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3
237 .  elif ${CPUTYPE} == "btver2"
238 MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3
239 .  elif ${CPUTYPE} == "btver1"
240 MACHINE_CPU = ssse3 sse4a sse3
241 .  elif ${CPUTYPE} == "amdfam10"
242 MACHINE_CPU = k8 3dnow sse4a sse3
243 .  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \
244     ${CPUTYPE} == "k8-sse3"
245 MACHINE_CPU = k8 3dnow sse3
246 .  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
247     ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8"
248 MACHINE_CPU = k8 3dnow
249 .  elif ${CPUTYPE} == "sapphirerapids" || ${CPUTYPE} == "tigerlake" || \
250     ${CPUTYPE} == "cooperlake" || ${CPUTYPE} == "cascadelake" || \
251     ${CPUTYPE} == "icelake-server" || ${CPUTYPE} == "icelake-client" || \
252     ${CPUTYPE} == "cannonlake" || ${CPUTYPE} == "knm" || \
253     ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl" || \
254     ${CPUTYPE} == "x86-64-v4"
255 MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3
256 .  elif ${CPUTYPE} == "alderlake" || ${CPUTYPE} == "skylake" || \
257     ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" || \
258     ${CPUTYPE} == "x86-64-v3"
259 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3
260 .  elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
261 MACHINE_CPU = avx sse42 sse41 ssse3 sse3
262 .  elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \
263     ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \
264     ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \
265     ${CPUTYPE} == "x86-64-v2"
266 MACHINE_CPU = sse42 sse41 ssse3 sse3
267 .  elif ${CPUTYPE} == "penryn"
268 MACHINE_CPU = sse41 ssse3 sse3
269 .  elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
270 MACHINE_CPU = ssse3 sse3
271 .  elif ${CPUTYPE} == "nocona"
272 MACHINE_CPU = sse3
273 .  endif
274 MACHINE_CPU += amd64 sse2 sse mmx
275 ########## powerpc
276 . elif ${MACHINE_ARCH} == "powerpc"
277 .  if ${CPUTYPE} == "e500"
278 MACHINE_CPU = booke softfp
279 .  endif
280 ########## riscv
281 . elif ${MACHINE_CPUARCH} == "riscv"
282 MACHINE_CPU = riscv
283 . endif
284 .endif
285
286 ########## arm
287 .if ${MACHINE_CPUARCH} == "arm"
288 MACHINE_CPU += arm
289 . if ${MACHINE_ARCH:Marmv6*} != ""
290 MACHINE_CPU += armv6
291 . endif
292 . if ${MACHINE_ARCH:Marmv7*} != ""
293 MACHINE_CPU += armv7
294 . endif
295 # armv6 and armv7 are a hybrid. It can use the softfp ABI, but doesn't emulate
296 # floating point in the general case, so don't define softfp for it at this
297 # time. arm is pure softfp, so define it for them.
298 . if ${MACHINE_ARCH:Marmv[67]*} == ""
299 MACHINE_CPU += softfp
300 . endif
301 # Normally armv6 and armv7 are hard float ABI from FreeBSD 11 onwards. However
302 # when CPUTYPE has 'soft' in it, we use the soft-float ABI to allow building of
303 # soft-float ABI libraries. In this case, we have to add the -mfloat-abi=softfp
304 # to force that.
305 . if ${MACHINE_ARCH:Marmv[67]*} && defined(CPUTYPE) && ${CPUTYPE:M*soft*} != ""
306 # Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI
307 # not a nice optimization. Please note: softfp ABI uses hardware floating
308 # instructions, but passes arguments to function calls in integer regsiters.
309 # -mfloat-abi=soft is full software floating point, but is not currently
310 # supported. softfp support in FreeBSD may disappear in FreeBSD 13.0 since
311 # it was a transition tool from FreeBSD 10 to 11 and is a bit of an odd duck.
312 CFLAGS += -mfloat-abi=softfp
313 . endif
314 .endif
315
316 .if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpcspe"
317 LDFLAGS.bfd+= -Wl,--secure-plt
318 .endif
319
320 .if ${MACHINE_ARCH} == "powerpcspe"
321 CFLAGS += -mcpu=8548 -mspe
322 CFLAGS.gcc+= -mabi=spe -mfloat-gprs=double -Wa,-me500
323 .endif
324
325 .if ${MACHINE_CPUARCH} == "riscv"
326 .if ${MACHINE_ARCH:Mriscv*sf}
327 CFLAGS += -march=rv64imac -mabi=lp64
328 .else
329 CFLAGS += -march=rv64imafdc -mabi=lp64d
330 .endif
331 .endif
332
333 # NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
334
335 .if !defined(NO_CPU_CFLAGS)
336 CFLAGS += ${_CPUCFLAGS}
337 .endif
338
339 #
340 # Prohibit the compiler from emitting SIMD instructions.
341 # These flags are added to CFLAGS in areas where the extra context-switch
342 # cost outweighs the advantages of SIMD instructions.
343 #
344 # gcc:
345 # Setting -mno-mmx implies -mno-3dnow
346 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
347 #
348 # clang:
349 # Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
350 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and
351 # -mno-sse42
352 # (-mfpmath= is not supported)
353 #
354 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
355 CFLAGS_NO_SIMD.clang= -mno-avx -mno-avx2
356 CFLAGS_NO_SIMD= -mno-mmx -mno-sse
357 .endif
358 CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}}
359
360 # Add in any architecture-specific CFLAGS.
361 # These come from make.conf or the command line or the environment.
362 CFLAGS += ${CFLAGS.${MACHINE_ARCH}}
363 CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}}
364