Skip to content

Commit 1f611c5

Browse files
committed
Make floating point optional depending on target_has_floating_point
1 parent 2cef818 commit 1f611c5

File tree

7 files changed

+74
-26
lines changed

7 files changed

+74
-26
lines changed

src/libcore/clone.rs

+2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ clone_impl! { u16 }
105105
clone_impl! { u32 }
106106
clone_impl! { u64 }
107107

108+
#[cfg(any(stage0, target_has_floating_point))]
108109
clone_impl! { f32 }
110+
#[cfg(any(stage0, target_has_floating_point))]
109111
clone_impl! { f64 }
110112

111113
clone_impl! { () }

src/libcore/default.rs

+2
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,7 @@ default_impl! { i16, 0 }
160160
default_impl! { i32, 0 }
161161
default_impl! { i64, 0 }
162162

163+
#[cfg(any(stage0, target_has_floating_point))]
163164
default_impl! { f32, 0.0f32 }
165+
#[cfg(any(stage0, target_has_floating_point))]
164166
default_impl! { f64, 0.0f64 }

src/libcore/fmt/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use prelude::v1::*;
1717
use cell::{UnsafeCell, Cell, RefCell, Ref, RefMut, BorrowState};
1818
use marker::PhantomData;
1919
use mem;
20+
#[cfg(any(stage0, target_has_floating_point))]
2021
use num::flt2dec;
2122
use ops::Deref;
2223
use result;
@@ -1023,6 +1024,7 @@ impl<'a> Formatter<'a> {
10231024
/// Takes the formatted parts and applies the padding.
10241025
/// Assumes that the caller already has rendered the parts with required precision,
10251026
/// so that `self.precision` can be ignored.
1027+
#[cfg(any(stage0, target_has_floating_point))]
10261028
fn pad_formatted_parts(&mut self, formatted: &flt2dec::Formatted) -> Result {
10271029
if let Some(mut width) = self.width {
10281030
// for the sign-aware zero padding, we render the sign first and
@@ -1059,6 +1061,7 @@ impl<'a> Formatter<'a> {
10591061
}
10601062
}
10611063

1064+
#[cfg(any(stage0, target_has_floating_point))]
10621065
fn write_formatted_parts(&mut self, formatted: &flt2dec::Formatted) -> Result {
10631066
fn write_bytes(buf: &mut Write, s: &[u8]) -> Result {
10641067
buf.write_str(unsafe { str::from_utf8_unchecked(s) })
@@ -1448,6 +1451,7 @@ impl<'a, T: ?Sized> Pointer for &'a mut T {
14481451
}
14491452

14501453
// Common code of floating point Debug and Display.
1454+
#[cfg(any(stage0, target_has_floating_point))]
14511455
fn float_to_decimal_common<T>(fmt: &mut Formatter, num: &T, negative_zero: bool) -> Result
14521456
where T: flt2dec::DecodableFloat
14531457
{
@@ -1472,6 +1476,7 @@ fn float_to_decimal_common<T>(fmt: &mut Formatter, num: &T, negative_zero: bool)
14721476
}
14731477

14741478
// Common code of floating point LowerExp and UpperExp.
1479+
#[cfg(any(stage0, target_has_floating_point))]
14751480
fn float_to_exponential_common<T>(fmt: &mut Formatter, num: &T, upper: bool) -> Result
14761481
where T: flt2dec::DecodableFloat
14771482
{
@@ -1524,7 +1529,9 @@ macro_rules! floating { ($ty:ident) => {
15241529
}
15251530
}
15261531
} }
1532+
#[cfg(any(stage0, target_has_floating_point))]
15271533
floating! { f32 }
1534+
#[cfg(any(stage0, target_has_floating_point))]
15281535
floating! { f64 }
15291536

15301537
// Implementation of Display/Debug for various core types

src/libcore/intrinsics.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,10 @@ extern "rust-intrinsic" {
448448
pub fn volatile_load<T>(src: *const T) -> T;
449449
/// Perform a volatile store to the `dst` pointer.
450450
pub fn volatile_store<T>(dst: *mut T, val: T);
451+
}
451452

453+
#[cfg(any(stage0, target_has_floating_point))]
454+
extern "rust-intrinsic" {
452455
/// Returns the square root of an `f32`
453456
pub fn sqrtf32(x: f32) -> f32;
454457
/// Returns the square root of an `f64`
@@ -570,8 +573,9 @@ extern "rust-intrinsic" {
570573
/// May assume inputs are finite.
571574
#[cfg(not(stage0))]
572575
pub fn frem_fast<T>(a: T, b: T) -> T;
576+
}
573577

574-
578+
extern "rust-intrinsic" {
575579
/// Returns the number of bits set in an integer type `T`
576580
pub fn ctpop<T>(x: T) -> T;
577581

src/libcore/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#![feature(staged_api)]
7979
#![feature(unboxed_closures)]
8080
#![feature(question_mark)]
81+
#![cfg_attr(not(stage0), feature(cfg_target_has_floating_point))]
8182

8283
#[macro_use]
8384
mod macros;
@@ -106,7 +107,9 @@ mod uint_macros;
106107
#[path = "num/u32.rs"] pub mod u32;
107108
#[path = "num/u64.rs"] pub mod u64;
108109

110+
#[cfg(any(stage0, target_has_floating_point))]
109111
#[path = "num/f32.rs"] pub mod f32;
112+
#[cfg(any(stage0, target_has_floating_point))]
110113
#[path = "num/f64.rs"] pub mod f64;
111114

112115
#[macro_use]

src/libcore/num/mod.rs

+26-16
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);
4444
mod wrapping;
4545

4646
// All these modules are technically private and only exposed for libcoretest:
47+
#[cfg(any(stage0, target_has_floating_point))]
4748
pub mod flt2dec;
49+
#[cfg(any(stage0, target_has_floating_point))]
4850
pub mod dec2flt;
4951
pub mod bignum;
5052
pub mod diy_float;
@@ -111,6 +113,7 @@ macro_rules! zero_one_impl_float {
111113
}
112114
)*)
113115
}
116+
#[cfg(any(stage0, target_has_floating_point))]
114117
zero_one_impl_float! { f32 f64 }
115118

116119
macro_rules! checked_op {
@@ -2213,6 +2216,7 @@ pub enum FpCategory {
22132216
#[unstable(feature = "core_float",
22142217
reason = "stable interface is via `impl f{32,64}` in later crates",
22152218
issue = "32110")]
2219+
#[cfg(any(stage0, target_has_floating_point))]
22162220
pub trait Float: Sized {
22172221
/// Returns the NaN value.
22182222
#[unstable(feature = "float_extras", reason = "needs removal",
@@ -2451,6 +2455,7 @@ impl fmt::Display for ParseIntError {
24512455
}
24522456

24532457
#[stable(feature = "rust1", since = "1.0.0")]
2458+
#[cfg(any(stage0, target_has_floating_point))]
24542459
pub use num::dec2flt::ParseFloatError;
24552460

24562461
// Conversion traits for primitive integer and float types
@@ -2498,19 +2503,24 @@ impl_from! { u32, i64 }
24982503
// they fit in the significand, which is 24 bits in f32 and 53 bits in f64.
24992504
// Lossy float conversions are not implemented at this time.
25002505

2501-
// Signed -> Float
2502-
impl_from! { i8, f32 }
2503-
impl_from! { i8, f64 }
2504-
impl_from! { i16, f32 }
2505-
impl_from! { i16, f64 }
2506-
impl_from! { i32, f64 }
2507-
2508-
// Unsigned -> Float
2509-
impl_from! { u8, f32 }
2510-
impl_from! { u8, f64 }
2511-
impl_from! { u16, f32 }
2512-
impl_from! { u16, f64 }
2513-
impl_from! { u32, f64 }
2514-
2515-
// Float -> Float
2516-
impl_from! { f32, f64 }
2506+
#[cfg(any(stage0, target_has_floating_point))]
2507+
mod _int_float_conv {
2508+
use convert::From;
2509+
2510+
// Signed -> Float
2511+
impl_from! { i8, f32 }
2512+
impl_from! { i8, f64 }
2513+
impl_from! { i16, f32 }
2514+
impl_from! { i16, f64 }
2515+
impl_from! { i32, f64 }
2516+
2517+
// Unsigned -> Float
2518+
impl_from! { u8, f32 }
2519+
impl_from! { u8, f64 }
2520+
impl_from! { u16, f32 }
2521+
impl_from! { u16, f64 }
2522+
impl_from! { u32, f64 }
2523+
2524+
// Float -> Float
2525+
impl_from! { f32, f64 }
2526+
}

src/libcore/ops.rs

+29-9
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ macro_rules! add_impl {
215215
)*)
216216
}
217217

218-
add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
218+
add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
219+
#[cfg(any(stage0, target_has_floating_point))]
220+
add_impl! { f32 f64 }
219221

220222
/// The `Sub` trait is used to specify the functionality of `-`.
221223
///
@@ -268,7 +270,9 @@ macro_rules! sub_impl {
268270
)*)
269271
}
270272

271-
sub_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
273+
sub_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
274+
#[cfg(any(stage0, target_has_floating_point))]
275+
sub_impl! { f32 f64 }
272276

273277
/// The `Mul` trait is used to specify the functionality of `*`.
274278
///
@@ -321,7 +325,9 @@ macro_rules! mul_impl {
321325
)*)
322326
}
323327

324-
mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
328+
mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
329+
#[cfg(any(stage0, target_has_floating_point))]
330+
mul_impl! { f32 f64 }
325331

326332
/// The `Div` trait is used to specify the functionality of `/`.
327333
///
@@ -392,6 +398,7 @@ macro_rules! div_impl_float {
392398
)*)
393399
}
394400

401+
#[cfg(any(stage0, target_has_floating_point))]
395402
div_impl_float! { f32 f64 }
396403

397404
/// The `Rem` trait is used to specify the functionality of `%`.
@@ -463,6 +470,7 @@ macro_rules! rem_impl_float {
463470
)*)
464471
}
465472

473+
#[cfg(any(stage0, target_has_floating_point))]
466474
rem_impl_float! { f32 f64 }
467475

468476
/// The `Neg` trait is used to specify the functionality of unary `-`.
@@ -530,7 +538,9 @@ macro_rules! neg_impl_unsigned {
530538
}
531539

532540
// neg_impl_unsigned! { usize u8 u16 u32 u64 }
533-
neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 }
541+
neg_impl_numeric! { isize i8 i16 i32 i64 }
542+
#[cfg(any(stage0, target_has_floating_point))]
543+
neg_impl_numeric! { f32 f64 }
534544

535545
/// The `Not` trait is used to specify the functionality of unary `!`.
536546
///
@@ -928,7 +938,9 @@ macro_rules! add_assign_impl {
928938
)+)
929939
}
930940

931-
add_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
941+
add_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
942+
#[cfg(any(stage0, target_has_floating_point))]
943+
add_assign_impl! { f32 f64 }
932944

933945
/// The `SubAssign` trait is used to specify the functionality of `-=`.
934946
///
@@ -972,7 +984,9 @@ macro_rules! sub_assign_impl {
972984
)+)
973985
}
974986

975-
sub_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
987+
sub_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
988+
#[cfg(any(stage0, target_has_floating_point))]
989+
sub_assign_impl! { f32 f64 }
976990

977991
/// The `MulAssign` trait is used to specify the functionality of `*=`.
978992
///
@@ -1016,7 +1030,9 @@ macro_rules! mul_assign_impl {
10161030
)+)
10171031
}
10181032

1019-
mul_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
1033+
mul_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
1034+
#[cfg(any(stage0, target_has_floating_point))]
1035+
mul_assign_impl! { f32 f64 }
10201036

10211037
/// The `DivAssign` trait is used to specify the functionality of `/=`.
10221038
///
@@ -1060,7 +1076,9 @@ macro_rules! div_assign_impl {
10601076
)+)
10611077
}
10621078

1063-
div_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
1079+
div_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
1080+
#[cfg(any(stage0, target_has_floating_point))]
1081+
div_assign_impl! { f32 f64 }
10641082

10651083
/// The `RemAssign` trait is used to specify the functionality of `%=`.
10661084
///
@@ -1104,7 +1122,9 @@ macro_rules! rem_assign_impl {
11041122
)+)
11051123
}
11061124

1107-
rem_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
1125+
rem_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
1126+
#[cfg(any(stage0, target_has_floating_point))]
1127+
rem_assign_impl! { f32 f64 }
11081128

11091129
/// The `BitAndAssign` trait is used to specify the functionality of `&=`.
11101130
///

0 commit comments

Comments
 (0)