1 2# Set default CPU compile flags and baseline CPUTYPE for each arch. The 3# compile flags must support the minimum CPU type for each architecture but 4# may tune support for more advanced processors. 5 6.if !defined(CPUTYPE) || empty(CPUTYPE) 7_CPUCFLAGS = 8. if ${MACHINE_CPUARCH} == "aarch64" 9MACHINE_CPU = arm64 10. elif ${MACHINE_CPUARCH} == "amd64" 11MACHINE_CPU = amd64 sse2 sse mmx 12. elif ${MACHINE_CPUARCH} == "arm" 13MACHINE_CPU = arm 14. elif ${MACHINE_CPUARCH} == "i386" 15MACHINE_CPU = i486 16. elif ${MACHINE_CPUARCH} == "mips" 17MACHINE_CPU = mips 18. elif ${MACHINE_CPUARCH} == "powerpc" 19MACHINE_CPU = aim 20. elif ${MACHINE_CPUARCH} == "riscv" 21MACHINE_CPU = riscv 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_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" 29. if ${CPUTYPE} == "barcelona" 30CPUTYPE = amdfam10 31. elif ${CPUTYPE} == "skx" 32CPUTYPE = skylake-avx512 33. elif ${CPUTYPE} == "core-avx2" 34CPUTYPE = haswell 35. elif ${CPUTYPE} == "core-avx-i" 36CPUTYPE = ivybridge 37. elif ${CPUTYPE} == "corei7-avx" 38CPUTYPE = sandybridge 39. elif ${CPUTYPE} == "corei7" 40CPUTYPE = nehalem 41. elif ${CPUTYPE} == "slm" 42CPUTYPE = silvermont 43. elif ${CPUTYPE} == "atom" 44CPUTYPE = bonnell 45. elif ${CPUTYPE} == "core" 46CPUTYPE = prescott 47. endif 48. if ${MACHINE_CPUARCH} == "amd64" 49. if ${CPUTYPE} == "prescott" 50CPUTYPE = nocona 51. endif 52. else 53. if ${CPUTYPE} == "k7" 54CPUTYPE = athlon 55. elif ${CPUTYPE} == "p4" 56CPUTYPE = pentium4 57. elif ${CPUTYPE} == "p4m" 58CPUTYPE = pentium4m 59. elif ${CPUTYPE} == "p3" 60CPUTYPE = pentium3 61. elif ${CPUTYPE} == "p3m" 62CPUTYPE = pentium3m 63. elif ${CPUTYPE} == "p-m" 64CPUTYPE = pentium-m 65. elif ${CPUTYPE} == "p2" 66CPUTYPE = pentium2 67. elif ${CPUTYPE} == "i686" 68CPUTYPE = pentiumpro 69. elif ${CPUTYPE} == "i586/mmx" 70CPUTYPE = pentium-mmx 71. elif ${CPUTYPE} == "i586" 72CPUTYPE = pentium 73. endif 74. endif 75. endif 76 77############################################################################### 78# Logic to set up correct gcc optimization flag. This must be included 79# after /etc/make.conf so it can react to the local value of CPUTYPE 80# defined therein. Consult: 81# http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html 82# http://gcc.gnu.org/onlinedocs/gcc/RS-6000-and-PowerPC-Options.html 83# http://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html 84# http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html 85# http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html 86 87. if ${MACHINE_CPUARCH} == "i386" 88. if ${CPUTYPE} == "crusoe" 89_CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0 90. elif ${CPUTYPE} == "k5" 91_CPUCFLAGS = -march=pentium 92. elif ${CPUTYPE} == "c7" 93_CPUCFLAGS = -march=c3-2 94. else 95_CPUCFLAGS = -march=${CPUTYPE} 96. endif 97. elif ${MACHINE_CPUARCH} == "amd64" 98_CPUCFLAGS = -march=${CPUTYPE} 99. elif ${MACHINE_CPUARCH} == "arm" 100. if ${CPUTYPE} == "xscale" 101#XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself 102#_CPUCFLAGS = -mcpu=xscale 103_CPUCFLAGS = -march=armv5te -D__XSCALE__ 104. elif ${CPUTYPE:M*soft*} != "" 105_CPUCFLAGS = -mfloat-abi=softfp 106. elif ${CPUTYPE} == "cortexa" 107_CPUCFLAGS = -march=armv7 -mfpu=vfp 108. elif ${CPUTYPE:Marmv[4567]*} != "" 109# Handle all the armvX types that FreeBSD runs: 110# armv4, armv4t, armv5, armv5te, armv6, armv6t2, armv7, armv7-a, armv7ve 111# they require -march=. All the others require -mcpu=. 112_CPUCFLAGS = -march=${CPUTYPE} 113. else 114# Common values for FreeBSD 115# arm: (any arm v4 or v5 processor you are targeting) 116# arm920t, arm926ej-s, marvell-pj4, fa526, fa626, 117# fa606te, fa626te, fa726te 118# armv6: (any arm v7 or v8 processor you are targeting and the arm1176jzf-s) 119# arm1176jzf-s, generic-armv7-a, cortex-a5, cortex-a7, cortex-a8, 120# cortex-a9, cortex-a12, cortex-a15, cortex-a17, cortex-a53, cortex-a57, 121# cortex-a72, exynos-m1 122_CPUCFLAGS = -mcpu=${CPUTYPE} 123. endif 124. elif ${MACHINE_ARCH} == "powerpc" 125. if ${CPUTYPE} == "e500" 126_CPUCFLAGS = -Wa,-me500 -msoft-float 127. else 128_CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64 129. endif 130. elif ${MACHINE_ARCH:Mpowerpc64*} != "" 131_CPUCFLAGS = -mcpu=${CPUTYPE} 132. elif ${MACHINE_CPUARCH} == "mips" 133# mips[1234], mips32, mips64, and all later releases need to have mips 134# preserved (releases later than r2 require external toolchain) 135. if ${CPUTYPE:Mmips32*} != "" || ${CPUTYPE:Mmips64*} != "" || \ 136 ${CPUTYPE:Mmips[1234]} != "" 137_CPUCFLAGS = -march=${CPUTYPE} 138. else 139# Default -march to the CPUTYPE passed in, with mips stripped off so we 140# accept either mips4kc or 4kc, mostly for historical reasons 141# Typical values for cores: 142# 4kc, 24kc, 34kc, 74kc, 1004kc, octeon, octeon+, octeon2, octeon3, 143# sb1, xlp, xlr 144_CPUCFLAGS = -march=${CPUTYPE:S/^mips//} 145. endif 146. elif ${MACHINE_CPUARCH} == "aarch64" 147. if ${CPUTYPE:Marmv*} != "" 148# Use -march when the CPU type is an architecture value, e.g. armv8.1-a 149_CPUCFLAGS = -march=${CPUTYPE} 150. else 151# Otherwise assume we have a CPU type 152_CPUCFLAGS = -mcpu=${CPUTYPE} 153. endif 154. endif 155 156# Set up the list of CPU features based on the CPU type. This is an 157# unordered list to make it easy for client makefiles to test for the 158# presence of a CPU feature. 159 160########## i386 161. if ${MACHINE_CPUARCH} == "i386" 162. if ${CPUTYPE} == "znver4" 163MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 164. elif ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \ 165 ${CPUTYPE} == "znver1" 166MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 167. elif ${CPUTYPE} == "bdver4" 168MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 169. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" 170MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 171. elif ${CPUTYPE} == "bdver1" 172MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 173. elif ${CPUTYPE} == "btver2" 174MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 175. elif ${CPUTYPE} == "btver1" 176MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 177. elif ${CPUTYPE} == "amdfam10" 178MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586 179. elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" 180MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586 181. elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \ 182 ${CPUTYPE} == "athlon-fx" 183MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586 184. elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \ 185 ${CPUTYPE} == "athlon-4" 186MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586 187. elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird" 188MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586 189. elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode" 190MACHINE_CPU = 3dnow mmx k6 k5 i586 191. elif ${CPUTYPE} == "k6" 192MACHINE_CPU = mmx k6 k5 i586 193. elif ${CPUTYPE} == "k5" 194MACHINE_CPU = k5 i586 195. elif ${CPUTYPE} == "sapphirerapids" || ${CPUTYPE} == "tigerlake" || \ 196 ${CPUTYPE} == "cooperlake" || ${CPUTYPE} == "cascadelake" || \ 197 ${CPUTYPE} == "icelake-server" || ${CPUTYPE} == "icelake-client" || \ 198 ${CPUTYPE} == "cannonlake" || ${CPUTYPE} == "knm" || \ 199 ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl" || \ 200 ${CPUTYPE} == "x86-64-v4" 201MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 f16c 202. elif ${CPUTYPE} == "alderlake" || ${CPUTYPE} == "skylake" || \ 203 ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" || \ 204 ${CPUTYPE} == "x86-64-v3" 205MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 f16c 206. elif ${CPUTYPE} == "ivybridge" 207MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 f16c 208. elif ${CPUTYPE} == "sandybridge" 209MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 210. elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \ 211 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \ 212 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \ 213 ${CPUTYPE} == "x86-64-v2" 214MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 215. elif ${CPUTYPE} == "penryn" 216MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586 217. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 218MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586 219. elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott" 220MACHINE_CPU = sse3 sse2 sse i686 mmx i586 221. elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \ 222 ${CPUTYPE} == "pentium-m" || ${CPUTYPE} == "x86-64" 223MACHINE_CPU = sse2 sse i686 mmx i586 224. elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m" 225MACHINE_CPU = sse i686 mmx i586 226. elif ${CPUTYPE} == "pentium2" 227MACHINE_CPU = i686 mmx i586 228. elif ${CPUTYPE} == "pentiumpro" 229MACHINE_CPU = i686 i586 230. elif ${CPUTYPE} == "pentium-mmx" 231MACHINE_CPU = mmx i586 232. elif ${CPUTYPE} == "pentium" 233MACHINE_CPU = i586 234. elif ${CPUTYPE} == "c7" 235MACHINE_CPU = sse3 sse2 sse i686 mmx i586 236. elif ${CPUTYPE} == "c3-2" 237MACHINE_CPU = sse i686 mmx i586 238. elif ${CPUTYPE} == "c3" 239MACHINE_CPU = 3dnow mmx i586 240. elif ${CPUTYPE} == "winchip2" 241MACHINE_CPU = 3dnow mmx 242. elif ${CPUTYPE} == "winchip-c6" 243MACHINE_CPU = mmx 244. endif 245MACHINE_CPU += i486 246########## amd64 247. elif ${MACHINE_CPUARCH} == "amd64" 248. if ${CPUTYPE} == "znver4" 249MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse4a sse3 f16c 250. elif ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \ 251 ${CPUTYPE} == "znver1" 252MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 f16c 253. elif ${CPUTYPE} == "bdver4" 254MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 f16c 255. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" 256MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 f16c 257. elif ${CPUTYPE} == "bdver1" 258MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 259. elif ${CPUTYPE} == "btver2" 260MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 f16c 261. elif ${CPUTYPE} == "btver1" 262MACHINE_CPU = ssse3 sse4a sse3 263. elif ${CPUTYPE} == "amdfam10" 264MACHINE_CPU = k8 3dnow sse4a sse3 265. elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \ 266 ${CPUTYPE} == "k8-sse3" 267MACHINE_CPU = k8 3dnow sse3 268. elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \ 269 ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8" 270MACHINE_CPU = k8 3dnow 271. elif ${CPUTYPE} == "sapphirerapids" || ${CPUTYPE} == "tigerlake" || \ 272 ${CPUTYPE} == "cooperlake" || ${CPUTYPE} == "cascadelake" || \ 273 ${CPUTYPE} == "icelake-server" || ${CPUTYPE} == "icelake-client" || \ 274 ${CPUTYPE} == "cannonlake" || ${CPUTYPE} == "knm" || \ 275 ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl" || \ 276 ${CPUTYPE} == "x86-64-v4" 277MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 f16c 278. elif ${CPUTYPE} == "alderlake" || ${CPUTYPE} == "skylake" || \ 279 ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" || \ 280 ${CPUTYPE} == "x86-64-v3" 281MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 f16c 282. elif ${CPUTYPE} == "ivybridge" 283MACHINE_CPU = avx sse42 sse41 ssse3 sse3 f16c 284. elif ${CPUTYPE} == "sandybridge" 285MACHINE_CPU = avx sse42 sse41 ssse3 sse3 286. elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \ 287 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \ 288 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \ 289 ${CPUTYPE} == "x86-64-v2" 290MACHINE_CPU = sse42 sse41 ssse3 sse3 291. elif ${CPUTYPE} == "penryn" 292MACHINE_CPU = sse41 ssse3 sse3 293. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 294MACHINE_CPU = ssse3 sse3 295. elif ${CPUTYPE} == "nocona" 296MACHINE_CPU = sse3 297. endif 298MACHINE_CPU += amd64 sse2 sse mmx 299########## Mips 300. elif ${MACHINE_CPUARCH} == "mips" 301MACHINE_CPU = mips 302########## powerpc 303. elif ${MACHINE_ARCH} == "powerpc" 304. if ${CPUTYPE} == "e500" 305MACHINE_CPU = booke softfp 306. elif ${CPUTYPE} == "g4" 307MACHINE_CPU = altivec 308. endif 309. elif ${MACHINE_ARCH} == "powerpc64" 310. if ${CPUTYPE} == "e5500" 311MACHINE_CPU = booke 312. elif ${CPUTYPE} == power7 313MACHINE_CPU = altivec vsx 314. elif ${CPUTYPE} == power8 315MACHINE_CPU = altivec vsx vsx2 316. elif ${CPUTYPE} == power9 317MACHINE_CPU = altivec vsx vsx2 vsx3 318. else 319MACHINE_CPU = altivec 320. endif 321. elif ${MACHINE_ARCH} == "powerpc64le" 322MACHINE_CPU = altivec vsx vsx2 323. if ${CPUTYPE} == power9 324MACHINE_CPU += vsx3 325. endif 326########## riscv 327. elif ${MACHINE_CPUARCH} == "riscv" 328MACHINE_CPU = riscv 329. endif 330.endif 331 332.if ${MACHINE_CPUARCH} == "mips" 333CFLAGS += -G0 334AFLAGS+= -${MIPS_ENDIAN} -mabi=${MIPS_ABI} 335CFLAGS+= -${MIPS_ENDIAN} -mabi=${MIPS_ABI} 336LDFLAGS+= -${MIPS_ENDIAN} -mabi=${MIPS_ABI} 337. if ${MACHINE_ARCH:Mmips*el*} != "" 338MIPS_ENDIAN= EL 339. else 340MIPS_ENDIAN= EB 341. endif 342. if ${MACHINE_ARCH:Mmips64*} != "" 343MIPS_ABI?= 64 344. elif ${MACHINE_ARCH:Mmipsn32*} != "" 345MIPS_ABI?= n32 346. else 347MIPS_ABI?= 32 348. endif 349. if ${MACHINE_ARCH:Mmips*hf} 350CFLAGS += -mhard-float 351. else 352CFLAGS += -msoft-float 353. endif 354.endif 355 356########## arm 357.if ${MACHINE_CPUARCH} == "arm" 358MACHINE_CPU += arm 359. if ${MACHINE_ARCH:Marmv6*} != "" 360MACHINE_CPU += armv6 361. endif 362. if ${MACHINE_ARCH:Marmv7*} != "" 363MACHINE_CPU += armv7 364. endif 365# armv6 and armv7 are a hybrid. It can use the softfp ABI, but doesn't emulate 366# floating point in the general case, so don't define softfp for it at this 367# time. arm is pure softfp, so define it for them. 368. if ${MACHINE_ARCH:Marmv[67]*} == "" 369MACHINE_CPU += softfp 370. endif 371# Normally armv6 and armv7 are hard float ABI from FreeBSD 11 onwards. However 372# when CPUTYPE has 'soft' in it, we use the soft-float ABI to allow building of 373# soft-float ABI libraries. In this case, we have to add the -mfloat-abi=softfp 374# to force that. 375. if ${MACHINE_ARCH:Marmv[67]*} && defined(CPUTYPE) && ${CPUTYPE:M*soft*} != "" 376# Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI 377# not a nice optimization. Please note: softfp ABI uses hardware floating 378# instructions, but passes arguments to function calls in integer regsiters. 379# -mfloat-abi=soft is full software floating point, but is not currently 380# supported. softfp support in FreeBSD may disappear in FreeBSD 13.0 since 381# it was a transition tool from FreeBSD 10 to 11 and is a bit of an odd duck. 382CFLAGS += -mfloat-abi=softfp 383. endif 384.endif 385 386.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpcspe" 387LDFLAGS.bfd+= -Wl,--secure-plt 388.endif 389 390.if ${MACHINE_ARCH} == "powerpcspe" 391CFLAGS += -mcpu=8548 -mspe 392CFLAGS.gcc+= -mabi=spe -mfloat-gprs=double -Wa,-me500 393.endif 394 395.if ${MACHINE_CPUARCH} == "riscv" 396.if ${MACHINE_ARCH:Mriscv*sf} 397CFLAGS += -march=rv64imac -mabi=lp64 398.else 399CFLAGS += -march=rv64imafdc -mabi=lp64d 400.endif 401.endif 402 403# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk 404 405.if !defined(NO_CPU_CFLAGS) 406CFLAGS += ${_CPUCFLAGS} 407.endif 408 409# 410# Prohibit the compiler from emitting SIMD instructions. 411# These flags are added to CFLAGS in areas where the extra context-switch 412# cost outweighs the advantages of SIMD instructions. 413# 414# gcc: 415# Setting -mno-mmx implies -mno-3dnow 416# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387 417# 418# clang: 419# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 420# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and 421# -mno-sse42 422# (-mfpmath= is not supported) 423# 424.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 425CFLAGS_NO_SIMD.clang= -mno-avx -mno-avx2 426CFLAGS_NO_SIMD= -mno-mmx -mno-sse 427.endif 428CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}} 429 430# Add in any architecture-specific CFLAGS. 431# These come from make.conf or the command line or the environment. 432CFLAGS += ${CFLAGS.${MACHINE_ARCH}} 433CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}} 434 435