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