Removed
Link Here
|
1 |
--- rust/vendor/lexical-core/src/atof/algorithm/math.rs.orig 2021-03-01 16:15:39 UTC |
2 |
+++ rust/vendor/lexical-core/src/atof/algorithm/math.rs |
3 |
@@ -956,7 +956,7 @@ pub fn mul(x: Limb, y: Limb, carry: Limb) |
4 |
// the following is always true: |
5 |
// `Wide::max_value() - (Narrow::max_value() * Narrow::max_value()) >= Narrow::max_value()` |
6 |
let z: Wide = as_wide(x) * as_wide(y) + as_wide(carry); |
7 |
- (as_limb(z), as_limb(z >> Limb::BITS)) |
8 |
+ (as_limb(z), as_limb(z >> <Limb as Integer>::BITS)) |
9 |
}} |
10 |
|
11 |
/// Multiply two small integers (with carry) (and return if overflow happens). |
12 |
@@ -979,7 +979,7 @@ pub fn div(x: Limb, y: Limb, rem: Limb) |
13 |
-> (Limb, Limb) |
14 |
{ |
15 |
// Cannot overflow, as long as wide is 2x as wide. |
16 |
- let x = as_wide(x) | (as_wide(rem) << Limb::BITS); |
17 |
+ let x = as_wide(x) | (as_wide(rem) << <Limb as Integer>::BITS); |
18 |
let y = as_wide(y); |
19 |
(as_limb(x / y), as_limb(x % y)) |
20 |
}} |
21 |
@@ -1046,7 +1046,7 @@ perftools_inline!{ |
22 |
pub fn trailing_zeros(x: &[Limb]) -> usize { |
23 |
// Get the index of the last non-zero value |
24 |
let index = trailing_zero_limbs(x); |
25 |
- let mut count = index.saturating_mul(Limb::BITS); |
26 |
+ let mut count = index.saturating_mul(<Limb as Integer>::BITS); |
27 |
if let Some(value) = x.get(index) { |
28 |
count = count.saturating_add(value.trailing_zeros().as_usize()); |
29 |
} |
30 |
@@ -1061,7 +1061,7 @@ pub fn bit_length(x: &[Limb]) -> usize { |
31 |
// Avoid overflowing, calculate via total number of bits |
32 |
// minus leading zero bits. |
33 |
let nlz = leading_zeros(x); |
34 |
- Limb::BITS.checked_mul(x.len()) |
35 |
+ <Limb as Integer>::BITS.checked_mul(x.len()) |
36 |
.map(|v| v - nlz) |
37 |
.unwrap_or(usize::max_value()) |
38 |
}} |
39 |
@@ -1080,14 +1080,14 @@ pub fn limb_length(x: &[Limb]) -> usize { |
40 |
/// |
41 |
/// Returns the truncated bits. |
42 |
/// |
43 |
-/// Assumes `n < Limb::BITS`, IE, internally shifting bits. |
44 |
+/// Assumes `n < <Limb as Integer>::BITS`, IE, internally shifting bits. |
45 |
perftools_inline!{ |
46 |
pub fn ishr_bits<T>(x: &mut T, n: usize) |
47 |
-> Limb |
48 |
where T: CloneableVecLike<Limb> |
49 |
{ |
50 |
- // Need to shift by the number of `bits % Limb::BITS`. |
51 |
- let bits = Limb::BITS; |
52 |
+ // Need to shift by the number of `bits % <Limb as Integer>::BITS`. |
53 |
+ let bits = <Limb as Integer>::BITS; |
54 |
debug_assert!(n < bits && n != 0); |
55 |
|
56 |
// Internally, for each item, we shift left by n, and add the previous |
57 |
@@ -1134,9 +1134,9 @@ pub fn ishr<T>(x: &mut T, n: usize) |
58 |
-> bool |
59 |
where T: CloneableVecLike<Limb> |
60 |
{ |
61 |
- let bits = Limb::BITS; |
62 |
- // Need to pad with zeros for the number of `bits / Limb::BITS`, |
63 |
- // and shift-left with carry for `bits % Limb::BITS`. |
64 |
+ let bits = <Limb as Integer>::BITS; |
65 |
+ // Need to pad with zeros for the number of `bits / <Limb as Integer>::BITS`, |
66 |
+ // and shift-left with carry for `bits % <Limb as Integer>::BITS`. |
67 |
let rem = n % bits; |
68 |
let div = n / bits; |
69 |
let is_zero = match div.is_zero() { |
70 |
@@ -1187,13 +1187,13 @@ pub fn shr<T>(x: &[Limb], n: usize) |
71 |
|
72 |
/// Shift-left bits inside a buffer. |
73 |
/// |
74 |
-/// Assumes `n < Limb::BITS`, IE, internally shifting bits. |
75 |
+/// Assumes `n < <Limb as Integer>::BITS`, IE, internally shifting bits. |
76 |
perftools_inline!{ |
77 |
pub fn ishl_bits<T>(x: &mut T, n: usize) |
78 |
where T: CloneableVecLike<Limb> |
79 |
{ |
80 |
- // Need to shift by the number of `bits % Limb::BITS)`. |
81 |
- let bits = Limb::BITS; |
82 |
+ // Need to shift by the number of `bits % <Limb as Integer>::BITS)`. |
83 |
+ let bits = <Limb as Integer>::BITS; |
84 |
debug_assert!(n < bits); |
85 |
if n.is_zero() { |
86 |
return; |
87 |
@@ -1223,7 +1223,7 @@ pub fn ishl_bits<T>(x: &mut T, n: usize) |
88 |
|
89 |
/// Shift-left bits inside a buffer. |
90 |
/// |
91 |
-/// Assumes `n < Limb::BITS`, IE, internally shifting bits. |
92 |
+/// Assumes `n < <Limb as Integer>::BITS`, IE, internally shifting bits. |
93 |
perftools_inline!{ |
94 |
pub fn shl_bits<T>(x: &[Limb], n: usize) |
95 |
-> T |
96 |
@@ -1253,9 +1253,9 @@ perftools_inline!{ |
97 |
pub fn ishl<T>(x: &mut T, n: usize) |
98 |
where T: CloneableVecLike<Limb> |
99 |
{ |
100 |
- let bits = Limb::BITS; |
101 |
- // Need to pad with zeros for the number of `bits / Limb::BITS`, |
102 |
- // and shift-left with carry for `bits % Limb::BITS`. |
103 |
+ let bits = <Limb as Integer>::BITS; |
104 |
+ // Need to pad with zeros for the number of `bits / <Limb as Integer>::BITS`, |
105 |
+ // and shift-left with carry for `bits % <Limb as Integer>::BITS`. |
106 |
let rem = n % bits; |
107 |
let div = n / bits; |
108 |
ishl_bits(x, rem); |
109 |
@@ -1912,7 +1912,7 @@ pub fn mul<T>(x: &[Limb], y: &[Limb]) |
110 |
// DIVISION |
111 |
|
112 |
/// Constants for algorithm D. |
113 |
-const ALGORITHM_D_B: Wide = 1 << Limb::BITS; |
114 |
+const ALGORITHM_D_B: Wide = 1 << <Limb as Integer>::BITS; |
115 |
const ALGORITHM_D_M: Wide = ALGORITHM_D_B - 1; |
116 |
|
117 |
/// Calculate qhat (an estimate for the quotient). |
118 |
@@ -1932,7 +1932,7 @@ fn calculate_qhat(x: &[Limb], y: &[Limb], j: usize) |
119 |
// rhat = (x[j+n]*B + x[j+n-1]) - qhat*y[n-1]; |
120 |
let x_jn = as_wide(x[j+n]); |
121 |
let x_jn1 = as_wide(x[j+n-1]); |
122 |
- let num = (x_jn << Limb::BITS) + x_jn1; |
123 |
+ let num = (x_jn << <Limb as Integer>::BITS) + x_jn1; |
124 |
let den = as_wide(y[n-1]); |
125 |
let mut qhat = num / den; |
126 |
let mut rhat = num - qhat * den; |
127 |
@@ -1949,7 +1949,7 @@ fn calculate_qhat(x: &[Limb], y: &[Limb], j: usize) |
128 |
let y_n2 = as_wide(y[n-2]); |
129 |
let y_n1 = as_wide(y[n-1]); |
130 |
// This only happens when the leading bit of qhat is set. |
131 |
- while qhat >= ALGORITHM_D_B || qhat * y_n2 > (rhat << Limb::BITS) + x_jn2 { |
132 |
+ while qhat >= ALGORITHM_D_B || qhat * y_n2 > (rhat << <Limb as Integer>::BITS) + x_jn2 { |
133 |
qhat -= 1; |
134 |
rhat += y_n1; |
135 |
if rhat >= ALGORITHM_D_B { |
136 |
@@ -1989,7 +1989,7 @@ fn multiply_and_subtract<T>(x: &mut T, y: &T, qhat: Wi |
137 |
let p = qhat * y_i; |
138 |
t = x_ij.wrapping_sub(k).wrapping_sub(as_signed_wide(p & ALGORITHM_D_M)); |
139 |
x[i+j] = as_limb(t); |
140 |
- k = as_signed_wide(p >> Limb::BITS) - (t >> Limb::BITS); |
141 |
+ k = as_signed_wide(p >> <Limb as Integer>::BITS) - (t >> <Limb as Integer>::BITS); |
142 |
} |
143 |
t = as_signed_wide(x[j+n]) - k; |
144 |
x[j+n] = as_limb(t); |
145 |
@@ -2045,7 +2045,7 @@ fn add_back<T>(x: &mut T, y: &T, mut t: SignedWide, j: |
146 |
for i in 0..n { |
147 |
t = as_signed_wide(as_wide(x[i+j]) + as_wide(y[i])) + k; |
148 |
x[i+j] = as_limb(t); |
149 |
- k = t >> Limb::BITS; |
150 |
+ k = t >> <Limb as Integer>::BITS; |
151 |
} |
152 |
let x_jn = as_signed_wide(x[j+n]) + k; |
153 |
x[j+n] = as_limb(x_jn); |
154 |
@@ -2068,7 +2068,7 @@ fn calculate_remainder<T>(x: &[Limb], y: &[Limb], s: u |
155 |
let n = y.len(); |
156 |
let mut r = T::default(); |
157 |
r.reserve_exact(n); |
158 |
- let rs = Limb::BITS - s; |
159 |
+ let rs = <Limb as Integer>::BITS - s; |
160 |
for i in 0..n-1 { |
161 |
let xi = as_wide(x[i]) >> s; |
162 |
let xi1 = as_wide(x[i+1]) << rs; |
163 |
@@ -2205,9 +2205,9 @@ pub fn quorem<T>(x: &mut T, y: &T) |
164 |
let mut carry: Wide = 0; |
165 |
for j in 0..m { |
166 |
let p = as_wide(y[j]) * as_wide(q) + carry; |
167 |
- carry = p >> Limb::BITS; |
168 |
+ carry = p >> <Limb as Integer>::BITS; |
169 |
let t = as_wide(x[j]).wrapping_sub(p & mask).wrapping_sub(borrow); |
170 |
- borrow = (t >> Limb::BITS) & 1; |
171 |
+ borrow = (t >> <Limb as Integer>::BITS) & 1; |
172 |
x[j] = as_limb(t); |
173 |
} |
174 |
small::normalize(x); |
175 |
@@ -2220,9 +2220,9 @@ pub fn quorem<T>(x: &mut T, y: &T) |
176 |
let mut carry: Wide = 0; |
177 |
for j in 0..m { |
178 |
let p = as_wide(y[j]) + carry; |
179 |
- carry = p >> Limb::BITS; |
180 |
+ carry = p >> <Limb as Integer>::BITS; |
181 |
let t = as_wide(x[j]).wrapping_sub(p & mask).wrapping_sub(borrow); |
182 |
- borrow = (t >> Limb::BITS) & 1; |
183 |
+ borrow = (t >> <Limb as Integer>::BITS) & 1; |
184 |
x[j] = as_limb(t); |
185 |
} |
186 |
small::normalize(x); |
187 |
@@ -3137,18 +3137,18 @@ mod tests { |
188 |
fn leading_zeros_test() { |
189 |
assert_eq!(Bigint::new().leading_zeros(), 0); |
190 |
|
191 |
- assert_eq!(Bigint::from_u16(0xFF).leading_zeros(), Limb::BITS-8); |
192 |
- assert_eq!(Bigint::from_u32(0xFF).leading_zeros(), Limb::BITS-8); |
193 |
+ assert_eq!(Bigint::from_u16(0xFF).leading_zeros(), <Limb as Integer>::BITS-8); |
194 |
+ assert_eq!(Bigint::from_u32(0xFF).leading_zeros(), <Limb as Integer>::BITS-8); |
195 |
assert_eq!(Bigint::from_u64(0xFF00000000).leading_zeros(), 24); |
196 |
assert_eq!(Bigint::from_u128(0xFF000000000000000000000000).leading_zeros(), 24); |
197 |
|
198 |
- assert_eq!(Bigint::from_u16(0xF).leading_zeros(), Limb::BITS-4); |
199 |
- assert_eq!(Bigint::from_u32(0xF).leading_zeros(), Limb::BITS-4); |
200 |
+ assert_eq!(Bigint::from_u16(0xF).leading_zeros(), <Limb as Integer>::BITS-4); |
201 |
+ assert_eq!(Bigint::from_u32(0xF).leading_zeros(), <Limb as Integer>::BITS-4); |
202 |
assert_eq!(Bigint::from_u64(0xF00000000).leading_zeros(), 28); |
203 |
assert_eq!(Bigint::from_u128(0xF000000000000000000000000).leading_zeros(), 28); |
204 |
|
205 |
- assert_eq!(Bigint::from_u16(0xF0).leading_zeros(), Limb::BITS-8); |
206 |
- assert_eq!(Bigint::from_u32(0xF0).leading_zeros(), Limb::BITS-8); |
207 |
+ assert_eq!(Bigint::from_u16(0xF0).leading_zeros(), <Limb as Integer>::BITS-8); |
208 |
+ assert_eq!(Bigint::from_u32(0xF0).leading_zeros(), <Limb as Integer>::BITS-8); |
209 |
assert_eq!(Bigint::from_u64(0xF000000000).leading_zeros(), 24); |
210 |
assert_eq!(Bigint::from_u128(0xF0000000000000000000000000).leading_zeros(), 24); |
211 |
} |