Skip to content

Commit dc7d7d2

Browse files
committed
add support for quadruple precision floating point
This currently requires linking against a library like libquadmath (or libgcc), because compiler-rt barely has any support for this and most hardware does not yet have 128-bit precision floating point. For this reason, it's currently hidden behind a feature gate. When compiler-rt is updated to trunk, some tests can be added for constant evaluation since there will be support for the comparison operators. Closes #13381
1 parent 09bfb92 commit dc7d7d2

File tree

21 files changed

+81
-10
lines changed

21 files changed

+81
-10
lines changed

src/libhexfloat/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) ->
105105
Some(Ident{ident, span}) => match token::get_ident(ident).get() {
106106
"f32" => Some(ast::TyF32),
107107
"f64" => Some(ast::TyF64),
108+
"f128" => Some(ast::TyF128),
108109
_ => {
109110
cx.span_err(span, "invalid floating point type in hexfloat!");
110111
None

src/librustc/front/feature_gate.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
5757
("linkage", Active),
5858
("struct_inherit", Active),
5959

60+
("quad_precision_float", Active),
61+
6062
// These are used to test this portion of the compiler, they don't actually
6163
// mean anything
6264
("test_accepted_feature", Accepted),
@@ -77,13 +79,15 @@ enum Status {
7779

7880
/// A set of features to be used by later passes.
7981
pub struct Features {
80-
pub default_type_params: Cell<bool>
82+
pub default_type_params: Cell<bool>,
83+
pub quad_precision_float: Cell<bool>
8184
}
8285

8386
impl Features {
8487
pub fn new() -> Features {
8588
Features {
86-
default_type_params: Cell::new(false)
89+
default_type_params: Cell::new(false),
90+
quad_precision_float: Cell::new(false)
8791
}
8892
}
8993
}
@@ -364,4 +368,5 @@ pub fn check_crate(sess: &Session, krate: &ast::Crate) {
364368
sess.abort_if_errors();
365369

366370
sess.features.default_type_params.set(cx.has_feature("default_type_params"));
371+
sess.features.quad_precision_float.set(cx.has_feature("quad_precision_float"));
367372
}

src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
317317
'D' => return ty::mk_mach_int(ast::TyI64),
318318
'f' => return ty::mk_mach_float(ast::TyF32),
319319
'F' => return ty::mk_mach_float(ast::TyF64),
320+
'Q' => return ty::mk_mach_float(ast::TyF128),
320321
_ => fail!("parse_ty: bad numeric type")
321322
}
322323
}

src/librustc/metadata/tyencode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
236236
match t {
237237
TyF32 => mywrite!(w, "Mf"),
238238
TyF64 => mywrite!(w, "MF"),
239+
TyF128 => mywrite!(w, "MQ")
239240
}
240241
}
241242
ty::ty_enum(def, ref substs) => {

src/librustc/middle/resolve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ fn PrimitiveTypeTable() -> PrimitiveTypeTable {
772772
table.intern("char", TyChar);
773773
table.intern("f32", TyFloat(TyF32));
774774
table.intern("f64", TyFloat(TyF64));
775+
table.intern("f128", TyFloat(TyF128));
775776
table.intern("int", TyInt(TyI));
776777
table.intern("i8", TyInt(TyI8));
777778
table.intern("i16", TyInt(TyI16));

src/librustc/middle/trans/debuginfo.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,8 @@ fn basic_type_metadata(cx: &CrateContext, t: ty::t) -> DIType {
11701170
},
11711171
ty::ty_float(float_ty) => match float_ty {
11721172
ast::TyF32 => ("f32".to_owned(), DW_ATE_float),
1173-
ast::TyF64 => ("f64".to_owned(), DW_ATE_float)
1173+
ast::TyF64 => ("f64".to_owned(), DW_ATE_float),
1174+
ast::TyF128 => ("f128".to_owned(), DW_ATE_float)
11741175
},
11751176
_ => cx.sess().bug("debuginfo::basic_type_metadata - t is invalid type")
11761177
};

src/librustc/middle/trans/reflect.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ impl<'a, 'b> Reflector<'a, 'b> {
163163
ty::ty_uint(ast::TyU64) => self.leaf("u64"),
164164
ty::ty_float(ast::TyF32) => self.leaf("f32"),
165165
ty::ty_float(ast::TyF64) => self.leaf("f64"),
166+
ty::ty_float(ast::TyF128) => self.leaf("f128"),
166167

167168
// Should rename to str_*/vec_*.
168169
ty::ty_str(vst) => {

src/librustc/middle/trans/type_.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ impl Type {
8888
ty!(llvm::LLVMDoubleTypeInContext(ccx.llcx))
8989
}
9090

91+
pub fn f128(ccx: &CrateContext) -> Type {
92+
ty!(llvm::LLVMFP128TypeInContext(ccx.llcx))
93+
}
94+
9195
pub fn bool(ccx: &CrateContext) -> Type {
9296
Type::i8(ccx)
9397
}
@@ -130,7 +134,8 @@ impl Type {
130134
pub fn float_from_ty(ccx: &CrateContext, t: ast::FloatTy) -> Type {
131135
match t {
132136
ast::TyF32 => Type::f32(ccx),
133-
ast::TyF64 => Type::f64(ccx)
137+
ast::TyF64 => Type::f64(ccx),
138+
ast::TyF128 => Type::f128(ccx)
134139
}
135140
}
136141

src/librustc/middle/ty.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ mod primitives {
706706
def_prim_ty!(TY_U64, super::ty_uint(ast::TyU64), 12)
707707
def_prim_ty!(TY_F32, super::ty_float(ast::TyF32), 14)
708708
def_prim_ty!(TY_F64, super::ty_float(ast::TyF64), 15)
709+
def_prim_ty!(TY_F128, super::ty_float(ast::TyF128), 16)
709710

710711
pub static TY_BOT: t_box_ = t_box_ {
711712
sty: super::ty_bot,
@@ -1305,6 +1306,9 @@ pub fn mk_f32() -> t { mk_prim_t(&primitives::TY_F32) }
13051306
#[inline]
13061307
pub fn mk_f64() -> t { mk_prim_t(&primitives::TY_F64) }
13071308

1309+
#[inline]
1310+
pub fn mk_f128() -> t { mk_prim_t(&primitives::TY_F128) }
1311+
13081312
#[inline]
13091313
pub fn mk_uint() -> t { mk_prim_t(&primitives::TY_UINT) }
13101314

@@ -1344,6 +1348,7 @@ pub fn mk_mach_float(tm: ast::FloatTy) -> t {
13441348
match tm {
13451349
ast::TyF32 => mk_f32(),
13461350
ast::TyF64 => mk_f64(),
1351+
ast::TyF128 => mk_f128()
13471352
}
13481353
}
13491354

src/librustc/middle/typeck/astconv.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ pub fn ast_ty_to_prim_ty(tcx: &ty::ctxt, ast_ty: &ast::Ty) -> Option<ty::t> {
341341
Some(ty::mk_mach_uint(uit))
342342
}
343343
ast::TyFloat(ft) => {
344+
if ft == ast::TyF128 && !tcx.sess.features.quad_precision_float.get() {
345+
tcx.sess.span_err(path.span, "quadruple precision floats are \
346+
missing complete runtime support");
347+
tcx.sess.span_note(path.span, "add \
348+
#[feature(quad_precision_float)] \
349+
to the crate attributes to enable");
350+
}
344351
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
345352
Some(ty::mk_mach_float(ft))
346353
}

0 commit comments

Comments
 (0)