bsd.cpu.mk revision 172706
1# $FreeBSD: head/share/mk/bsd.cpu.mk 172706 2007-10-16 18:32:37Z cognet $
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} == "sparc64"
16. elif ${MACHINE_ARCH} == "arm"
17MACHINE_CPU = arm
18. endif
19.else
20
21# Handle aliases (not documented in make.conf to avoid user confusion
22# between e.g. i586 and pentium)
23
24. if ${MACHINE_ARCH} == "i386"
25.  if ${CPUTYPE} == "nocona"
26CPUTYPE = prescott
27.  elif ${CPUTYPE} == "core" || ${CPUTYPE} == "core2"
28CPUTYPE = prescott
29.  elif ${CPUTYPE} == "p4"
30CPUTYPE = pentium4
31.  elif ${CPUTYPE} == "p4m"
32CPUTYPE = pentium4m
33.  elif ${CPUTYPE} == "p3"
34CPUTYPE = pentium3
35.  elif ${CPUTYPE} == "p3m"
36CPUTYPE = pentium3m
37.  elif ${CPUTYPE} == "p-m"
38CPUTYPE = pentium-m
39.  elif ${CPUTYPE} == "p2"
40CPUTYPE = pentium2
41.  elif ${CPUTYPE} == "i686"
42CPUTYPE = pentiumpro
43.  elif ${CPUTYPE} == "i586/mmx"
44CPUTYPE = pentium-mmx
45.  elif ${CPUTYPE} == "i586"
46CPUTYPE = pentium
47.  elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
48     ${CPUTYPE} == "k8"
49CPUTYPE = athlon-mp
50.  elif ${CPUTYPE} == "k7"
51CPUTYPE = athlon
52.  endif
53. elif ${MACHINE_ARCH} == "amd64"
54.  if ${CPUTYPE} == "prescott" || ${CPUTYPE} == "core2"
55CPUTYPE = nocona
56.  endif
57. endif
58
59###############################################################################
60# Logic to set up correct gcc optimization flag.  This must be included
61# after /etc/make.conf so it can react to the local value of CPUTYPE
62# defined therein.  Consult:
63#	http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
64#	http://gcc.gnu.org/onlinedocs/gcc/IA-64-Options.html
65#	http://gcc.gnu.org/onlinedocs/gcc/RS-6000-and-PowerPC-Options.html
66#	http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html
67#	http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86-64-Options.html
68
69. if ${MACHINE_ARCH} == "i386"
70.  if ${CPUTYPE} == "crusoe"
71_CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0
72.  elif ${CPUTYPE} == "k5"
73_CPUCFLAGS = -march=pentium
74.  else
75_CPUCFLAGS = -march=${CPUTYPE}
76.  endif # GCC on 'i386'
77.  if ${CPUTYPE} == "crusoe"
78_ICC_CPUCFLAGS = -tpp6 -xiM
79.  elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
80    ${CPUTYPE} == "athlon-4"
81_ICC_CPUCFLAGS = -tpp6 -xiMK
82.  elif ${CPUTYPE} == "athlon-tbird" || ${CPUTYPE} == "athlon"
83_ICC_CPUCFLAGS = -tpp6 -xiM
84.  elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "k6"
85_ICC_CPUCFLAGS = -tpp6 -xi
86.  elif ${CPUTYPE} == "k5"
87_ICC_CPUCFLAGS = -tpp5
88.  elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m"
89_ICC_CPUCFLAGS = -tpp7 -xiMKW
90.  elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m" || \
91     ${CPUTYPE} == "pentium-m"
92_ICC_CPUCFLAGS = -tpp6 -xiMK
93.  elif ${CPUTYPE} == "pentium2" || ${CPUTYPE} == "pentiumpro"
94_ICC_CPUCFLAGS = -tpp6 -xiM
95.  elif ${CPUTYPE} == "pentium-mmx"
96_ICC_CPUCFLAGS = -tpp5 -xM
97.  elif ${CPUTYPE} == "pentium"
98_ICC_CPUCFLAGS = -tpp5
99.  else
100_ICC_CPUCFLAGS =
101.  endif # ICC on 'i386'
102. elif ${MACHINE_ARCH} == "amd64"
103_CPUCFLAGS = -march=${CPUTYPE}
104. elif ${MACHINE_ARCH} == "arm"
105.  if ${CPUTYPE} == "xscale"
106#XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself
107#_CPUCFLAGS = -mcpu=xscale
108_CPUCFLAGS = -march=armv5te -D__XSCALE__
109.  else
110_CPUCFLAGS = -mcpu=${CPUTYPE}
111.  endif
112. endif
113
114# Set up the list of CPU features based on the CPU type.  This is an
115# unordered list to make it easy for client makefiles to test for the
116# presence of a CPU feature.
117
118. if ${MACHINE_ARCH} == "i386"
119.  if ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64"
120MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586 i486 i386
121.  elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
122    ${CPUTYPE} == "athlon-4"
123MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586 i486 i386
124.  elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird"
125MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586 i486 i386
126.  elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2"
127MACHINE_CPU = 3dnow mmx k6 k5 i586 i486 i386
128.  elif ${CPUTYPE} == "k6"
129MACHINE_CPU = mmx k6 k5 i586 i486 i386
130.  elif ${CPUTYPE} == "k5"
131MACHINE_CPU = k5 i586 i486 i386
132.  elif ${CPUTYPE} == "c3"
133MACHINE_CPU = 3dnow mmx i586 i486 i386
134.  elif ${CPUTYPE} == "c3-2"
135MACHINE_CPU = sse mmx i586 i486 i386
136.  elif ${CPUTYPE} == "prescott"
137MACHINE_CPU = sse3 sse2 sse i686 mmx i586 i486 i386
138.  elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || ${CPUTYPE} == "pentium-m"
139MACHINE_CPU = sse2 sse i686 mmx i586 i486 i386
140.  elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m"
141MACHINE_CPU = sse i686 mmx i586 i486 i386
142.  elif ${CPUTYPE} == "pentium2"
143MACHINE_CPU = i686 mmx i586 i486 i386
144.  elif ${CPUTYPE} == "pentiumpro"
145MACHINE_CPU = i686 i586 i486 i386
146.  elif ${CPUTYPE} == "pentium-mmx"
147MACHINE_CPU = mmx i586 i486 i386
148.  elif ${CPUTYPE} == "pentium"
149MACHINE_CPU = i586 i486 i386
150.  elif ${CPUTYPE} == "i486"
151MACHINE_CPU = i486 i386
152.  elif ${CPUTYPE} == "i386"
153MACHINE_CPU = i386
154.  endif
155. elif ${MACHINE_ARCH} == "amd64"
156.  if ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || ${CPUTYPE} == "k8"
157MACHINE_CPU = k8 3dnow
158.  elif ${CPUTYPE} == "nocona"
159MACHINE_CPU = sse3
160.  endif
161MACHINE_CPU += amd64 sse2 sse mmx
162. elif ${MACHINE_ARCH} == "ia64"
163.  if ${CPUTYPE} == "itanium"
164MACHINE_CPU = itanium
165.  endif
166. endif
167.endif
168
169.if ${MACHINE_ARCH} == "arm" && defined(TARGET_BIG_ENDIAN)
170CFLAGS += -mbig-endian
171LDFLAGS += -mbig-endian
172LD += -EB
173.endif
174
175# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
176
177.if !defined(NO_CPU_CFLAGS)
178. if ${CC} == "icc"
179CFLAGS += ${_ICC_CPUCFLAGS}
180. else
181CFLAGS += ${_CPUCFLAGS}
182. endif
183.endif
184