Skip to content

Commit cd9591b

Browse files
committed
Inline methods, to make them faster
1 parent b894fbf commit cd9591b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

ff/src/fields/models/webnode.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const fn gte_modulus<C: Fp256Parameters>(x: &BigInteger256) -> bool {
8787
}
8888

8989
#[ark_ff_asm::unroll_for_loops]
90+
#[inline(always)]
9091
const fn conditional_reduce<C: Fp256Parameters>(x: &mut BigInteger256) {
9192
if gte_modulus::<C>(&x) {
9293
for i in 0..9 {
@@ -102,7 +103,7 @@ const fn conditional_reduce<C: Fp256Parameters>(x: &mut BigInteger256) {
102103
}
103104

104105
#[ark_ff_asm::unroll_for_loops]
105-
#[allow(unused)]
106+
#[inline(always)]
106107
fn add_assign<C: Fp256Parameters>(x: &mut BigInteger256, y: &BigInteger256) {
107108
let y = &y.0;
108109
let mut tmp: u32;
@@ -274,6 +275,7 @@ impl<C: Fp256Parameters> Fp256<C> {
274275
};
275276

276277
#[ark_ff_asm::unroll_for_loops]
278+
#[inline(always)]
277279
const fn const_mul_without_reduce(&mut self, other: &Self, _modulus: &BigInteger256, _inv: u32) {
278280
let x = &mut self.0.0;
279281
let y = &other.0.0;
@@ -312,11 +314,13 @@ impl<C: Fp256Parameters> Fp256<C> {
312314
x[Self::NLIMBS - 1] = xy[Self::NLIMBS - 1] as u32;
313315
}
314316

317+
#[inline(always)]
315318
const fn const_mul(&mut self, other: &Self, modulus: &BigInteger256, inv: u32) {
316319
self.const_mul_without_reduce(other, modulus, inv);
317320
self.const_reduce(modulus);
318321
}
319322

323+
#[inline(always)]
320324
const fn const_reduce(&mut self, _modulus: &BigInteger256) {
321325
conditional_reduce::<C>(&mut self.0);
322326
}
@@ -340,6 +344,7 @@ impl<C: Fp256Parameters> Fp256<C> {
340344
}
341345

342346
#[ark_ff_asm::unroll_for_loops]
347+
#[inline(always)]
343348
const fn const_square(&mut self) {
344349
let mut x = [0u64; 9];
345350
for i in 0..9 {
@@ -434,6 +439,7 @@ impl<C: Fp256Parameters> core::ops::DivAssign<Self> for Fp256<C> {
434439
}
435440
impl<C: Fp256Parameters> Add<Self> for Fp256<C> {
436441
type Output = Self;
442+
#[inline(always)]
437443
fn add(mut self, other: Self) -> Self {
438444
self.add_assign(other);
439445
self
@@ -454,18 +460,21 @@ impl<C: Fp256Parameters> Div<Self> for Fp256<C> {
454460
}
455461
}
456462
impl<C: Fp256Parameters> core::ops::AddAssign<Self> for Fp256<C> {
463+
#[inline(always)]
457464
fn add_assign(&mut self, other: Self) {
458465
add_assign::<C>(&mut self.0, &other.0)
459466
}
460467
}
461468
impl<C: Fp256Parameters> Mul<Self> for Fp256<C> {
462469
type Output = Self;
470+
#[inline(always)]
463471
fn mul(mut self, other: Self) -> Self {
464472
self.mul_assign(other);
465473
self
466474
}
467475
}
468476
impl<C: Fp256Parameters> core::ops::MulAssign<Self> for Fp256<C> {
477+
#[inline(always)]
469478
fn mul_assign(&mut self, other: Self) {
470479
self.const_mul(&other, &C::MODULUS, C::INV as u32);
471480
}
@@ -528,24 +537,28 @@ impl<'a, C: Fp256Parameters> core::iter::Sum<&'a Self> for Fp256<C> {
528537
}
529538
impl<'a, C: Fp256Parameters> Add<&'a Self> for Fp256<C> {
530539
type Output = Self;
540+
#[inline(always)]
531541
fn add(mut self, other: &'a Self) -> Self {
532542
self.add_assign(other);
533543
self
534544
}
535545
}
536546
impl<'a, C: Fp256Parameters> core::ops::AddAssign<&'a Self> for Fp256<C> {
547+
#[inline(always)]
537548
fn add_assign(&mut self, other: &'a Self) {
538549
add_assign::<C>(&mut self.0, &other.0)
539550
}
540551
}
541552
impl<'a, C: Fp256Parameters> Mul<&'a Self> for Fp256<C> {
542553
type Output = Self;
554+
#[inline(always)]
543555
fn mul(mut self, other: &'a Self) -> Self {
544556
self.mul_assign(other);
545557
self
546558
}
547559
}
548560
impl<'a, C: Fp256Parameters> core::ops::MulAssign<&'a Self> for Fp256<C> {
561+
#[inline(always)]
549562
fn mul_assign(&mut self, other: &'a Self) {
550563
self.const_mul(&other, &C::MODULUS, C::INV as u32)
551564
}
@@ -802,14 +815,13 @@ impl<C: Fp256Parameters> Field for Fp256<C> {
802815
.and_then(|f| F::from_u8(flags).map(|flag| (f, flag)))
803816
}
804817
}
805-
#[inline]
818+
#[inline(always)]
806819
fn square(&self) -> Self {
807820
let mut temp = self.clone();
808821
temp.square_in_place();
809822
temp
810823
}
811-
#[inline]
812-
#[allow(unused_braces, clippy::absurd_extreme_comparisons)]
824+
#[inline(always)]
813825
fn square_in_place(&mut self) -> &mut Self {
814826
self.const_square();
815827
self

0 commit comments

Comments
 (0)