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 cortexa53 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_ARCH} == "powerpc" 17MACHINE_CPU = aim 18. elif ${MACHINE_ARCH} == "powerpc64" 19MACHINE_CPU = aim altivec 20. elif ${MACHINE_ARCH} == "powerpc64le" 21MACHINE_CPU = aim altivec vsx vsx2 22. elif ${MACHINE_CPUARCH} == "riscv" 23MACHINE_CPU = riscv 24. endif 25.else 26 27# Handle aliases (not documented in make.conf to avoid user confusion 28# between e.g. i586 and pentium) 29 30. if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" 31. if ${CPUTYPE} == "barcelona" 32CPUTYPE = amdfam10 33. elif ${CPUTYPE} == "skx" 34CPUTYPE = skylake-avx512 35. elif ${CPUTYPE} == "core-avx2" 36CPUTYPE = haswell 37. elif ${CPUTYPE} == "core-avx-i" 38CPUTYPE = ivybridge 39. elif ${CPUTYPE} == "corei7-avx" 40CPUTYPE = sandybridge 41. elif ${CPUTYPE} == "corei7" 42CPUTYPE = nehalem 43. elif ${CPUTYPE} == "slm" 44CPUTYPE = silvermont 45. elif ${CPUTYPE} == "atom" 46CPUTYPE = bonnell 47. elif ${CPUTYPE} == "core" 48CPUTYPE = prescott 49. endif 50. if ${MACHINE_CPUARCH} == "amd64" 51. if ${CPUTYPE} == "prescott" 52CPUTYPE = nocona 53. endif 54. else 55. if ${CPUTYPE} == "k7" 56CPUTYPE = athlon 57. elif ${CPUTYPE} == "p4" 58CPUTYPE = pentium4 59. elif ${CPUTYPE} == "p4m" 60CPUTYPE = pentium4m 61. elif ${CPUTYPE} == "p3" 62CPUTYPE = pentium3 63. elif ${CPUTYPE} == "p3m" 64CPUTYPE = pentium3m 65. elif ${CPUTYPE} == "p-m" 66CPUTYPE = pentium-m 67. elif ${CPUTYPE} == "p2" 68CPUTYPE = pentium2 69. elif ${CPUTYPE} == "i686" 70CPUTYPE = pentiumpro 71. elif ${CPUTYPE} == "i586/mmx" 72CPUTYPE = pentium-mmx 73. elif ${CPUTYPE} == "i586" 74CPUTYPE = pentium 75. endif 76. endif 77. endif 78 79############################################################################### 80# Logic to set up correct gcc optimization flag. This must be included 81# after /etc/make.conf so it can react to the local value of CPUTYPE 82# defined therein. Consult: 83# http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html 84# http://gcc.gnu.org/onlinedocs/gcc/RS-6000-and-PowerPC-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:M*soft*} != "" 102_CPUCFLAGS = -mfloat-abi=softfp 103. elif ${CPUTYPE} == "cortexa" 104_CPUCFLAGS = -march=armv7 -mfpu=vfp 105. elif ${CPUTYPE:Marmv[67]*} != "" 106# Handle all the armvX types that FreeBSD runs: 107# armv7, armv7-a, armv7ve 108# they require -march=. All the others require -mcpu=. 109_CPUCFLAGS = -march=${CPUTYPE} 110. else 111# Common values for FreeBSD 112# armv7: generic-armv7-a, cortex-a5, cortex-a7, cortex-a8, cortex-a9, 113# cortex-a12, cortex-a15, cortex-a17 114# cortex-a53, cortex-a57, cortex-a72, 115# exynos-m1 116_CPUCFLAGS = -mcpu=${CPUTYPE} 117. endif 118. elif ${MACHINE_ARCH} == "powerpc" 119. if ${CPUTYPE} == "e500" 120_CPUCFLAGS = -Wa,-me500 -msoft-float 121. else 122_CPUCFLAGS = -mcpu=${CPUTYPE} 123. endif 124. elif ${MACHINE_ARCH:Mpowerpc64*} != "" 125_CPUCFLAGS = -mcpu=${CPUTYPE} 126. elif ${MACHINE_CPUARCH} == "aarch64" 127MACHINE_CPU = arm64 128. if ${CPUTYPE} == "generic" 129MACHINE_CPU += cortexa53 130. elif ${CPUTYPE} == "armv8-a" 131MACHINE_CPU += cortexa53 132. elif ${CPUTYPE:M*cortex-a53*} != "" 133MACHINE_CPU += cortexa53 134. endif 135. if ${CPUTYPE:Marmv*} != "" 136# Use -march when the CPU type is an architecture value, e.g. armv8.1-a 137_CPUCFLAGS = -march=${CPUTYPE} 138. else 139# Otherwise assume we have a CPU type 140_CPUCFLAGS = -mcpu=${CPUTYPE} 141. endif 142. endif 143 144# Set up the list of CPU features based on the CPU type. This is an 145# unordered list to make it easy for client makefiles to test for the 146# presence of a CPU feature. 147 148########## i386 149. if ${MACHINE_CPUARCH} == "i386" 150. if ${CPUTYPE} == "znver4" 151MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 152. elif ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \ 153 ${CPUTYPE} == "znver1" 154MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 155. elif ${CPUTYPE} == "bdver4" 156MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 157. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" 158MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 159. elif ${CPUTYPE} == "bdver1" 160MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 161. elif ${CPUTYPE} == "btver2" 162MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 163. elif ${CPUTYPE} == "btver1" 164MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 165. elif ${CPUTYPE} == "amdfam10" 166MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586 167. elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" 168MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586 169. elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \ 170 ${CPUTYPE} == "athlon-fx" 171MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586 172. elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \ 173 ${CPUTYPE} == "athlon-4" 174MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586 175. elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird" 176MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586 177. elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode" 178MACHINE_CPU = 3dnow mmx k6 k5 i586 179. elif ${CPUTYPE} == "k6" 180MACHINE_CPU = mmx k6 k5 i586 181. elif ${CPUTYPE} == "k5" 182MACHINE_CPU = k5 i586 183. elif ${CPUTYPE} == "sapphirerapids" || ${CPUTYPE} == "tigerlake" || \ 184 ${CPUTYPE} == "cooperlake" || ${CPUTYPE} == "cascadelake" || \ 185 ${CPUTYPE} == "icelake-server" || ${CPUTYPE} == "icelake-client" || \ 186 ${CPUTYPE} == "cannonlake" || ${CPUTYPE} == "knm" || \ 187 ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl" || \ 188 ${CPUTYPE} == "x86-64-v4" 189MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 f16c 190. elif ${CPUTYPE} == "alderlake" || ${CPUTYPE} == "skylake" || \ 191 ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" || \ 192 ${CPUTYPE} == "x86-64-v3" 193MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 f16c 194. elif ${CPUTYPE} == "ivybridge" 195MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 f16c 196. elif ${CPUTYPE} == "sandybridge" 197MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 198. elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \ 199 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \ 200 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \ 201 ${CPUTYPE} == "x86-64-v2" 202MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 203. elif ${CPUTYPE} == "penryn" 204MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586 205. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 206MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586 207. elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott" 208MACHINE_CPU = sse3 sse2 sse i686 mmx i586 209. elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \ 210 ${CPUTYPE} == "pentium-m" || ${CPUTYPE} == "x86-64" 211MACHINE_CPU = sse2 sse i686 mmx i586 212. elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m" 213MACHINE_CPU = sse i686 mmx i586 214. elif ${CPUTYPE} == "pentium2" 215MACHINE_CPU = i686 mmx i586 216. elif ${CPUTYPE} == "pentiumpro" 217MACHINE_CPU = i686 i586 218. elif ${CPUTYPE} == "pentium-mmx" 219MACHINE_CPU = mmx i586 220. elif ${CPUTYPE} == "pentium" 221MACHINE_CPU = i586 222. elif ${CPUTYPE} == "c7" 223MACHINE_CPU = sse3 sse2 sse i686 mmx i586 224. elif ${CPUTYPE} == "c3-2" 225MACHINE_CPU = sse i686 mmx i586 226. elif ${CPUTYPE} == "c3" 227MACHINE_CPU = 3dnow mmx i586 228. elif ${CPUTYPE} == "winchip2" 229MACHINE_CPU = 3dnow mmx 230. elif ${CPUTYPE} == "winchip-c6" 231MACHINE_CPU = mmx 232. endif 233MACHINE_CPU += i486 234########## amd64 235. elif ${MACHINE_CPUARCH} == "amd64" 236. if ${CPUTYPE} == "znver4" 237MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse4a sse3 f16c 238. elif ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \ 239 ${CPUTYPE} == "znver1" 240MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 f16c 241. elif ${CPUTYPE} == "bdver4" 242MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 f16c 243. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" 244MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 f16c 245. elif ${CPUTYPE} == "bdver1" 246MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 247. elif ${CPUTYPE} == "btver2" 248MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 f16c 249. elif ${CPUTYPE} == "btver1" 250MACHINE_CPU = ssse3 sse4a sse3 251. elif ${CPUTYPE} == "amdfam10" 252MACHINE_CPU = k8 3dnow sse4a sse3 253. elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \ 254 ${CPUTYPE} == "k8-sse3" 255MACHINE_CPU = k8 3dnow sse3 256. elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \ 257 ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8" 258MACHINE_CPU = k8 3dnow 259. elif ${CPUTYPE} == "sapphirerapids" || ${CPUTYPE} == "tigerlake" || \ 260 ${CPUTYPE} == "cooperlake" || ${CPUTYPE} == "cascadelake" || \ 261 ${CPUTYPE} == "icelake-server" || ${CPUTYPE} == "icelake-client" || \ 262 ${CPUTYPE} == "cannonlake" || ${CPUTYPE} == "knm" || \ 263 ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl" || \ 264 ${CPUTYPE} == "x86-64-v4" 265MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 f16c 266. elif ${CPUTYPE} == "alderlake" || ${CPUTYPE} == "skylake" || \ 267 ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" || \ 268 ${CPUTYPE} == "x86-64-v3" 269MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 f16c 270. elif ${CPUTYPE} == "ivybridge" 271MACHINE_CPU = avx sse42 sse41 ssse3 sse3 f16c 272. elif ${CPUTYPE} == "sandybridge" 273MACHINE_CPU = avx sse42 sse41 ssse3 sse3 274. elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \ 275 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \ 276 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \ 277 ${CPUTYPE} == "x86-64-v2" 278MACHINE_CPU = sse42 sse41 ssse3 sse3 279. elif ${CPUTYPE} == "penryn" 280MACHINE_CPU = sse41 ssse3 sse3 281. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 282MACHINE_CPU = ssse3 sse3 283. elif ${CPUTYPE} == "nocona" 284MACHINE_CPU = sse3 285. endif 286MACHINE_CPU += amd64 sse2 sse mmx 287########## powerpc 288. elif ${MACHINE_ARCH} == "powerpc64" 289. if ${CPUTYPE} == "e5500" 290MACHINE_CPU = booke 291. elif ${CPUTYPE} == "power7" 292MACHINE_CPU = altivec vsx 293. elif ${CPUTYPE} == "power8" 294MACHINE_CPU = altivec vsx vsx2 295. elif ${CPUTYPE} == "power9" || ${CPUTYPE} == "power10" || \ 296 ${CPUTYPE} == "power11" 297MACHINE_CPU = altivec vsx vsx2 vsx3 298. else 299MACHINE_CPU = aim altivec 300. endif 301. elif ${MACHINE_ARCH} == "powerpc64le" 302MACHINE_CPU = aim altivec vsx vsx2 303. if ${CPUTYPE} == "power9" || ${CPUTYPE} == "power10" || \ 304 ${CPUTYPE} == "power11" 305MACHINE_CPU += vsx3 306. endif 307########## riscv 308. elif ${MACHINE_CPUARCH} == "riscv" 309MACHINE_CPU = riscv 310. endif 311.endif 312 313########## arm64/aarch64 314.if ${MACHINE_CPUARCH} == "aarch64" 315# Add the Cortex-A53 erratum 843419 workaround if we are targeting it. 316. if ${MACHINE_CPU:Mcortexa53} != "" 317LDFLAGS += -Wl,--fix-cortex-a53-843419 318. endif 319.endif 320 321########## arm 322.if ${MACHINE_CPUARCH} == "arm" 323MACHINE_CPU += arm 324. if ${MACHINE_ARCH:Marmv7*} != "" 325MACHINE_CPU += armv7 326. endif 327# Normally armv7 is hard float ABI from FreeBSD 11 onwards. However 328# when CPUTYPE has 'soft' in it, we use the soft-float ABI to allow building of 329# soft-float ABI libraries. In this case, we have to add the -mfloat-abi=softfp 330# to force that. 331. if defined(CPUTYPE) && ${CPUTYPE:M*soft*} != "" 332# Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI 333# not a nice optimization. Please note: softfp ABI uses hardware floating 334# instructions, but passes arguments to function calls in integer regsiters. 335# -mfloat-abi=soft is full software floating point, but is not currently 336# supported. softfp support in FreeBSD may disappear in FreeBSD 13.0 since 337# it was a transition tool from FreeBSD 10 to 11 and is a bit of an odd duck. 338CFLAGS += -mfloat-abi=softfp 339. endif 340.endif 341 342.if ${MACHINE_ARCH} == "powerpc" 343LDFLAGS.bfd+= -Wl,--secure-plt 344.endif 345 346.if ${MACHINE_CPUARCH} == "riscv" 347CFLAGS += -march=rv64imafdc -mabi=lp64d 348.endif 349 350# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk 351 352.if !defined(NO_CPU_CFLAGS) 353CFLAGS += ${_CPUCFLAGS} 354CXXFLAGS += ${_CPUCFLAGS} 355.endif 356 357# 358# Prohibit the compiler from emitting SIMD instructions. 359# These flags are added to CFLAGS in areas where the extra context-switch 360# cost outweighs the advantages of SIMD instructions. 361# 362# gcc: 363# Setting -mno-mmx implies -mno-3dnow 364# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387 365# 366# clang: 367# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 368# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and 369# -mno-sse42 370# (-mfpmath= is not supported) 371# 372.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 373CFLAGS_NO_SIMD.clang= -mno-avx -mno-avx2 374CFLAGS_NO_SIMD= -mno-mmx -mno-sse 375.endif 376CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}} 377 378# Add in any architecture-specific CFLAGS. 379# These come from make.conf or the command line or the environment. 380CFLAGS += ${CFLAGS.${MACHINE_ARCH}} 381CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}} 382 383# 384# MACHINE_ABI is a list of properties about the ABI used for MACHINE_ARCH. 385# The following properties are indicated with one of the follow values: 386# 387# Byte order: big-endian, little-endian 388# Floating point ABI: soft-float, hard-float 389# Size of long (size_t, etc): long32, long64 390# Pointer type: ptr32, ptr64 391# Size of time_t: time32, time64 392# 393.if (${MACHINE} == "arm" && (defined(CPUTYPE) && ${CPUTYPE:M*soft*})) || \ 394 (${MACHINE_ARCH} == "powerpc" && (defined(CPUTYPE) && ${CPUTYPE} == "e500")) 395MACHINE_ABI+= soft-float 396.else 397MACHINE_ABI+= hard-float 398.endif 399# Currently all 64-bit FreeBSD architectures include 64 in their name 400# (see arch(7)). We need a special case for cross-building from macOS 401# (which uses arm64/arm). 402.if ${MACHINE_ARCH:M*64*} || \ 403 (defined(BOOTSTRAPPING) && ${.MAKE.OS} == "Darwin" && ${MACHINE} == "arm64") 404MACHINE_ABI+= long64 405.else 406MACHINE_ABI+= long32 407.endif 408.if ${MACHINE_ABI:Mlong64} 409MACHINE_ABI+= ptr64 410.else 411MACHINE_ABI+= ptr32 412.endif 413.if ${MACHINE_ARCH} == "i386" 414MACHINE_ABI+= time32 415.else 416MACHINE_ABI+= time64 417.endif 418.if ${MACHINE_ARCH:Mpowerpc*} && !${MACHINE_ARCH:M*le} 419MACHINE_ABI+= big-endian 420.else 421MACHINE_ABI+= little-endian 422.endif 423