Skip to content

Commit bcc3e8c

Browse files
committed
auto merge of #13415 : thestinger/rust/f128, r=alexcrichton
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
2 parents 3ec3c09 + dc7d7d2 commit bcc3e8c

File tree

21 files changed

+81
-10
lines changed

21 files changed

+81
-10
lines changed

src/libhexfloat/lib.rs

+1
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

+7-2
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

+1
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

+1
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

+1
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

+2-1
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

+1
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

+6-1
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

+5
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

+7
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
}

src/librustdoc/html/format.rs

+1
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ impl fmt::Show for clean::Type {
332332
ast::TyUint(ast::TyU64) => "u64",
333333
ast::TyFloat(ast::TyF32) => "f32",
334334
ast::TyFloat(ast::TyF64) => "f64",
335+
ast::TyFloat(ast::TyF128) => "f128",
335336
ast::TyStr => "str",
336337
ast::TyBool => "bool",
337338
ast::TyChar => "char",

src/libstd/intrinsics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ pub trait TyVisitor {
9595

9696
fn visit_f32(&mut self) -> bool;
9797
fn visit_f64(&mut self) -> bool;
98+
#[cfg(not(stage0))]
99+
fn visit_f128(&mut self) -> bool;
98100

99101
fn visit_char(&mut self) -> bool;
100102

src/libstd/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@
5252
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
5353
html_root_url = "http://static.rust-lang.org/doc/master")]
5454
#![feature(macro_rules, globs, asm, managed_boxes, thread_local, link_args,
55-
simd, linkage, default_type_params, phase, concat_idents)]
55+
simd, linkage, default_type_params, phase, concat_idents, quad_precision_float)]
5656

5757
// Don't link to std. We are std.
5858
#![no_std]
5959

60+
// NOTE: remove after snapshot
61+
#![allow(unknown_features)]
6062
#![deny(missing_doc)]
6163

6264
// When testing libstd, bring in libuv as the I/O backend so tests can print

src/libstd/reflect.rs

+8
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
176176
true
177177
}
178178

179+
#[cfg(not(stage0))]
180+
fn visit_f128(&mut self) -> bool {
181+
self.align_to::<f128>();
182+
if ! self.inner.visit_f128() { return false; }
183+
self.bump_past::<f128>();
184+
true
185+
}
186+
179187
fn visit_char(&mut self) -> bool {
180188
self.align_to::<char>();
181189
if ! self.inner.visit_char() { return false; }

src/libstd/repr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
280280

281281
fn visit_f32(&mut self) -> bool { self.write::<f32>() }
282282
fn visit_f64(&mut self) -> bool { self.write::<f64>() }
283+
#[cfg(not(stage0))]
284+
fn visit_f128(&mut self) -> bool { fail!("not implemented") }
283285

284286
fn visit_char(&mut self) -> bool {
285287
self.get::<char>(|this, &ch| {

src/libsyntax/ast.rs

+1
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ impl fmt::Show for UintTy {
730730
pub enum FloatTy {
731731
TyF32,
732732
TyF64,
733+
TyF128
733734
}
734735

735736
impl fmt::Show for FloatTy {

src/libsyntax/ast_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub fn uint_ty_max(t: UintTy) -> u64 {
187187
}
188188

189189
pub fn float_ty_to_str(t: FloatTy) -> ~str {
190-
match t { TyF32 => "f32".to_owned(), TyF64 => "f64".to_owned() }
190+
match t { TyF32 => "f32".to_owned(), TyF64 => "f64".to_owned(), TyF128 => "f128".to_owned() }
191191
}
192192

193193
pub fn is_call_expr(e: @Expr) -> bool {

src/libsyntax/ext/quote.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
436436
LIT_FLOAT(fident, fty) => {
437437
let s_fty = match fty {
438438
ast::TyF32 => "TyF32".to_owned(),
439-
ast::TyF64 => "TyF64".to_owned()
439+
ast::TyF64 => "TyF64".to_owned(),
440+
ast::TyF128 => "TyF128".to_owned()
440441
};
441442
let e_fty = cx.expr_ident(sp, id_ext(s_fty));
442443

src/libsyntax/parse/lexer.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,15 @@ fn scan_number(c: char, rdr: &mut StringReader) -> token::Token {
593593
/* FIXME (#2252): if this is out of range for either a
594594
32-bit or 64-bit float, it won't be noticed till the
595595
back-end. */
596-
} else {
597-
fatal_span(rdr, start_bpos, rdr.last_pos,
598-
"expected `f32` or `f64` suffix".to_owned());
596+
} else if c == '1' && n == '2' && nextnextch(rdr).unwrap_or('\x00') == '8' {
597+
bump(rdr);
598+
bump(rdr);
599+
bump(rdr);
600+
check_float_base(rdr, start_bpos, rdr.last_pos, base);
601+
return token::LIT_FLOAT(str_to_ident(num_str.as_slice()), ast::TyF128);
599602
}
603+
fatal_span(rdr, start_bpos, rdr.last_pos,
604+
"expected `f32`, `f64` or `f128` suffix".to_owned());
600605
}
601606
if is_float {
602607
check_float_base(rdr, start_bpos, rdr.last_pos, base);
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(quad_precision_float)]
12+
13+
static x: f128 = 1.0 + 2.0;
14+
15+
fn foo(a: f128) -> f128 { a }
16+
17+
pub fn main() {
18+
let y = x;
19+
foo(y);
20+
}

src/test/run-pass/reflect-visit-type.rs

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ impl TyVisitor for MyVisitor {
5858

5959
fn visit_f32(&mut self) -> bool { true }
6060
fn visit_f64(&mut self) -> bool { true }
61+
fn visit_f128(&mut self) -> bool { true }
6162

6263
fn visit_char(&mut self) -> bool { true }
6364

0 commit comments

Comments
 (0)