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} == "powerpc" 18MACHINE_CPU = aim 19. elif ${MACHINE_CPUARCH} == "riscv" 20MACHINE_CPU = riscv 21. endif 22.else 23 24# Handle aliases (not documented in make.conf to avoid user confusion 25# between e.g. i586 and pentium) 26 27. if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" 28. if ${CPUTYPE} == "barcelona" 29CPUTYPE = amdfam10 30. elif ${CPUTYPE} == "skx" 31CPUTYPE = skylake-avx512 32. elif ${CPUTYPE} == "core-avx2" 33CPUTYPE = haswell 34. elif ${CPUTYPE} == "core-avx-i" 35CPUTYPE = ivybridge 36. elif ${CPUTYPE} == "corei7-avx" 37CPUTYPE = sandybridge 38. elif ${CPUTYPE} == "corei7" 39CPUTYPE = nehalem 40. elif ${CPUTYPE} == "slm" 41CPUTYPE = silvermont 42. elif ${CPUTYPE} == "atom" 43CPUTYPE = bonnell 44. elif ${CPUTYPE} == "core" 45CPUTYPE = prescott 46. endif 47. if ${MACHINE_CPUARCH} == "amd64" 48. if ${CPUTYPE} == "prescott" 49CPUTYPE = nocona 50. endif 51. else 52. if ${CPUTYPE} == "k7" 53CPUTYPE = athlon 54. elif ${CPUTYPE} == "p4" 55CPUTYPE = pentium4 56. elif ${CPUTYPE} == "p4m" 57CPUTYPE = pentium4m 58. elif ${CPUTYPE} == "p3" 59CPUTYPE = pentium3 60. elif ${CPUTYPE} == "p3m" 61CPUTYPE = pentium3m 62. elif ${CPUTYPE} == "p-m" 63CPUTYPE = pentium-m 64. elif ${CPUTYPE} == "p2" 65CPUTYPE = pentium2 66. elif ${CPUTYPE} == "i686" 67CPUTYPE = pentiumpro 68. elif ${CPUTYPE} == "i586/mmx" 69CPUTYPE = pentium-mmx 70. elif ${CPUTYPE} == "i586" 71CPUTYPE = pentium 72. endif 73. endif 74. endif 75 76############################################################################### 77# Logic to set up correct gcc optimization flag. This must be included 78# after /etc/make.conf so it can react to the local value of CPUTYPE 79# defined therein. Consult: 80# http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html 81# http://gcc.gnu.org/onlinedocs/gcc/RS-6000-and-PowerPC-Options.html 82# http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html 83# http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html 84 85. if ${MACHINE_CPUARCH} == "i386" 86. if ${CPUTYPE} == "crusoe" 87_CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0 88. elif ${CPUTYPE} == "k5" 89_CPUCFLAGS = -march=pentium 90. elif ${CPUTYPE} == "c7" 91_CPUCFLAGS = -march=c3-2 92. else 93_CPUCFLAGS = -march=${CPUTYPE} 94. endif 95. elif ${MACHINE_CPUARCH} == "amd64" 96_CPUCFLAGS = -march=${CPUTYPE} 97. elif ${MACHINE_CPUARCH} == "arm" 98. if ${CPUTYPE} == "xscale" 99#XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself 100#_CPUCFLAGS = -mcpu=xscale 101_CPUCFLAGS = -march=armv5te -D__XSCALE__ 102. elif ${CPUTYPE:M*soft*} != "" 103_CPUCFLAGS = -mfloat-abi=softfp 104. elif ${CPUTYPE} == "cortexa" 105_CPUCFLAGS = -march=armv7 -mfpu=vfp 106. elif ${CPUTYPE:Marmv[4567]*} != "" 107# Handle all the armvX types that FreeBSD runs: 108# armv4, armv4t, armv5, armv5te, armv6, armv6t2, armv7, armv7-a, armv7ve 109# they require -march=. All the others require -mcpu=. 110_CPUCFLAGS = -march=${CPUTYPE} 111. else 112# Common values for FreeBSD 113# arm: (any arm v4 or v5 processor you are targeting) 114# arm920t, arm926ej-s, marvell-pj4, fa526, fa626, 115# fa606te, fa626te, fa726te 116# armv6: 117# arm1176jzf-s 118# armv7: generic-armv7-a, cortex-a5, cortex-a7, cortex-a8, cortex-a9, 119# cortex-a12, cortex-a15, cortex-a17 120# cortex-a53, cortex-a57, cortex-a72, 121# exynos-m1 122_CPUCFLAGS = -mcpu=${CPUTYPE} 123. endif 124. elif ${MACHINE_ARCH} == "powerpc" 125. if ${CPUTYPE} == "e500" 126_CPUCFLAGS = -Wa,-me500 -msoft-float 127. else 128_CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64 129. endif 130. elif ${MACHINE_ARCH:Mpowerpc64*} != "" 131_CPUCFLAGS = -mcpu=${CPUTYPE} 132. elif ${MACHINE_CPUARCH} == "aarch64" 133. if ${CPUTYPE:Marmv*} != "" 134# Use -march when the CPU type is an architecture value, e.g. armv8.1-a 135_CPUCFLAGS = -march=${CPUTYPE} 136. else 137# Otherwise assume we have a CPU type 138_CPUCFLAGS = -mcpu=${CPUTYPE} 139. endif 140. endif 141 142# Set up the list of CPU features based on the CPU type. This is an 143# unordered list to make it easy for client makefiles to test for the 144# presence of a CPU feature. 145 146########## i386 147. if ${MACHINE_CPUARCH} == "i386" 148. if ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \ 149 ${CPUTYPE} == "znver1" 150MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 151. elif ${CPUTYPE} == "bdver4" 152MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 153. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \ 154 ${CPUTYPE} == "bdver1" 155MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 156. elif ${CPUTYPE} == "btver2" 157MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 158. elif ${CPUTYPE} == "btver1" 159MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 160. elif ${CPUTYPE} == "amdfam10" 161MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586 162. elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" 163MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586 164. elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \ 165 ${CPUTYPE} == "athlon-fx" 166MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586 167. elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \ 168 ${CPUTYPE} == "athlon-4" 169MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586 170. elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird" 171MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586 172. elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode" 173MACHINE_CPU = 3dnow mmx k6 k5 i586 174. elif ${CPUTYPE} == "k6" 175MACHINE_CPU = mmx k6 k5 i586 176. elif ${CPUTYPE} == "k5" 177MACHINE_CPU = k5 i586 178. elif ${CPUTYPE} == "sapphirerapids" || ${CPUTYPE} == "tigerlake" || \ 179 ${CPUTYPE} == "cooperlake" || ${CPUTYPE} == "cascadelake" || \ 180 ${CPUTYPE} == "icelake-server" || ${CPUTYPE} == "icelake-client" || \ 181 ${CPUTYPE} == "cannonlake" || ${CPUTYPE} == "knm" || \ 182 ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl" || \ 183 ${CPUTYPE} == "x86-64-v4" 184MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 185. elif ${CPUTYPE} == "alderlake" || ${CPUTYPE} == "skylake" || \ 186 ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" || \ 187 ${CPUTYPE} == "x86-64-v3" 188MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 189. elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge" 190MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 191. elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \ 192 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \ 193 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \ 194 ${CPUTYPE} == "x86-64-v2" 195MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 196. elif ${CPUTYPE} == "penryn" 197MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586 198. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 199MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586 200. elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott" 201MACHINE_CPU = sse3 sse2 sse i686 mmx i586 202. elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \ 203 ${CPUTYPE} == "pentium-m" || ${CPUTYPE} == "x86-64" 204MACHINE_CPU = sse2 sse i686 mmx i586 205. elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m" 206MACHINE_CPU = sse i686 mmx i586 207. elif ${CPUTYPE} == "pentium2" 208MACHINE_CPU = i686 mmx i586 209. elif ${CPUTYPE} == "pentiumpro" 210MACHINE_CPU = i686 i586 211. elif ${CPUTYPE} == "pentium-mmx" 212MACHINE_CPU = mmx i586 213. elif ${CPUTYPE} == "pentium" 214MACHINE_CPU = i586 215. elif ${CPUTYPE} == "c7" 216MACHINE_CPU = sse3 sse2 sse i686 mmx i586 217. elif ${CPUTYPE} == "c3-2" 218MACHINE_CPU = sse i686 mmx i586 219. elif ${CPUTYPE} == "c3" 220MACHINE_CPU = 3dnow mmx i586 221. elif ${CPUTYPE} == "winchip2" 222MACHINE_CPU = 3dnow mmx 223. elif ${CPUTYPE} == "winchip-c6" 224MACHINE_CPU = mmx 225. endif 226MACHINE_CPU += i486 227########## amd64 228. elif ${MACHINE_CPUARCH} == "amd64" 229. if ${CPUTYPE} == "znver3" || ${CPUTYPE} == "znver2" || \ 230 ${CPUTYPE} == "znver1" 231MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse4a sse3 232. elif ${CPUTYPE} == "bdver4" 233MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 234. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \ 235 ${CPUTYPE} == "bdver1" 236MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 237. elif ${CPUTYPE} == "btver2" 238MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 239. elif ${CPUTYPE} == "btver1" 240MACHINE_CPU = ssse3 sse4a sse3 241. elif ${CPUTYPE} == "amdfam10" 242MACHINE_CPU = k8 3dnow sse4a sse3 243. elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \ 244 ${CPUTYPE} == "k8-sse3" 245MACHINE_CPU = k8 3dnow sse3 246. elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \ 247 ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8" 248MACHINE_CPU = k8 3dnow 249. elif ${CPUTYPE} == "sapphirerapids" || ${CPUTYPE} == "tigerlake" || \ 250 ${CPUTYPE} == "cooperlake" || ${CPUTYPE} == "cascadelake" || \ 251 ${CPUTYPE} == "icelake-server" || ${CPUTYPE} == "icelake-client" || \ 252 ${CPUTYPE} == "cannonlake" || ${CPUTYPE} == "knm" || \ 253 ${CPUTYPE} == "skylake-avx512" || ${CPUTYPE} == "knl" || \ 254 ${CPUTYPE} == "x86-64-v4" 255MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 256. elif ${CPUTYPE} == "alderlake" || ${CPUTYPE} == "skylake" || \ 257 ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" || \ 258 ${CPUTYPE} == "x86-64-v3" 259MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 260. elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge" 261MACHINE_CPU = avx sse42 sse41 ssse3 sse3 262. elif ${CPUTYPE} == "tremont" || ${CPUTYPE} == "goldmont-plus" || \ 263 ${CPUTYPE} == "goldmont" || ${CPUTYPE} == "westmere" || \ 264 ${CPUTYPE} == "nehalem" || ${CPUTYPE} == "silvermont" || \ 265 ${CPUTYPE} == "x86-64-v2" 266MACHINE_CPU = sse42 sse41 ssse3 sse3 267. elif ${CPUTYPE} == "penryn" 268MACHINE_CPU = sse41 ssse3 sse3 269. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 270MACHINE_CPU = ssse3 sse3 271. elif ${CPUTYPE} == "nocona" 272MACHINE_CPU = sse3 273. endif 274MACHINE_CPU += amd64 sse2 sse mmx 275########## powerpc 276. elif ${MACHINE_ARCH} == "powerpc" 277. if ${CPUTYPE} == "e500" 278MACHINE_CPU = booke softfp 279. endif 280########## riscv 281. elif ${MACHINE_CPUARCH} == "riscv" 282MACHINE_CPU = riscv 283. endif 284.endif 285 286########## arm 287.if ${MACHINE_CPUARCH} == "arm" 288MACHINE_CPU += arm 289. if ${MACHINE_ARCH:Marmv6*} != "" 290MACHINE_CPU += armv6 291. endif 292. if ${MACHINE_ARCH:Marmv7*} != "" 293MACHINE_CPU += armv7 294. endif 295# armv6 and armv7 are a hybrid. It can use the softfp ABI, but doesn't emulate 296# floating point in the general case, so don't define softfp for it at this 297# time. arm is pure softfp, so define it for them. 298. if ${MACHINE_ARCH:Marmv[67]*} == "" 299MACHINE_CPU += softfp 300. endif 301# Normally armv6 and armv7 are hard float ABI from FreeBSD 11 onwards. However 302# when CPUTYPE has 'soft' in it, we use the soft-float ABI to allow building of 303# soft-float ABI libraries. In this case, we have to add the -mfloat-abi=softfp 304# to force that. 305. if ${MACHINE_ARCH:Marmv[67]*} && defined(CPUTYPE) && ${CPUTYPE:M*soft*} != "" 306# Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI 307# not a nice optimization. Please note: softfp ABI uses hardware floating 308# instructions, but passes arguments to function calls in integer regsiters. 309# -mfloat-abi=soft is full software floating point, but is not currently 310# supported. softfp support in FreeBSD may disappear in FreeBSD 13.0 since 311# it was a transition tool from FreeBSD 10 to 11 and is a bit of an odd duck. 312CFLAGS += -mfloat-abi=softfp 313. endif 314.endif 315 316.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpcspe" 317LDFLAGS.bfd+= -Wl,--secure-plt 318.endif 319 320.if ${MACHINE_ARCH} == "powerpcspe" 321CFLAGS += -mcpu=8548 -mspe 322CFLAGS.gcc+= -mabi=spe -mfloat-gprs=double -Wa,-me500 323.endif 324 325.if ${MACHINE_CPUARCH} == "riscv" 326.if ${MACHINE_ARCH:Mriscv*sf} 327CFLAGS += -march=rv64imac -mabi=lp64 328.else 329CFLAGS += -march=rv64imafdc -mabi=lp64d 330.endif 331.endif 332 333# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk 334 335.if !defined(NO_CPU_CFLAGS) 336CFLAGS += ${_CPUCFLAGS} 337.endif 338 339# 340# Prohibit the compiler from emitting SIMD instructions. 341# These flags are added to CFLAGS in areas where the extra context-switch 342# cost outweighs the advantages of SIMD instructions. 343# 344# gcc: 345# Setting -mno-mmx implies -mno-3dnow 346# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387 347# 348# clang: 349# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 350# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and 351# -mno-sse42 352# (-mfpmath= is not supported) 353# 354.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 355CFLAGS_NO_SIMD.clang= -mno-avx -mno-avx2 356CFLAGS_NO_SIMD= -mno-mmx -mno-sse 357.endif 358CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}} 359 360# Add in any architecture-specific CFLAGS. 361# These come from make.conf or the command line or the environment. 362CFLAGS += ${CFLAGS.${MACHINE_ARCH}} 363CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}} 364 365