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