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