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