git: 50fd2fbec96c - stable/13 - libcompiler_rt Makefile.inc: update _Float16/__bf16 checks

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Sat, 20 Apr 2024 10:34:59 UTC
The branch stable/13 has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=50fd2fbec96c46961addac790c10c1d49d3673f9

commit 50fd2fbec96c46961addac790c10c1d49d3673f9
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-04-17 20:20:47 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-04-20 10:29:10 +0000

    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 f276adc148433d009d198c2ebccdd3303377e237)
---
 lib/libcompiler_rt/Makefile.inc | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/lib/libcompiler_rt/Makefile.inc b/lib/libcompiler_rt/Makefile.inc
index c0dacb5c9d7e..4fc02bae5710 100644
--- a/lib/libcompiler_rt/Makefile.inc
+++ b/lib/libcompiler_rt/Makefile.inc
@@ -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
+
+#
+# _Float16 support, only on some architectures, and with certain compiler
+# versions.
+#
+.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
+
 #
-# bfloat16 support, only used on some architectures.
+# __bf16 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))) || \
+    ((${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