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} == "sparc64" 22MACHINE_CPU = ultrasparc 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} == "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. elif ${MACHINE_ARCH} == "sparc64" 75. if ${CPUTYPE} == "us" 76CPUTYPE = ultrasparc 77. elif ${CPUTYPE} == "us3" 78CPUTYPE = ultrasparc3 79. endif 80. endif 81 82############################################################################### 83# Logic to set up correct gcc optimization flag. This must be included 84# after /etc/make.conf so it can react to the local value of CPUTYPE 85# defined therein. Consult: 86# http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html 87# http://gcc.gnu.org/onlinedocs/gcc/RS-6000-and-PowerPC-Options.html 88# http://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html 89# http://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html 90# http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html 91 92. if ${MACHINE_CPUARCH} == "i386" 93. if ${CPUTYPE} == "crusoe" 94_CPUCFLAGS = -march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0 95. elif ${CPUTYPE} == "k5" 96_CPUCFLAGS = -march=pentium 97. elif ${CPUTYPE} == "c7" 98_CPUCFLAGS = -march=c3-2 99. else 100_CPUCFLAGS = -march=${CPUTYPE} 101. endif 102. elif ${MACHINE_CPUARCH} == "amd64" 103_CPUCFLAGS = -march=${CPUTYPE} 104. elif ${MACHINE_CPUARCH} == "arm" 105. if ${CPUTYPE} == "xscale" 106#XXX: gcc doesn't seem to like -mcpu=xscale, and dies while rebuilding itself 107#_CPUCFLAGS = -mcpu=xscale 108_CPUCFLAGS = -march=armv5te -D__XSCALE__ 109. elif ${CPUTYPE} == "armv6" 110_CPUCFLAGS = -march=${CPUTYPE} -DARM_ARCH_6=1 111. elif ${CPUTYPE} == "cortexa" 112_CPUCFLAGS = -march=armv7 -DARM_ARCH_6=1 -mfpu=vfp 113. else 114_CPUCFLAGS = -mcpu=${CPUTYPE} 115. endif 116. elif ${MACHINE_ARCH} == "powerpc" 117. if ${CPUTYPE} == "e500" 118_CPUCFLAGS = -Wa,-me500 -msoft-float 119. else 120_CPUCFLAGS = -mcpu=${CPUTYPE} -mno-powerpc64 121. endif 122. elif ${MACHINE_ARCH} == "powerpc64" 123_CPUCFLAGS = -mcpu=${CPUTYPE} 124. elif ${MACHINE_CPUARCH} == "mips" 125. if ${CPUTYPE} == "mips32" 126_CPUCFLAGS = -march=mips32 127. elif ${CPUTYPE} == "mips32r2" 128_CPUCFLAGS = -march=mips32r2 129. elif ${CPUTYPE} == "mips64" 130_CPUCFLAGS = -march=mips64 131. elif ${CPUTYPE} == "mips64r2" 132_CPUCFLAGS = -march=mips64r2 133. elif ${CPUTYPE} == "mips4kc" 134_CPUCFLAGS = -march=4kc 135. elif ${CPUTYPE} == "mips24kc" 136_CPUCFLAGS = -march=24kc 137. endif 138. elif ${MACHINE_ARCH} == "sparc64" 139. if ${CPUTYPE} == "v9" 140_CPUCFLAGS = -mcpu=v9 141. elif ${CPUTYPE} == "ultrasparc" 142_CPUCFLAGS = -mcpu=ultrasparc 143. elif ${CPUTYPE} == "ultrasparc3" 144_CPUCFLAGS = -mcpu=ultrasparc3 145. endif 146. endif 147 148# Set up the list of CPU features based on the CPU type. This is an 149# unordered list to make it easy for client makefiles to test for the 150# presence of a CPU feature. 151 152########## i386 153. if ${MACHINE_CPUARCH} == "i386" 154. if ${CPUTYPE} == "bdver4" 155MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 156. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \ 157 ${CPUTYPE} == "bdver1" 158MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 159. elif ${CPUTYPE} == "btver2" 160MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 161. elif ${CPUTYPE} == "btver1" 162MACHINE_CPU = ssse3 sse4a sse3 sse2 sse mmx k6 k5 i586 163. elif ${CPUTYPE} == "amdfam10" 164MACHINE_CPU = athlon-xp athlon k7 3dnow sse4a sse3 sse2 sse mmx k6 k5 i586 165. elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" 166MACHINE_CPU = athlon-xp athlon k7 3dnow sse3 sse2 sse mmx k6 k5 i586 167. elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \ 168 ${CPUTYPE} == "athlon-fx" 169MACHINE_CPU = athlon-xp athlon k7 3dnow sse2 sse mmx k6 k5 i586 170. elif ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \ 171 ${CPUTYPE} == "athlon-4" 172MACHINE_CPU = athlon-xp athlon k7 3dnow sse mmx k6 k5 i586 173. elif ${CPUTYPE} == "athlon" || ${CPUTYPE} == "athlon-tbird" 174MACHINE_CPU = athlon k7 3dnow mmx k6 k5 i586 175. elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "geode" 176MACHINE_CPU = 3dnow mmx k6 k5 i586 177. elif ${CPUTYPE} == "k6" 178MACHINE_CPU = mmx k6 k5 i586 179. elif ${CPUTYPE} == "k5" 180MACHINE_CPU = k5 i586 181. elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "knl" 182MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 183. elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" 184MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 185. elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge" 186MACHINE_CPU = avx sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 187. elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \ 188 ${CPUTYPE} == "silvermont" 189MACHINE_CPU = sse42 sse41 ssse3 sse3 sse2 sse i686 mmx i586 190. elif ${CPUTYPE} == "penryn" 191MACHINE_CPU = sse41 ssse3 sse3 sse2 sse i686 mmx i586 192. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 193MACHINE_CPU = ssse3 sse3 sse2 sse i686 mmx i586 194. elif ${CPUTYPE} == "yonah" || ${CPUTYPE} == "prescott" 195MACHINE_CPU = sse3 sse2 sse i686 mmx i586 196. elif ${CPUTYPE} == "pentium4" || ${CPUTYPE} == "pentium4m" || \ 197 ${CPUTYPE} == "pentium-m" 198MACHINE_CPU = sse2 sse i686 mmx i586 199. elif ${CPUTYPE} == "pentium3" || ${CPUTYPE} == "pentium3m" 200MACHINE_CPU = sse i686 mmx i586 201. elif ${CPUTYPE} == "pentium2" 202MACHINE_CPU = i686 mmx i586 203. elif ${CPUTYPE} == "pentiumpro" 204MACHINE_CPU = i686 i586 205. elif ${CPUTYPE} == "pentium-mmx" 206MACHINE_CPU = mmx i586 207. elif ${CPUTYPE} == "pentium" 208MACHINE_CPU = i586 209. elif ${CPUTYPE} == "c7" 210MACHINE_CPU = sse3 sse2 sse i686 mmx i586 211. elif ${CPUTYPE} == "c3-2" 212MACHINE_CPU = sse i686 mmx i586 213. elif ${CPUTYPE} == "c3" 214MACHINE_CPU = 3dnow mmx i586 215. elif ${CPUTYPE} == "winchip2" 216MACHINE_CPU = 3dnow mmx 217. elif ${CPUTYPE} == "winchip-c6" 218MACHINE_CPU = mmx 219. endif 220MACHINE_CPU += i486 221########## amd64 222. elif ${MACHINE_CPUARCH} == "amd64" 223. if ${CPUTYPE} == "bdver4" 224MACHINE_CPU = xop avx2 avx sse42 sse41 ssse3 sse4a sse3 225. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \ 226 ${CPUTYPE} == "bdver1" 227MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3 228. elif ${CPUTYPE} == "btver2" 229MACHINE_CPU = avx sse42 sse41 ssse3 sse4a sse3 230. elif ${CPUTYPE} == "btver1" 231MACHINE_CPU = ssse3 sse4a sse3 232. elif ${CPUTYPE} == "amdfam10" 233MACHINE_CPU = k8 3dnow sse4a sse3 234. elif ${CPUTYPE} == "opteron-sse3" || ${CPUTYPE} == "athlon64-sse3" || \ 235 ${CPUTYPE} == "k8-sse3" 236MACHINE_CPU = k8 3dnow sse3 237. elif ${CPUTYPE} == "opteron" || ${CPUTYPE} == "athlon64" || \ 238 ${CPUTYPE} == "athlon-fx" || ${CPUTYPE} == "k8" 239MACHINE_CPU = k8 3dnow 240. elif ${CPUTYPE} == "skylake" || ${CPUTYPE} == "knl" 241MACHINE_CPU = avx512 avx2 avx sse42 sse41 ssse3 sse3 242. elif ${CPUTYPE} == "broadwell" || ${CPUTYPE} == "haswell" 243MACHINE_CPU = avx2 avx sse42 sse41 ssse3 sse3 244. elif ${CPUTYPE} == "ivybridge" || ${CPUTYPE} == "sandybridge" 245MACHINE_CPU = avx sse42 sse41 ssse3 sse3 246. elif ${CPUTYPE} == "westmere" || ${CPUTYPE} == "nehalem" || \ 247 ${CPUTYPE} == "silvermont" 248MACHINE_CPU = sse42 sse41 ssse3 sse3 249. elif ${CPUTYPE} == "penryn" 250MACHINE_CPU = sse41 ssse3 sse3 251. elif ${CPUTYPE} == "core2" || ${CPUTYPE} == "bonnell" 252MACHINE_CPU = ssse3 sse3 253. elif ${CPUTYPE} == "nocona" 254MACHINE_CPU = sse3 255. endif 256MACHINE_CPU += amd64 sse2 sse mmx 257########## powerpc 258. elif ${MACHINE_ARCH} == "powerpc" 259. if ${CPUTYPE} == "e500" 260MACHINE_CPU = booke softfp 261. endif 262########## sparc64 263. elif ${MACHINE_ARCH} == "sparc64" 264. if ${CPUTYPE} == "v9" 265MACHINE_CPU = v9 266. elif ${CPUTYPE} == "ultrasparc" 267MACHINE_CPU = v9 ultrasparc 268. elif ${CPUTYPE} == "ultrasparc3" 269MACHINE_CPU = v9 ultrasparc ultrasparc3 270. endif 271. endif 272.endif 273 274.if ${MACHINE_CPUARCH} == "mips" 275CFLAGS += -G0 276.endif 277 278########## arm 279.if ${MACHINE_CPUARCH} == "arm" 280MACHINE_CPU += arm 281. if ${MACHINE_ARCH:Marmv6*} != "" 282MACHINE_CPU += armv6 283. endif 284# armv6 is a hybrid. It uses the softfp ABI, but doesn't emulate 285# floating point in the general case, so don't define softfp for 286# it at this time. arm and armeb are pure softfp, so define it 287# for them. 288. if ${MACHINE_ARCH:Marmv6*} == "" 289MACHINE_CPU += softfp 290. endif 291.if ${MACHINE_ARCH} == "armv6" 292# Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI 293# not a nice optimization. 294CFLAGS += -mfloat-abi=softfp 295.endif 296.endif 297 298# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk 299 300.if !defined(NO_CPU_CFLAGS) 301CFLAGS += ${_CPUCFLAGS} 302.endif 303 304# 305# Prohibit the compiler from emitting SIMD instructions. 306# These flags are added to CFLAGS in areas where the extra context-switch 307# cost outweighs the advantages of SIMD instructions. 308# 309# gcc: 310# Setting -mno-mmx implies -mno-3dnow 311# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387 312# 313# clang: 314# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 315# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and 316# -mno-sse42 317# (-mfpmath= is not supported) 318# 319.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 320CFLAGS_NO_SIMD.clang= -mno-avx 321CFLAGS_NO_SIMD= -mno-mmx -mno-sse 322.endif 323CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}} 324 325# Add in any architecture-specific CFLAGS. 326# These come from make.conf or the command line or the environment. 327CFLAGS += ${CFLAGS.${MACHINE_ARCH}} 328CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}} 329