Open usamoi opened 6 months ago
@rustbot label A-floating-point A-linkage I-unsound
cc @Amanieu for compiler builtins shenanigans
We probably need to se COMPILER_RT_HAS_FLOAT16
during our compiler-rt build.
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-high
We probably need to se
COMPILER_RT_HAS_FLOAT16
during our compiler-rt build.
Yes, I think that would solve the problem. Is _Float16
supported by Clang on all targets? Or do we need some sort of per-target allowlist?
Is
_Float16
supported by Clang on all targets? Or do we need some sort of per-target allowlist?
I looks like it's not available on all targets: https://clang.llvm.org/docs/LanguageExtensions.html#half-precision-floating-point
@beetrees put up https://github.com/rust-lang/compiler-builtins/pull/593 which uses our nightly f16
type to provide the extend/trunc symbols and should fix this. Need to double check the edge cases because the ABI (integer or float) is apparently dependent on whether SSE2 is available.
In general, LLVM will call builtins with the default C ABI, so any target features that affect the ABI (SSE2, soft-float, etc.) need to be the same when compiling compiler-builtins
/compiler-rt
as when compiling user code to avoid miscompilations. _Float16
is only available in clang and gcc when SSE2 is enabled, so as long as compiler-builtins
was built with SSE2 enabled (as it is by default for all the not-bare-metal-or-UEFI i686-*
and x86_64-*
targets) the ABI should line up.
Related: #116558
I tried this code:
I expected to see this happen: It prints
114
.Instead, this happened: It prints an unknown value,
0.00017929077
,-0.045898438
or other.After debugging, I found both
compiler_builtins
andlibgcc
provide the symbol__extendhfsf2
.__extendhfsf2
is acompiler-rt
intrinsics for casting a_Float16
tofloat
. Incompiler_builtins
, the only argument of__extendhfsf2
is passed in a general-proposed register, However, inlibgcc
, the only argument of__extendhfsf2
is passed inxmm
.related: https://github.com/llvm/llvm-project/issues/56854
Meta
rustc --version --verbose
: