Rename divn/muln to shr/shl.
This commit is contained in:
parent
a0fcf717c8
commit
b971bdedda
|
@ -276,7 +276,7 @@ impl PrimeFieldRepr for FqRepr {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn divn(&mut self, mut n: u32) {
|
||||
fn shr(&mut self, mut n: u32) {
|
||||
if n >= 64 * 6 {
|
||||
*self = Self::from(0);
|
||||
return;
|
||||
|
@ -324,7 +324,7 @@ impl PrimeFieldRepr for FqRepr {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn muln(&mut self, mut n: u32) {
|
||||
fn shl(&mut self, mut n: u32) {
|
||||
if n >= 64 * 6 {
|
||||
*self = Self::from(0);
|
||||
return;
|
||||
|
@ -965,29 +965,29 @@ fn test_fq_repr_div2() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_fq_repr_divn() {
|
||||
fn test_fq_repr_shr() {
|
||||
let mut a = FqRepr([0xaa5cdd6172847ffd, 0x43242c06aed55287, 0x9ddd5b312f3dd104, 0xc5541fd48046b7e7, 0x16080cf4071e0b05, 0x1225f2901aea514e]);
|
||||
a.divn(0);
|
||||
a.shr(0);
|
||||
assert_eq!(
|
||||
a,
|
||||
FqRepr([0xaa5cdd6172847ffd, 0x43242c06aed55287, 0x9ddd5b312f3dd104, 0xc5541fd48046b7e7, 0x16080cf4071e0b05, 0x1225f2901aea514e])
|
||||
);
|
||||
a.divn(1);
|
||||
a.shr(1);
|
||||
assert_eq!(
|
||||
a,
|
||||
FqRepr([0xd52e6eb0b9423ffe, 0x21921603576aa943, 0xceeead98979ee882, 0xe2aa0fea40235bf3, 0xb04067a038f0582, 0x912f9480d7528a7])
|
||||
);
|
||||
a.divn(50);
|
||||
a.shr(50);
|
||||
assert_eq!(
|
||||
a,
|
||||
FqRepr([0x8580d5daaa50f54b, 0xab6625e7ba208864, 0x83fa9008d6fcf3bb, 0x19e80e3c160b8aa, 0xbe52035d4a29c2c1, 0x244])
|
||||
);
|
||||
a.divn(130);
|
||||
a.shr(130);
|
||||
assert_eq!(
|
||||
a,
|
||||
FqRepr([0xa0fea40235bf3cee, 0x4067a038f0582e2a, 0x2f9480d7528a70b0, 0x91, 0x0, 0x0])
|
||||
);
|
||||
a.divn(64);
|
||||
a.shr(64);
|
||||
assert_eq!(
|
||||
a,
|
||||
FqRepr([0x4067a038f0582e2a, 0x2f9480d7528a70b0, 0x91, 0x0, 0x0, 0x0])
|
||||
|
|
|
@ -113,7 +113,7 @@ impl PrimeFieldRepr for FrRepr {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn divn(&mut self, mut n: u32) {
|
||||
fn shr(&mut self, mut n: u32) {
|
||||
if n >= 64 * 4 {
|
||||
*self = Self::from(0);
|
||||
return;
|
||||
|
@ -161,7 +161,7 @@ impl PrimeFieldRepr for FrRepr {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn muln(&mut self, mut n: u32) {
|
||||
fn shl(&mut self, mut n: u32) {
|
||||
if n >= 64 * 4 {
|
||||
*self = Self::from(0);
|
||||
return;
|
||||
|
@ -670,29 +670,29 @@ fn test_fr_repr_div2() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_fr_repr_divn() {
|
||||
fn test_fr_repr_shr() {
|
||||
let mut a = FrRepr([0xb33fbaec482a283f, 0x997de0d3a88cb3df, 0x9af62d2a9a0e5525, 0x36003ab08de70da1]);
|
||||
a.divn(0);
|
||||
a.shr(0);
|
||||
assert_eq!(
|
||||
a,
|
||||
FrRepr([0xb33fbaec482a283f, 0x997de0d3a88cb3df, 0x9af62d2a9a0e5525, 0x36003ab08de70da1])
|
||||
);
|
||||
a.divn(1);
|
||||
a.shr(1);
|
||||
assert_eq!(
|
||||
a,
|
||||
FrRepr([0xd99fdd762415141f, 0xccbef069d44659ef, 0xcd7b16954d072a92, 0x1b001d5846f386d0])
|
||||
);
|
||||
a.divn(50);
|
||||
a.shr(50);
|
||||
assert_eq!(
|
||||
a,
|
||||
FrRepr([0xbc1a7511967bf667, 0xc5a55341caa4b32f, 0x75611bce1b4335e, 0x6c0])
|
||||
);
|
||||
a.divn(130);
|
||||
a.shr(130);
|
||||
assert_eq!(
|
||||
a,
|
||||
FrRepr([0x1d5846f386d0cd7, 0x1b0, 0x0, 0x0])
|
||||
);
|
||||
a.divn(64);
|
||||
a.shr(64);
|
||||
assert_eq!(
|
||||
a,
|
||||
FrRepr([0x1b0, 0x0, 0x0, 0x0])
|
||||
|
|
|
@ -376,14 +376,14 @@ pub trait PrimeFieldRepr: Sized +
|
|||
fn div2(&mut self);
|
||||
|
||||
/// Performs a rightwise bitshift of this number by some amount.
|
||||
fn divn(&mut self, amt: u32);
|
||||
fn shr(&mut self, amt: u32);
|
||||
|
||||
/// Performs a leftwise bitshift of this number, effectively multiplying
|
||||
/// it by 2. Overflow is ignored.
|
||||
fn mul2(&mut self);
|
||||
|
||||
/// Performs a leftwise bitshift of this number by some amount.
|
||||
fn muln(&mut self, amt: u32);
|
||||
fn shl(&mut self, amt: u32);
|
||||
|
||||
/// Writes this `PrimeFieldRepr` as a big endian integer. Always writes
|
||||
/// `(num_bits` / 8) bytes.
|
||||
|
|
|
@ -3,8 +3,8 @@ use ::{PrimeFieldRepr};
|
|||
|
||||
pub fn random_repr_tests<R: PrimeFieldRepr>() {
|
||||
random_encoding_tests::<R>();
|
||||
random_muln_tests::<R>();
|
||||
random_divn_tests::<R>();
|
||||
random_shl_tests::<R>();
|
||||
random_shr_tests::<R>();
|
||||
}
|
||||
|
||||
fn random_encoding_tests<R: PrimeFieldRepr>() {
|
||||
|
@ -22,7 +22,7 @@ fn random_encoding_tests<R: PrimeFieldRepr>() {
|
|||
}
|
||||
}
|
||||
|
||||
fn random_muln_tests<R: PrimeFieldRepr>() {
|
||||
fn random_shl_tests<R: PrimeFieldRepr>() {
|
||||
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
|
||||
|
||||
for _ in 0..100 {
|
||||
|
@ -36,14 +36,14 @@ fn random_muln_tests<R: PrimeFieldRepr>() {
|
|||
r1.mul2();
|
||||
}
|
||||
|
||||
r2.muln(shift);
|
||||
r2.shl(shift);
|
||||
|
||||
assert_eq!(r1, r2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn random_divn_tests<R: PrimeFieldRepr>() {
|
||||
fn random_shr_tests<R: PrimeFieldRepr>() {
|
||||
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
|
||||
|
||||
for _ in 0..100 {
|
||||
|
@ -57,7 +57,7 @@ fn random_divn_tests<R: PrimeFieldRepr>() {
|
|||
r1.div2();
|
||||
}
|
||||
|
||||
r2.divn(shift);
|
||||
r2.shr(shift);
|
||||
|
||||
assert_eq!(r1, r2);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue