-
Notifications
You must be signed in to change notification settings - Fork 4
Add support for Float16, Float32, Float64 and Float128 #17
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
Changes from 7 commits
d0977e3
a486dbf
fa18a18
b94cb8c
0dad11f
c4e7c04
55788e4
2eaac23
dabf5fa
16e1ad7
73db249
9274c63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| b6f163f52 | ||
| d61ce945badf4c9d8237a13ca135e3c46ad13be3 |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,8 @@ | ||||||||||||||||||||||||||||||||||||||||
| #[cfg(feature = "master")] | ||||||||||||||||||||||||||||||||||||||||
| use std::convert::TryInto; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #[cfg(feature = "master")] | ||||||||||||||||||||||||||||||||||||||||
| use gccjit::CType; | ||||||||||||||||||||||||||||||||||||||||
| use gccjit::{RValue, Struct, Type}; | ||||||||||||||||||||||||||||||||||||||||
| use rustc_codegen_ssa::common::TypeKind; | ||||||||||||||||||||||||||||||||||||||||
| use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods, TypeMembershipMethods}; | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -120,10 +125,28 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { | |||||||||||||||||||||||||||||||||||||||
| self.isize_type | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #[cfg(feature = "master")] | ||||||||||||||||||||||||||||||||||||||||
| fn type_f16(&self) -> Type<'gcc> { | ||||||||||||||||||||||||||||||||||||||||
| if self.supports_f16_type { | ||||||||||||||||||||||||||||||||||||||||
| return self.context.new_c_type(CType::Float16); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| unimplemented!("f16") | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #[cfg(not(feature = "master"))] | ||||||||||||||||||||||||||||||||||||||||
| fn type_f16(&self) -> Type<'gcc> { | ||||||||||||||||||||||||||||||||||||||||
| unimplemented!("f16_f128") | ||||||||||||||||||||||||||||||||||||||||
| unimplemented!("f16") | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #[cfg(feature = "master")] | ||||||||||||||||||||||||||||||||||||||||
| fn type_f32(&self) -> Type<'gcc> { | ||||||||||||||||||||||||||||||||||||||||
| if self.supports_f32_type { | ||||||||||||||||||||||||||||||||||||||||
| return self.context.new_c_type(CType::Float32); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| self.float_type | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
Owner
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. Don't forget to implement |
||||||||||||||||||||||||||||||||||||||||
| #[cfg(not(feature = "master"))] | ||||||||||||||||||||||||||||||||||||||||
| fn type_f32(&self) -> Type<'gcc> { | ||||||||||||||||||||||||||||||||||||||||
| self.float_type | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
| #[cfg(feature = "master")] | |
| fn type_f32(&self) -> Type<'gcc> { | |
| if self.supports_f32_type { | |
| return self.context.new_c_type(CType::Float32); | |
| } | |
| self.float_type | |
| } | |
| #[cfg(not(feature = "master"))] | |
| fn type_f32(&self) -> Type<'gcc> { | |
| self.float_type | |
| } | |
| fn type_f32(&self) -> Type<'gcc> { | |
| #[cfg(feature = "master")] | |
| if self.supports_f32_type { | |
| return self.context.new_c_type(CType::Float32); | |
| } | |
| self.float_type | |
| } |
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.
Depending on what you decide to do above, you could return Float32/Float64 in those functions if you decide to add the support for checking if those types are supported.
Of course, we would keep returing Float and Double on platforms where those types are not supported.
Outdated
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.
Same here.
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.
You'll need to do this:
| } else if typ.is_floating_point() { | |
| } | |
| #[cfg(feature="master")] | |
| else if typ.is_floating_point() { |
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.
This syntax isn't supported.
Unless you can put this above the if, I guess you can revert to 2 different implementations:
#[cfg(feature="master")]
if typ.is_floating_point() {
match typ.get_size() {
2 => return TypeKind::Half,
4 => return TypeKind::Float,
8 => return TypeKind::Double,
16 => return TypeKind::FP128,
_ => return TypeKind::Void,
}
}
Outdated
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.
Maybe this should be unreachable!() instead?
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.
I'm surprised the CI didn't complain about formatting, but it's missing an empty line between the two methods.