xref: /freebsd/share/mk/bsd.cpu.mk (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
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. if ${MACHINE_CPUARCH} == "i386"
154.  if ${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} == "skylake" || ${CPUTYPE} == "knl"
182MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
183.  elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell"
184MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
185.  elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
186MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
187.  elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \
188    ${CPUTYPE} == "silvermont"
189MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
190.  elif ${CPUTYPE} == "penryn"
191MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586
192.  elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
193MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586
194.  elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott"
195MACHINE_CPU = sse3 sse2 sse i686 mmx i586
196.  elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \
197    ${CPUTYPE} == "pentium-m"
198MACHINE_CPU = sse2 sse i686 mmx i586
199.  elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m"
200MACHINE_CPU = sse i686 mmx i586
201.  elif ${CPUTYPE} == "pentium2"
202MACHINE_CPU = i686 mmx i586
203.  elif ${CPUTYPE} == "pentiumpro"
204MACHINE_CPU = i686 i586
205.  elif ${CPUTYPE} == "pentium-mmx"
206MACHINE_CPU = mmx i586
207.  elif ${CPUTYPE} == "pentium"
208MACHINE_CPU = i586
209.  elif ${CPUTYPE} == "c7"
210MACHINE_CPU = sse3 sse2 sse i686 mmx i586
211.  elif ${CPUTYPE} == "c3-2"
212MACHINE_CPU = sse i686 mmx i586
213.  elif ${CPUTYPE} == "c3"
214MACHINE_CPU = 3dnow mmx i586
215.  elif ${CPUTYPE} == "winchip2"
216MACHINE_CPU = 3dnow mmx
217.  elif ${CPUTYPE} == "winchip-c6"
218MACHINE_CPU = mmx
219.  endif
220MACHINE_CPU += i486
221. elif ${MACHINE_CPUARCH} == "amd64"
222.  if ${CPUTYPE} == "bdver4"
223MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3
224.  elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
225    ${CPUTYPE} == "bdver1"
226MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3
227.  elif ${CPUTYPE} == "btver2"
228MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3
229.  elif ${CPUTYPE} == "btver1"
230MACHINE_CPU = ssse3 sse4a sse3
231.  elif ${CPUTYPE} == "amdfam10"
232MACHINE_CPU = k8 3dnow sse4a sse3
233.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \
234    ${CPUTYPE} == "k8-sse3"
235MACHINE_CPU = k8 3dnow sse3
236.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
237    ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8"
238MACHINE_CPU = k8 3dnow
239.  elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "knl"
240MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3
241.  elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell"
242MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3
243.  elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
244MACHINE_CPU = avx sse42 sse41 ssse3 sse3
245.  elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \
246    ${CPUTYPE} == "silvermont"
247MACHINE_CPU = sse42 sse41 ssse3 sse3
248.  elif ${CPUTYPE} == "penryn"
249MACHINE_CPU = sse41 ssse3 sse3
250.  elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
251MACHINE_CPU = ssse3 sse3
252.  elif ${CPUTYPE} == "nocona"
253MACHINE_CPU = sse3
254.  endif
255MACHINE_CPU += amd64 sse2 sse mmx
256. elif ${MACHINE_ARCH} == "powerpc"
257.  if ${CPUTYPE} == "e500"
258MACHINE_CPU = booke
259.  endif
260. elif ${MACHINE_ARCH} == "sparc64"
261.  if ${CPUTYPE} == "v9"
262MACHINE_CPU = v9
263.  elif ${CPUTYPE} == "ultrasparc"
264MACHINE_CPU = v9 ultrasparc
265.  elif ${CPUTYPE} == "ultrasparc3"
266MACHINE_CPU = v9 ultrasparc ultrasparc3
267.  endif
268. endif
269.endif
270
271.if ${MACHINE_CPUARCH} == "mips"
272CFLAGS += -G0
273.endif
274
275.if ${MACHINE_ARCH} == "armv6"
276_CPUCFLAGS += -mfloat-abi=softfp
277.endif
278
279# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
280
281.if !defined(NO_CPU_CFLAGS)
282CFLAGS += ${_CPUCFLAGS}
283.endif
284
285# Add in any architecture-specific CFLAGS.
286# These come from make.conf or the command line or the environment.
287CFLAGS += ${CFLAGS.${MACHINE_ARCH}}
288CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}}
289