-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add support for Float16, Float32, Float64 and Float128 #17
Add support for Float16, Float32, Float64 and Float128 #17
Conversation
35bc8ff
to
6b2a99a
Compare
src/context.rs
Outdated
#[cfg(feature = "master")] | ||
let float64_type = context.new_c_type(CType::Float64); | ||
#[cfg(feature = "master")] | ||
let float128_type = context.new_c_type(CType::Float128); |
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.
Those types might not be available on some platforms, so it might be wrong to query these types here.
Depending on how much you want to add stuff in this PR, you have two options:
- Do the same as detecting 128-bit integers support: we might want to change the GCC API to take a type as a parameter.
- Only query the types in the functions like
type_f16
below so that it only panics when used.
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.
So far I query the types only in the functions().
As the next step I will try to detect whether new types are supported.
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 mean, just calling new_c_type()
here will give an error if the type is not supported.
Here's how I detect 128-bit support with the old way of doing things.
@@ -132,8 +137,13 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { | |||
self.double_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.
6b2a99a
to
f9c3617
Compare
src/type_.rs
Outdated
fn type_f16(&self) -> Type<'gcc> { | ||
unimplemented!("f16_f128") | ||
self.context.new_c_type(CType::Float16) | ||
} |
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.
src/type_.rs
Outdated
#[cfg(feature = "master")] | ||
fn type_f128(&self) -> Type<'gcc> { | ||
self.context.new_c_type(CType::Float128) | ||
} |
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.
Do you want to add more stuff for this PR (like the checks if the types are supported on the target platform for at least Float32 and Float64) or do you want to merge as is (with the above formatting nitpicks fixed)? |
Yes, I plan to add checks if Float32 and Float64 are supported. |
f9c3617
to
46eea99
Compare
46eea99
to
2743807
Compare
d71f067
to
6280647
Compare
98af2e1
to
8920002
Compare
d9dc4cb
to
7004c96
Compare
850b944
to
6f3aa00
Compare
Upgrade libgccjit.version Limit new Floatxx types to master branch only apply rustfmt Make new types available only when requested Make new types available only when requested Check if Float16 and Float128 are supported by the target platform Replace Float with Float32 and Double with Float64 if target dependent type is defined Add support for Float16|32|64|128 in the builder Fix cargo fmt errors Update gccjit wrapper update hash of ligccjit
…he no-f16-f128 feautes introduced incompatibility
reorder type_kind reorder type_kind reorder type_kind fix fix fix fix
fix formatting
894f00c
to
55788e4
Compare
src/type_.rs
Outdated
#[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 | ||
} |
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.
Would it work to do the following?
#[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 | |
} |
src/type_.rs
Outdated
4 => TypeKind::Float, | ||
8 => TypeKind::Double, | ||
16 => TypeKind::FP128, | ||
_ => TypeKind::Void, |
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?
TypeKind::Float | ||
} else if typ.is_compatible_with(self.double_type) { | ||
TypeKind::Double | ||
} 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.
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,
}
}
#[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.
Don't forget to implement type_f64
as well.
0d05848
to
2eaac23
Compare
55467aa
to
9274c63
Compare
Thank you so much for your work! |
No description provided.