diff --git a/compiler-rt/cmake/builtin-config-ix.cmake b/compiler-rt/cmake/builtin-config-ix.cmake --- a/compiler-rt/cmake/builtin-config-ix.cmake +++ b/compiler-rt/cmake/builtin-config-ix.cmake @@ -30,6 +30,14 @@ " ) +builtin_check_c_compiler_source(COMPILER_RT_HAS_BFLOAT16 +" +__bf16 foo(__bf16 x) { + return x; +} +" +) + builtin_check_c_compiler_source(COMPILER_RT_HAS_ASM_LSE " asm(\".arch armv8-a+lse\"); diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -165,10 +165,8 @@ subvsi3.c subvti3.c trampoline_setup.c - truncdfbf2.c truncdfhf2.c truncdfsf2.c - truncsfbf2.c truncsfhf2.c ucmpdi2.c ucmpti2.c @@ -183,6 +181,15 @@ umodti3.c ) +# Build BF16 files only when "__bf16" is available. +if(COMPILER_RT_HAS_BFLOAT16) + set(GENERIC_SOURCES + ${GENERIC_SOURCES} + truncdfbf2.c + truncsfbf2.c + ) +endif() + # TODO: Several "tf" files (and divtc3.c, but not multc3.c) are in # GENERIC_SOURCES instead of here. set(GENERIC_TF_SOURCES @@ -699,6 +706,8 @@ append_list_if(COMPILER_RT_HAS_FLOAT16 -DCOMPILER_RT_HAS_FLOAT16 BUILTIN_CFLAGS) + append_list_if(COMPILER_RT_HAS_BFLOAT16 -DCOMPILER_RT_HAS_BFLOAT16 BUILTIN_CFLAGS) + append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS) # These flags would normally be added to CMAKE_C_FLAGS by the llvm diff --git a/compiler-rt/lib/builtins/fp_trunc.h b/compiler-rt/lib/builtins/fp_trunc.h --- a/compiler-rt/lib/builtins/fp_trunc.h +++ b/compiler-rt/lib/builtins/fp_trunc.h @@ -60,7 +60,7 @@ static const int dstSigBits = 10; #elif defined DST_BFLOAT -typedef uint16_t dst_t; +typedef __bf16 dst_t; typedef uint16_t dst_rep_t; #define DST_REP_C UINT16_C static const int dstSigBits = 7;