Skip to content

Commit

Permalink
[compiler-rt][BF16] Provide __truncdfbf2 and __truncsfbf2 only when _…
Browse files Browse the repository at this point in the history
…_bf16 is available

Differential Revision: https://reviews.llvm.org/D131147

(cherry picked from commit f061cfb)
  • Loading branch information
phoebewang authored and tru committed Aug 12, 2022
1 parent fa0ff57 commit 54d0758
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions compiler-rt/cmake/builtin-config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ _Float16 foo(_Float16 x) {
"
)

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\");
Expand Down
11 changes: 9 additions & 2 deletions compiler-rt/lib/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@ set(GENERIC_SOURCES
subvsi3.c
subvti3.c
trampoline_setup.c
truncdfbf2.c
truncdfhf2.c
truncdfsf2.c
truncsfbf2.c
truncsfhf2.c
ucmpdi2.c
ucmpti2.c
Expand All @@ -183,6 +181,15 @@ set(GENERIC_SOURCES
umodti3.c
)

# Build BF16 files only when "__bf16" is available.
if(COMPILER_RT_HAS_BFLOAT16 AND NOT APPLE)
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
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/fp_trunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef uint16_t dst_rep_t;
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;
Expand Down

0 comments on commit 54d0758

Please sign in to comment.