xref: /freebsd/share/mk/bsd.cpu.mk (revision 895f86f15fbf6540071feb9328c3c50ed1f027b8)
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.  else
114# Common values for FreeBSD
115# arm:
116#	arm920t, arm926ej-s, marvell-pj4, fa526, fa626,
117#	fa606te, fa626te, fa726te
118# armv6:
119# 	arm1176jzf-s, generic-armv7-a, cortex-a5, cortex-a7, cortex-a8,
120#	cortex-a9, cortex-a12, cortex-a15, cortex-a17, cortex-a53, cortex-a57,
121#	cortex-a72, 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} == "powerpc64"
131_CPUCFLAGS = -mcpu=${CPUTYPE}
132. elif ${MACHINE_CPUARCH} == "mips"
133# mips[1234], mips32, mips64, and all later releases need to have mips
134# preserved (releases later than r2 require external toolchain)
135.  if ${CPUTYPE:Mmips32*} != "" || ${CPUTYPE:Mmips64*} != "" || \
136	${CPUTYPE:Mmips[1234]} != ""
137_CPUCFLAGS = -march=${CPUTYPE}
138. else
139# Default -march to the CPUTYPE passed in, with mips stripped off so we
140# accept either mips4kc or 4kc, mostly for historical reasons
141# Typical values for cores:
142#	4kc, 24kc, 34kc, 74kc, 1004kc, octeon, octeon+, octeon2, octeon3,
143#	sb1, xlp, xlr
144_CPUCFLAGS = -march=${CPUTYPE:S/^mips//}
145. endif
146. elif ${MACHINE_ARCH} == "sparc64"
147.  if ${CPUTYPE} == "v9"
148_CPUCFLAGS = -mcpu=v9
149.  elif ${CPUTYPE} == "ultrasparc"
150_CPUCFLAGS = -mcpu=ultrasparc
151.  elif ${CPUTYPE} == "ultrasparc3"
152_CPUCFLAGS = -mcpu=ultrasparc3
153.  endif
154. elif ${MACHINE_CPUARCH} == "aarch64"
155_CPUCFLAGS = -mcpu=${CPUTYPE}
156. endif
157
158# Set up the list of CPU features based on the CPU type.  This is an
159# unordered list to make it easy for client makefiles to test for the
160# presence of a CPU feature.
161
162########## i386
163. if ${MACHINE_CPUARCH} == "i386"
164.  if ${CPUTYPE} == "bdver4"
165MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
166.  elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
167    ${CPUTYPE} == "bdver1"
168MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
169.  elif ${CPUTYPE} == "btver2"
170MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
171.  elif ${CPUTYPE} == "btver1"
172MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
173.  elif ${CPUTYPE} == "amdfam10"
174MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586
175.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3"
176MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586
177.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
178    ${CPUTYPE} == "athlon-fx"
179MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586
180.  elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
181    ${CPUTYPE} == "athlon-4"
182MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586
183.  elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird"
184MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586
185.  elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode"
186MACHINE_CPU = 3dnow mmx k6 k5 i586
187.  elif ${CPUTYPE} == "k6"
188MACHINE_CPU = mmx k6 k5 i586
189.  elif ${CPUTYPE} == "k5"
190MACHINE_CPU = k5 i586
191.  elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "knl"
192MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
193.  elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell"
194MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
195.  elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
196MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
197.  elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \
198    ${CPUTYPE} == "silvermont"
199MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
200.  elif ${CPUTYPE} == "penryn"
201MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586
202.  elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
203MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586
204.  elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott"
205MACHINE_CPU = sse3 sse2 sse i686 mmx i586
206.  elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \
207    ${CPUTYPE} == "pentium-m"
208MACHINE_CPU = sse2 sse i686 mmx i586
209.  elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m"
210MACHINE_CPU = sse i686 mmx i586
211.  elif ${CPUTYPE} == "pentium2"
212MACHINE_CPU = i686 mmx i586
213.  elif ${CPUTYPE} == "pentiumpro"
214MACHINE_CPU = i686 i586
215.  elif ${CPUTYPE} == "pentium-mmx"
216MACHINE_CPU = mmx i586
217.  elif ${CPUTYPE} == "pentium"
218MACHINE_CPU = i586
219.  elif ${CPUTYPE} == "c7"
220MACHINE_CPU = sse3 sse2 sse i686 mmx i586
221.  elif ${CPUTYPE} == "c3-2"
222MACHINE_CPU = sse i686 mmx i586
223.  elif ${CPUTYPE} == "c3"
224MACHINE_CPU = 3dnow mmx i586
225.  elif ${CPUTYPE} == "winchip2"
226MACHINE_CPU = 3dnow mmx
227.  elif ${CPUTYPE} == "winchip-c6"
228MACHINE_CPU = mmx
229.  endif
230MACHINE_CPU += i486
231########## amd64
232. elif ${MACHINE_CPUARCH} == "amd64"
233.  if ${CPUTYPE} == "bdver4"
234MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3
235.  elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
236    ${CPUTYPE} == "bdver1"
237MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3
238.  elif ${CPUTYPE} == "btver2"
239MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3
240.  elif ${CPUTYPE} == "btver1"
241MACHINE_CPU = ssse3 sse4a sse3
242.  elif ${CPUTYPE} == "amdfam10"
243MACHINE_CPU = k8 3dnow sse4a sse3
244.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \
245    ${CPUTYPE} == "k8-sse3"
246MACHINE_CPU = k8 3dnow sse3
247.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
248    ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8"
249MACHINE_CPU = k8 3dnow
250.  elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "knl"
251MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3
252.  elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell"
253MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3
254.  elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
255MACHINE_CPU = avx sse42 sse41 ssse3 sse3
256.  elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \
257    ${CPUTYPE} == "silvermont"
258MACHINE_CPU = sse42 sse41 ssse3 sse3
259.  elif ${CPUTYPE} == "penryn"
260MACHINE_CPU = sse41 ssse3 sse3
261.  elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
262MACHINE_CPU = ssse3 sse3
263.  elif ${CPUTYPE} == "nocona"
264MACHINE_CPU = sse3
265.  endif
266MACHINE_CPU += amd64 sse2 sse mmx
267########## Mips
268. elif ${MACHINE_CPUARCH} == "mips"
269MACHINE_CPU = mips
270########## powerpc
271. elif ${MACHINE_ARCH} == "powerpc"
272.  if ${CPUTYPE} == "e500"
273MACHINE_CPU = booke softfp
274.  endif
275########## sparc64
276. elif ${MACHINE_ARCH} == "sparc64"
277.  if ${CPUTYPE} == "v9"
278MACHINE_CPU = v9
279.  elif ${CPUTYPE} == "ultrasparc"
280MACHINE_CPU = v9 ultrasparc
281.  elif ${CPUTYPE} == "ultrasparc3"
282MACHINE_CPU = v9 ultrasparc ultrasparc3
283.  endif
284. endif
285.endif
286
287.if ${MACHINE_CPUARCH} == "mips"
288CFLAGS += -G0
289.endif
290
291########## arm
292.if ${MACHINE_CPUARCH} == "arm"
293MACHINE_CPU += arm
294. if ${MACHINE_ARCH:Marmv6*} != ""
295MACHINE_CPU += armv6
296. endif
297# armv6 is a hybrid. It uses the softfp ABI, but doesn't emulate
298# floating point in the general case, so don't define softfp for
299# it at this time. arm and armeb are pure softfp, so define it
300# for them.
301. if ${MACHINE_ARCH:Marmv6*} == ""
302MACHINE_CPU += softfp
303. endif
304.if ${MACHINE_ARCH} == "armv6"
305# Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI
306# not a nice optimization.
307CFLAGS += -mfloat-abi=softfp
308.endif
309.endif
310
311# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
312
313.if !defined(NO_CPU_CFLAGS)
314CFLAGS += ${_CPUCFLAGS}
315.endif
316
317#
318# Prohibit the compiler from emitting SIMD instructions.
319# These flags are added to CFLAGS in areas where the extra context-switch
320# cost outweighs the advantages of SIMD instructions.
321#
322# gcc:
323# Setting -mno-mmx implies -mno-3dnow
324# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
325#
326# clang:
327# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
328# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and
329# -mno-sse42
330# (-mfpmath= is not supported)
331#
332.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
333CFLAGS_NO_SIMD.clang= -mno-avx
334CFLAGS_NO_SIMD= -mno-mmx -mno-sse
335.endif
336CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}}
337
338# Add in any architecture-specific CFLAGS.
339# These come from make.conf or the command line or the environment.
340CFLAGS += ${CFLAGS.${MACHINE_ARCH}}
341CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}}
342