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.
7 .if !defined(CPUTYPE) || empty(CPUTYPE)
9 . if ${MACHINE_CPUARCH} == "aarch64"
11 . elif ${MACHINE_CPUARCH} == "amd64"
12 MACHINE_CPU = amd64 sse2 sse mmx
13 . elif ${MACHINE_CPUARCH} == "arm"
15 . elif ${MACHINE_CPUARCH} == "i386"
17 . elif ${MACHINE_CPUARCH} == "mips"
19 . elif ${MACHINE_CPUARCH} == "powerpc"
21 . elif ${MACHINE_CPUARCH} == "riscv"
23 . elif ${MACHINE_CPUARCH} == "sparc64"
24 MACHINE_CPU = ultrasparc
28 # Handle aliases (not documented in make.conf to avoid user confusion
29 # between e.g. i586 and pentium)
31 . if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
32 . if ${CPUTYPE} == "barcelona"
34 . elif ${CPUTYPE} == "core-avx2"
36 . elif ${CPUTYPE} == "core-avx-i"
38 . elif ${CPUTYPE} == "corei7-avx"
40 . elif ${CPUTYPE} == "corei7"
42 . elif ${CPUTYPE} == "slm"
44 . elif ${CPUTYPE} == "atom"
46 . elif ${CPUTYPE} == "core"
49 . if ${MACHINE_CPUARCH} == "amd64"
50 . if ${CPUTYPE} == "prescott"
54 . if ${CPUTYPE} == "k7"
56 . elif ${CPUTYPE} == "p4"
58 . elif ${CPUTYPE} == "p4m"
60 . elif ${CPUTYPE} == "p3"
62 . elif ${CPUTYPE} == "p3m"
64 . elif ${CPUTYPE} == "p-m"
66 . elif ${CPUTYPE} == "p2"
68 . elif ${CPUTYPE} == "i686"
70 . elif ${CPUTYPE} == "i586/mmx"
72 . elif ${CPUTYPE} == "i586"
76 . elif ${MACHINE_ARCH} == "sparc64"
77 . if ${CPUTYPE} == "us"
79 . elif ${CPUTYPE} == "us3"
84 ###############################################################################
85 # Logic to set up correct gcc optimization flag. This must be included
86 # after /etc/make.conf so it can react to the local value of CPUTYPE
87 # defined therein. Consult:
88 # http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
89 # http://gcc.gnu.org/onlinedocs/gcc/RS-6000-and-PowerPC-Options.html
90 # http://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html
91 # http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html
92 # http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html
94 . if ${MACHINE_CPUARCH} == "i386"
95 . if ${CPUTYPE} == "crusoe"
96 _CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0
97 . elif ${CPUTYPE} == "k5"
98 _CPUCFLAGS = -march=pentium
99 . elif ${CPUTYPE} == "c7"
100 _CPUCFLAGS = -march=c3-2
102 _CPUCFLAGS = -march=${CPUTYPE}
104 . elif ${MACHINE_CPUARCH} == "amd64"
105 _CPUCFLAGS = -march=${CPUTYPE}
106 . elif ${MACHINE_CPUARCH} == "arm"
107 . if ${CPUTYPE} == "xscale"
108 #XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself
109 #_CPUCFLAGS = -mcpu=xscale
110 _CPUCFLAGS = -march=armv5te -D__XSCALE__
111 . elif ${CPUTYPE:M*soft*} != ""
112 _CPUCFLAGS = -mfloat-abi=softfp
113 . elif ${CPUTYPE} == "armv6"
114 _CPUCFLAGS = -march=${CPUTYPE}
115 . elif ${CPUTYPE} == "cortexa"
116 _CPUCFLAGS = -march=armv7 -mfpu=vfp
117 . elif ${CPUTYPE:Marmv[4567]*} != ""
118 # Handle all the armvX types that FreeBSD runs:
119 # armv4, armv4t, armv5, armv5te, armv6, armv6t2, armv7, armv7-a, armv7ve
120 # they require -march=. All the others require -mcpu=.
121 _CPUCFLAGS = -march=${CPUTYPE}
123 # Common values for FreeBSD
124 # arm: (any arm v4 or v5 processor you are targeting)
125 # arm920t, arm926ej-s, marvell-pj4, fa526, fa626,
126 # fa606te, fa626te, fa726te
127 # armv6: (any arm v7 or v8 processor you are targeting and the arm1176jzf-s)
128 # arm1176jzf-s, generic-armv7-a, cortex-a5, cortex-a7, cortex-a8,
129 # cortex-a9, cortex-a12, cortex-a15, cortex-a17, cortex-a53, cortex-a57,
130 # cortex-a72, exynos-m1
131 _CPUCFLAGS = -mcpu=${CPUTYPE}
133 . elif ${MACHINE_ARCH} == "powerpc"
134 . if ${CPUTYPE} == "e500"
135 _CPUCFLAGS = -Wa,-me500 -msoft-float
137 _CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64
139 . elif ${MACHINE_ARCH} == "powerpcspe"
140 _CPUCFLAGS = -Wa,-me500 -mspe=yes -mabi=spe -mfloat-gprs=double
141 . elif ${MACHINE_ARCH} == "powerpc64"
142 _CPUCFLAGS = -mcpu=${CPUTYPE}
143 . elif ${MACHINE_CPUARCH} == "mips"
144 # mips[1234], mips32, mips64, and all later releases need to have mips
145 # preserved (releases later than r2 require external toolchain)
146 . if ${CPUTYPE:Mmips32*} != "" || ${CPUTYPE:Mmips64*} != "" || \
147 ${CPUTYPE:Mmips[1234]} != ""
148 _CPUCFLAGS = -march=${CPUTYPE}
150 # Default -march to the CPUTYPE passed in, with mips stripped off so we
151 # accept either mips4kc or 4kc, mostly for historical reasons
152 # Typical values for cores:
153 # 4kc, 24kc, 34kc, 74kc, 1004kc, octeon, octeon+, octeon2, octeon3,
155 _CPUCFLAGS = -march=${CPUTYPE:S/^mips//}
157 . elif ${MACHINE_ARCH} == "sparc64"
158 . if ${CPUTYPE} == "v9"
159 _CPUCFLAGS = -mcpu=v9
160 . elif ${CPUTYPE} == "ultrasparc"
161 _CPUCFLAGS = -mcpu=ultrasparc
162 . elif ${CPUTYPE} == "ultrasparc3"
163 _CPUCFLAGS = -mcpu=ultrasparc3
165 . elif ${MACHINE_CPUARCH} == "aarch64"
166 _CPUCFLAGS = -mcpu=${CPUTYPE}
169 # Set up the list of CPU features based on the CPU type. This is an
170 # unordered list to make it easy for client makefiles to test for the
171 # presence of a CPU feature.
174 . if ${MACHINE_CPUARCH} == "i386"
175 . if ${CPUTYPE} == "znver1"
176 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
177 . elif ${CPUTYPE} == "bdver4"
178 MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
179 . elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
180 ${CPUTYPE} == "bdver1"
181 MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
182 . elif ${CPUTYPE} == "btver2"
183 MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
184 . elif ${CPUTYPE} == "btver1"
185 MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
186 . elif ${CPUTYPE} == "amdfam10"
187 MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586
188 . elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3"
189 MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586
190 . elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
191 ${CPUTYPE} == "athlon-fx"
192 MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586
193 . elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
194 ${CPUTYPE} == "athlon-4"
195 MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586
196 . elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird"
197 MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586
198 . elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode"
199 MACHINE_CPU = 3dnow mmx k6 k5 i586
200 . elif ${CPUTYPE} == "k6"
201 MACHINE_CPU = mmx k6 k5 i586
202 . elif ${CPUTYPE} == "k5"
203 MACHINE_CPU = k5 i586
204 . elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "knl"
205 MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
206 . elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell"
207 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
208 . elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
209 MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
210 . elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \
211 ${CPUTYPE} == "silvermont"
212 MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
213 . elif ${CPUTYPE} == "penryn"
214 MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586
215 . elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
216 MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586
217 . elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott"
218 MACHINE_CPU = sse3 sse2 sse i686 mmx i586
219 . elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \
220 ${CPUTYPE} == "pentium-m"
221 MACHINE_CPU = sse2 sse i686 mmx i586
222 . elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m"
223 MACHINE_CPU = sse i686 mmx i586
224 . elif ${CPUTYPE} == "pentium2"
225 MACHINE_CPU = i686 mmx i586
226 . elif ${CPUTYPE} == "pentiumpro"
227 MACHINE_CPU = i686 i586
228 . elif ${CPUTYPE} == "pentium-mmx"
229 MACHINE_CPU = mmx i586
230 . elif ${CPUTYPE} == "pentium"
232 . elif ${CPUTYPE} == "c7"
233 MACHINE_CPU = sse3 sse2 sse i686 mmx i586
234 . elif ${CPUTYPE} == "c3-2"
235 MACHINE_CPU = sse i686 mmx i586
236 . elif ${CPUTYPE} == "c3"
237 MACHINE_CPU = 3dnow mmx i586
238 . elif ${CPUTYPE} == "winchip2"
239 MACHINE_CPU = 3dnow mmx
240 . elif ${CPUTYPE} == "winchip-c6"
245 . elif ${MACHINE_CPUARCH} == "amd64"
246 . if ${CPUTYPE} == "znver1"
247 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3
248 . elif ${CPUTYPE} == "bdver4"
249 MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3
250 . elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
251 ${CPUTYPE} == "bdver1"
252 MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3
253 . elif ${CPUTYPE} == "btver2"
254 MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3
255 . elif ${CPUTYPE} == "btver1"
256 MACHINE_CPU = ssse3 sse4a sse3
257 . elif ${CPUTYPE} == "amdfam10"
258 MACHINE_CPU = k8 3dnow sse4a sse3
259 . elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \
260 ${CPUTYPE} == "k8-sse3"
261 MACHINE_CPU = k8 3dnow sse3
262 . elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
263 ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8"
264 MACHINE_CPU = k8 3dnow
265 . elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "knl"
266 MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3
267 . elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell"
268 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3
269 . elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
270 MACHINE_CPU = avx sse42 sse41 ssse3 sse3
271 . elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \
272 ${CPUTYPE} == "silvermont"
273 MACHINE_CPU = sse42 sse41 ssse3 sse3
274 . elif ${CPUTYPE} == "penryn"
275 MACHINE_CPU = sse41 ssse3 sse3
276 . elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
277 MACHINE_CPU = ssse3 sse3
278 . elif ${CPUTYPE} == "nocona"
281 MACHINE_CPU += amd64 sse2 sse mmx
283 . elif ${MACHINE_CPUARCH} == "mips"
286 . elif ${MACHINE_ARCH} == "powerpc"
287 . if ${CPUTYPE} == "e500"
288 MACHINE_CPU = booke softfp
291 . elif ${MACHINE_CPUARCH} == "riscv"
294 . elif ${MACHINE_ARCH} == "sparc64"
295 . if ${CPUTYPE} == "v9"
297 . elif ${CPUTYPE} == "ultrasparc"
298 MACHINE_CPU = v9 ultrasparc
299 . elif ${CPUTYPE} == "ultrasparc3"
300 MACHINE_CPU = v9 ultrasparc ultrasparc3
305 .if ${MACHINE_CPUARCH} == "mips"
307 . if ${MACHINE_ARCH:Mmips*el*} != ""
316 . if ${MACHINE_ARCH:Mmips64*} != ""
320 . elif ${MACHINE_ARCH:Mmipsn32*} != ""
329 . if ${MACHINE_ARCH:Mmips*hf}
330 CFLAGS += -mhard-float
332 CFLAGS += -msoft-float
337 .if ${MACHINE_CPUARCH} == "arm"
339 . if ${MACHINE_ARCH:Marmv6*} != ""
342 # armv6 is a hybrid. It can use the softfp ABI, but doesn't emulate
343 # floating point in the general case, so don't define softfp for
344 # it at this time. arm and armeb are pure softfp, so define it
346 . if ${MACHINE_ARCH:Marmv6*} == ""
347 MACHINE_CPU += softfp
349 # Normally armv6 is hard float ABI from FreeBSD 11 onwards. However
350 # when CPUTYPE has 'soft' in it, we use the soft-float ABI to allow
351 # building of soft-float ABI libraries. In this case, we have to
352 # add the -mfloat-abi=softfp to force that.
353 .if ${MACHINE_ARCH:Marmv6*} && defined(CPUTYPE) && ${CPUTYPE:M*soft*} != ""
354 # Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI
355 # not a nice optimization.
356 CFLAGS += -mfloat-abi=softfp
360 .if ${MACHINE_ARCH} == "powerpcspe"
361 CFLAGS += -mcpu=8540 -Wa,-me500 -mspe=yes -mabi=spe -mfloat-gprs=double
364 .if ${MACHINE_CPUARCH} == "riscv"
365 .if ${TARGET_ARCH:Mriscv*sf}
366 CFLAGS += -march=rv64imac -mabi=lp64
367 ACFLAGS += -march=rv64imac -mabi=lp64
369 CFLAGS += -march=rv64imafdc -mabi=lp64
370 ACFLAGS += -march=rv64imafdc -mabi=lp64
374 # NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
376 .if !defined(NO_CPU_CFLAGS)
377 CFLAGS += ${_CPUCFLAGS}
381 # Prohibit the compiler from emitting SIMD instructions.
382 # These flags are added to CFLAGS in areas where the extra context-switch
383 # cost outweighs the advantages of SIMD instructions.
386 # Setting -mno-mmx implies -mno-3dnow
387 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
390 # Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
391 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and
393 # (-mfpmath= is not supported)
395 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
396 CFLAGS_NO_SIMD.clang= -mno-avx
397 CFLAGS_NO_SIMD= -mno-mmx -mno-sse
399 CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}}
401 # Add in any architecture-specific CFLAGS.
402 # These come from make.conf or the command line or the environment.
403 CFLAGS += ${CFLAGS.${MACHINE_ARCH}}
404 CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}}