Skip to content

Commit e17f681

Browse files
committed
Convert i128s to SignedWideWord
1 parent 0dbc01a commit e17f681

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/limb.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub type WideWord = u64;
4545
#[cfg(target_pointer_width = "32")]
4646
pub(crate) type SignedWord = i32;
4747

48+
/// Signed equivalent of a wide word.
49+
#[cfg(target_pointer_width = "32")]
50+
pub(crate) type SignedWideWord = i64;
51+
4852
//
4953
// 64-bit definitions
5054
//
@@ -61,6 +65,10 @@ pub type WideWord = u128;
6165
#[cfg(target_pointer_width = "64")]
6266
pub(crate) type SignedWord = i64;
6367

68+
/// Signed equivalent of a wide word.
69+
#[cfg(target_pointer_width = "64")]
70+
pub(crate) type SignedWideWord = i128;
71+
6472
/// Highest bit in a [`Limb`].
6573
pub(crate) const HI_BIT: usize = Limb::BITS - 1;
6674

src/modular/bernstein_yang.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
//!
77
//! Copyright (c) 2023 Privacy Scaling Explorations Team
88
9-
#![allow(clippy::needless_range_loop)]
9+
#![allow(clippy::needless_range_loop, trivial_numeric_casts)]
1010

11-
use crate::limb::{Limb, SignedWord, WideWord, Word};
11+
use crate::limb::{Limb, SignedWideWord, SignedWord, WideWord, Word};
1212
use core::{
1313
cmp::PartialEq,
1414
ops::{Add, Mul, Neg, Sub},
@@ -95,7 +95,7 @@ impl<const L: usize> BernsteinYangInverter<L> {
9595
let (mut steps, mut f, mut g) = (
9696
BITS as SignedWord,
9797
f.lowest() as SignedWord,
98-
g.lowest() as i128,
98+
g.lowest() as SignedWideWord,
9999
);
100100
let mut t: Matrix = [[1, 0], [0, 1]];
101101

@@ -108,7 +108,7 @@ impl<const L: usize> BernsteinYangInverter<L> {
108108
break;
109109
}
110110
if delta > 0 {
111-
(delta, f, g) = (-delta, g as SignedWord, -f as i128);
111+
(delta, f, g) = (-delta, g as SignedWord, -f as SignedWideWord);
112112
(t[0], t[1]) = (t[1], [-t[0][0], -t[0][1]]);
113113
}
114114

@@ -119,7 +119,7 @@ impl<const L: usize> BernsteinYangInverter<L> {
119119
let w = (g as SignedWord).wrapping_mul(f.wrapping_mul(3) ^ 28) & mask;
120120

121121
t[1] = [t[0][0] * w + t[1][0], t[0][1] * w + t[1][1]];
122-
g += w as i128 * f as i128;
122+
g += w as SignedWideWord * f as SignedWideWord;
123123
}
124124

125125
(delta, t)

0 commit comments

Comments
 (0)