-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
core::num::f16b Rust's 16bit Brain Float
#160859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
54d3b15
722e10f
42d0875
da40684
7e193e5
f541885
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -332,6 +332,9 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { | |
| Primitive::Float(Float::F16) => { | ||
| bug!("the va_arg intrinsic does not support `f16`") | ||
| } | ||
| Primitive::Float(Float::F16B) => { | ||
| bug!("the va_arg intrinsic does not support `f16b`") | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well we could support this actually, it doesn't participate in argument promotion. Idk if it's useful. |
||
| Primitive::Float(Float::F32) => { | ||
| // c_double is actually f32 on avr. | ||
| if self.cx().sess().target.arch != Arch::Avr { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -353,6 +353,7 @@ pub(crate) fn target_config(sess: &Session) -> TargetConfig { | |
| internal_target_features, | ||
| has_reliable_f16: true, | ||
| has_reliable_f16_math: true, | ||
| has_reliable_f16b: true, | ||
| has_reliable_f128: true, | ||
| has_reliable_f128_math: true, | ||
| }; | ||
|
|
@@ -390,6 +391,21 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) { | |
| _ => true, | ||
| }; | ||
|
|
||
| // The heuristic for evaluating to true is twofold, namely; | ||
| // | ||
| // 1. Can LLVM compile an IR snippet containing `fpext bfloat %<var> to float` | ||
| // 2. Does the documentation indicate `bf16` support, can be seen in the | ||
| // tracking issue; <https://github.com/rust-lang/rust/issues/160630> | ||
| cfg.has_reliable_f16b = match (target_arch, target_os) { | ||
| // This is similar to <https://github.com/llvm/llvm-project/issues/94434>, however | ||
| // does not work until LLVM 23 on Windows. | ||
| (Arch::Arm64EC, _) => major >= 23, | ||
| (Arch::AArch64, _) | (Arch::X86_64, _) | (Arch::RiscV64, _) | (Arch::LoongArch64, _) => { | ||
| major >= 21 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't LLVM 21 the minimum version anyway? |
||
| } | ||
| _ => false, | ||
| }; | ||
|
|
||
| cfg.has_reliable_f128 = match (target_arch, target_os) { | ||
| // Unsupported https://github.com/llvm/llvm-project/issues/121122 | ||
| (Arch::AmdGpu, _) => false, | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the calling convention of other targets?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe only these files were changed because they have an exhaustive match on However, my version of abi-cafe found two interesting failures: GCC and Clang are inconsistent on // callee, compiled with GCC 12
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
typedef struct Many1 {
__bf16 f0;
} Many1;
void struct_in_1(Many1 arg0) {
printf("%d", arg0.f0);
}// caller, compiled with clang 23
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
typedef struct Many1 {
__bf16 f0;
} Many1;
void struct_in_1(Many1 arg0);
void do_test(void) {
{
Many1 arg0 = { .f0 = (((union { uint16_t bits; __bf16 value; }){ .bits = 49600 }).value) };
printf("%d", arg0.f0);
struct_in_1(arg0);
}
}hits The current Rust implementation matches clang, and is hence incompatible with GCC armv7 with hardware floats also runs into incompatibilities Finally, you can let this ICE on many targets, e.g. mips, powerpc, s390x, sparc
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also (e.g. on I think the ICEs are probably a blocker? That needs a mechanism similar to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I added it because of the exhaustive match statement in With regard to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Exactly
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's your take on those ABI mismatches? We should track that somewhere.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not particularly certain what It doesn't, at least to my knowledge, have hardware support. Given we aren't implementing scalar arithmetic and an
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No comment on whether this is the right approach, but always use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't use those custom macros in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't seem possible to use in |
Uh oh!
There was an error while loading. Please reload this page.