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_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" 127. if ${CPUTYPE:Marmv*} != "" 128# Use -march when the CPU type is an architecture value, e.g. armv8.1-a 129_CPUCFLAGS = -march=${CPUTYPE} 130. else 131# Otherwise assume we have a CPU type 132_CPUCFLAGS = -mcpu=${CPUTYPE} 133. endif 134. endif 135 136# Set up the list of CPU features based on the CPU type. This is an 137# unordered list to make it easy for client makefiles to test for the 138# presence of a CPU feature. 139 140########## i386 141. if ${MACHINE_CPUARCH} == "i386" 142. if ${CPUTYPE} == "znver4" 143MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 144. elif ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \ 145 ${CPUTYPE} == "znver1" 146MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 147. elif ${CPUTYPE} == "bdver4" 148MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 149. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" 150MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 151. elif ${CPUTYPE} == "bdver1" 152MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 153. elif ${CPUTYPE} == "btver2" 154MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 f16c 155. elif ${CPUTYPE} == "btver1" 156MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 157. elif ${CPUTYPE} == "amdfam10" 158MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586 159. elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" 160MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586 161. elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \ 162 ${CPUTYPE} == "athlon-fx" 163MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586 164. elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \ 165 ${CPUTYPE} == "athlon-4" 166MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586 167. elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird" 168MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586 169. elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode" 170MACHINE_CPU = 3dnow mmx k6 k5 i586 171. elif ${CPUTYPE} == "k6" 172MACHINE_CPU = mmx k6 k5 i586 173. elif ${CPUTYPE} == "k5" 174MACHINE_CPU = k5 i586 175. elif ${CPUTYPE} == "sapphirerapids" || ${CPUTYPE} == "tigerlake" || \ 176 ${CPUTYPE} == "cooperlake" || ${CPUTYPE} == "cascadelake" || \ 177 ${CPUTYPE} == "icelake-server" || ${CPUTYPE} == "icelake-client" || \ 178 ${CPUTYPE} == "cannonlake" || ${CPUTYPE} == "knm" || \ 179 ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl" || \ 180 ${CPUTYPE} == "x86-64-v4" 181MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 f16c 182. elif ${CPUTYPE} == "alderlake" || ${CPUTYPE} == "skylake" || \ 183 ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" || \ 184 ${CPUTYPE} == "x86-64-v3" 185MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 f16c 186. elif ${CPUTYPE} == "ivybridge" 187MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 f16c 188. elif ${CPUTYPE} == "sandybridge" 189MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 190. elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \ 191 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \ 192 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \ 193 ${CPUTYPE} == "x86-64-v2" 194MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 195. elif ${CPUTYPE} == "penryn" 196MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586 197. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 198MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586 199. elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott" 200MACHINE_CPU = sse3 sse2 sse i686 mmx i586 201. elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \ 202 ${CPUTYPE} == "pentium-m" || ${CPUTYPE} == "x86-64" 203MACHINE_CPU = sse2 sse i686 mmx i586 204. elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m" 205MACHINE_CPU = sse i686 mmx i586 206. elif ${CPUTYPE} == "pentium2" 207MACHINE_CPU = i686 mmx i586 208. elif ${CPUTYPE} == "pentiumpro" 209MACHINE_CPU = i686 i586 210. elif ${CPUTYPE} == "pentium-mmx" 211MACHINE_CPU = mmx i586 212. elif ${CPUTYPE} == "pentium" 213MACHINE_CPU = i586 214. elif ${CPUTYPE} == "c7" 215MACHINE_CPU = sse3 sse2 sse i686 mmx i586 216. elif ${CPUTYPE} == "c3-2" 217MACHINE_CPU = sse i686 mmx i586 218. elif ${CPUTYPE} == "c3" 219MACHINE_CPU = 3dnow mmx i586 220. elif ${CPUTYPE} == "winchip2" 221MACHINE_CPU = 3dnow mmx 222. elif ${CPUTYPE} == "winchip-c6" 223MACHINE_CPU = mmx 224. endif 225MACHINE_CPU += i486 226########## amd64 227. elif ${MACHINE_CPUARCH} == "amd64" 228. if ${CPUTYPE} == "znver4" 229MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse4a sse3 f16c 230. elif ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \ 231 ${CPUTYPE} == "znver1" 232MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 f16c 233. elif ${CPUTYPE} == "bdver4" 234MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 f16c 235. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" 236MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 f16c 237. elif ${CPUTYPE} == "bdver1" 238MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 239. elif ${CPUTYPE} == "btver2" 240MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 f16c 241. elif ${CPUTYPE} == "btver1" 242MACHINE_CPU = ssse3 sse4a sse3 243. elif ${CPUTYPE} == "amdfam10" 244MACHINE_CPU = k8 3dnow sse4a sse3 245. elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \ 246 ${CPUTYPE} == "k8-sse3" 247MACHINE_CPU = k8 3dnow sse3 248. elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \ 249 ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8" 250MACHINE_CPU = k8 3dnow 251. elif ${CPUTYPE} == "sapphirerapids" || ${CPUTYPE} == "tigerlake" || \ 252 ${CPUTYPE} == "cooperlake" || ${CPUTYPE} == "cascadelake" || \ 253 ${CPUTYPE} == "icelake-server" || ${CPUTYPE} == "icelake-client" || \ 254 ${CPUTYPE} == "cannonlake" || ${CPUTYPE} == "knm" || \ 255 ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl" || \ 256 ${CPUTYPE} == "x86-64-v4" 257MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 f16c 258. elif ${CPUTYPE} == "alderlake" || ${CPUTYPE} == "skylake" || \ 259 ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" || \ 260 ${CPUTYPE} == "x86-64-v3" 261MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 f16c 262. elif ${CPUTYPE} == "ivybridge" 263MACHINE_CPU = avx sse42 sse41 ssse3 sse3 f16c 264. elif ${CPUTYPE} == "sandybridge" 265MACHINE_CPU = avx sse42 sse41 ssse3 sse3 266. elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \ 267 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \ 268 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \ 269 ${CPUTYPE} == "x86-64-v2" 270MACHINE_CPU = sse42 sse41 ssse3 sse3 271. elif ${CPUTYPE} == "penryn" 272MACHINE_CPU = sse41 ssse3 sse3 273. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 274MACHINE_CPU = ssse3 sse3 275. elif ${CPUTYPE} == "nocona" 276MACHINE_CPU = sse3 277. endif 278MACHINE_CPU += amd64 sse2 sse mmx 279########## powerpc 280. elif ${MACHINE_ARCH} == "powerpc64" 281. if ${CPUTYPE} == "e5500" 282MACHINE_CPU = booke 283. elif ${CPUTYPE} == "power7" 284MACHINE_CPU = altivec vsx 285. elif ${CPUTYPE} == "power8" 286MACHINE_CPU = altivec vsx vsx2 287. elif ${CPUTYPE} == "power9" || ${CPUTYPE} == "power10" || \ 288 ${CPUTYPE} == "power11" 289MACHINE_CPU = altivec vsx vsx2 vsx3 290. else 291MACHINE_CPU = aim altivec 292. endif 293. elif ${MACHINE_ARCH} == "powerpc64le" 294MACHINE_CPU = aim altivec vsx vsx2 295. if ${CPUTYPE} == "power9" || ${CPUTYPE} == "power10" || \ 296 ${CPUTYPE} == "power11" 297MACHINE_CPU += vsx3 298. endif 299########## riscv 300. elif ${MACHINE_CPUARCH} == "riscv" 301MACHINE_CPU = riscv 302. endif 303.endif 304 305########## arm 306.if ${MACHINE_CPUARCH} == "arm" 307MACHINE_CPU += arm 308. if ${MACHINE_ARCH:Marmv7*} != "" 309MACHINE_CPU += armv7 310. endif 311# Normally armv7 is hard float ABI from FreeBSD 11 onwards. However 312# when CPUTYPE has 'soft' in it, we use the soft-float ABI to allow building of 313# soft-float ABI libraries. In this case, we have to add the -mfloat-abi=softfp 314# to force that. 315. if defined(CPUTYPE) && ${CPUTYPE:M*soft*} != "" 316# Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI 317# not a nice optimization. Please note: softfp ABI uses hardware floating 318# instructions, but passes arguments to function calls in integer regsiters. 319# -mfloat-abi=soft is full software floating point, but is not currently 320# supported. softfp support in FreeBSD may disappear in FreeBSD 13.0 since 321# it was a transition tool from FreeBSD 10 to 11 and is a bit of an odd duck. 322CFLAGS += -mfloat-abi=softfp 323. endif 324.endif 325 326.if ${MACHINE_ARCH} == "powerpc" 327LDFLAGS.bfd+= -Wl,--secure-plt 328.endif 329 330.if ${MACHINE_CPUARCH} == "riscv" 331CFLAGS += -march=rv64imafdc -mabi=lp64d 332.endif 333 334# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk 335 336.if !defined(NO_CPU_CFLAGS) 337CFLAGS += ${_CPUCFLAGS} 338CXXFLAGS += ${_CPUCFLAGS} 339.endif 340 341# 342# Prohibit the compiler from emitting SIMD instructions. 343# These flags are added to CFLAGS in areas where the extra context-switch 344# cost outweighs the advantages of SIMD instructions. 345# 346# gcc: 347# Setting -mno-mmx implies -mno-3dnow 348# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387 349# 350# clang: 351# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 352# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and 353# -mno-sse42 354# (-mfpmath= is not supported) 355# 356.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 357CFLAGS_NO_SIMD.clang= -mno-avx -mno-avx2 358CFLAGS_NO_SIMD= -mno-mmx -mno-sse 359.endif 360CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}} 361 362# Add in any architecture-specific CFLAGS. 363# These come from make.conf or the command line or the environment. 364CFLAGS += ${CFLAGS.${MACHINE_ARCH}} 365CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}} 366 367# 368# MACHINE_ABI is a list of properties about the ABI used for MACHINE_ARCH. 369# The following properties are indicated with one of the follow values: 370# 371# Byte order: big-endian, little-endian 372# Floating point ABI: soft-float, hard-float 373# Size of long (size_t, etc): long32, long64 374# Pointer type: ptr32, ptr64 375# Size of time_t: time32, time64 376# 377.if (${MACHINE} == "arm" && (defined(CPUTYPE) && ${CPUTYPE:M*soft*})) || \ 378 (${MACHINE_ARCH} == "powerpc" && (defined(CPUTYPE) && ${CPUTYPE} == "e500")) 379MACHINE_ABI+= soft-float 380.else 381MACHINE_ABI+= hard-float 382.endif 383# Currently all 64-bit FreeBSD architectures include 64 in their name 384# (see arch(7)). We need a special case for cross-building from macOS 385# (which uses arm64/arm). 386.if ${MACHINE_ARCH:M*64*} || \ 387 (defined(BOOTSTRAPPING) && ${.MAKE.OS} == "Darwin" && ${MACHINE} == "arm64") 388MACHINE_ABI+= long64 389.else 390MACHINE_ABI+= long32 391.endif 392.if ${MACHINE_ABI:Mlong64} 393MACHINE_ABI+= ptr64 394.else 395MACHINE_ABI+= ptr32 396.endif 397.if ${MACHINE_ARCH} == "i386" 398MACHINE_ABI+= time32 399.else 400MACHINE_ABI+= time64 401.endif 402.if ${MACHINE_ARCH:Mpowerpc*} && !${MACHINE_ARCH:M*le} 403MACHINE_ABI+= big-endian 404.else 405MACHINE_ABI+= little-endian 406.endif 407