xref: /freebsd/share/mk/bsd.cpu.mk (revision 1ce1c6895245648ba022f7187df1626904dc1f89)
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"
10MACHINE_CPU = arm64
11. elif ${MACHINE_CPUARCH} == "amd64"
12MACHINE_CPU = amd64 sse2 sse mmx
13. elif ${MACHINE_CPUARCH} == "arm"
14MACHINE_CPU = arm
15. elif ${MACHINE_CPUARCH} == "i386"
16MACHINE_CPU = i486
17. elif ${MACHINE_CPUARCH} == "mips"
18MACHINE_CPU = mips
19. elif ${MACHINE_CPUARCH} == "powerpc"
20MACHINE_CPU = aim
21. elif ${MACHINE_CPUARCH} == "sparc64"
22MACHINE_CPU = ultrasparc
23. endif
24.else
25
26# Handle aliases (not documented in make.conf to avoid user confusion
27# between e.g. i586 and pentium)
28
29. if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
30.  if ${CPUTYPE} == "barcelona"
31CPUTYPE = amdfam10
32.  elif ${CPUTYPE} == "core-avx2"
33CPUTYPE = haswell
34.  elif ${CPUTYPE} == "core-avx-i"
35CPUTYPE = ivybridge
36.  elif ${CPUTYPE} == "corei7-avx"
37CPUTYPE = sandybridge
38.  elif ${CPUTYPE} == "corei7"
39CPUTYPE = nehalem
40.  elif ${CPUTYPE} == "slm"
41CPUTYPE = silvermont
42.  elif ${CPUTYPE} == "atom"
43CPUTYPE = bonnell
44.  elif ${CPUTYPE} == "core"
45CPUTYPE = prescott
46.  endif
47.  if ${MACHINE_CPUARCH} == "amd64"
48.   if ${CPUTYPE} == "prescott"
49CPUTYPE = nocona
50.   endif
51.  else
52.   if ${CPUTYPE} == "k7"
53CPUTYPE = athlon
54.   elif ${CPUTYPE} == "p4"
55CPUTYPE = pentium4
56.   elif ${CPUTYPE} == "p4m"
57CPUTYPE = pentium4m
58.   elif ${CPUTYPE} == "p3"
59CPUTYPE = pentium3
60.   elif ${CPUTYPE} == "p3m"
61CPUTYPE = pentium3m
62.   elif ${CPUTYPE} == "p-m"
63CPUTYPE = pentium-m
64.   elif ${CPUTYPE} == "p2"
65CPUTYPE = pentium2
66.   elif ${CPUTYPE} == "i686"
67CPUTYPE = pentiumpro
68.   elif ${CPUTYPE} == "i586/mmx"
69CPUTYPE = pentium-mmx
70.   elif ${CPUTYPE} == "i586"
71CPUTYPE = pentium
72.   endif
73.  endif
74. elif ${MACHINE_ARCH} == "sparc64"
75.  if ${CPUTYPE} == "us"
76CPUTYPE = ultrasparc
77.  elif ${CPUTYPE} == "us3"
78CPUTYPE = ultrasparc3
79.  endif
80. endif
81
82###############################################################################
83# Logic to set up correct gcc optimization flag.  This must be included
84# after /etc/make.conf so it can react to the local value of CPUTYPE
85# defined therein.  Consult:
86#	http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
87#	http://gcc.gnu.org/onlinedocs/gcc/RS-6000-and-PowerPC-Options.html
88#	http://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html
89#	http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html
90#	http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html
91
92. if ${MACHINE_CPUARCH} == "i386"
93.  if ${CPUTYPE} == "crusoe"
94_CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0
95.  elif ${CPUTYPE} == "k5"
96_CPUCFLAGS = -march=pentium
97.  elif ${CPUTYPE} == "c7"
98_CPUCFLAGS = -march=c3-2
99.  else
100_CPUCFLAGS = -march=${CPUTYPE}
101.  endif
102. elif ${MACHINE_CPUARCH} == "amd64"
103_CPUCFLAGS = -march=${CPUTYPE}
104. elif ${MACHINE_CPUARCH} == "arm"
105.  if ${CPUTYPE} == "xscale"
106#XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself
107#_CPUCFLAGS = -mcpu=xscale
108_CPUCFLAGS = -march=armv5te -D__XSCALE__
109. elif ${CPUTYPE} == "armv6"
110_CPUCFLAGS = -march=${CPUTYPE} -DARM_ARCH_6=1
111. elif ${CPUTYPE} == "cortexa"
112_CPUCFLAGS = -march=armv7 -DARM_ARCH_6=1 -mfpu=vfp
113. elif ${CPUTYPE:Marmv[4567]*} != ""
114# Handle all the armvX types that FreeBSD runs:
115#	armv4, armv4t, armv5, armv5te, armv6, armv6t2, armv7, armv7-a, armv7ve
116# they require -march=. All the others require -mcpu=.
117_CPUCFLAGS = -march=${CPUTYPE}
118. else
119# Common values for FreeBSD
120# arm:
121#	arm920t, arm926ej-s, marvell-pj4, fa526, fa626,
122#	fa606te, fa626te, fa726te
123# armv6:
124# 	arm1176jzf-s, generic-armv7-a, cortex-a5, cortex-a7, cortex-a8,
125#	cortex-a9, cortex-a12, cortex-a15, cortex-a17, cortex-a53, cortex-a57,
126#	cortex-a72, exynos-m1
127_CPUCFLAGS = -mcpu=${CPUTYPE}
128. endif
129. elif ${MACHINE_ARCH} == "powerpc"
130.  if ${CPUTYPE} == "e500"
131_CPUCFLAGS = -Wa,-me500 -msoft-float
132.  else
133_CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64
134.  endif
135. elif ${MACHINE_ARCH} == "powerpc64"
136_CPUCFLAGS = -mcpu=${CPUTYPE}
137. elif ${MACHINE_CPUARCH} == "mips"
138# mips[1234], mips32, mips64, and all later releases need to have mips
139# preserved (releases later than r2 require external toolchain)
140.  if ${CPUTYPE:Mmips32*} != "" || ${CPUTYPE:Mmips64*} != "" || \
141	${CPUTYPE:Mmips[1234]} != ""
142_CPUCFLAGS = -march=${CPUTYPE}
143. else
144# Default -march to the CPUTYPE passed in, with mips stripped off so we
145# accept either mips4kc or 4kc, mostly for historical reasons
146# Typical values for cores:
147#	4kc, 24kc, 34kc, 74kc, 1004kc, octeon, octeon+, octeon2, octeon3,
148#	sb1, xlp, xlr
149_CPUCFLAGS = -march=${CPUTYPE:S/^mips//}
150. endif
151. elif ${MACHINE_ARCH} == "sparc64"
152.  if ${CPUTYPE} == "v9"
153_CPUCFLAGS = -mcpu=v9
154.  elif ${CPUTYPE} == "ultrasparc"
155_CPUCFLAGS = -mcpu=ultrasparc
156.  elif ${CPUTYPE} == "ultrasparc3"
157_CPUCFLAGS = -mcpu=ultrasparc3
158.  endif
159. elif ${MACHINE_CPUARCH} == "aarch64"
160_CPUCFLAGS = -mcpu=${CPUTYPE}
161. endif
162
163# Set up the list of CPU features based on the CPU type.  This is an
164# unordered list to make it easy for client makefiles to test for the
165# presence of a CPU feature.
166
167########## i386
168. if ${MACHINE_CPUARCH} == "i386"
169.  if ${CPUTYPE} == "bdver4"
170MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
171.  elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
172    ${CPUTYPE} == "bdver1"
173MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
174.  elif ${CPUTYPE} == "btver2"
175MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
176.  elif ${CPUTYPE} == "btver1"
177MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
178.  elif ${CPUTYPE} == "amdfam10"
179MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586
180.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3"
181MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586
182.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
183    ${CPUTYPE} == "athlon-fx"
184MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586
185.  elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
186    ${CPUTYPE} == "athlon-4"
187MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586
188.  elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird"
189MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586
190.  elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode"
191MACHINE_CPU = 3dnow mmx k6 k5 i586
192.  elif ${CPUTYPE} == "k6"
193MACHINE_CPU = mmx k6 k5 i586
194.  elif ${CPUTYPE} == "k5"
195MACHINE_CPU = k5 i586
196.  elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "knl"
197MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
198.  elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell"
199MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
200.  elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
201MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
202.  elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \
203    ${CPUTYPE} == "silvermont"
204MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
205.  elif ${CPUTYPE} == "penryn"
206MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586
207.  elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
208MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586
209.  elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott"
210MACHINE_CPU = sse3 sse2 sse i686 mmx i586
211.  elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \
212    ${CPUTYPE} == "pentium-m"
213MACHINE_CPU = sse2 sse i686 mmx i586
214.  elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m"
215MACHINE_CPU = sse i686 mmx i586
216.  elif ${CPUTYPE} == "pentium2"
217MACHINE_CPU = i686 mmx i586
218.  elif ${CPUTYPE} == "pentiumpro"
219MACHINE_CPU = i686 i586
220.  elif ${CPUTYPE} == "pentium-mmx"
221MACHINE_CPU = mmx i586
222.  elif ${CPUTYPE} == "pentium"
223MACHINE_CPU = i586
224.  elif ${CPUTYPE} == "c7"
225MACHINE_CPU = sse3 sse2 sse i686 mmx i586
226.  elif ${CPUTYPE} == "c3-2"
227MACHINE_CPU = sse i686 mmx i586
228.  elif ${CPUTYPE} == "c3"
229MACHINE_CPU = 3dnow mmx i586
230.  elif ${CPUTYPE} == "winchip2"
231MACHINE_CPU = 3dnow mmx
232.  elif ${CPUTYPE} == "winchip-c6"
233MACHINE_CPU = mmx
234.  endif
235MACHINE_CPU += i486
236########## amd64
237. elif ${MACHINE_CPUARCH} == "amd64"
238.  if ${CPUTYPE} == "bdver4"
239MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3
240.  elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
241    ${CPUTYPE} == "bdver1"
242MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3
243.  elif ${CPUTYPE} == "btver2"
244MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3
245.  elif ${CPUTYPE} == "btver1"
246MACHINE_CPU = ssse3 sse4a sse3
247.  elif ${CPUTYPE} == "amdfam10"
248MACHINE_CPU = k8 3dnow sse4a sse3
249.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \
250    ${CPUTYPE} == "k8-sse3"
251MACHINE_CPU = k8 3dnow sse3
252.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
253    ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8"
254MACHINE_CPU = k8 3dnow
255.  elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "knl"
256MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3
257.  elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell"
258MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3
259.  elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
260MACHINE_CPU = avx sse42 sse41 ssse3 sse3
261.  elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \
262    ${CPUTYPE} == "silvermont"
263MACHINE_CPU = sse42 sse41 ssse3 sse3
264.  elif ${CPUTYPE} == "penryn"
265MACHINE_CPU = sse41 ssse3 sse3
266.  elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
267MACHINE_CPU = ssse3 sse3
268.  elif ${CPUTYPE} == "nocona"
269MACHINE_CPU = sse3
270.  endif
271MACHINE_CPU += amd64 sse2 sse mmx
272########## Mips
273. elif ${MACHINE_CPUARCH} == "mips"
274MACHINE_CPU = mips
275########## powerpc
276. elif ${MACHINE_ARCH} == "powerpc"
277.  if ${CPUTYPE} == "e500"
278MACHINE_CPU = booke softfp
279.  endif
280########## sparc64
281. elif ${MACHINE_ARCH} == "sparc64"
282.  if ${CPUTYPE} == "v9"
283MACHINE_CPU = v9
284.  elif ${CPUTYPE} == "ultrasparc"
285MACHINE_CPU = v9 ultrasparc
286.  elif ${CPUTYPE} == "ultrasparc3"
287MACHINE_CPU = v9 ultrasparc ultrasparc3
288.  endif
289. endif
290.endif
291
292.if ${MACHINE_CPUARCH} == "mips"
293CFLAGS += -G0
294.endif
295
296########## arm
297.if ${MACHINE_CPUARCH} == "arm"
298MACHINE_CPU += arm
299. if ${MACHINE_ARCH:Marmv6*} != ""
300MACHINE_CPU += armv6
301. endif
302# armv6 is a hybrid. It uses the softfp ABI, but doesn't emulate
303# floating point in the general case, so don't define softfp for
304# it at this time. arm and armeb are pure softfp, so define it
305# for them.
306. if ${MACHINE_ARCH:Marmv6*} == ""
307MACHINE_CPU += softfp
308. endif
309.if ${MACHINE_ARCH} == "armv6"
310# Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI
311# not a nice optimization.
312CFLAGS += -mfloat-abi=softfp
313.endif
314.endif
315
316# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
317
318.if !defined(NO_CPU_CFLAGS)
319CFLAGS += ${_CPUCFLAGS}
320.endif
321
322#
323# Prohibit the compiler from emitting SIMD instructions.
324# These flags are added to CFLAGS in areas where the extra context-switch
325# cost outweighs the advantages of SIMD instructions.
326#
327# gcc:
328# Setting -mno-mmx implies -mno-3dnow
329# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
330#
331# clang:
332# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
333# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and
334# -mno-sse42
335# (-mfpmath= is not supported)
336#
337.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
338CFLAGS_NO_SIMD.clang= -mno-avx
339CFLAGS_NO_SIMD= -mno-mmx -mno-sse
340.endif
341CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}}
342
343# Add in any architecture-specific CFLAGS.
344# These come from make.conf or the command line or the environment.
345CFLAGS += ${CFLAGS.${MACHINE_ARCH}}
346CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}}
347