xref: /freebsd/share/mk/bsd.cpu.mk (revision 6b129086dcee14496517fae085b448e3edc69bc7)
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} == "i386"
10MACHINE_CPU = i486
11. elif ${MACHINE_CPUARCH} == "amd64"
12MACHINE_CPU = amd64 sse2 sse mmx
13. elif ${MACHINE_CPUARCH} == "powerpc"
14MACHINE_CPU = aim
15. elif ${MACHINE_CPUARCH} == "sparc64"
16MACHINE_CPU = ultrasparc
17. elif ${MACHINE_CPUARCH} == "arm"
18MACHINE_CPU = arm
19. elif ${MACHINE_CPUARCH} == "mips"
20MACHINE_CPU = mips
21. endif
22.else
23
24# Handle aliases (not documented in make.conf to avoid user confusion
25# between e.g. i586 and pentium)
26
27. if ${MACHINE_CPUARCH} == "i386"
28.  if ${CPUTYPE} == "barcelona"
29CPUTYPE = amdfam10
30.  elif ${CPUTYPE} == "k7"
31CPUTYPE = athlon
32.  elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem"
33CPUTYPE = corei7
34.  elif ${CPUTYPE} == "core"
35CPUTYPE = prescott
36.  elif ${CPUTYPE} == "p4"
37CPUTYPE = pentium4
38.  elif ${CPUTYPE} == "p4m"
39CPUTYPE = pentium4m
40.  elif ${CPUTYPE} == "p3"
41CPUTYPE = pentium3
42.  elif ${CPUTYPE} == "p3m"
43CPUTYPE = pentium3m
44.  elif ${CPUTYPE} == "p-m"
45CPUTYPE = pentium-m
46.  elif ${CPUTYPE} == "p2"
47CPUTYPE = pentium2
48.  elif ${CPUTYPE} == "i686"
49CPUTYPE = pentiumpro
50.  elif ${CPUTYPE} == "i586/mmx"
51CPUTYPE = pentium-mmx
52.  elif ${CPUTYPE} == "i586"
53CPUTYPE = pentium
54.  endif
55. elif ${MACHINE_CPUARCH} == "amd64"
56.  if ${CPUTYPE} == "barcelona"
57CPUTYPE = amdfam10
58.  elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem"
59CPUTYPE = corei7
60.  elif ${CPUTYPE} == "prescott"
61CPUTYPE = nocona
62.  endif
63. elif ${MACHINE_ARCH} == "sparc64"
64.  if ${CPUTYPE} == "us"
65CPUTYPE = ultrasparc
66.  elif ${CPUTYPE} == "us3"
67CPUTYPE = ultrasparc3
68.  endif
69. endif
70
71###############################################################################
72# Logic to set up correct gcc optimization flag.  This must be included
73# after /etc/make.conf so it can react to the local value of CPUTYPE
74# defined therein.  Consult:
75#	http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
76#	http://gcc.gnu.org/onlinedocs/gcc/IA_002d64-Options.html
77#	http://gcc.gnu.org/onlinedocs/gcc/RS_002f6000-and-PowerPC-Options.html
78#	http://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html
79#	http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html
80#	http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html
81
82. if ${MACHINE_CPUARCH} == "i386"
83.  if ${CPUTYPE} == "crusoe"
84_CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0
85.  elif ${CPUTYPE} == "k5"
86_CPUCFLAGS = -march=pentium
87.  elif ${CPUTYPE} == "c7"
88_CPUCFLAGS = -march=c3-2
89.  else
90_CPUCFLAGS = -march=${CPUTYPE}
91.  endif
92. elif ${MACHINE_CPUARCH} == "amd64"
93_CPUCFLAGS = -march=${CPUTYPE}
94. elif ${MACHINE_CPUARCH} == "arm"
95.  if ${CPUTYPE} == "xscale"
96#XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself
97#_CPUCFLAGS = -mcpu=xscale
98_CPUCFLAGS = -march=armv5te -D__XSCALE__
99. elif ${CPUTYPE} == "armv6"
100_CPUCFLAGS = -march=${CPUTYPE} -DARM_ARCH_6=1
101. elif ${CPUTYPE} == "cortexa"
102_CPUCFLAGS = -DARM_ARCH_6=1 -mfpu=vfp
103.  else
104_CPUCFLAGS = -mcpu=${CPUTYPE}
105.  endif
106. elif ${MACHINE_ARCH} == "powerpc"
107.  if ${CPUTYPE} == "e500"
108_CPUCFLAGS = -Wa,-me500 -msoft-float
109.  else
110_CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64
111.  endif
112. elif ${MACHINE_ARCH} == "powerpc64"
113_CPUCFLAGS = -mcpu=${CPUTYPE}
114. elif ${MACHINE_CPUARCH} == "mips"
115.  if ${CPUTYPE} == "mips32"
116_CPUCFLAGS = -march=mips32
117.  elif ${CPUTYPE} == "mips32r2"
118_CPUCFLAGS = -march=mips32r2
119.  elif ${CPUTYPE} == "mips64"
120_CPUCFLAGS = -march=mips64
121.  elif ${CPUTYPE} == "mips64r2"
122_CPUCFLAGS = -march=mips64r2
123.  elif ${CPUTYPE} == "mips4kc"
124_CPUCFLAGS = -march=4kc
125.  elif ${CPUTYPE} == "mips24kc"
126_CPUCFLAGS = -march=24kc
127.  endif
128. elif ${MACHINE_ARCH} == "sparc64"
129.  if ${CPUTYPE} == "v9"
130_CPUCFLAGS = -mcpu=v9
131.  elif ${CPUTYPE} == "ultrasparc"
132_CPUCFLAGS = -mcpu=ultrasparc
133.  elif ${CPUTYPE} == "ultrasparc3"
134_CPUCFLAGS = -mcpu=ultrasparc3
135.  endif
136. endif
137
138# Set up the list of CPU features based on the CPU type.  This is an
139# unordered list to make it easy for client makefiles to test for the
140# presence of a CPU feature.
141
142. if ${MACHINE_CPUARCH} == "i386"
143.  if ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
144    ${CPUTYPE} == "bdver1"
145MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
146.  elif ${CPUTYPE} == "btver2"
147MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
148.  elif ${CPUTYPE} == "btver1"
149MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
150.  elif ${CPUTYPE} == "amdfam10"
151MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586
152.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3"
153MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586
154.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
155    ${CPUTYPE} == "athlon-fx"
156MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586
157.  elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
158    ${CPUTYPE} == "athlon-4"
159MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586
160.  elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird"
161MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586
162.  elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode"
163MACHINE_CPU = 3dnow mmx k6 k5 i586
164.  elif ${CPUTYPE} == "k6"
165MACHINE_CPU = mmx k6 k5 i586
166.  elif ${CPUTYPE} == "k5"
167MACHINE_CPU = k5 i586
168.  elif ${CPUTYPE} == "core-avx2"
169MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
170.  elif ${CPUTYPE} == "core-avx-i" || ${CPUTYPE} == "corei7-avx"
171MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
172.  elif ${CPUTYPE} == "slm" || ${CPUTYPE} == "corei7"
173MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
174.  elif ${CPUTYPE} == "penryn"
175MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586
176.  elif ${CPUTYPE} == "atom" || ${CPUTYPE} == "core2"
177MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586
178.  elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott"
179MACHINE_CPU = sse3 sse2 sse i686 mmx i586
180.  elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \
181    ${CPUTYPE} == "pentium-m"
182MACHINE_CPU = sse2 sse i686 mmx i586
183.  elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m"
184MACHINE_CPU = sse i686 mmx i586
185.  elif ${CPUTYPE} == "pentium2"
186MACHINE_CPU = i686 mmx i586
187.  elif ${CPUTYPE} == "pentiumpro"
188MACHINE_CPU = i686 i586
189.  elif ${CPUTYPE} == "pentium-mmx"
190MACHINE_CPU = mmx i586
191.  elif ${CPUTYPE} == "pentium"
192MACHINE_CPU = i586
193.  elif ${CPUTYPE} == "c7"
194MACHINE_CPU = sse3 sse2 sse i686 mmx i586
195.  elif ${CPUTYPE} == "c3-2"
196MACHINE_CPU = sse i686 mmx i586
197.  elif ${CPUTYPE} == "c3"
198MACHINE_CPU = 3dnow mmx i586
199.  elif ${CPUTYPE} == "winchip2"
200MACHINE_CPU = 3dnow mmx
201.  elif ${CPUTYPE} == "winchip-c6"
202MACHINE_CPU = mmx
203.  endif
204MACHINE_CPU += i486
205. elif ${MACHINE_CPUARCH} == "amd64"
206.  if ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
207    ${CPUTYPE} == "bdver1"
208MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3
209.  elif ${CPUTYPE} == "btver2"
210MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3
211.  elif ${CPUTYPE} == "btver1"
212MACHINE_CPU = ssse3 sse4a sse3
213.  elif ${CPUTYPE} == "amdfam10"
214MACHINE_CPU = k8 3dnow sse4a sse3
215.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \
216    ${CPUTYPE} == "k8-sse3"
217MACHINE_CPU = k8 3dnow sse3
218.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
219    ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8"
220MACHINE_CPU = k8 3dnow
221.  elif ${CPUTYPE} == "core-avx2"
222MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3
223.  elif ${CPUTYPE} == "core-avx-i" || ${CPUTYPE} == "corei7-avx"
224MACHINE_CPU = avx sse42 sse41 ssse3 sse3
225.  elif ${CPUTYPE} == "slm" || ${CPUTYPE} == "corei7"
226MACHINE_CPU = sse42 sse41 ssse3 sse3
227.  elif ${CPUTYPE} == "penryn"
228MACHINE_CPU = sse41 ssse3 sse3
229.  elif ${CPUTYPE} == "atom" || ${CPUTYPE} == "core2"
230MACHINE_CPU = ssse3 sse3
231.  elif ${CPUTYPE} == "nocona"
232MACHINE_CPU = sse3
233.  endif
234MACHINE_CPU += amd64 sse2 sse mmx
235. elif ${MACHINE_ARCH} == "powerpc"
236.  if ${CPUTYPE} == "e500"
237MACHINE_CPU = booke
238.  endif
239. elif ${MACHINE_ARCH} == "sparc64"
240.  if ${CPUTYPE} == "v9"
241MACHINE_CPU = v9
242.  elif ${CPUTYPE} == "ultrasparc"
243MACHINE_CPU = v9 ultrasparc
244.  elif ${CPUTYPE} == "ultrasparc3"
245MACHINE_CPU = v9 ultrasparc ultrasparc3
246.  endif
247. endif
248.endif
249
250.if ${MACHINE_CPUARCH} == "mips"
251CFLAGS += -G0
252.endif
253
254# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
255
256.if !defined(NO_CPU_CFLAGS)
257CFLAGS += ${_CPUCFLAGS}
258.endif
259
260# Add in any architecture-specific CFLAGS.
261# These come from make.conf or the command line or the environment.
262CFLAGS += ${CFLAGS.${MACHINE_ARCH}}
263CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}}
264