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"
26 # Handle aliases (not documented in make.conf to avoid user confusion
27 # between e.g. i586 and pentium)
29 . if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
30 . if ${CPUTYPE} == "barcelona"
32 . elif ${CPUTYPE} == "skx"
33 CPUTYPE = skylake-avx512
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"
78 ###############################################################################
79 # Logic to set up correct gcc optimization flag. This must be included
80 # after /etc/make.conf so it can react to the local value of CPUTYPE
81 # defined therein. Consult:
82 # http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
83 # http://gcc.gnu.org/onlinedocs/gcc/RS-6000-and-PowerPC-Options.html
84 # http://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html
85 # http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html
86 # http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html
88 . if ${MACHINE_CPUARCH} == "i386"
89 . if ${CPUTYPE} == "crusoe"
90 _CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0
91 . elif ${CPUTYPE} == "k5"
92 _CPUCFLAGS = -march=pentium
93 . elif ${CPUTYPE} == "c7"
94 _CPUCFLAGS = -march=c3-2
96 _CPUCFLAGS = -march=${CPUTYPE}
98 . elif ${MACHINE_CPUARCH} == "amd64"
99 _CPUCFLAGS = -march=${CPUTYPE}
100 . elif ${MACHINE_CPUARCH} == "arm"
101 . if ${CPUTYPE} == "xscale"
102 #XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself
103 #_CPUCFLAGS = -mcpu=xscale
104 _CPUCFLAGS = -march=armv5te -D__XSCALE__
105 . elif ${CPUTYPE:M*soft*} != ""
106 _CPUCFLAGS = -mfloat-abi=softfp
107 . elif ${CPUTYPE} == "cortexa"
108 _CPUCFLAGS = -march=armv7 -mfpu=vfp
109 . elif ${CPUTYPE:Marmv[4567]*} != ""
110 # Handle all the armvX types that FreeBSD runs:
111 # armv4, armv4t, armv5, armv5te, armv6, armv6t2, armv7, armv7-a, armv7ve
112 # they require -march=. All the others require -mcpu=.
113 _CPUCFLAGS = -march=${CPUTYPE}
115 # Common values for FreeBSD
116 # arm: (any arm v4 or v5 processor you are targeting)
117 # arm920t, arm926ej-s, marvell-pj4, fa526, fa626,
118 # fa606te, fa626te, fa726te
119 # armv6: (any arm v7 or v8 processor you are targeting and the arm1176jzf-s)
120 # arm1176jzf-s, generic-armv7-a, cortex-a5, cortex-a7, cortex-a8,
121 # cortex-a9, cortex-a12, cortex-a15, cortex-a17, cortex-a53, cortex-a57,
122 # cortex-a72, exynos-m1
123 _CPUCFLAGS = -mcpu=${CPUTYPE}
125 . elif ${MACHINE_ARCH} == "powerpc"
126 . if ${CPUTYPE} == "e500"
127 _CPUCFLAGS = -Wa,-me500 -msoft-float
129 _CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64
131 . elif ${MACHINE_ARCH:Mpowerpc64*} != ""
132 _CPUCFLAGS = -mcpu=${CPUTYPE}
133 . elif ${MACHINE_CPUARCH} == "mips"
134 # mips[1234], mips32, mips64, and all later releases need to have mips
135 # preserved (releases later than r2 require external toolchain)
136 . if ${CPUTYPE:Mmips32*} != "" || ${CPUTYPE:Mmips64*} != "" || \
137 ${CPUTYPE:Mmips[1234]} != ""
138 _CPUCFLAGS = -march=${CPUTYPE}
140 # Default -march to the CPUTYPE passed in, with mips stripped off so we
141 # accept either mips4kc or 4kc, mostly for historical reasons
142 # Typical values for cores:
143 # 4kc, 24kc, 34kc, 74kc, 1004kc, octeon, octeon+, octeon2, octeon3,
145 _CPUCFLAGS = -march=${CPUTYPE:S/^mips//}
147 . elif ${MACHINE_CPUARCH} == "aarch64"
148 . if ${CPUTYPE:Marmv*} != ""
149 # Use -march when the CPU type is an architecture value, e.g. armv8.1-a
150 _CPUCFLAGS = -march=${CPUTYPE}
152 # Otherwise assume we have a CPU type
153 _CPUCFLAGS = -mcpu=${CPUTYPE}
157 # Set up the list of CPU features based on the CPU type. This is an
158 # unordered list to make it easy for client makefiles to test for the
159 # presence of a CPU feature.
162 . if ${MACHINE_CPUARCH} == "i386"
163 . if ${CPUTYPE} == "znver2" || ${CPUTYPE} == "znver1"
164 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
165 . elif ${CPUTYPE} == "bdver4"
166 MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
167 . elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
168 ${CPUTYPE} == "bdver1"
169 MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
170 . elif ${CPUTYPE} == "btver2"
171 MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
172 . elif ${CPUTYPE} == "btver1"
173 MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586
174 . elif ${CPUTYPE} == "amdfam10"
175 MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586
176 . elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3"
177 MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586
178 . elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
179 ${CPUTYPE} == "athlon-fx"
180 MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586
181 . elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
182 ${CPUTYPE} == "athlon-4"
183 MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586
184 . elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird"
185 MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586
186 . elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode"
187 MACHINE_CPU = 3dnow mmx k6 k5 i586
188 . elif ${CPUTYPE} == "k6"
189 MACHINE_CPU = mmx k6 k5 i586
190 . elif ${CPUTYPE} == "k5"
191 MACHINE_CPU = k5 i586
192 . elif ${CPUTYPE} == "tigerlake" || ${CPUTYPE} == "cooperlake" || \
193 ${CPUTYPE} == "cascadelake" || ${CPUTYPE} == "icelake-server" || \
194 ${CPUTYPE} == "icelake-client" || ${CPUTYPE} == "cannonlake" || \
195 ${CPUTYPE} == "knm" || ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl"
196 MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
197 . elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "broadwell" || \
198 ${CPUTYPE} == "haswell"
199 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
200 . elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
201 MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
202 . elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \
203 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \
204 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont"
205 MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586
206 . elif ${CPUTYPE} == "penryn"
207 MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586
208 . elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
209 MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586
210 . elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott"
211 MACHINE_CPU = sse3 sse2 sse i686 mmx i586
212 . elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \
213 ${CPUTYPE} == "pentium-m"
214 MACHINE_CPU = sse2 sse i686 mmx i586
215 . elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m"
216 MACHINE_CPU = sse i686 mmx i586
217 . elif ${CPUTYPE} == "pentium2"
218 MACHINE_CPU = i686 mmx i586
219 . elif ${CPUTYPE} == "pentiumpro"
220 MACHINE_CPU = i686 i586
221 . elif ${CPUTYPE} == "pentium-mmx"
222 MACHINE_CPU = mmx i586
223 . elif ${CPUTYPE} == "pentium"
225 . elif ${CPUTYPE} == "c7"
226 MACHINE_CPU = sse3 sse2 sse i686 mmx i586
227 . elif ${CPUTYPE} == "c3-2"
228 MACHINE_CPU = sse i686 mmx i586
229 . elif ${CPUTYPE} == "c3"
230 MACHINE_CPU = 3dnow mmx i586
231 . elif ${CPUTYPE} == "winchip2"
232 MACHINE_CPU = 3dnow mmx
233 . elif ${CPUTYPE} == "winchip-c6"
238 . elif ${MACHINE_CPUARCH} == "amd64"
239 . if ${CPUTYPE} == "znver2" || ${CPUTYPE} == "znver1"
240 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3
241 . elif ${CPUTYPE} == "bdver4"
242 MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3
243 . elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
244 ${CPUTYPE} == "bdver1"
245 MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3
246 . elif ${CPUTYPE} == "btver2"
247 MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3
248 . elif ${CPUTYPE} == "btver1"
249 MACHINE_CPU = ssse3 sse4a sse3
250 . elif ${CPUTYPE} == "amdfam10"
251 MACHINE_CPU = k8 3dnow sse4a sse3
252 . elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \
253 ${CPUTYPE} == "k8-sse3"
254 MACHINE_CPU = k8 3dnow sse3
255 . elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \
256 ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8"
257 MACHINE_CPU = k8 3dnow
258 . elif ${CPUTYPE} == "tigerlake" || ${CPUTYPE} == "cooperlake" || \
259 ${CPUTYPE} == "cascadelake" || ${CPUTYPE} == "icelake-server" || \
260 ${CPUTYPE} == "icelake-client" || ${CPUTYPE} == "cannonlake" || \
261 ${CPUTYPE} == "knm" || ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl"
262 MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3
263 . elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "broadwell" || \
264 ${CPUTYPE} == "haswell"
265 MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3
266 . elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge"
267 MACHINE_CPU = avx sse42 sse41 ssse3 sse3
268 . elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \
269 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \
270 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont"
271 MACHINE_CPU = sse42 sse41 ssse3 sse3
272 . elif ${CPUTYPE} == "penryn"
273 MACHINE_CPU = sse41 ssse3 sse3
274 . elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell"
275 MACHINE_CPU = ssse3 sse3
276 . elif ${CPUTYPE} == "nocona"
279 MACHINE_CPU += amd64 sse2 sse mmx
281 . elif ${MACHINE_CPUARCH} == "mips"
284 . elif ${MACHINE_ARCH} == "powerpc"
285 . if ${CPUTYPE} == "e500"
286 MACHINE_CPU = booke softfp
289 . elif ${MACHINE_CPUARCH} == "riscv"
294 .if ${MACHINE_CPUARCH} == "mips"
296 AFLAGS+= -${MIPS_ENDIAN} -mabi=${MIPS_ABI}
297 CFLAGS+= -${MIPS_ENDIAN} -mabi=${MIPS_ABI}
298 LDFLAGS+= -${MIPS_ENDIAN} -mabi=${MIPS_ABI}
299 . if ${MACHINE_ARCH:Mmips*el*} != ""
304 . if ${MACHINE_ARCH:Mmips64*} != ""
306 . elif ${MACHINE_ARCH:Mmipsn32*} != ""
311 . if ${MACHINE_ARCH:Mmips*hf}
312 CFLAGS += -mhard-float
314 CFLAGS += -msoft-float
319 .if ${MACHINE_CPUARCH} == "arm"
321 . if ${MACHINE_ARCH:Marmv6*} != ""
324 . if ${MACHINE_ARCH:Marmv7*} != ""
327 # armv6 and armv7 are a hybrid. It can use the softfp ABI, but doesn't emulate
328 # floating point in the general case, so don't define softfp for it at this
329 # time. arm is pure softfp, so define it for them.
330 . if ${MACHINE_ARCH:Marmv[67]*} == ""
331 MACHINE_CPU += softfp
333 # Normally armv6 and armv7 are hard float ABI from FreeBSD 11 onwards. However
334 # when CPUTYPE has 'soft' in it, we use the soft-float ABI to allow building of
335 # soft-float ABI libraries. In this case, we have to add the -mfloat-abi=softfp
337 . if ${MACHINE_ARCH:Marmv[67]*} && defined(CPUTYPE) && ${CPUTYPE:M*soft*} != ""
338 # Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI
339 # not a nice optimization. Please note: softfp ABI uses hardware floating
340 # instructions, but passes arguments to function calls in integer regsiters.
341 # -mfloat-abi=soft is full software floating point, but is not currently
342 # supported. softfp support in FreeBSD may disappear in FreeBSD 13.0 since
343 # it was a transition tool from FreeBSD 10 to 11 and is a bit of an odd duck.
344 CFLAGS += -mfloat-abi=softfp
348 .if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpcspe"
349 LDFLAGS.bfd+= -Wl,--secure-plt
352 .if ${MACHINE_ARCH} == "powerpcspe"
353 CFLAGS += -mcpu=8548 -mspe
354 CFLAGS.gcc+= -mabi=spe -mfloat-gprs=double -Wa,-me500
357 .if ${MACHINE_CPUARCH} == "riscv"
358 .if ${MACHINE_ARCH:Mriscv*sf}
359 CFLAGS += -march=rv64imac -mabi=lp64
361 CFLAGS += -march=rv64imafdc -mabi=lp64d
365 # NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
367 .if !defined(NO_CPU_CFLAGS)
368 CFLAGS += ${_CPUCFLAGS}
372 # Prohibit the compiler from emitting SIMD instructions.
373 # These flags are added to CFLAGS in areas where the extra context-switch
374 # cost outweighs the advantages of SIMD instructions.
377 # Setting -mno-mmx implies -mno-3dnow
378 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
381 # Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
382 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and
384 # (-mfpmath= is not supported)
386 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
387 CFLAGS_NO_SIMD.clang= -mno-avx -mno-avx2
388 CFLAGS_NO_SIMD= -mno-mmx -mno-sse
390 CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}}
392 # Add in any architecture-specific CFLAGS.
393 # These come from make.conf or the command line or the environment.
394 CFLAGS += ${CFLAGS.${MACHINE_ARCH}}
395 CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}}