Skip to content

Commit 30b6b45

Browse files
committed
remove unneeded code
1 parent 20c567c commit 30b6b45

File tree

3 files changed

+0
-220
lines changed

3 files changed

+0
-220
lines changed

src/int/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
use core::ops;
22

3-
macro_rules! hty {
4-
($ty:ty) => {
5-
<$ty as LargeInt>::HighHalf
6-
};
7-
}
8-
9-
macro_rules! os_ty {
10-
($ty:ty) => {
11-
<$ty as Int>::OtherSign
12-
};
13-
}
14-
153
pub mod addsub;
164
pub mod mul;
175
pub mod shift;

src/int/sdiv.rs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,5 @@
1-
use int::Int;
21
use super::specialized_div_rem::*;
32

4-
trait Div: Int {
5-
/// Returns `a / b`
6-
fn div(self, other: Self) -> Self {
7-
let s_a = self >> (Self::BITS - 1);
8-
let s_b = other >> (Self::BITS - 1);
9-
// NOTE it's OK to overflow here because of the `.unsigned()` below.
10-
// This whole operation is computing the absolute value of the inputs
11-
// So some overflow will happen when dealing with e.g. `i64::MIN`
12-
// where the absolute value is `(-i64::MIN) as u64`
13-
let a = (self ^ s_a).wrapping_sub(s_a);
14-
let b = (other ^ s_b).wrapping_sub(s_b);
15-
let s = s_a ^ s_b;
16-
17-
let r = a.unsigned().aborting_div(b.unsigned());
18-
(Self::from_unsigned(r) ^ s) - s
19-
}
20-
}
21-
22-
impl Div for i32 {}
23-
impl Div for i64 {}
24-
impl Div for i128 {}
25-
26-
trait Mod: Int {
27-
/// Returns `a % b`
28-
fn mod_(self, other: Self) -> Self {
29-
let s = other >> (Self::BITS - 1);
30-
// NOTE(wrapping_sub) see comment in the `div`
31-
let b = (other ^ s).wrapping_sub(s);
32-
let s = self >> (Self::BITS - 1);
33-
let a = (self ^ s).wrapping_sub(s);
34-
35-
let r = a.unsigned().aborting_rem(b.unsigned());
36-
(Self::from_unsigned(r) ^ s) - s
37-
}
38-
}
39-
40-
impl Mod for i32 {}
41-
impl Mod for i64 {}
42-
impl Mod for i128 {}
43-
44-
trait Divmod: Int {
45-
/// Returns `a / b` and sets `*rem = n % d`
46-
fn divmod<F>(self, other: Self, rem: &mut Self, div: F) -> Self
47-
where
48-
F: Fn(Self, Self) -> Self,
49-
{
50-
let r = div(self, other);
51-
// NOTE won't overflow because it's using the result from the
52-
// previous division
53-
*rem = self - r.wrapping_mul(other);
54-
r
55-
}
56-
}
57-
58-
impl Divmod for i32 {}
59-
impl Divmod for i64 {}
603
// NOTE: there are aborts inside the specialized_div_rem functions if division by 0
614
// is encountered, however these should be unreachable and optimized away unless
625
// uses of `std/core::intrinsics::unchecked_div/rem` do not have a 0 check in front

src/int/udiv.rs

Lines changed: 0 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,5 @@
1-
use int::{Int, LargeInt};
21
use super::specialized_div_rem::*;
32

4-
macro_rules! udivmod_inner {
5-
($n:expr, $d:expr, $rem:expr, $ty:ty) => {{
6-
let (n, d, rem) = ($n, $d, $rem);
7-
// NOTE X is unknown, K != 0
8-
if n.high() == 0 {
9-
if d.high() == 0 {
10-
// 0 X
11-
// ---
12-
// 0 X
13-
14-
if let Some(rem) = rem {
15-
*rem = <$ty>::from(n.low().aborting_rem(d.low()));
16-
}
17-
return <$ty>::from(n.low().aborting_div(d.low()))
18-
} else {
19-
// 0 X
20-
// ---
21-
// K X
22-
if let Some(rem) = rem {
23-
*rem = n;
24-
}
25-
return 0;
26-
};
27-
}
28-
29-
let mut sr;
30-
let mut q;
31-
let mut r;
32-
33-
if d.low() == 0 {
34-
if d.high() == 0 {
35-
// K X
36-
// ---
37-
// 0 0
38-
// NOTE This should be unreachable in safe Rust because the program will panic before
39-
// this intrinsic is called
40-
::abort();
41-
}
42-
43-
if n.low() == 0 {
44-
// K 0
45-
// ---
46-
// K 0
47-
if let Some(rem) = rem {
48-
*rem = <$ty>::from_parts(0, n.high().aborting_rem(d.high()));
49-
}
50-
return <$ty>::from(n.high().aborting_div(d.high()))
51-
}
52-
53-
// K K
54-
// ---
55-
// K 0
56-
57-
if d.high().is_power_of_two() {
58-
if let Some(rem) = rem {
59-
*rem = <$ty>::from_parts(n.low(), n.high() & (d.high() - 1));
60-
}
61-
return <$ty>::from(n.high() >> d.high().trailing_zeros());
62-
}
63-
64-
sr = d.high().leading_zeros().wrapping_sub(n.high().leading_zeros());
65-
66-
// D > N
67-
if sr > <hty!($ty)>::BITS - 2 {
68-
if let Some(rem) = rem {
69-
*rem = n;
70-
}
71-
return 0;
72-
}
73-
74-
sr += 1;
75-
76-
// 1 <= sr <= <hty!($ty)>::BITS - 1
77-
q = n << (<$ty>::BITS - sr);
78-
r = n >> sr;
79-
} else if d.high() == 0 {
80-
// K X
81-
// ---
82-
// 0 K
83-
if d.low().is_power_of_two() {
84-
if let Some(rem) = rem {
85-
*rem = <$ty>::from(n.low() & (d.low() - 1));
86-
}
87-
88-
if d.low() == 1 {
89-
return n;
90-
} else {
91-
let sr = d.low().trailing_zeros();
92-
return n >> sr;
93-
};
94-
}
95-
96-
sr = 1 + <hty!($ty)>::BITS + d.low().leading_zeros() - n.high().leading_zeros();
97-
98-
// 2 <= sr <= u64::BITS - 1
99-
q = n << (<$ty>::BITS - sr);
100-
r = n >> sr;
101-
} else {
102-
// K X
103-
// ---
104-
// K K
105-
sr = d.high().leading_zeros().wrapping_sub(n.high().leading_zeros());
106-
107-
// D > N
108-
if sr > <hty!($ty)>::BITS - 1 {
109-
if let Some(rem) = rem {
110-
*rem = n;
111-
}
112-
return 0;
113-
}
114-
115-
sr += 1;
116-
117-
// 1 <= sr <= <hty!($ty)>::BITS
118-
q = n << (<$ty>::BITS - sr);
119-
r = n >> sr;
120-
}
121-
122-
// Not a special case
123-
// q and r are initialized with
124-
// q = n << (u64::BITS - sr)
125-
// r = n >> sr
126-
// 1 <= sr <= u64::BITS - 1
127-
let mut carry = 0;
128-
129-
// Don't use a range because they may generate references to memcpy in unoptimized code
130-
let mut i = 0;
131-
while i < sr {
132-
i += 1;
133-
134-
// r:q = ((r:q) << 1) | carry
135-
r = (r << 1) | (q >> (<$ty>::BITS - 1));
136-
q = (q << 1) | carry as $ty;
137-
138-
// carry = 0
139-
// if r >= d {
140-
// r -= d;
141-
// carry = 1;
142-
// }
143-
let s = (d.wrapping_sub(r).wrapping_sub(1)) as os_ty!($ty) >> (<$ty>::BITS - 1);
144-
carry = (s & 1) as hty!($ty);
145-
r -= d & s as $ty;
146-
}
147-
148-
if let Some(rem) = rem {
149-
*rem = r;
150-
}
151-
(q << 1) | carry as $ty
152-
}}
153-
}
1543
// NOTE: there are aborts inside the specialized_div_rem functions if division by 0
1554
// is encountered, however these should be unreachable and optimized away unless
1565
// uses of `std/core::intrinsics::unchecked_div/rem` do not have a 0 check in front

0 commit comments

Comments
 (0)