Skip to content

Commit d0977e3

Browse files
author
Robert Zakrzewski
committed
Add support for Float16, Float32, Float64 and Float128
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
1 parent a63b83e commit d0977e3

File tree

4 files changed

+90
-8
lines changed

4 files changed

+90
-8
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libgccjit.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b6f163f52
1+
ac1853f579dbfdc53f2c22317e673ae99686eca2

src/builder.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,24 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
748748
// FIXME(antoyo): this seems to produce the wrong result.
749749
return self.context.new_call(self.location, fmodf, &[a, b]);
750750
}
751+
752+
#[cfg(feature = "master")]
753+
match self.cx.type_kind(a_type) {
754+
TypeKind::Half | TypeKind::Float => {
755+
let fmodf = self.context.get_builtin_function("fmodf");
756+
return self.context.new_call(self.location, fmodf, &[a, b]);
757+
}
758+
TypeKind::Double => {
759+
let fmod = self.context.get_builtin_function("fmod");
760+
return self.context.new_call(self.location, fmod, &[a, b]);
761+
}
762+
TypeKind::FP128 => {
763+
let fmodl = self.context.get_builtin_function("fmodl");
764+
return self.context.new_call(self.location, fmodl, &[a, b]);
765+
}
766+
_ => (),
767+
}
768+
751769
if let Some(vector_type) = a_type_unqualified.dyncast_vector() {
752770
assert_eq!(a_type_unqualified, b.get_type().unqualified());
753771

src/type_.rs

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use gccjit::{RValue, Struct, Type};
1+
use std::convert::TryInto;
2+
3+
use gccjit::{CType, RValue, Struct, Type};
24
use rustc_codegen_ssa::common::TypeKind;
35
use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods, TypeMembershipMethods};
46
use rustc_middle::ty::layout::TyAndLayout;
@@ -120,10 +122,28 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
120122
self.isize_type
121123
}
122124

125+
#[cfg(feature = "master")]
126+
fn type_f16(&self) -> Type<'gcc> {
127+
if self.context.get_target_info().supports_target_dependent_type(CType::Float16) {
128+
return self.context.new_c_type(CType::Float16);
129+
}
130+
unimplemented!("f16")
131+
}
132+
133+
#[cfg(not(feature = "master"))]
123134
fn type_f16(&self) -> Type<'gcc> {
124-
unimplemented!("f16_f128")
135+
unimplemented!("f16")
136+
}
137+
138+
#[cfg(feature = "master")]
139+
fn type_f32(&self) -> Type<'gcc> {
140+
if self.context.get_target_info().supports_target_dependent_type(CType::Float32) {
141+
return self.context.new_c_type(CType::Float32);
142+
}
143+
self.float_type
125144
}
126145

146+
#[cfg(not(feature = "master"))]
127147
fn type_f32(&self) -> Type<'gcc> {
128148
self.float_type
129149
}
@@ -132,8 +152,17 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
132152
self.double_type
133153
}
134154

155+
#[cfg(feature = "master")]
156+
fn type_f128(&self) -> Type<'gcc> {
157+
if self.context.get_target_info().supports_target_dependent_type(CType::Float128) {
158+
return self.context.new_c_type(CType::Float128);
159+
}
160+
unimplemented!("f128")
161+
}
162+
163+
#[cfg(not(feature = "master"))]
135164
fn type_f128(&self) -> Type<'gcc> {
136-
unimplemented!("f16_f128")
165+
unimplemented!("f128")
137166
}
138167

139168
fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc> {
@@ -161,6 +190,31 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
161190
typ
162191
}
163192

193+
#[cfg(feature = "master")]
194+
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind {
195+
if self.is_int_type_or_bool(typ) {
196+
TypeKind::Integer
197+
} else if typ.is_compatible_with(self.float_type) {
198+
TypeKind::Float
199+
} else if typ.is_compatible_with(self.double_type) {
200+
TypeKind::Double
201+
} else if typ.is_vector() {
202+
TypeKind::Vector
203+
} else if typ.is_floating_point() {
204+
match typ.get_size() {
205+
2 => TypeKind::Half,
206+
4 => TypeKind::Float,
207+
8 => TypeKind::Double,
208+
16 => TypeKind::FP128,
209+
_ => TypeKind::Void,
210+
}
211+
} else {
212+
// TODO(antoyo): support other types.
213+
TypeKind::Void
214+
}
215+
}
216+
217+
#[cfg(not(feature = "master"))]
164218
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind {
165219
if self.is_int_type_or_bool(typ) {
166220
TypeKind::Integer
@@ -210,6 +264,16 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
210264
unimplemented!();
211265
}
212266

267+
#[cfg(feature = "master")]
268+
fn float_width(&self, typ: Type<'gcc>) -> usize {
269+
if typ.is_floating_point() {
270+
(typ.get_size() * u8::BITS).try_into().unwrap()
271+
} else {
272+
panic!("Cannot get width of float type {:?}", typ);
273+
}
274+
}
275+
276+
#[cfg(not(feature = "master"))]
213277
fn float_width(&self, typ: Type<'gcc>) -> usize {
214278
let f32 = self.context.new_type::<f32>();
215279
let f64 = self.context.new_type::<f64>();

0 commit comments

Comments
 (0)