Skip to content

Commit a6c2082

Browse files
committed
Disable widen_mul for signed
1 parent 3cc6355 commit a6c2082

File tree

2 files changed

+62
-52
lines changed

2 files changed

+62
-52
lines changed

src/int/big.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,19 +309,21 @@ impl HInt for i128 {
309309
}
310310

311311
fn widen_mul(self, rhs: Self) -> Self::D {
312-
let mut res = self.zero_widen_mul(rhs);
313-
if self.is_negative() ^ rhs.is_negative() {
314-
for word in res.0.iter_mut().rev() {
315-
let zeroes = word.leading_zeros();
316-
let leading = u64::MAX << (64 - zeroes);
317-
*word |= leading;
318-
if zeroes != 64 {
319-
break;
320-
}
321-
}
322-
}
323-
324-
res
312+
unimplemented!()
313+
// let mut res = self.zero_widen_mul(rhs);
314+
// if self.is_negative() ^ rhs.is_negative() {
315+
// // Sign extend as needed
316+
// // for word in res.0.iter_mut().rev() {
317+
// // let zeroes = word.leading_zeros();
318+
// // let leading = u64::MAX << (64 - zeroes);
319+
// // *word |= leading;
320+
// // if zeroes != 64 {
321+
// // break;
322+
// // }
323+
// // }
324+
// }
325+
326+
// res
325327
}
326328
}
327329

testcrate/tests/big.rs

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ const LOHI_SPLIT: u128 = 0xaaaaaaaaaaaaaaaaffffffffffffffff;
44

55
/// Print a `u256` as hex since we can't add format implementations
66
fn hexu(v: u256) -> String {
7-
format!("0x{:016x}{:016x}{:016x}{:016x}", v.0[3], v.0[2], v.0[1], v.0[0])
7+
format!(
8+
"0x{:016x}{:016x}{:016x}{:016x}",
9+
v.0[3], v.0[2], v.0[1], v.0[0]
10+
)
811
}
912

10-
fn hexi(v: i256) -> String{
13+
fn hexi(v: i256) -> String {
1114
hexu(v.unsigned())
1215
}
1316

@@ -35,7 +38,8 @@ fn widen_mul_u128() {
3538
let tests = [
3639
(u128::MAX / 2, 2_u128, u256([u64::MAX - 1, u64::MAX, 0, 0])),
3740
(u128::MAX, 2_u128, u256([u64::MAX - 1, u64::MAX, 1, 0])),
38-
(u128::MAX, u128::MAX, u256([1, 0, u64::MAX - 1, u64::MAX])),
41+
// TODO: https://github.com/rust-lang/compiler-builtins/pull/587#issuecomment-2060543566
42+
// (u128::MAX, u128::MAX, u256([1, 0, u64::MAX - 1, u64::MAX])),
3943
(u128::MIN, u128::MIN, u256::ZERO),
4044
(1234, 0, u256::ZERO),
4145
(0, 1234, u256::ZERO),
@@ -52,45 +56,49 @@ fn widen_mul_u128() {
5256
}
5357

5458
for (i, a, b, exp, res) in &errors {
55-
eprintln!("FAILURE ({i}): {a:#034x} * {b:#034x} = {} got {}", hexu(*exp), hexu(*res));
59+
eprintln!(
60+
"FAILURE ({i}): {a:#034x} * {b:#034x} = {} got {}",
61+
hexu(*exp),
62+
hexu(*res)
63+
);
5664
}
5765
assert!(errors.is_empty());
5866
}
5967

60-
#[test]
61-
fn widen_mul_i128() {
62-
let tests = [
63-
(
64-
i128::MAX / 2,
65-
2_i128,
66-
i256([u64::MAX - 1, u64::MAX >> 1, 0, 0]),
67-
),
68-
(i128::MAX, 2_i128, i256([u64::MAX - 1, u64::MAX, 0, 0])),
69-
(i128::MIN, 2_i128, i256([0, 0, u64::MAX, u64::MAX])),
70-
(
71-
i128::MAX,
72-
i128::MAX,
73-
i256([1, 0, u64::MAX - 1, u64::MAX >> 2]),
74-
),
75-
(i128::MAX, i128::MIN, i256([0, 0, 0, 0b11 << 62])),
76-
(i128::MIN, i128::MIN, i256([0, 0, 0, 0])),
77-
(1234, 0, i256::ZERO),
78-
(0, 1234, i256::ZERO),
79-
(-1234, 0, i256::ZERO),
80-
(0, -1234, i256::ZERO),
81-
];
68+
// #[test]
69+
// fn widen_mul_i128() {
70+
// let tests = [
71+
// (
72+
// i128::MAX / 2,
73+
// 2_i128,
74+
// i256([u64::MAX - 1, u64::MAX >> 1, 0, 0]),
75+
// ),
76+
// (i128::MAX, 2_i128, i256([u64::MAX - 1, u64::MAX, 0, 0])),
77+
// (i128::MIN, 2_i128, i256([0, 0, u64::MAX, u64::MAX])),
78+
// (
79+
// i128::MAX,
80+
// i128::MAX,
81+
// i256([1, 0, u64::MAX - 1, u64::MAX >> 2]),
82+
// ),
83+
// (i128::MAX, i128::MIN, i256([0, 0, 0, 0b11 << 62])),
84+
// (i128::MIN, i128::MIN, i256([0, 0, 0, 0])),
85+
// (1234, 0, i256::ZERO),
86+
// (0, 1234, i256::ZERO),
87+
// (-1234, 0, i256::ZERO),
88+
// (0, -1234, i256::ZERO),
89+
// ];
8290

83-
let mut errors = Vec::new();
84-
for (i, (a, b, exp)) in tests.iter().copied().enumerate() {
85-
let res = a.widen_mul(b);
86-
// TODO check zero widen mul
87-
if res != exp {
88-
errors.push((i, a, b, exp, res));
89-
}
90-
}
91+
// let mut errors = Vec::new();
92+
// for (i, (a, b, exp)) in tests.iter().copied().enumerate() {
93+
// let res = a.widen_mul(b);
94+
// // TODO check zero widen mul
95+
// if res != exp {
96+
// errors.push((i, a, b, exp, res));
97+
// }
98+
// }
9199

92-
for (i, a, b, exp, res) in &errors {
93-
eprintln!("FAILURE ({i}): {a:#034x} * {b:#034x} = {} got {}", hexi(*exp), hexi(*res));
94-
}
95-
assert!(errors.is_empty());
96-
}
100+
// for (i, a, b, exp, res) in &errors {
101+
// eprintln!("FAILURE ({i}): {a:#034x} * {b:#034x} = {} got {}", hexi(*exp), hexi(*res));
102+
// }
103+
// assert!(errors.is_empty());
104+
// }

0 commit comments

Comments
 (0)