Skip to content

Commit c1a22e2

Browse files
committed
Improve arithmetic definition
1 parent 8b5db3a commit c1a22e2

File tree

3 files changed

+29
-52
lines changed

3 files changed

+29
-52
lines changed

spartan_parallel/src/scalar/fp.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,5 +220,6 @@ where
220220
}
221221
}
222222

223-
crate::impl_binops_additive!(Scalar, Scalar);
224-
crate::impl_binops_multiplicative!(Scalar, Scalar);
223+
crate::impl_add_binop_specify_output!(Scalar, Scalar, Scalar);
224+
crate::impl_sub_binop_specify_output!(Scalar, Scalar, Scalar);
225+
crate::impl_binops_multiplicative_mixed!(Scalar, Scalar, Scalar);

spartan_parallel/src/scalar/fp2.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,6 @@ impl AppendToTranscript for [ScalarExt2] {
244244
}
245245
}
246246

247-
crate::impl_binops_additive!(ScalarExt2, ScalarExt2);
248-
crate::impl_binops_multiplicative!(ScalarExt2, ScalarExt2);
247+
crate::impl_add_binop_specify_output!(ScalarExt2, ScalarExt2, ScalarExt2);
248+
crate::impl_sub_binop_specify_output!(ScalarExt2, ScalarExt2, ScalarExt2);
249+
crate::impl_binops_multiplicative_mixed!(ScalarExt2, ScalarExt2, ScalarExt2);

spartan_parallel/src/scalar/mod.rs

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ macro_rules! impl_add_binop_specify_output {
208208
&self + &rhs
209209
}
210210
}
211+
212+
impl AddAssign<$rhs> for $lhs {
213+
fn add_assign(&mut self, rhs: $rhs) {
214+
*self = &*self + &rhs;
215+
}
216+
}
217+
218+
impl<'b> AddAssign<&'b $rhs> for $lhs {
219+
fn add_assign(&mut self, rhs: &'b $rhs) {
220+
*self = &*self + rhs;
221+
}
222+
}
211223
};
212224
}
213225

@@ -238,15 +250,18 @@ macro_rules! impl_sub_binop_specify_output {
238250
&self - &rhs
239251
}
240252
}
241-
};
242-
}
243253

244-
/// impl_binops_additive_specify_output
245-
#[macro_export]
246-
macro_rules! impl_binops_additive_specify_output {
247-
($lhs:ident, $rhs:ident, $output:ident) => {
248-
crate::impl_add_binop_specify_output!($lhs, $rhs, $output);
249-
crate::impl_sub_binop_specify_output!($lhs, $rhs, $output);
254+
impl SubAssign<$rhs> for $lhs {
255+
fn sub_assign(&mut self, rhs: $rhs) {
256+
*self = &*self - &rhs;
257+
}
258+
}
259+
260+
impl<'b> SubAssign<&'b $rhs> for $lhs {
261+
fn sub_assign(&mut self, rhs: &'b $rhs) {
262+
*self = &*self - rhs;
263+
}
264+
}
250265
};
251266
}
252267

@@ -277,46 +292,6 @@ macro_rules! impl_binops_multiplicative_mixed {
277292
&self * &rhs
278293
}
279294
}
280-
};
281-
}
282-
283-
/// macro_rules! impl_binops_additive
284-
#[macro_export]
285-
macro_rules! impl_binops_additive {
286-
($lhs:ident, $rhs:ident) => {
287-
crate::impl_binops_additive_specify_output!($lhs, $rhs, $lhs);
288-
289-
impl SubAssign<$rhs> for $lhs {
290-
fn sub_assign(&mut self, rhs: $rhs) {
291-
*self = &*self - &rhs;
292-
}
293-
}
294-
295-
impl AddAssign<$rhs> for $lhs {
296-
fn add_assign(&mut self, rhs: $rhs) {
297-
*self = &*self + &rhs;
298-
}
299-
}
300-
301-
impl<'b> SubAssign<&'b $rhs> for $lhs {
302-
fn sub_assign(&mut self, rhs: &'b $rhs) {
303-
*self = &*self - rhs;
304-
}
305-
}
306-
307-
impl<'b> AddAssign<&'b $rhs> for $lhs {
308-
fn add_assign(&mut self, rhs: &'b $rhs) {
309-
*self = &*self + rhs;
310-
}
311-
}
312-
};
313-
}
314-
315-
/// macro_rules! impl_binops_multiplicative
316-
#[macro_export]
317-
macro_rules! impl_binops_multiplicative {
318-
($lhs:ident, $rhs:ident) => {
319-
crate::impl_binops_multiplicative_mixed!($lhs, $rhs, $lhs);
320295

321296
impl MulAssign<$rhs> for $lhs {
322297
fn mul_assign(&mut self, rhs: $rhs) {

0 commit comments

Comments
 (0)