Skip to content

Commit 6aef025

Browse files
committed
Remove unused code
1 parent 752ab52 commit 6aef025

File tree

3 files changed

+0
-221
lines changed

3 files changed

+0
-221
lines changed

src/int/mod.rs

-12
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 leading_zeros;
175
pub mod mul;

src/int/sdiv.rs

-58
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,5 @@
11
use int::Int;
22

3-
trait Div: Int {
4-
/// Returns `a / b`
5-
fn div(self, other: Self) -> Self {
6-
let s_a = self >> (Self::BITS - 1);
7-
let s_b = other >> (Self::BITS - 1);
8-
// NOTE it's OK to overflow here because of the `.unsigned()` below.
9-
// This whole operation is computing the absolute value of the inputs
10-
// So some overflow will happen when dealing with e.g. `i64::MIN`
11-
// where the absolute value is `(-i64::MIN) as u64`
12-
let a = (self ^ s_a).wrapping_sub(s_a);
13-
let b = (other ^ s_b).wrapping_sub(s_b);
14-
let s = s_a ^ s_b;
15-
16-
let r = a.unsigned().aborting_div(b.unsigned());
17-
(Self::from_unsigned(r) ^ s) - s
18-
}
19-
}
20-
21-
impl Div for i32 {}
22-
impl Div for i64 {}
23-
impl Div for i128 {}
24-
25-
trait Mod: Int {
26-
/// Returns `a % b`
27-
fn mod_(self, other: Self) -> Self {
28-
let s = other >> (Self::BITS - 1);
29-
// NOTE(wrapping_sub) see comment in the `div`
30-
let b = (other ^ s).wrapping_sub(s);
31-
let s = self >> (Self::BITS - 1);
32-
let a = (self ^ s).wrapping_sub(s);
33-
34-
let r = a.unsigned().aborting_rem(b.unsigned());
35-
(Self::from_unsigned(r) ^ s) - s
36-
}
37-
}
38-
39-
impl Mod for i32 {}
40-
impl Mod for i64 {}
41-
impl Mod for i128 {}
42-
43-
trait Divmod: Int {
44-
/// Returns `a / b` and sets `*rem = n % d`
45-
fn divmod<F>(self, other: Self, rem: &mut Self, div: F) -> Self
46-
where
47-
F: Fn(Self, Self) -> Self,
48-
{
49-
let r = div(self, other);
50-
// NOTE won't overflow because it's using the result from the
51-
// previous division
52-
*rem = self - r.wrapping_mul(other);
53-
r
54-
}
55-
}
56-
57-
impl Divmod for i32 {}
58-
impl Divmod for i64 {}
59-
60-
613
intrinsics! {
624
#[maybe_use_optimized_c_shim]
635
#[arm_aeabi_alias = __aeabi_idiv]

src/int/udiv.rs

-151
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,5 @@
11
use int::{Int, LargeInt};
22

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

0 commit comments

Comments
 (0)