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_CPUARCH} == "aarch64" 10MACHINE_CPU = arm64 11. elif ${MACHINE_CPUARCH} == "amd64" 12MACHINE_CPU = amd64 sse2 sse mmx 13. elif ${MACHINE_CPUARCH} == "arm" 14MACHINE_CPU = arm 15. elif ${MACHINE_CPUARCH} == "i386" 16MACHINE_CPU = i486 17. elif ${MACHINE_CPUARCH} == "mips" 18MACHINE_CPU = mips 19. elif ${MACHINE_CPUARCH} == "powerpc" 20MACHINE_CPU = aim 21. elif ${MACHINE_CPUARCH} == "riscv" 22MACHINE_CPU = riscv 23. endif 24.else 25 26# Handle aliases (not documented in make.conf to avoid user confusion 27# between e.g. i586 and pentium) 28 29. if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" 30. if ${CPUTYPE} == "barcelona" 31CPUTYPE = amdfam10 32. elif ${CPUTYPE} == "skx" 33CPUTYPE = skylake-avx512 34. elif ${CPUTYPE} == "core-avx2" 35CPUTYPE = haswell 36. elif ${CPUTYPE} == "core-avx-i" 37CPUTYPE = ivybridge 38. elif ${CPUTYPE} == "corei7-avx" 39CPUTYPE = sandybridge 40. elif ${CPUTYPE} == "corei7" 41CPUTYPE = nehalem 42. elif ${CPUTYPE} == "slm" 43CPUTYPE = silvermont 44. elif ${CPUTYPE} == "atom" 45CPUTYPE = bonnell 46. elif ${CPUTYPE} == "core" 47CPUTYPE = prescott 48. endif 49. if ${MACHINE_CPUARCH} == "amd64" 50. if ${CPUTYPE} == "prescott" 51CPUTYPE = nocona 52. endif 53. else 54. if ${CPUTYPE} == "k7" 55CPUTYPE = athlon 56. elif ${CPUTYPE} == "p4" 57CPUTYPE = pentium4 58. elif ${CPUTYPE} == "p4m" 59CPUTYPE = pentium4m 60. elif ${CPUTYPE} == "p3" 61CPUTYPE = pentium3 62. elif ${CPUTYPE} == "p3m" 63CPUTYPE = pentium3m 64. elif ${CPUTYPE} == "p-m" 65CPUTYPE = pentium-m 66. elif ${CPUTYPE} == "p2" 67CPUTYPE = pentium2 68. elif ${CPUTYPE} == "i686" 69CPUTYPE = pentiumpro 70. elif ${CPUTYPE} == "i586/mmx" 71CPUTYPE = pentium-mmx 72. elif ${CPUTYPE} == "i586" 73CPUTYPE = pentium 74. endif 75. endif 76. endif 77 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 87 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 95. else 96_CPUCFLAGS = -march=${CPUTYPE} 97. endif 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} 114. else 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: 120# arm1176jzf-s 121# armv7: generic-armv7-a, cortex-a5, cortex-a7, cortex-a8, cortex-a9, 122# cortex-a12, cortex-a15, cortex-a17 123# cortex-a53, cortex-a57, cortex-a72, 124# exynos-m1 125_CPUCFLAGS = -mcpu=${CPUTYPE} 126. endif 127. elif ${MACHINE_ARCH} == "powerpc" 128. if ${CPUTYPE} == "e500" 129_CPUCFLAGS = -Wa,-me500 -msoft-float 130. else 131_CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64 132. endif 133. elif ${MACHINE_ARCH:Mpowerpc64*} != "" 134_CPUCFLAGS = -mcpu=${CPUTYPE} 135. elif ${MACHINE_CPUARCH} == "mips" 136# mips[1234], mips32, mips64, and all later releases need to have mips 137# preserved (releases later than r2 require external toolchain) 138. if ${CPUTYPE:Mmips32*} != "" || ${CPUTYPE:Mmips64*} != "" || \ 139 ${CPUTYPE:Mmips[1234]} != "" 140_CPUCFLAGS = -march=${CPUTYPE} 141. else 142# Default -march to the CPUTYPE passed in, with mips stripped off so we 143# accept either mips4kc or 4kc, mostly for historical reasons 144# Typical values for cores: 145# 4kc, 24kc, 34kc, 74kc, 1004kc, octeon, octeon+, octeon2, octeon3, 146# sb1, xlp, xlr 147_CPUCFLAGS = -march=${CPUTYPE:S/^mips//} 148. endif 149. elif ${MACHINE_CPUARCH} == "aarch64" 150. if ${CPUTYPE:Marmv*} != "" 151# Use -march when the CPU type is an architecture value, e.g. armv8.1-a 152_CPUCFLAGS = -march=${CPUTYPE} 153. else 154# Otherwise assume we have a CPU type 155_CPUCFLAGS = -mcpu=${CPUTYPE} 156. endif 157. endif 158 159# Set up the list of CPU features based on the CPU type. This is an 160# unordered list to make it easy for client makefiles to test for the 161# presence of a CPU feature. 162 163########## i386 164. if ${MACHINE_CPUARCH} == "i386" 165. if ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \ 166 ${CPUTYPE} == "znver1" 167MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 168. elif ${CPUTYPE} == "bdver4" 169MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 170. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \ 171 ${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 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 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 206. elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge" 207MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 208. elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \ 209 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \ 210 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \ 211 ${CPUTYPE} == "x86-64-v2" 212MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 213. elif ${CPUTYPE} == "penryn" 214MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586 215. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 216MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586 217. elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott" 218MACHINE_CPU = sse3 sse2 sse i686 mmx i586 219. elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \ 220 ${CPUTYPE} == "pentium-m" || ${CPUTYPE} == "x86-64" 221MACHINE_CPU = sse2 sse i686 mmx i586 222. elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m" 223MACHINE_CPU = sse i686 mmx i586 224. elif ${CPUTYPE} == "pentium2" 225MACHINE_CPU = i686 mmx i586 226. elif ${CPUTYPE} == "pentiumpro" 227MACHINE_CPU = i686 i586 228. elif ${CPUTYPE} == "pentium-mmx" 229MACHINE_CPU = mmx i586 230. elif ${CPUTYPE} == "pentium" 231MACHINE_CPU = i586 232. elif ${CPUTYPE} == "c7" 233MACHINE_CPU = sse3 sse2 sse i686 mmx i586 234. elif ${CPUTYPE} == "c3-2" 235MACHINE_CPU = sse i686 mmx i586 236. elif ${CPUTYPE} == "c3" 237MACHINE_CPU = 3dnow mmx i586 238. elif ${CPUTYPE} == "winchip2" 239MACHINE_CPU = 3dnow mmx 240. elif ${CPUTYPE} == "winchip-c6" 241MACHINE_CPU = mmx 242. endif 243MACHINE_CPU += i486 244########## amd64 245. elif ${MACHINE_CPUARCH} == "amd64" 246. if ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \ 247 ${CPUTYPE} == "znver1" 248MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 249. elif ${CPUTYPE} == "bdver4" 250MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 251. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \ 252 ${CPUTYPE} == "bdver1" 253MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 254. elif ${CPUTYPE} == "btver2" 255MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 256. elif ${CPUTYPE} == "btver1" 257MACHINE_CPU = ssse3 sse4a sse3 258. elif ${CPUTYPE} == "amdfam10" 259MACHINE_CPU = k8 3dnow sse4a sse3 260. elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \ 261 ${CPUTYPE} == "k8-sse3" 262MACHINE_CPU = k8 3dnow sse3 263. elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \ 264 ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8" 265MACHINE_CPU = k8 3dnow 266. elif ${CPUTYPE} == "sapphirerapids" || ${CPUTYPE} == "tigerlake" || \ 267 ${CPUTYPE} == "cooperlake" || ${CPUTYPE} == "cascadelake" || \ 268 ${CPUTYPE} == "icelake-server" || ${CPUTYPE} == "icelake-client" || \ 269 ${CPUTYPE} == "cannonlake" || ${CPUTYPE} == "knm" || \ 270 ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl" || \ 271 ${CPUTYPE} == "x86-64-v4" 272MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 273. elif ${CPUTYPE} == "alderlake" || ${CPUTYPE} == "skylake" || \ 274 ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" || \ 275 ${CPUTYPE} == "x86-64-v3" 276MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 277. elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge" 278MACHINE_CPU = avx sse42 sse41 ssse3 sse3 279. elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \ 280 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \ 281 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \ 282 ${CPUTYPE} == "x86-64-v2" 283MACHINE_CPU = sse42 sse41 ssse3 sse3 284. elif ${CPUTYPE} == "penryn" 285MACHINE_CPU = sse41 ssse3 sse3 286. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 287MACHINE_CPU = ssse3 sse3 288. elif ${CPUTYPE} == "nocona" 289MACHINE_CPU = sse3 290. endif 291MACHINE_CPU += amd64 sse2 sse mmx 292########## Mips 293. elif ${MACHINE_CPUARCH} == "mips" 294MACHINE_CPU = mips 295########## powerpc 296. elif ${MACHINE_ARCH} == "powerpc" 297. if ${CPUTYPE} == "e500" 298MACHINE_CPU = booke softfp 299. endif 300########## riscv 301. elif ${MACHINE_CPUARCH} == "riscv" 302MACHINE_CPU = riscv 303. endif 304.endif 305 306.if ${MACHINE_CPUARCH} == "mips" 307CFLAGS += -G0 308AFLAGS+= -${MIPS_ENDIAN} -mabi=${MIPS_ABI} 309CFLAGS+= -${MIPS_ENDIAN} -mabi=${MIPS_ABI} 310LDFLAGS+= -${MIPS_ENDIAN} -mabi=${MIPS_ABI} 311. if ${MACHINE_ARCH:Mmips*el*} != "" 312MIPS_ENDIAN= EL 313. else 314MIPS_ENDIAN= EB 315. endif 316. if ${MACHINE_ARCH:Mmips64*} != "" 317MIPS_ABI?= 64 318. elif ${MACHINE_ARCH:Mmipsn32*} != "" 319MIPS_ABI?= n32 320. else 321MIPS_ABI?= 32 322. endif 323. if ${MACHINE_ARCH:Mmips*hf} 324CFLAGS += -mhard-float 325. else 326CFLAGS += -msoft-float 327. endif 328.endif 329 330########## arm 331.if ${MACHINE_CPUARCH} == "arm" 332MACHINE_CPU += arm 333. if ${MACHINE_ARCH:Marmv6*} != "" 334MACHINE_CPU += armv6 335. endif 336. if ${MACHINE_ARCH:Marmv7*} != "" 337MACHINE_CPU += armv7 338. endif 339# armv6 and armv7 are a hybrid. It can use the softfp ABI, but doesn't emulate 340# floating point in the general case, so don't define softfp for it at this 341# time. arm is pure softfp, so define it for them. 342. if ${MACHINE_ARCH:Marmv[67]*} == "" 343MACHINE_CPU += softfp 344. endif 345# Normally armv6 and armv7 are hard float ABI from FreeBSD 11 onwards. However 346# when CPUTYPE has 'soft' in it, we use the soft-float ABI to allow building of 347# soft-float ABI libraries. In this case, we have to add the -mfloat-abi=softfp 348# to force that. 349. if ${MACHINE_ARCH:Marmv[67]*} && defined(CPUTYPE) && ${CPUTYPE:M*soft*} != "" 350# Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI 351# not a nice optimization. Please note: softfp ABI uses hardware floating 352# instructions, but passes arguments to function calls in integer regsiters. 353# -mfloat-abi=soft is full software floating point, but is not currently 354# supported. softfp support in FreeBSD may disappear in FreeBSD 13.0 since 355# it was a transition tool from FreeBSD 10 to 11 and is a bit of an odd duck. 356CFLAGS += -mfloat-abi=softfp 357. endif 358.endif 359 360.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpcspe" 361LDFLAGS.bfd+= -Wl,--secure-plt 362.endif 363 364.if ${MACHINE_ARCH} == "powerpcspe" 365CFLAGS += -mcpu=8548 -mspe 366CFLAGS.gcc+= -mabi=spe -mfloat-gprs=double -Wa,-me500 367.endif 368 369.if ${MACHINE_CPUARCH} == "riscv" 370.if ${MACHINE_ARCH:Mriscv*sf} 371CFLAGS += -march=rv64imac -mabi=lp64 372.else 373CFLAGS += -march=rv64imafdc -mabi=lp64d 374.endif 375.endif 376 377# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk 378 379.if !defined(NO_CPU_CFLAGS) 380CFLAGS += ${_CPUCFLAGS} 381.endif 382 383# 384# Prohibit the compiler from emitting SIMD instructions. 385# These flags are added to CFLAGS in areas where the extra context-switch 386# cost outweighs the advantages of SIMD instructions. 387# 388# gcc: 389# Setting -mno-mmx implies -mno-3dnow 390# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387 391# 392# clang: 393# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 394# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and 395# -mno-sse42 396# (-mfpmath= is not supported) 397# 398.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 399CFLAGS_NO_SIMD.clang= -mno-avx -mno-avx2 400CFLAGS_NO_SIMD= -mno-mmx -mno-sse 401.endif 402CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}} 403 404# Add in any architecture-specific CFLAGS. 405# These come from make.conf or the command line or the environment. 406CFLAGS += ${CFLAGS.${MACHINE_ARCH}} 407CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}} 408 409