-
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
Changes from all 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}; | ||||||||||
|
@@ -121,19 +126,35 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { | |||||||||
} | ||||||||||
|
||||||||||
fn type_f16(&self) -> Type<'gcc> { | ||||||||||
unimplemented!("f16_f128") | ||||||||||
#[cfg(feature = "master")] | ||||||||||
if self.supports_f16_type { | ||||||||||
return self.context.new_c_type(CType::Float16); | ||||||||||
} | ||||||||||
bug!("unsupported float width 16") | ||||||||||
} | ||||||||||
|
||||||||||
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 | ||||||||||
} | ||||||||||
|
||||||||||
fn type_f64(&self) -> Type<'gcc> { | ||||||||||
#[cfg(feature = "master")] | ||||||||||
if self.supports_f64_type { | ||||||||||
return self.context.new_c_type(CType::Float64); | ||||||||||
} | ||||||||||
self.double_type | ||||||||||
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. Depending on what you decide to do above, you could return Of course, we would keep returing |
||||||||||
} | ||||||||||
|
||||||||||
fn type_f128(&self) -> Type<'gcc> { | ||||||||||
unimplemented!("f16_f128") | ||||||||||
#[cfg(feature = "master")] | ||||||||||
if self.supports_f128_type { | ||||||||||
return self.context.new_c_type(CType::Float128); | ||||||||||
} | ||||||||||
bug!("unsupported float width 128") | ||||||||||
} | ||||||||||
|
||||||||||
fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc> { | ||||||||||
|
@@ -161,6 +182,41 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { | |||||||||
typ | ||||||||||
} | ||||||||||
|
||||||||||
#[cfg(feature = "master")] | ||||||||||
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind { | ||||||||||
if self.is_int_type_or_bool(typ) { | ||||||||||
TypeKind::Integer | ||||||||||
} else if typ.get_pointee().is_some() { | ||||||||||
TypeKind::Pointer | ||||||||||
} else if typ.is_vector() { | ||||||||||
TypeKind::Vector | ||||||||||
} else if typ.dyncast_array().is_some() { | ||||||||||
TypeKind::Array | ||||||||||
} else if typ.is_struct().is_some() { | ||||||||||
TypeKind::Struct | ||||||||||
} else if typ.dyncast_function_ptr_type().is_some() { | ||||||||||
TypeKind::Function | ||||||||||
} else if typ.is_compatible_with(self.float_type) { | ||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. You'll need to do this:
Suggested change
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 syntax isn't supported.
|
||||||||||
match typ.get_size() { | ||||||||||
2 => TypeKind::Half, | ||||||||||
4 => TypeKind::Float, | ||||||||||
8 => TypeKind::Double, | ||||||||||
16 => TypeKind::FP128, | ||||||||||
size => unreachable!("Floating-point type of size {}", size), | ||||||||||
} | ||||||||||
} else if typ == self.type_void() { | ||||||||||
TypeKind::Void | ||||||||||
} else { | ||||||||||
// TODO(antoyo): support other types. | ||||||||||
unimplemented!(); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
#[cfg(not(feature = "master"))] | ||||||||||
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind { | ||||||||||
if self.is_int_type_or_bool(typ) { | ||||||||||
TypeKind::Integer | ||||||||||
|
@@ -210,6 +266,16 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { | |||||||||
unimplemented!(); | ||||||||||
} | ||||||||||
|
||||||||||
#[cfg(feature = "master")] | ||||||||||
fn float_width(&self, typ: Type<'gcc>) -> usize { | ||||||||||
if typ.is_floating_point() { | ||||||||||
(typ.get_size() * u8::BITS).try_into().unwrap() | ||||||||||
} else { | ||||||||||
panic!("Cannot get width of float type {:?}", typ); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
#[cfg(not(feature = "master"))] | ||||||||||
fn float_width(&self, typ: Type<'gcc>) -> usize { | ||||||||||
let f32 = self.context.new_type::<f32>(); | ||||||||||
let f64 = self.context.new_type::<f64>(); | ||||||||||
|
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.