Skip to content

Commit f4a5292

Browse files
committed
Reorder arithmetic definition
1 parent c1a22e2 commit f4a5292

File tree

2 files changed

+65
-59
lines changed

2 files changed

+65
-59
lines changed

spartan_parallel/src/scalar/fp.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,6 @@ use zeroize::Zeroize;
1515
#[derive(Clone, Copy, Eq, Serialize, Deserialize, Hash, Debug)]
1616
pub struct Scalar(Goldilocks);
1717

18-
impl Mul<Goldilocks> for Scalar {
19-
type Output = Scalar;
20-
21-
#[inline]
22-
fn mul(self, rhs: Goldilocks) -> Self::Output {
23-
(*self.inner() * rhs).into()
24-
}
25-
}
26-
impl<'a> Mul<&'a Goldilocks> for Scalar {
27-
type Output = Self;
28-
29-
#[inline]
30-
fn mul(mut self, rhs: &'a Goldilocks) -> Self::Output {
31-
self *= rhs;
32-
self
33-
}
34-
}
35-
impl MulAssign<&Goldilocks> for Scalar {
36-
#[inline]
37-
fn mul_assign(&mut self, rhs: &Goldilocks) {
38-
self.0 *= rhs;
39-
}
40-
}
41-
impl MulAssign<Goldilocks> for Scalar {
42-
#[inline]
43-
fn mul_assign(&mut self, rhs: Goldilocks) {
44-
self.mul_assign(&rhs)
45-
}
46-
}
47-
4818
impl SpartanExtensionField for Scalar {
4919
type InnerType = Goldilocks;
5020
type BaseField = Goldilocks;
@@ -197,6 +167,38 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a Scalar {
197167
}
198168
}
199169

170+
impl Mul<Goldilocks> for Scalar {
171+
type Output = Scalar;
172+
173+
#[inline]
174+
fn mul(self, rhs: Goldilocks) -> Self::Output {
175+
(*self.inner() * rhs).into()
176+
}
177+
}
178+
179+
impl<'a> Mul<&'a Goldilocks> for Scalar {
180+
type Output = Self;
181+
182+
#[inline]
183+
fn mul(mut self, rhs: &'a Goldilocks) -> Self::Output {
184+
self *= rhs;
185+
self
186+
}
187+
}
188+
189+
impl MulAssign<&Goldilocks> for Scalar {
190+
#[inline]
191+
fn mul_assign(&mut self, rhs: &Goldilocks) {
192+
self.0 *= rhs;
193+
}
194+
}
195+
impl MulAssign<Goldilocks> for Scalar {
196+
#[inline]
197+
fn mul_assign(&mut self, rhs: Goldilocks) {
198+
self.mul_assign(&rhs)
199+
}
200+
}
201+
200202
impl<T> Sum<T> for Scalar
201203
where
202204
T: Borrow<Scalar>,

spartan_parallel/src/scalar/fp2.rs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,6 @@ impl From<GoldilocksExt2> for ScalarExt2 {
2020
}
2121
}
2222

23-
impl Mul<Goldilocks> for ScalarExt2 {
24-
type Output = ScalarExt2;
25-
26-
#[inline]
27-
fn mul(self, rhs: Goldilocks) -> Self::Output {
28-
(self.inner() * &rhs).into()
29-
}
30-
}
31-
impl<'a> Mul<&'a Goldilocks> for ScalarExt2 {
32-
type Output = Self;
33-
34-
#[inline]
35-
fn mul(mut self, rhs: &'a Goldilocks) -> Self::Output {
36-
self *= rhs;
37-
self
38-
}
39-
}
40-
impl MulAssign<&Goldilocks> for ScalarExt2 {
41-
#[inline]
42-
fn mul_assign(&mut self, rhs: &Goldilocks) {
43-
self.0 *= rhs;
44-
}
45-
}
46-
impl MulAssign<Goldilocks> for ScalarExt2 {
47-
#[inline]
48-
fn mul_assign(&mut self, rhs: Goldilocks) {
49-
self.mul_assign(&rhs)
50-
}
51-
}
5223
impl SpartanExtensionField for ScalarExt2 {
5324
type InnerType = GoldilocksExt2;
5425
type BaseField = Goldilocks;
@@ -205,6 +176,39 @@ impl<'a, 'b> Mul<&'b ScalarExt2> for &'a ScalarExt2 {
205176
}
206177
}
207178

179+
impl Mul<Goldilocks> for ScalarExt2 {
180+
type Output = ScalarExt2;
181+
182+
#[inline]
183+
fn mul(self, rhs: Goldilocks) -> Self::Output {
184+
(self.inner() * &rhs).into()
185+
}
186+
}
187+
188+
impl<'a> Mul<&'a Goldilocks> for ScalarExt2 {
189+
type Output = Self;
190+
191+
#[inline]
192+
fn mul(mut self, rhs: &'a Goldilocks) -> Self::Output {
193+
self *= rhs;
194+
self
195+
}
196+
}
197+
198+
impl MulAssign<&Goldilocks> for ScalarExt2 {
199+
#[inline]
200+
fn mul_assign(&mut self, rhs: &Goldilocks) {
201+
self.0 *= rhs;
202+
}
203+
}
204+
205+
impl MulAssign<Goldilocks> for ScalarExt2 {
206+
#[inline]
207+
fn mul_assign(&mut self, rhs: Goldilocks) {
208+
self.mul_assign(&rhs)
209+
}
210+
}
211+
208212
impl<T> Sum<T> for ScalarExt2
209213
where
210214
T: Borrow<ScalarExt2>,

0 commit comments

Comments
 (0)