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