1.include <bsd.compiler.mk> 2 3CRTARCH= ${MACHINE_CPUARCH:C/amd64/x86_64/:C/powerpc/ppc/} 4 5CRTSRC= ${SRCTOP}/contrib/llvm-project/compiler-rt/lib/builtins 6 7.if ${MACHINE_ARCH} == "powerpc64le" 8# Long double is IEEE binary128. Search the generic builtins first so the 9# IEEE-128 sources win over the IBM double-double versions of the same file 10# names in the ppc/ directory. 11.PATH: ${CRTSRC} 12.endif 13.PATH: ${CRTSRC}/${CRTARCH} 14.PATH: ${CRTSRC} 15 16SRCF+= absvdi2 17SRCF+= absvsi2 18SRCF+= absvti2 19SRCF+= addvdi3 20SRCF+= addvsi3 21SRCF+= addvti3 22SRCF+= apple_versioning 23SRCF+= ashldi3 24SRCF+= ashlti3 25SRCF+= ashrdi3 26SRCF+= ashrti3 27SRCF+= bswapdi2 28SRCF+= bswapsi2 29SRCF+= clear_cache 30SRCF+= clzdi2 31SRCF+= clzsi2 32SRCF+= clzti2 33SRCF+= cmpdi2 34SRCF+= cmpti2 35SRCF+= ctzdi2 36SRCF+= ctzsi2 37SRCF+= ctzti2 38SRCF+= divdc3 39SRCF+= divdi3 40SRCF+= divmoddi4 41SRCF+= divmodsi4 42SRCF+= divmodti4 43SRCF+= divsc3 44SRCF+= divsi3 45SRCF+= divti3 46SRCF+= enable_execute_stack 47SRCF+= extendhfsf2 48SRCF+= ffsdi2 49SRCF+= ffssi2 50SRCF+= ffsti2 51SRCF+= fixdfdi 52SRCF+= fixdfti 53SRCF+= fixsfdi 54SRCF+= fixsfti 55SRCF+= fixunsdfdi 56SRCF+= fixunsdfsi 57SRCF+= fixunsdfti 58SRCF+= fixunssfdi 59SRCF+= fixunssfsi 60SRCF+= fixunssfti 61SRCF+= floattidf 62SRCF+= floattisf 63SRCF+= floatunsidf 64SRCF+= floatunsisf 65SRCF+= floatuntidf 66SRCF+= floatuntisf 67SRCF+= int_util 68SRCF+= lshrdi3 69SRCF+= lshrti3 70SRCF+= moddi3 71SRCF+= modsi3 72SRCF+= modti3 73SRCF+= muldc3 74SRCF+= muldi3 75SRCF+= mulodi4 76SRCF+= mulosi4 77SRCF+= muloti4 78SRCF+= mulsc3 79SRCF+= multi3 80SRCF+= mulvdi3 81SRCF+= mulvsi3 82SRCF+= mulvti3 83SRCF+= negdf2 84SRCF+= negdi2 85SRCF+= negsf2 86SRCF+= negti2 87SRCF+= negvdi2 88SRCF+= negvsi2 89SRCF+= negvti2 90SRCF+= paritydi2 91SRCF+= paritysi2 92SRCF+= parityti2 93SRCF+= popcountdi2 94SRCF+= popcountsi2 95SRCF+= popcountti2 96SRCF+= powidf2 97SRCF+= powisf2 98SRCF+= subvdi3 99SRCF+= subvsi3 100SRCF+= subvti3 101SRCF+= trampoline_setup 102SRCF+= truncdfhf2 103SRCF+= truncsfhf2 104SRCF+= ucmpdi2 105SRCF+= ucmpti2 106SRCF+= udivdi3 107SRCF+= udivmoddi4 108SRCF+= udivmodsi4 109SRCF+= udivmodti4 110SRCF+= udivsi3 111SRCF+= udivti3 112SRCF+= umoddi3 113SRCF+= umodsi3 114SRCF+= umodti3 115 116# Enable compiler-rt's atomic implementation only for clang, as it uses clang 117# specific builtins, and gcc packages usually come with their own libatomic. 118# Exclude arm which has its own implementations of atomic functions, below. 119.if "${COMPILER_TYPE}" == "clang" && ${MACHINE_CPUARCH} != "arm" 120SRCF+= atomic 121.endif 122 123# Avoid using SSE2 instructions on i386, if unsupported. 124.if ${MACHINE_CPUARCH} == "i386" && empty(MACHINE_CPU:Msse2) 125SRCS+= floatdidf.c 126SRCS+= floatdisf.c 127SRCS+= floatundidf.c 128SRCS+= floatundisf.c 129.else 130SRCF+= floatdidf 131SRCF+= floatdisf 132SRCF+= floatundidf 133SRCF+= floatundisf 134.endif 135 136# 137# 80-bit long double functions, only used on x86. 138# 139.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" 140SRCF+= divxc3 141SRCF+= fixxfdi 142SRCF+= fixxfti 143SRCF+= fixunsxfdi 144SRCF+= fixunsxfsi 145SRCF+= fixunsxfti 146SRCF+= floattixf 147SRCF+= floatuntixf 148SRCF+= mulxc3 149SRCF+= powixf2 150 151# Avoid using SSE2 instructions on i386, if unsupported. 152.if ${MACHINE_CPUARCH} == "i386" && empty(MACHINE_CPU:Msse2) 153SRCS+= floatdixf.c 154SRCS+= floatundixf.c 155.else 156SRCF+= floatdixf 157SRCF+= floatundixf 158.endif 159.endif 160 161# 128-bit float is an amd64 feature 162.if ${MACHINE_CPUARCH} == "amd64" 163SRCF+= extendxftf2 164SRCF+= trunctfxf2 165.endif 166 167# __cpu_model support, only used on aarch64 and x86 168.if ${MACHINE_CPUARCH} == "aarch64" 169SRCS+= cpu_model/aarch64.c 170.elif ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" 171SRCS+= cpu_model/x86.c 172.endif 173 174# The fp_mode implementation for amd64 and i386 is shared, while other 175# architectures use the regular approach. 176.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" 177SRCS+= i386/fp_mode.c 178.else 179SRCF+= fp_mode 180.endif 181 182# 183# 128-bit quad precision long double support, 184# only used on some architectures. 185# 186.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" || \ 187 ${MACHINE_CPUARCH} == "riscv" 188SRCF+= addtf3 189SRCF+= comparetf2 190SRCF+= divtc3 191SRCF+= divtf3 192SRCF+= extenddftf2 193SRCF+= extendhftf2 194SRCF+= extendsftf2 195SRCF+= fixtfdi 196SRCF+= fixtfsi 197SRCF+= fixtfti 198SRCF+= fixunstfdi 199SRCF+= fixunstfsi 200SRCF+= fixunstfti 201SRCF+= floatditf 202SRCF+= floatsitf 203SRCF+= floattitf 204SRCF+= floatunditf 205SRCF+= floatunsitf 206SRCF+= floatuntitf 207SRCF+= multc3 208SRCF+= multf3 209SRCF+= powitf2 210SRCF+= subtf3 211SRCF+= trunctfdf2 212SRCF+= trunctfhf2 213SRCF+= trunctfsf2 214.endif 215 216# 217# IEEE binary128 long double support for powerpc64le. PowerPC names the 218# IEEE-128 soft-float builtins with a "kf" infix (KFmode) instead of the 219# generic "tf" (see clang's PPCSystemLibrary in RuntimeLibcalls.td), so build 220# the generic IEEE-128 sources but rename each exported symbol to its kf name. 221# The .PATH reordering above makes these resolve to the generic implementations 222# rather than the IBM double-double versions in ppc/. 223# 224.if ${MACHINE_ARCH} == "powerpc64le" 225.for _f _old _new in \ 226 addtf3 __addtf3 __addkf3 \ 227 subtf3 __subtf3 __subkf3 \ 228 multf3 __multf3 __mulkf3 \ 229 divtf3 __divtf3 __divkf3 \ 230 powitf2 __powitf2 __powikf2 \ 231 extendsftf2 __extendsftf2 __extendsfkf2 \ 232 extenddftf2 __extenddftf2 __extenddfkf2 \ 233 trunctfsf2 __trunctfsf2 __trunckfsf2 \ 234 trunctfdf2 __trunctfdf2 __trunckfdf2 \ 235 fixtfsi __fixtfsi __fixkfsi \ 236 fixtfdi __fixtfdi __fixkfdi \ 237 fixtfti __fixtfti __fixkfti \ 238 fixunstfsi __fixunstfsi __fixunskfsi \ 239 fixunstfdi __fixunstfdi __fixunskfdi \ 240 fixunstfti __fixunstfti __fixunskfti \ 241 floatsitf __floatsitf __floatsikf \ 242 floatditf __floatditf __floatdikf \ 243 floattitf __floattitf __floattikf \ 244 floatunsitf __floatunsitf __floatunsikf \ 245 floatunditf __floatunditf __floatundikf \ 246 floatuntitf __floatuntitf __floatuntikf 247SRCF+= ${_f} 248CFLAGS.${_f}.c+= -D${_old}=${_new} 249.endfor 250 251# subtf3.c implements __subtf3 as __addtf3(a, -b), so its hardcoded call to 252# __addtf3 must also be renamed to resolve to the kf-named add. 253CFLAGS.subtf3.c+= -D__addtf3=__addkf3 254 255# Complex IEEE-128 multiply/divide keep the generic tf names: PowerPC does not 256# override MUL_C128/DIV_C128, so clang emits __multc3/__divtc3 for IEEE-128. 257SRCF+= divtc3 258SRCF+= multc3 259 260# The kf comparisons cannot use a -D rename of comparetf2.c because its internal 261# COMPILER_RT_ALIAS stringizes the (unrenamed) target name; provide them here. 262# comparekf2.c is FreeBSD-local, so put its directory on .PATH: this fragment is 263# also .include'd by libgcc_s/libgcc_eh, whose .CURDIR differs from ours. 264.PATH: ${SRCTOP}/lib/libcompiler_rt 265SRCS+= comparekf2.c 266CFLAGS.comparekf2.c+= -I${CRTSRC} 267.endif 268 269# These are already shipped by libc.a on some architectures. 270.if ${MACHINE_CPUARCH} != "riscv" 271SRCF+= adddf3 272SRCF+= addsf3 273SRCF+= divdf3 274SRCF+= divsf3 275SRCF+= extendsfdf2 276SRCF+= fixdfsi 277SRCF+= fixsfsi 278SRCF+= floatsidf 279SRCF+= floatsisf 280SRCF+= muldf3 281SRCF+= mulsf3 282SRCF+= subdf3 283SRCF+= subsf3 284SRCF+= truncdfsf2 285.endif 286 287SRCF+= comparedf2 288SRCF+= comparesf2 289 290# Helper to reduce complexity of _Float16 and __bf16 statements below. 291.if ${MACHINE_CPUARCH} == "aarch64" || \ 292 ${MACHINE_CPUARCH} == "amd64" || \ 293 (${MACHINE_CPUARCH} == "i386" && !empty(MACHINE_CPU:Msse2)) 294CRT_COMMON_F16_ARCH=t 295.endif 296 297# 298# _Float16 support, only on some architectures, and with certain compiler 299# versions. 300# 301.if ((${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 150000) && \ 302 (defined(CRT_COMMON_F16_ARCH) || \ 303 ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "riscv")) || \ 304 ((${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 120000) && \ 305 (defined(CRT_COMMON_F16_ARCH))) 306CFLAGS+= -DCOMPILER_RT_HAS_FLOAT16 307.endif 308 309# 310# __bf16 support, only on some architectures, and with certain compiler 311# versions. 312# 313.if ((${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 150000) && \ 314 (defined(CRT_COMMON_F16_ARCH))) || \ 315 ((${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 180000) && \ 316 ${MACHINE_CPUARCH} == "riscv") || \ 317 ((${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 130000) && \ 318 (defined(CRT_COMMON_F16_ARCH))) 319CFLAGS+= -DCOMPILER_RT_HAS_BFLOAT16 320SRCF+= extendbfsf2 321SRCF+= truncdfbf2 322SRCF+= truncsfbf2 323.endif 324 325# FreeBSD-specific atomic intrinsics. 326.if ${MACHINE_CPUARCH} == "arm" 327.PATH: ${SRCTOP}/sys/arm/arm 328 329SRCF+= stdatomic 330CFLAGS+= -DEMIT_SYNC_ATOMICS 331.endif 332 333.for file in ${SRCF} 334. if exists(${CRTSRC}/${CRTARCH}/${file}.S) 335SRCS+= ${file}.S 336. else 337SRCS+= ${file}.c 338. endif 339.endfor 340 341.if ${MACHINE_CPUARCH} == "arm" 342SRCS+= aeabi_cdcmp.S 343SRCS+= aeabi_cdcmpeq_check_nan.c 344SRCS+= aeabi_cfcmp.S 345SRCS+= aeabi_cfcmpeq_check_nan.c 346SRCS+= aeabi_dcmp.S 347SRCS+= aeabi_div0.c 348SRCS+= aeabi_drsub.c 349SRCS+= aeabi_fcmp.S 350SRCS+= aeabi_frsub.c 351SRCS+= aeabi_idivmod.S 352SRCS+= aeabi_ldivmod.S 353SRCS+= aeabi_memcmp.S 354SRCS+= aeabi_memcpy.S 355SRCS+= aeabi_memmove.S 356SRCS+= aeabi_memset.S 357SRCS+= aeabi_uidivmod.S 358SRCS+= aeabi_uldivmod.S 359 360SRCS+= switch16.S 361SRCS+= switch32.S 362SRCS+= switch8.S 363SRCS+= switchu8.S 364SRCS+= sync_synchronize.S 365.endif 366