bsd.cpu.mk revision 243310
172878Skris# $FreeBSD: head/share/mk/bsd.cpu.mk 243310 2012-11-19 21:58:14Z jkim $
272878Skris
3100772Sjhb# Set default CPU compile flags and baseline CPUTYPE for each arch.  The
4100772Sjhb# compile flags must support the minimum CPU type for each architecture but
5100772Sjhb# may tune support for more advanced processors.
672878Skris
7101232Sru.if !defined(CPUTYPE) || empty(CPUTYPE)
8136606Sobrien_CPUCFLAGS =
9212540Simp. if ${MACHINE_CPUARCH} == "i386"
10113374SobrienMACHINE_CPU = i486
11212540Simp. elif ${MACHINE_CPUARCH} == "amd64"
12206973SdelphijMACHINE_CPU = amd64 sse2 sse mmx
13212540Simp. elif ${MACHINE_CPUARCH} == "ia64"
14103560SjhbMACHINE_CPU = itanium
15212540Simp. elif ${MACHINE_CPUARCH} == "powerpc"
16176776SrajMACHINE_CPU = aim
17212540Simp. elif ${MACHINE_CPUARCH} == "sparc64"
18216820SmariusMACHINE_CPU = ultrasparc
19212540Simp. elif ${MACHINE_CPUARCH} == "arm"
20129217ScognetMACHINE_CPU = arm
21212540Simp. elif ${MACHINE_CPUARCH} == "mips"
22177385SimpMACHINE_CPU = mips
23100773Sjhb. endif
24100772Sjhb.else
2572878Skris
2672878Skris# Handle aliases (not documented in make.conf to avoid user confusion
2772878Skris# between e.g. i586 and pentium)
2872878Skris
29212540Simp. if ${MACHINE_CPUARCH} == "i386"
30243310Sjkim.  if ${CPUTYPE} == "nocona" || ${CPUTYPE} == "core" || \
31243310Sjkim    ${CPUTYPE} == "core2" || ${CPUTYPE} == "corei7" || \
32243310Sjkim    ${CPUTYPE} == "corei7-avx" || ${CPUTYPE} == "core-avx-i"
33166071SdesCPUTYPE = prescott
34136607Sobrien.  elif ${CPUTYPE} == "p4"
35136606SobrienCPUTYPE = pentium4
36136606Sobrien.  elif ${CPUTYPE} == "p4m"
37136606SobrienCPUTYPE = pentium4m
38136606Sobrien.  elif ${CPUTYPE} == "p3"
39136606SobrienCPUTYPE = pentium3
40136606Sobrien.  elif ${CPUTYPE} == "p3m"
41136606SobrienCPUTYPE = pentium3m
42136606Sobrien.  elif ${CPUTYPE} == "p-m"
43136606SobrienCPUTYPE = pentium-m
44136606Sobrien.  elif ${CPUTYPE} == "p2"
45136606SobrienCPUTYPE = pentium2
46136606Sobrien.  elif ${CPUTYPE} == "i686"
47136606SobrienCPUTYPE = pentiumpro
48136606Sobrien.  elif ${CPUTYPE} == "i586/mmx"
49136606SobrienCPUTYPE = pentium-mmx
50136606Sobrien.  elif ${CPUTYPE} == "i586"
51136606SobrienCPUTYPE = pentium
52218896Smm.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \
53243310Sjkim    ${CPUTYPE} == "k8-sse3" || ${CPUTYPE} == "amdfam10" || \
54243310Sjkim    ${CPUTYPE} == "btver1" || ${CPUTYPE} == "bdver1" || ${CPUTYPE} == "bdver2"
55218896SmmCPUTYPE = prescott
56136607Sobrien.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
57243310Sjkim    ${CPUTYPE} == "k8"
58133525SobrienCPUTYPE = athlon-mp
59103045Smux.  elif ${CPUTYPE} == "k7"
60103045SmuxCPUTYPE = athlon
61100773Sjhb.  endif
62212540Simp. elif ${MACHINE_CPUARCH} == "amd64"
63219376Smm.  if ${CPUTYPE} == "prescott"
64136607SobrienCPUTYPE = nocona
65136607Sobrien.  endif
66216820Smarius. elif ${MACHINE_ARCH} == "sparc64"
67216820Smarius.  if ${CPUTYPE} == "us"
68216820SmariusCPUTYPE = ultrasparc
69216820Smarius.  elif ${CPUTYPE} == "us3"
70216820SmariusCPUTYPE = ultrasparc3
71216820Smarius.  endif
7272878Skris. endif
7372878Skris
74136606Sobrien###############################################################################
7596421Sobrien# Logic to set up correct gcc optimization flag.  This must be included
7672878Skris# after /etc/make.conf so it can react to the local value of CPUTYPE
7796421Sobrien# defined therein.  Consult:
78160536Simp#	http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
79179989Sale#	http://gcc.gnu.org/onlinedocs/gcc/IA_002d64-Options.html
80179989Sale#	http://gcc.gnu.org/onlinedocs/gcc/RS_002f6000-and-PowerPC-Options.html
81177385Simp#	http://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html
8296421Sobrien#	http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html
83179989Sale#	http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html
8472878Skris
85212540Simp. if ${MACHINE_CPUARCH} == "i386"
86127888Sdfr.  if ${CPUTYPE} == "crusoe"
87133000Sobrien_CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0
88136606Sobrien.  elif ${CPUTYPE} == "k5"
89136606Sobrien_CPUCFLAGS = -march=pentium
90219640Smm.  elif ${CPUTYPE} == "core2"
91219640Smm_CPUCFLAGS = -march=prescott
92136606Sobrien.  else
93136606Sobrien_CPUCFLAGS = -march=${CPUTYPE}
94136606Sobrien.  endif # GCC on 'i386'
95212540Simp. elif ${MACHINE_CPUARCH} == "amd64"
96136607Sobrien_CPUCFLAGS = -march=${CPUTYPE}
97212540Simp. elif ${MACHINE_CPUARCH} == "arm"
98136606Sobrien.  if ${CPUTYPE} == "xscale"
99172706Scognet#XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself
100172706Scognet#_CPUCFLAGS = -mcpu=xscale
101239272Sgonzo_CPUCFLAGS = -march=armv5te -D__XSCALE__ -DARM_WANT_TP_ADDRESS
102239272Sgonzo. elif ${CPUTYPE} == "armv6"
103239272Sgonzo_CPUCFLAGS = -march=${CPUTYPE} -DARM_ARCH_6=1
104239272Sgonzo. elif ${CPUTYPE} == "cortexa"
105239272Sgonzo_CPUCFLAGS = -march=armv6 -DARM_ARCH_6=1 -mfpu=vfp
106136606Sobrien.  else
107239272Sgonzo_CPUCFLAGS = -mcpu=${CPUTYPE} -DARM_WANT_TP_ADDRESS
108135678Scognet.  endif
109215274Simp. elif ${MACHINE_ARCH} == "powerpc"
110176776Sraj.  if ${CPUTYPE} == "e500"
111176776Sraj_CPUCFLAGS = -Wa,-me500 -msoft-float
112188923Snwhitehorn.  else
113190681Snwhitehorn_CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64
114176776Sraj.  endif
115209868Snwhitehorn. elif ${MACHINE_ARCH} == "powerpc64"
116209868Snwhitehorn_CPUCFLAGS = -mcpu=${CPUTYPE}
117212540Simp. elif ${MACHINE_CPUARCH} == "mips"
118177385Simp.  if ${CPUTYPE} == "mips32"
119177385Simp_CPUCFLAGS = -march=mips32
120177385Simp.  elif ${CPUTYPE} == "mips32r2"
121177385Simp_CPUCFLAGS = -march=mips32r2
122177385Simp.  elif ${CPUTYPE} == "mips64"
123177385Simp_CPUCFLAGS = -march=mips64
124177385Simp.  elif ${CPUTYPE} == "mips64r2"
125177385Simp_CPUCFLAGS = -march=mips64r2
126177385Simp.  elif ${CPUTYPE} == "mips4kc"
127177385Simp_CPUCFLAGS = -march=4kc
128177385Simp.  elif ${CPUTYPE} == "mips24kc"
129177385Simp_CPUCFLAGS = -march=24kc
130177385Simp.  endif
131216820Smarius. elif ${MACHINE_ARCH} == "sparc64"
132216820Smarius.  if ${CPUTYPE} == "v9"
133216820Smarius_CPUCFLAGS = -mcpu=v9
134216820Smarius.  elif ${CPUTYPE} == "ultrasparc"
135216820Smarius_CPUCFLAGS = -mcpu=ultrasparc
136216820Smarius.  elif ${CPUTYPE} == "ultrasparc3"
137216820Smarius_CPUCFLAGS = -mcpu=ultrasparc3
138216820Smarius.  endif
13972878Skris. endif
14072878Skris
14172878Skris# Set up the list of CPU features based on the CPU type.  This is an
14272878Skris# unordered list to make it easy for client makefiles to test for the
14372878Skris# presence of a CPU feature.
14472878Skris
145212540Simp. if ${MACHINE_CPUARCH} == "i386"
146243310Sjkim.  if ${CPUTYPE} == "bdver1" || ${CPUTYPE} == "bdver2"
147243310SjkimMACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
148243310SjkimMACHINE_CPU += i486 i386
149243310Sjkim.  elif ${CPUTYPE} == "btver1"
150243310SjkimMACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 i486 i386
151243310Sjkim.  elif ${CPUTYPE} == "amdfam10"
152243310SjkimMACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586
153243310SjkimMACHINE_CPU += i486 i386
154243310Sjkim.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3"
155218896SmmMACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586 i486 i386
156218896Smm.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64"
157136607SobrienMACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586 i486 i386
158136607Sobrien.  elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
159125254Sbde    ${CPUTYPE} == "athlon-4"
160136606SobrienMACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586 i486 i386
161126657Sbde.  elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird"
162112768SobrienMACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586 i486 i386
163219376Smm.  elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode"
164103045SmuxMACHINE_CPU = 3dnow mmx k6 k5 i586 i486 i386
165103562Sjhb.  elif ${CPUTYPE} == "k6"
16674069SsobomaxMACHINE_CPU = mmx k6 k5 i586 i486 i386
167103562Sjhb.  elif ${CPUTYPE} == "k5"
16872878SkrisMACHINE_CPU = k5 i586 i486 i386
169160497Sdes.  elif ${CPUTYPE} == "c3"
170161259SdesMACHINE_CPU = 3dnow mmx i586 i486 i386
171160497Sdes.  elif ${CPUTYPE} == "c3-2"
172160497SdesMACHINE_CPU = sse mmx i586 i486 i386
173176665Sjhb.  elif ${CPUTYPE} == "c7"
174176665SjhbMACHINE_CPU = sse3 sse2 sse i686 mmx i586 i486 i386
175243310Sjkim.  elif ${CPUTYPE} == "corei7-avx" || ${CPUTYPE} == "core-avx-i"
176243310SjkimMACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 i486 i386
177243310Sjkim.  elif ${CPUTYPE} == "corei7"
178243310SjkimMACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 i486 i386
179219640Smm.  elif ${CPUTYPE} == "core2"
180219640SmmMACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586 i486 i386
181166071Sdes.  elif ${CPUTYPE} == "prescott"
182166069SdesMACHINE_CPU = sse3 sse2 sse i686 mmx i586 i486 i386
183243310Sjkim.  elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \
184243310Sjkim    ${CPUTYPE} == "pentium-m"
185103045SmuxMACHINE_CPU = sse2 sse i686 mmx i586 i486 i386
186136606Sobrien.  elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m"
18773145SkrisMACHINE_CPU = sse i686 mmx i586 i486 i386
188136606Sobrien.  elif ${CPUTYPE} == "pentium2"
18974553SkrisMACHINE_CPU = i686 mmx i586 i486 i386
190136606Sobrien.  elif ${CPUTYPE} == "pentiumpro"
19172878SkrisMACHINE_CPU = i686 i586 i486 i386
192136606Sobrien.  elif ${CPUTYPE} == "pentium-mmx"
19373145SkrisMACHINE_CPU = mmx i586 i486 i386
194136606Sobrien.  elif ${CPUTYPE} == "pentium"
19572878SkrisMACHINE_CPU = i586 i486 i386
196103562Sjhb.  elif ${CPUTYPE} == "i486"
19772878SkrisMACHINE_CPU = i486 i386
198103562Sjhb.  elif ${CPUTYPE} == "i386"
19972878SkrisMACHINE_CPU = i386
200103562Sjhb.  endif
201212540Simp. elif ${MACHINE_CPUARCH} == "amd64"
202243310Sjkim.  if ${CPUTYPE} == "bdver1" || ${CPUTYPE} == "bdver2"
203243310SjkimMACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3
204243310Sjkim.  elif ${CPUTYPE} == "btver1"
205243310SjkimMACHINE_CPU = ssse3 sse4a sse3
206243310Sjkim.  elif ${CPUTYPE} == "amdfam10"
207243310SjkimMACHINE_CPU = k8 3dnow sse4a sse3
208243310Sjkim.  elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \
209243310Sjkim    ${CPUTYPE} == "k8-sse3"
210218896SmmMACHINE_CPU = k8 3dnow sse3
211243310Sjkim.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
212243310Sjkim    ${CPUTYPE} == "k8"
213138685SobrienMACHINE_CPU = k8 3dnow
214243310Sjkim.  elif ${CPUTYPE} == "corei7-avx" || ${CPUTYPE} == "core-avx-i"
215243310SjkimMACHINE_CPU = avx sse42 sse41 ssse3 sse3
216243310Sjkim.  elif ${CPUTYPE} == "corei7"
217243310SjkimMACHINE_CPU = sse42 sse41 ssse3 sse3
218219640Smm.  elif ${CPUTYPE} == "core2"
219219640SmmMACHINE_CPU = ssse3 sse3
220219640Smm.  elif ${CPUTYPE} == "nocona"
221138685SobrienMACHINE_CPU = sse3
222136607Sobrien.  endif
223138685SobrienMACHINE_CPU += amd64 sse2 sse mmx
224212540Simp. elif ${MACHINE_CPUARCH} == "ia64"
225103562Sjhb.  if ${CPUTYPE} == "itanium"
22672878SkrisMACHINE_CPU = itanium
227103562Sjhb.  endif
228216820Smarius. elif ${MACHINE_ARCH} == "powerpc"
229216820Smarius.  if ${CPUTYPE} == "e500"
230216820SmariusMACHINE_CPU = booke
231216820Smarius.  endif
232216820Smarius. elif ${MACHINE_ARCH} == "sparc64"
233216820Smarius.  if ${CPUTYPE} == "v9"
234216820SmariusMACHINE_CPU = v9
235216820Smarius.  elif ${CPUTYPE} == "ultrasparc"
236216820SmariusMACHINE_CPU = v9 ultrasparc
237216820Smarius.  elif ${CPUTYPE} == "ultrasparc3"
238216820SmariusMACHINE_CPU = v9 ultrasparc ultrasparc3
239216820Smarius.  endif
24072878Skris. endif
24172878Skris.endif
242103561Sjhb
243216820Smarius.if ${MACHINE_CPUARCH} == "mips"
244204559SimpCFLAGS += -G0
245177385Simp.endif
246177385Simp
247124347Sru# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
248103561Sjhb
249103561Sjhb.if !defined(NO_CPU_CFLAGS)
250103561SjhbCFLAGS += ${_CPUCFLAGS}
251103561Sjhb.endif
252