xref: /freebsd/share/mk/bsd.cpu.mk (revision 5ca34122ecdd5abc62bdae39663fec9ac8523d87)
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/IA_002d64-Options.html
88#	http://gcc.gnu.org/onlinedocs/gcc/RS_002f6000-and-PowerPC-Options.html
89#	http://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html
90#	http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html
91#	http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html
92
93. if ${MACHINE_CPUARCH} == "i386"
94.  if ${CPUTYPE} == "crusoe"
95_CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0
96.  elif ${CPUTYPE} == "k5"
97_CPUCFLAGS = -march=pentium
98.  elif ${CPUTYPE} == "c7"
99_CPUCFLAGS = -march=c3-2
100.  else
101_CPUCFLAGS = -march=${CPUTYPE}
102.  endif
103. elif ${MACHINE_CPUARCH} == "amd64"
104_CPUCFLAGS = -march=${CPUTYPE}
105. elif ${MACHINE_CPUARCH} == "arm"
106.  if ${CPUTYPE} == "xscale"
107#XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself
108#_CPUCFLAGS = -mcpu=xscale
109_CPUCFLAGS = -march=armv5te -D__XSCALE__
110. elif ${CPUTYPE} == "armv6"
111_CPUCFLAGS = -march=${CPUTYPE} -DARM_ARCH_6=1
112. elif ${CPUTYPE} == "cortexa"
113_CPUCFLAGS = -march=armv7 -DARM_ARCH_6=1 -mfpu=vfp
114.  else
115_CPUCFLAGS = -mcpu=${CPUTYPE}
116.  endif
117. elif ${MACHINE_ARCH} == "powerpc"
118.  if ${CPUTYPE} == "e500"
119_CPUCFLAGS = -Wa,-me500 -msoft-float
120.  else
121_CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64
122.  endif
123. elif ${MACHINE_ARCH} == "powerpc64"
124_CPUCFLAGS = -mcpu=${CPUTYPE}
125. elif ${MACHINE_CPUARCH} == "mips"
126.  if ${CPUTYPE} == "mips32"
127_CPUCFLAGS = -march=mips32
128.  elif ${CPUTYPE} == "mips32r2"
129_CPUCFLAGS = -march=mips32r2
130.  elif ${CPUTYPE} == "mips64"
131_CPUCFLAGS = -march=mips64
132.  elif ${CPUTYPE} == "mips64r2"
133_CPUCFLAGS = -march=mips64r2
134.  elif ${CPUTYPE} == "mips4kc"
135_CPUCFLAGS = -march=4kc
136.  elif ${CPUTYPE} == "mips24kc"
137_CPUCFLAGS = -march=24kc
138.  endif
139. elif ${MACHINE_ARCH} == "sparc64"
140.  if ${CPUTYPE} == "v9"
141_CPUCFLAGS = -mcpu=v9
142.  elif ${CPUTYPE} == "ultrasparc"
143_CPUCFLAGS = -mcpu=ultrasparc
144.  elif ${CPUTYPE} == "ultrasparc3"
145_CPUCFLAGS = -mcpu=ultrasparc3
146.  endif
147. endif
148
149# Set up the list of CPU features based on the CPU type.  This is an
150# unordered list to make it easy for client makefiles to test for the
151# presence of a CPU feature.
152
153########## i386
154. if ${MACHINE_CPUARCH} == "i386"
155.  if ${CPUTYPE} == "bdver4"
156MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
157.  elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
158    ${CPUTYPE} == "bdver1"
159MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
160.  elif ${CPUTYPE} == "btver2"
161MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
162.  elif ${CPUTYPE} == "btver1"
163MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
164.  elif ${CPUTYPE} == "amdfam10"
165MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586
166.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3"
167MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586
168.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
169    ${CPUTYPE} == "athlon-fx"
170MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586
171.  elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
172    ${CPUTYPE} == "athlon-4"
173MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586
174.  elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird"
175MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586
176.  elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode"
177MACHINE_CPU = 3dnow mmx k6 k5 i586
178.  elif ${CPUTYPE} == "k6"
179MACHINE_CPU = mmx k6 k5 i586
180.  elif ${CPUTYPE} == "k5"
181MACHINE_CPU = k5 i586
182.  elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "knl"
183MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
184.  elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell"
185MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
186.  elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
187MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
188.  elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \
189    ${CPUTYPE} == "silvermont"
190MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
191.  elif ${CPUTYPE} == "penryn"
192MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586
193.  elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
194MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586
195.  elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott"
196MACHINE_CPU = sse3 sse2 sse i686 mmx i586
197.  elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \
198    ${CPUTYPE} == "pentium-m"
199MACHINE_CPU = sse2 sse i686 mmx i586
200.  elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m"
201MACHINE_CPU = sse i686 mmx i586
202.  elif ${CPUTYPE} == "pentium2"
203MACHINE_CPU = i686 mmx i586
204.  elif ${CPUTYPE} == "pentiumpro"
205MACHINE_CPU = i686 i586
206.  elif ${CPUTYPE} == "pentium-mmx"
207MACHINE_CPU = mmx i586
208.  elif ${CPUTYPE} == "pentium"
209MACHINE_CPU = i586
210.  elif ${CPUTYPE} == "c7"
211MACHINE_CPU = sse3 sse2 sse i686 mmx i586
212.  elif ${CPUTYPE} == "c3-2"
213MACHINE_CPU = sse i686 mmx i586
214.  elif ${CPUTYPE} == "c3"
215MACHINE_CPU = 3dnow mmx i586
216.  elif ${CPUTYPE} == "winchip2"
217MACHINE_CPU = 3dnow mmx
218.  elif ${CPUTYPE} == "winchip-c6"
219MACHINE_CPU = mmx
220.  endif
221MACHINE_CPU += i486
222########## amd64
223. elif ${MACHINE_CPUARCH} == "amd64"
224.  if ${CPUTYPE} == "bdver4"
225MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3
226.  elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
227    ${CPUTYPE} == "bdver1"
228MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3
229.  elif ${CPUTYPE} == "btver2"
230MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3
231.  elif ${CPUTYPE} == "btver1"
232MACHINE_CPU = ssse3 sse4a sse3
233.  elif ${CPUTYPE} == "amdfam10"
234MACHINE_CPU = k8 3dnow sse4a sse3
235.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \
236    ${CPUTYPE} == "k8-sse3"
237MACHINE_CPU = k8 3dnow sse3
238.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
239    ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8"
240MACHINE_CPU = k8 3dnow
241.  elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "knl"
242MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3
243.  elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell"
244MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3
245.  elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
246MACHINE_CPU = avx sse42 sse41 ssse3 sse3
247.  elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \
248    ${CPUTYPE} == "silvermont"
249MACHINE_CPU = sse42 sse41 ssse3 sse3
250.  elif ${CPUTYPE} == "penryn"
251MACHINE_CPU = sse41 ssse3 sse3
252.  elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
253MACHINE_CPU = ssse3 sse3
254.  elif ${CPUTYPE} == "nocona"
255MACHINE_CPU = sse3
256.  endif
257MACHINE_CPU += amd64 sse2 sse mmx
258########## powerpc
259. elif ${MACHINE_ARCH} == "powerpc"
260.  if ${CPUTYPE} == "e500"
261MACHINE_CPU = booke softfp
262.  endif
263########## sparc64
264. elif ${MACHINE_ARCH} == "sparc64"
265.  if ${CPUTYPE} == "v9"
266MACHINE_CPU = v9
267.  elif ${CPUTYPE} == "ultrasparc"
268MACHINE_CPU = v9 ultrasparc
269.  elif ${CPUTYPE} == "ultrasparc3"
270MACHINE_CPU = v9 ultrasparc ultrasparc3
271.  endif
272. endif
273.endif
274
275.if ${MACHINE_CPUARCH} == "mips"
276CFLAGS += -G0
277.endif
278
279########## arm
280.if ${MACHINE_CPUARCH} == "arm"
281MACHINE_CPU += arm
282. if ${MACHINE_ARCH:Marmv6*} != ""
283MACHINE_CPU += armv6
284. endif
285# armv6 is a hybrid. It uses the softfp ABI, but doesn't emulate
286# floating point in the general case, so don't define softfp for
287# it at this time. arm and armeb are pure softfp, so define it
288# for them.
289. if ${MACHINE_ARCH:Marmv6*} == ""
290MACHINE_CPU += softfp
291. endif
292.if ${MACHINE_ARCH} == "armv6"
293# Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI
294# not a nice optimization.
295CFLAGS += -mfloat-abi=softfp
296.endif
297.endif
298
299# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
300
301.if !defined(NO_CPU_CFLAGS)
302CFLAGS += ${_CPUCFLAGS}
303.endif
304
305#
306# Prohibit the compiler from emitting SIMD instructions.
307# These flags are added to CFLAGS in areas where the extra context-switch
308# cost outweighs the advantages of SIMD instructions.
309#
310# gcc:
311# Setting -mno-mmx implies -mno-3dnow
312# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
313#
314# clang:
315# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
316# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and
317# -mno-sse42
318# (-mfpmath= is not supported)
319#
320.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
321CFLAGS_NO_SIMD.clang= -mno-avx
322CFLAGS_NO_SIMD= -mno-mmx -mno-sse
323.endif
324CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}}
325
326# Add in any architecture-specific CFLAGS.
327# These come from make.conf or the command line or the environment.
328CFLAGS += ${CFLAGS.${MACHINE_ARCH}}
329CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}}
330