-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
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
9d827dd
32aec0e
8d58dc5
8e446d7
471ad0e
92923bb
ca9ec71
a6d66d0
3bc0032
d88e0d4
d1c5eee
8a51190
42162a9
f9b0cce
f76c208
b5705ce
b5496fb
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 |
|---|---|---|
|
|
@@ -156,6 +156,10 @@ impl<'gcc, 'tcx> BaseTypeCodegenMethods for CodegenCx<'gcc, 'tcx> { | |
| bug!("unsupported float width 16") | ||
| } | ||
|
|
||
| fn type_f16b(&self) -> Type<'gcc> { | ||
| bug!("f16b is not supported by the GCC codegen backend") | ||
|
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 GCC actually supports this type: https://github.com/rust-lang/gccjit.rs/blob/master/src/context.rs#L1482
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. Thanks 😄, I will aim to add it in a follow up PR 👍 |
||
| } | ||
|
|
||
| fn type_f32(&self) -> Type<'gcc> { | ||
| #[cfg(feature = "master")] | ||
| if self.supports_f32_type { | ||
|
|
||
| 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 |
|---|---|---|
|
|
@@ -139,6 +139,11 @@ impl abi::Float { | |
| use abi::Float::*; | ||
| match *self { | ||
| F16 => tcx.types.f16, | ||
| F16B => Ty::new_adt( | ||
| tcx, | ||
| tcx.adt_def(tcx.require_lang_item(LangItem::BFloat, DUMMY_SP)), | ||
|
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. This is... interesting.^^ Why does this need both a lang item and a new variant in
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. Because we don't (at present) want to make it a true builtin (like This is different from |
||
| ty::List::empty(), | ||
| ), | ||
| F32 => tcx.types.f32, | ||
| F64 => tcx.types.f64, | ||
| F128 => tcx.types.f128, | ||
|
|
||
|
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 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
View changes since the review