libcompiler_rt Makefile.inc: update _Float16/__bf16 checks

Clang supports __bf16 for riscv from version 18.0 onwards, so update the
checks for it. While here, rewrite the checks so they are hopefully more
readable, and also handle gcc a little better.

In addition, define COMPILER_RT_HAS_FLOAT16 and COMPILER_RT_HAS_BFLOAT16
when these features should be available, since there are some parts in
compiler-rt that check for these defines.

PR:		276104
MFC after:	1 month

(cherry picked from commit f276adc148)
This commit is contained in:
Dimitry Andric 2024-04-17 22:20:47 +02:00
parent 5b763c0e1f
commit 50fd2fbec9

View File

@ -228,13 +228,36 @@ SRCF+= comparedf2
SRCF+= comparesf2
.endif
# Helper to reduce complexity of _Float16 and __bf16 statements below.
.if ${MACHINE_CPUARCH} == "aarch64" || \
${MACHINE_CPUARCH} == "amd64" || \
${MACHINE_CPUARCH} == "arm" || \
(${MACHINE_CPUARCH} == "i386" && !empty(MACHINE_CPU:Msse2))
CRT_COMMON_F16_ARCH=t
.endif
#
# bfloat16 support, only used on some architectures.
# _Float16 support, only on some architectures, and with certain compiler
# versions.
#
.if (${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" || \
${MACHINE_CPUARCH} == "arm" || (${MACHINE_CPUARCH} == "i386" && \
!empty(MACHINE_CPU:Msse2)) || ${MACHINE_CPUARCH} == "riscv") && \
!(${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} < 130000)
.if ((${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 150000) && \
(defined(CRT_COMMON_F16_ARCH) || ${MACHINE_CPUARCH} == "riscv")) || \
((${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 120000) && \
(defined(CRT_COMMON_F16_ARCH)))
CFLAGS+= -DCOMPILER_RT_HAS_FLOAT16
.endif
#
# __bf16 support, only on some architectures, and with certain compiler
# versions.
#
.if ((${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 150000) && \
(defined(CRT_COMMON_F16_ARCH))) || \
((${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 180000) && \
${MACHINE_CPUARCH} == "riscv") || \
((${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 130000) && \
(defined(CRT_COMMON_F16_ARCH)))
CFLAGS+= -DCOMPILER_RT_HAS_BFLOAT16
SRCF+= truncdfbf2
SRCF+= truncsfbf2
.endif