浏览代码

Remove unused code

Aaron Kutch 4 年之前
父节点
当前提交
6aef025a36
共有 3 个文件被更改,包括 0 次插入221 次删除
  1. 0 12
      src/int/mod.rs
  2. 0 58
      src/int/sdiv.rs
  3. 0 151
      src/int/udiv.rs

+ 0 - 12
src/int/mod.rs

@@ -1,17 +1,5 @@
 use core::ops;
 
-macro_rules! hty {
-    ($ty:ty) => {
-        <$ty as LargeInt>::HighHalf
-    };
-}
-
-macro_rules! os_ty {
-    ($ty:ty) => {
-        <$ty as Int>::OtherSign
-    };
-}
-
 pub mod addsub;
 pub mod leading_zeros;
 pub mod mul;

+ 0 - 58
src/int/sdiv.rs

@@ -1,63 +1,5 @@
 use int::Int;
 
-trait Div: Int {
-    /// Returns `a / b`
-    fn div(self, other: Self) -> Self {
-        let s_a = self >> (Self::BITS - 1);
-        let s_b = other >> (Self::BITS - 1);
-        // NOTE it's OK to overflow here because of the `.unsigned()` below.
-        // This whole operation is computing the absolute value of the inputs
-        // So some overflow will happen when dealing with e.g. `i64::MIN`
-        // where the absolute value is `(-i64::MIN) as u64`
-        let a = (self ^ s_a).wrapping_sub(s_a);
-        let b = (other ^ s_b).wrapping_sub(s_b);
-        let s = s_a ^ s_b;
-
-        let r = a.unsigned().aborting_div(b.unsigned());
-        (Self::from_unsigned(r) ^ s) - s
-    }
-}
-
-impl Div for i32 {}
-impl Div for i64 {}
-impl Div for i128 {}
-
-trait Mod: Int {
-    /// Returns `a % b`
-    fn mod_(self, other: Self) -> Self {
-        let s = other >> (Self::BITS - 1);
-        // NOTE(wrapping_sub) see comment in the `div`
-        let b = (other ^ s).wrapping_sub(s);
-        let s = self >> (Self::BITS - 1);
-        let a = (self ^ s).wrapping_sub(s);
-
-        let r = a.unsigned().aborting_rem(b.unsigned());
-        (Self::from_unsigned(r) ^ s) - s
-    }
-}
-
-impl Mod for i32 {}
-impl Mod for i64 {}
-impl Mod for i128 {}
-
-trait Divmod: Int {
-    /// Returns `a / b` and sets `*rem = n % d`
-    fn divmod<F>(self, other: Self, rem: &mut Self, div: F) -> Self
-    where
-        F: Fn(Self, Self) -> Self,
-    {
-        let r = div(self, other);
-        // NOTE won't overflow because it's using the result from the
-        // previous division
-        *rem = self - r.wrapping_mul(other);
-        r
-    }
-}
-
-impl Divmod for i32 {}
-impl Divmod for i64 {}
-
-
 intrinsics! {
     #[maybe_use_optimized_c_shim]
     #[arm_aeabi_alias = __aeabi_idiv]

+ 0 - 151
src/int/udiv.rs

@@ -1,156 +1,5 @@
 use int::{Int, LargeInt};
 
-macro_rules! udivmod_inner {
-    ($n:expr, $d:expr, $rem:expr, $ty:ty) => {{
-        let (n, d, rem) = ($n, $d, $rem);
-        // NOTE X is unknown, K != 0
-        if n.high() == 0 {
-            if d.high() == 0 {
-                // 0 X
-                // ---
-                // 0 X
-
-                if let Some(rem) = rem {
-                    *rem = <$ty>::from(n.low().aborting_rem(d.low()));
-                }
-                return <$ty>::from(n.low().aborting_div(d.low()))
-            } else {
-                // 0 X
-                // ---
-                // K X
-                if let Some(rem) = rem {
-                    *rem = n;
-                }
-                return 0;
-            };
-        }
-
-        let mut sr;
-        let mut q;
-        let mut r;
-
-        if d.low() == 0 {
-            if d.high() == 0 {
-                // K X
-                // ---
-                // 0 0
-                // NOTE This should be unreachable in safe Rust because the program will panic before
-                // this intrinsic is called
-                ::abort();
-            }
-
-            if n.low() == 0 {
-                // K 0
-                // ---
-                // K 0
-                if let Some(rem) = rem {
-                    *rem = <$ty>::from_parts(0, n.high().aborting_rem(d.high()));
-                }
-                return <$ty>::from(n.high().aborting_div(d.high()))
-            }
-
-            // K K
-            // ---
-            // K 0
-
-            if d.high().is_power_of_two() {
-                if let Some(rem) = rem {
-                    *rem = <$ty>::from_parts(n.low(), n.high() & (d.high() - 1));
-                }
-                return <$ty>::from(n.high() >> d.high().trailing_zeros());
-            }
-
-            sr = d.high().leading_zeros().wrapping_sub(n.high().leading_zeros());
-
-            // D > N
-            if sr > <hty!($ty)>::BITS - 2 {
-                if let Some(rem) = rem {
-                    *rem = n;
-                }
-                return 0;
-            }
-
-            sr += 1;
-
-            // 1 <= sr <= <hty!($ty)>::BITS - 1
-            q = n << (<$ty>::BITS - sr);
-            r = n >> sr;
-        } else if d.high() == 0 {
-            // K X
-            // ---
-            // 0 K
-            if d.low().is_power_of_two() {
-                if let Some(rem) = rem {
-                    *rem = <$ty>::from(n.low() & (d.low() - 1));
-                }
-
-                if d.low() == 1 {
-                    return n;
-                } else {
-                    let sr = d.low().trailing_zeros();
-                    return n >> sr;
-                };
-            }
-
-            sr = 1 + <hty!($ty)>::BITS + d.low().leading_zeros() - n.high().leading_zeros();
-
-            // 2 <= sr <= u64::BITS - 1
-            q = n << (<$ty>::BITS - sr);
-            r = n >> sr;
-        } else {
-            // K X
-            // ---
-            // K K
-            sr = d.high().leading_zeros().wrapping_sub(n.high().leading_zeros());
-
-            // D > N
-            if sr > <hty!($ty)>::BITS - 1 {
-                if let Some(rem) = rem {
-                    *rem = n;
-                }
-                return 0;
-            }
-
-            sr += 1;
-
-            // 1 <= sr <= <hty!($ty)>::BITS
-            q = n << (<$ty>::BITS - sr);
-            r = n >> sr;
-        }
-
-        // Not a special case
-        // q and r are initialized with
-        // q = n << (u64::BITS - sr)
-        // r = n >> sr
-        // 1 <= sr <= u64::BITS - 1
-        let mut carry = 0;
-
-        // Don't use a range because they may generate references to memcpy in unoptimized code
-        let mut i = 0;
-        while i < sr {
-            i += 1;
-
-            // r:q = ((r:q) << 1) | carry
-            r = (r << 1) | (q >> (<$ty>::BITS - 1));
-            q = (q << 1) | carry as $ty;
-
-            // carry = 0
-            // if r >= d {
-            //     r -= d;
-            //     carry = 1;
-            // }
-            let s = (d.wrapping_sub(r).wrapping_sub(1)) as os_ty!($ty) >> (<$ty>::BITS - 1);
-            carry = (s & 1) as hty!($ty);
-            r -= d & s as $ty;
-        }
-
-        if let Some(rem) = rem {
-            *rem = r;
-        }
-        (q << 1) | carry as $ty
-    }}
-}
-
 intrinsics! {
     #[maybe_use_optimized_c_shim]
     #[arm_aeabi_alias = __aeabi_uidiv]