diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-12-11 13:07:11 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-12-21 09:26:21 -0800 |
| commit | cd1848a1a60f40f25019e455b1050efd69707604 (patch) | |
| tree | 951659efd37119d3e132e2f05225cf9b18060c86 /src/libcore/num | |
| parent | e2834a20e7c5bbfb1502f582545153dc6b25a70c (diff) | |
Register new snapshots
Lots of cruft to remove!
Diffstat (limited to 'src/libcore/num')
| -rw-r--r-- | src/libcore/num/bignum.rs | 9 | ||||
| -rw-r--r-- | src/libcore/num/mod.rs | 161 | ||||
| -rw-r--r-- | src/libcore/num/wrapping.rs | 181 |
3 files changed, 1 insertions, 350 deletions
diff --git a/src/libcore/num/bignum.rs b/src/libcore/num/bignum.rs index 5d15ada4e75..66c6deb3615 100644 --- a/src/libcore/num/bignum.rs +++ b/src/libcore/num/bignum.rs @@ -55,15 +55,6 @@ macro_rules! impl_full_ops { ($($ty:ty: add($addfn:path), mul/div($bigty:ident);)*) => ( $( impl FullOps for $ty { - #[cfg(stage0)] - fn full_add(self, other: $ty, carry: bool) -> (bool, $ty) { - // this cannot overflow, the output is between 0 and 2*2^nbits - 1 - // FIXME will LLVM optimize this into ADC or similar??? - let (v, carry1) = unsafe { $addfn(self, other) }; - let (v, carry2) = unsafe { $addfn(v, if carry {1} else {0}) }; - (carry1 || carry2, v) - } - #[cfg(not(stage0))] fn full_add(self, other: $ty, carry: bool) -> (bool, $ty) { // this cannot overflow, the output is between 0 and 2*2^nbits - 1 // FIXME will LLVM optimize this into ADC or similar??? diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 8abb12706a5..f180a513b86 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -115,11 +115,6 @@ macro_rules! zero_one_impl_float { } zero_one_impl_float! { f32 f64 } -// Just for stage0; a byte swap on a byte is a no-op -// Delete this once it becomes unused -#[cfg(stage0)] -unsafe fn bswap8(x: u8) -> u8 { x } - macro_rules! checked_op { ($U:ty, $op:path, $x:expr, $y:expr) => {{ let (result, overflowed) = unsafe { $op($x as $U, $y as $U) }; @@ -785,15 +780,6 @@ macro_rules! int_impl { } #[lang = "i8"] -#[cfg(stage0)] -impl i8 { - int_impl! { i8, u8, 8, - intrinsics::i8_add_with_overflow, - intrinsics::i8_sub_with_overflow, - intrinsics::i8_mul_with_overflow } -} -#[lang = "i8"] -#[cfg(not(stage0))] impl i8 { int_impl! { i8, u8, 8, intrinsics::add_with_overflow, @@ -802,15 +788,6 @@ impl i8 { } #[lang = "i16"] -#[cfg(stage0)] -impl i16 { - int_impl! { i16, u16, 16, - intrinsics::i16_add_with_overflow, - intrinsics::i16_sub_with_overflow, - intrinsics::i16_mul_with_overflow } -} -#[lang = "i16"] -#[cfg(not(stage0))] impl i16 { int_impl! { i16, u16, 16, intrinsics::add_with_overflow, @@ -819,15 +796,6 @@ impl i16 { } #[lang = "i32"] -#[cfg(stage0)] -impl i32 { - int_impl! { i32, u32, 32, - intrinsics::i32_add_with_overflow, - intrinsics::i32_sub_with_overflow, - intrinsics::i32_mul_with_overflow } -} -#[lang = "i32"] -#[cfg(not(stage0))] impl i32 { int_impl! { i32, u32, 32, intrinsics::add_with_overflow, @@ -836,15 +804,6 @@ impl i32 { } #[lang = "i64"] -#[cfg(stage0)] -impl i64 { - int_impl! { i64, u64, 64, - intrinsics::i64_add_with_overflow, - intrinsics::i64_sub_with_overflow, - intrinsics::i64_mul_with_overflow } -} -#[lang = "i64"] -#[cfg(not(stage0))] impl i64 { int_impl! { i64, u64, 64, intrinsics::add_with_overflow, @@ -854,16 +813,6 @@ impl i64 { #[cfg(target_pointer_width = "32")] #[lang = "isize"] -#[cfg(stage0)] -impl isize { - int_impl! { i32, u32, 32, - intrinsics::i32_add_with_overflow, - intrinsics::i32_sub_with_overflow, - intrinsics::i32_mul_with_overflow } -} -#[cfg(target_pointer_width = "32")] -#[lang = "isize"] -#[cfg(not(stage0))] impl isize { int_impl! { i32, u32, 32, intrinsics::add_with_overflow, @@ -873,16 +822,6 @@ impl isize { #[cfg(target_pointer_width = "64")] #[lang = "isize"] -#[cfg(stage0)] -impl isize { - int_impl! { i64, u64, 64, - intrinsics::i64_add_with_overflow, - intrinsics::i64_sub_with_overflow, - intrinsics::i64_mul_with_overflow } -} -#[cfg(target_pointer_width = "64")] -#[lang = "isize"] -#[cfg(not(stage0))] impl isize { int_impl! { i64, u64, 64, intrinsics::add_with_overflow, @@ -980,25 +919,6 @@ macro_rules! uint_impl { unsafe { $ctlz(self as $ActualT) as u32 } } - #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(stage0)] - #[inline] - pub fn trailing_zeros(self) -> u32 { - // As of LLVM 3.6 the codegen for the zero-safe cttz8 intrinsic - // emits two conditional moves on x86_64. By promoting the value to - // u16 and setting bit 8, we get better code without any conditional - // operations. - // FIXME: There's a LLVM patch (http://reviews.llvm.org/D9284) - // pending, remove this workaround once LLVM generates better code - // for cttz8. - unsafe { - if $BITS == 8 { - intrinsics::cttz16(self as u16 | 0x100) as u32 - } else { - $cttz(self as $ActualT) as u32 - } - } - } /// Returns the number of trailing zeros in the binary representation /// of `self`. /// @@ -1012,7 +932,6 @@ macro_rules! uint_impl { /// assert_eq!(n.trailing_zeros(), 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(stage0))] #[inline] pub fn trailing_zeros(self) -> u32 { // As of LLVM 3.6 the codegen for the zero-safe cttz8 intrinsic @@ -1563,19 +1482,6 @@ macro_rules! uint_impl { } #[lang = "u8"] -#[cfg(stage0)] -impl u8 { - uint_impl! { u8, 8, - intrinsics::ctpop8, - intrinsics::ctlz8, - intrinsics::cttz8, - bswap8, - intrinsics::u8_add_with_overflow, - intrinsics::u8_sub_with_overflow, - intrinsics::u8_mul_with_overflow } -} -#[lang = "u8"] -#[cfg(not(stage0))] impl u8 { uint_impl! { u8, 8, intrinsics::ctpop, @@ -1588,19 +1494,6 @@ impl u8 { } #[lang = "u16"] -#[cfg(stage0)] -impl u16 { - uint_impl! { u16, 16, - intrinsics::ctpop16, - intrinsics::ctlz16, - intrinsics::cttz16, - intrinsics::bswap16, - intrinsics::u16_add_with_overflow, - intrinsics::u16_sub_with_overflow, - intrinsics::u16_mul_with_overflow } -} -#[lang = "u16"] -#[cfg(not(stage0))] impl u16 { uint_impl! { u16, 16, intrinsics::ctpop, @@ -1613,19 +1506,6 @@ impl u16 { } #[lang = "u32"] -#[cfg(stage0)] -impl u32 { - uint_impl! { u32, 32, - intrinsics::ctpop32, - intrinsics::ctlz32, - intrinsics::cttz32, - intrinsics::bswap32, - intrinsics::u32_add_with_overflow, - intrinsics::u32_sub_with_overflow, - intrinsics::u32_mul_with_overflow } -} -#[lang = "u32"] -#[cfg(not(stage0))] impl u32 { uint_impl! { u32, 32, intrinsics::ctpop, @@ -1638,19 +1518,6 @@ impl u32 { } #[lang = "u64"] -#[cfg(stage0)] -impl u64 { - uint_impl! { u64, 64, - intrinsics::ctpop64, - intrinsics::ctlz64, - intrinsics::cttz64, - intrinsics::bswap64, - intrinsics::u64_add_with_overflow, - intrinsics::u64_sub_with_overflow, - intrinsics::u64_mul_with_overflow } -} -#[lang = "u64"] -#[cfg(not(stage0))] impl u64 { uint_impl! { u64, 64, intrinsics::ctpop, @@ -1664,20 +1531,6 @@ impl u64 { #[cfg(target_pointer_width = "32")] #[lang = "usize"] -#[cfg(stage0)] -impl usize { - uint_impl! { u32, 32, - intrinsics::ctpop32, - intrinsics::ctlz32, - intrinsics::cttz32, - intrinsics::bswap32, - intrinsics::u32_add_with_overflow, - intrinsics::u32_sub_with_overflow, - intrinsics::u32_mul_with_overflow } -} -#[cfg(target_pointer_width = "32")] -#[lang = "usize"] -#[cfg(not(stage0))] impl usize { uint_impl! { u32, 32, intrinsics::ctpop, @@ -1691,20 +1544,6 @@ impl usize { #[cfg(target_pointer_width = "64")] #[lang = "usize"] -#[cfg(stage0)] -impl usize { - uint_impl! { u64, 64, - intrinsics::ctpop64, - intrinsics::ctlz64, - intrinsics::cttz64, - intrinsics::bswap64, - intrinsics::u64_add_with_overflow, - intrinsics::u64_sub_with_overflow, - intrinsics::u64_mul_with_overflow } -} -#[cfg(target_pointer_width = "64")] -#[lang = "usize"] -#[cfg(not(stage0))] impl usize { uint_impl! { u64, 64, intrinsics::ctpop, diff --git a/src/libcore/num/wrapping.rs b/src/libcore/num/wrapping.rs index 88f71e63da6..a7d5fcafd56 100644 --- a/src/libcore/num/wrapping.rs +++ b/src/libcore/num/wrapping.rs @@ -12,30 +12,7 @@ #![unstable(feature = "wrapping", reason = "may be removed or relocated", issue = "27755")] -#[cfg(stage0)] -pub use intrinsics::{ - u8_add_with_overflow, i8_add_with_overflow, - u16_add_with_overflow, i16_add_with_overflow, - u32_add_with_overflow, i32_add_with_overflow, - u64_add_with_overflow, i64_add_with_overflow, - - u8_sub_with_overflow, i8_sub_with_overflow, - u16_sub_with_overflow, i16_sub_with_overflow, - u32_sub_with_overflow, i32_sub_with_overflow, - u64_sub_with_overflow, i64_sub_with_overflow, - - u8_mul_with_overflow, i8_mul_with_overflow, - u16_mul_with_overflow, i16_mul_with_overflow, - u32_mul_with_overflow, i32_mul_with_overflow, - u64_mul_with_overflow, i64_mul_with_overflow, -}; - -#[cfg(not(stage0))] -pub use intrinsics::{ - add_with_overflow, - sub_with_overflow, - mul_with_overflow, -}; +pub use intrinsics::{add_with_overflow, sub_with_overflow, mul_with_overflow}; use super::Wrapping; @@ -203,42 +180,18 @@ macro_rules! signed_overflowing_impl { ($($t:ident)*) => ($( impl OverflowingOps for $t { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _add_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: $t) -> ($t, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _sub_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: $t) -> ($t, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _mul_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: $t) -> ($t, bool) { unsafe { mul_with_overflow(self, rhs) @@ -289,42 +242,18 @@ macro_rules! unsigned_overflowing_impl { ($($t:ident)*) => ($( impl OverflowingOps for $t { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _add_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: $t) -> ($t, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _sub_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: $t) -> ($t, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _mul_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: $t) -> ($t, bool) { unsafe { mul_with_overflow(self, rhs) @@ -365,45 +294,18 @@ unsigned_overflowing_impl! { u8 u16 u32 u64 } #[cfg(target_pointer_width = "64")] impl OverflowingOps for usize { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u64_add_with_overflow(self as u64, rhs as u64); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: usize) -> (usize, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u64_sub_with_overflow(self as u64, rhs as u64); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: usize) -> (usize, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u64_mul_with_overflow(self as u64, rhs as u64); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: usize) -> (usize, bool) { unsafe { mul_with_overflow(self, rhs) @@ -439,45 +341,18 @@ impl OverflowingOps for usize { #[cfg(target_pointer_width = "32")] impl OverflowingOps for usize { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u32_add_with_overflow(self as u32, rhs as u32); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: usize) -> (usize, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u32_sub_with_overflow(self as u32, rhs as u32); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: usize) -> (usize, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u32_mul_with_overflow(self as u32, rhs as u32); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: usize) -> (usize, bool) { unsafe { mul_with_overflow(self, rhs) @@ -513,45 +388,18 @@ impl OverflowingOps for usize { #[cfg(target_pointer_width = "64")] impl OverflowingOps for isize { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i64_add_with_overflow(self as i64, rhs as i64); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: isize) -> (isize, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i64_sub_with_overflow(self as i64, rhs as i64); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: isize) -> (isize, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i64_mul_with_overflow(self as i64, rhs as i64); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: isize) -> (isize, bool) { unsafe { mul_with_overflow(self, rhs) @@ -587,45 +435,18 @@ impl OverflowingOps for isize { #[cfg(target_pointer_width = "32")] impl OverflowingOps for isize { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i32_add_with_overflow(self as i32, rhs as i32); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: isize) -> (isize, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i32_sub_with_overflow(self as i32, rhs as i32); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: isize) -> (isize, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i32_mul_with_overflow(self as i32, rhs as i32); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: isize) -> (isize, bool) { unsafe { mul_with_overflow(self, rhs) |
