xref: /freebsd/share/mk/bsd.cpu.mk (revision 830940567b49bb0c08dfaed40418999e76616909)
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_ARCH} == "i386"
10MACHINE_CPU = i486
11. elif ${MACHINE_ARCH} == "amd64"
12MACHINE_CPU = amd64 sse2 sse
13. elif ${MACHINE_ARCH} == "ia64"
14MACHINE_CPU = itanium
15. elif ${MACHINE_ARCH} == "powerpc"
16MACHINE_CPU = aim
17. elif ${MACHINE_ARCH} == "sparc64"
18. elif ${MACHINE_ARCH} == "arm"
19MACHINE_CPU = arm
20. elif ${MACHINE_ARCH} == "mips"
21MACHINE_CPU = mips
22. endif
23.else
24
25# Handle aliases (not documented in make.conf to avoid user confusion
26# between e.g. i586 and pentium)
27
28. if ${MACHINE_ARCH} == "i386"
29.  if ${CPUTYPE} == "nocona"
30CPUTYPE = prescott
31.  elif ${CPUTYPE} == "core" || ${CPUTYPE} == "core2"
32CPUTYPE = prescott
33.  elif ${CPUTYPE} == "p4"
34CPUTYPE = pentium4
35.  elif ${CPUTYPE} == "p4m"
36CPUTYPE = pentium4m
37.  elif ${CPUTYPE} == "p3"
38CPUTYPE = pentium3
39.  elif ${CPUTYPE} == "p3m"
40CPUTYPE = pentium3m
41.  elif ${CPUTYPE} == "p-m"
42CPUTYPE = pentium-m
43.  elif ${CPUTYPE} == "p2"
44CPUTYPE = pentium2
45.  elif ${CPUTYPE} == "i686"
46CPUTYPE = pentiumpro
47.  elif ${CPUTYPE} == "i586/mmx"
48CPUTYPE = pentium-mmx
49.  elif ${CPUTYPE} == "i586"
50CPUTYPE = pentium
51.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
52     ${CPUTYPE} == "k8"
53CPUTYPE = athlon-mp
54.  elif ${CPUTYPE} == "k7"
55CPUTYPE = athlon
56.  endif
57. elif ${MACHINE_ARCH} == "amd64"
58.  if ${CPUTYPE} == "prescott" || ${CPUTYPE} == "core2"
59CPUTYPE = nocona
60.  endif
61. endif
62
63###############################################################################
64# Logic to set up correct gcc optimization flag.  This must be included
65# after /etc/make.conf so it can react to the local value of CPUTYPE
66# defined therein.  Consult:
67#	http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
68#	http://gcc.gnu.org/onlinedocs/gcc/IA_002d64-Options.html
69#	http://gcc.gnu.org/onlinedocs/gcc/RS_002f6000-and-PowerPC-Options.html
70#	http://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html
71#	http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html
72#	http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html
73
74. if ${MACHINE_ARCH} == "i386"
75.  if ${CPUTYPE} == "crusoe"
76_CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0
77.  elif ${CPUTYPE} == "k5"
78_CPUCFLAGS = -march=pentium
79.  else
80_CPUCFLAGS = -march=${CPUTYPE}
81.  endif # GCC on 'i386'
82.  if ${CPUTYPE} == "crusoe"
83_ICC_CPUCFLAGS = -tpp6 -xiM
84.  elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
85    ${CPUTYPE} == "athlon-4"
86_ICC_CPUCFLAGS = -tpp6 -xiMK
87.  elif ${CPUTYPE} == "athlon-tbird" || ${CPUTYPE} == "athlon"
88_ICC_CPUCFLAGS = -tpp6 -xiM
89.  elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "k6"
90_ICC_CPUCFLAGS = -tpp6 -xi
91.  elif ${CPUTYPE} == "k5"
92_ICC_CPUCFLAGS = -tpp5
93.  elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m"
94_ICC_CPUCFLAGS = -tpp7 -xiMKW
95.  elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m" || \
96     ${CPUTYPE} == "pentium-m"
97_ICC_CPUCFLAGS = -tpp6 -xiMK
98.  elif ${CPUTYPE} == "pentium2" || ${CPUTYPE} == "pentiumpro"
99_ICC_CPUCFLAGS = -tpp6 -xiM
100.  elif ${CPUTYPE} == "pentium-mmx"
101_ICC_CPUCFLAGS = -tpp5 -xM
102.  elif ${CPUTYPE} == "pentium"
103_ICC_CPUCFLAGS = -tpp5
104.  else
105_ICC_CPUCFLAGS =
106.  endif # ICC on 'i386'
107. elif ${MACHINE_ARCH} == "amd64"
108_CPUCFLAGS = -march=${CPUTYPE}
109. elif ${MACHINE_ARCH} == "arm"
110.  if ${CPUTYPE} == "xscale"
111#XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself
112#_CPUCFLAGS = -mcpu=xscale
113_CPUCFLAGS = -march=armv5te -D__XSCALE__
114.  else
115_CPUCFLAGS = -mcpu=${CPUTYPE}
116.  endif
117. elif ${MACHINE_ARCH} == "powerpc"
118.  if ${CPUTYPE} == "e500"
119MACHINE_CPU = booke
120_CPUCFLAGS = -Wa,-me500 -msoft-float
121.  else
122_CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64
123.  endif
124. elif ${MACHINE_ARCH} == "mips"
125.  if ${CPUTYPE} == "mips32"
126_CPUCFLAGS = -march=mips32
127.  elif ${CPUTYPE} == "mips32r2"
128_CPUCFLAGS = -march=mips32r2
129.  elif ${CPUTYPE} == "mips64"
130_CPUCFLAGS = -march=mips64
131.  elif ${CPUTYPE} == "mips64r2"
132_CPUCFLAGS = -march=mips64r2
133.  elif ${CPUTYPE} == "mips4kc"
134_CPUCFLAGS = -march=4kc
135.  elif ${CPUTYPE} == "mips24kc"
136_CPUCFLAGS = -march=24kc
137.  endif
138. endif
139
140# Set up the list of CPU features based on the CPU type.  This is an
141# unordered list to make it easy for client makefiles to test for the
142# presence of a CPU feature.
143
144. if ${MACHINE_ARCH} == "i386"
145.  if ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64"
146MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586 i486 i386
147.  elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
148    ${CPUTYPE} == "athlon-4"
149MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586 i486 i386
150.  elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird"
151MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586 i486 i386
152.  elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2"
153MACHINE_CPU = 3dnow mmx k6 k5 i586 i486 i386
154.  elif ${CPUTYPE} == "k6"
155MACHINE_CPU = mmx k6 k5 i586 i486 i386
156.  elif ${CPUTYPE} == "k5"
157MACHINE_CPU = k5 i586 i486 i386
158.  elif ${CPUTYPE} == "c3"
159MACHINE_CPU = 3dnow mmx i586 i486 i386
160.  elif ${CPUTYPE} == "c3-2"
161MACHINE_CPU = sse mmx i586 i486 i386
162.  elif ${CPUTYPE} == "c7"
163MACHINE_CPU = 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_ARCH} == "amd64"
184.  if ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || ${CPUTYPE} == "k8"
185MACHINE_CPU = k8 3dnow
186.  elif ${CPUTYPE} == "nocona"
187MACHINE_CPU = sse3
188.  endif
189MACHINE_CPU += amd64 sse2 sse mmx
190. elif ${MACHINE_ARCH} == "ia64"
191.  if ${CPUTYPE} == "itanium"
192MACHINE_CPU = itanium
193.  endif
194. endif
195.endif
196
197.if ${MACHINE_ARCH} == "arm" && defined(TARGET_BIG_ENDIAN)
198CFLAGS += -mbig-endian
199LDFLAGS += -mbig-endian
200LD += -EB
201.endif
202
203.if ${MACHINE_ARCH} == "mips"
204. if defined(TARGET_BIG_ENDIAN)
205CFLAGS += -EB
206LDFLAGS += -Wl,-EB
207LD += -EB
208. else
209CFLAGS += -EL
210LDFLAGS += -Wl,-EL
211LD += -EL
212. endif
213CFLAGS += -msoft-float -G0 -mno-dsp -mabicalls
214.endif
215
216# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
217
218.if !defined(NO_CPU_CFLAGS)
219. if ${CC} == "icc"
220CFLAGS += ${_ICC_CPUCFLAGS}
221. else
222CFLAGS += ${_CPUCFLAGS}
223. endif
224.endif
225