Skip to content

Commit

Permalink
testing for only #[inline(always)]
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlawfulMonad committed Jun 13, 2017
1 parent 6cdae94 commit 156c92d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
38 changes: 19 additions & 19 deletions src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ impl ExtendedPoint {
impl<'a,'b> Add<&'b ProjectiveNielsPoint> for &'a ExtendedPoint {
type Output = CompletedPoint;

#[inline]
#[inline(always)]
fn add(self, other: &'b ProjectiveNielsPoint) -> CompletedPoint {
let Y_plus_X = self.Y + self.X;
let Y_minus_X = self.Y - self.X;
Expand All @@ -738,7 +738,7 @@ impl<'a,'b> Add<&'b ProjectiveNielsPoint> for &'a ExtendedPoint {

impl Add<ProjectiveNielsPoint> for ExtendedPoint {
type Output = CompletedPoint;
#[inline]
#[inline(always)]
fn add(self, other: ProjectiveNielsPoint) -> CompletedPoint {
&self + &other
}
Expand All @@ -747,7 +747,7 @@ impl Add<ProjectiveNielsPoint> for ExtendedPoint {
impl<'a,'b> Sub<&'b ProjectiveNielsPoint> for &'a ExtendedPoint {
type Output = CompletedPoint;

#[inline]
#[inline(always)]
fn sub(self, other: &'b ProjectiveNielsPoint) -> CompletedPoint {
let Y_plus_X = self.Y + self.X;
let Y_minus_X = self.Y - self.X;
Expand All @@ -769,7 +769,7 @@ impl<'a,'b> Sub<&'b ProjectiveNielsPoint> for &'a ExtendedPoint {
impl<'a,'b> Add<&'b AffineNielsPoint> for &'a ExtendedPoint {
type Output = CompletedPoint;

#[inline]
#[inline(always)]
fn add(self, other: &'b AffineNielsPoint) -> CompletedPoint {
let Y_plus_X = self.Y + self.X;
let Y_minus_X = self.Y - self.X;
Expand All @@ -790,7 +790,7 @@ impl<'a,'b> Add<&'b AffineNielsPoint> for &'a ExtendedPoint {
impl<'a,'b> Sub<&'b AffineNielsPoint> for &'a ExtendedPoint {
type Output = CompletedPoint;

#[inline]
#[inline(always)]
fn sub(self, other: &'b AffineNielsPoint) -> CompletedPoint {
let Y_plus_X = self.Y + self.X;
let Y_minus_X = self.Y - self.X;
Expand All @@ -810,29 +810,29 @@ impl<'a,'b> Sub<&'b AffineNielsPoint> for &'a ExtendedPoint {

impl<'a,'b> Add<&'b ExtendedPoint> for &'a ExtendedPoint {
type Output = ExtendedPoint;
#[inline]
#[inline(always)]
fn add(self, other: &'b ExtendedPoint) -> ExtendedPoint {
(self + &other.to_projective_niels()).to_extended()
}
}

impl<'b> AddAssign<&'b ExtendedPoint> for ExtendedPoint {
#[inline]
#[inline(always)]
fn add_assign(&mut self, _rhs: &'b ExtendedPoint) {
*self = (self as &ExtendedPoint) + _rhs;
}
}

impl<'a,'b> Sub<&'b ExtendedPoint> for &'a ExtendedPoint {
type Output = ExtendedPoint;
#[inline]
#[inline(always)]
fn sub(self, other: &'b ExtendedPoint) -> ExtendedPoint {
(self - &other.to_projective_niels()).to_extended()
}
}

impl<'b> SubAssign<&'b ExtendedPoint> for ExtendedPoint {
#[inline]
#[inline(always)]
fn sub_assign(&mut self, _rhs: &'b ExtendedPoint) {
*self = (self as &ExtendedPoint) - _rhs;
}
Expand All @@ -845,7 +845,7 @@ impl<'b> SubAssign<&'b ExtendedPoint> for ExtendedPoint {
impl<'a> Neg for &'a ExtendedPoint {
type Output = ExtendedPoint;

#[inline]
#[inline(always)]
fn neg(self) -> ExtendedPoint {
ExtendedPoint{
X: -self.X,
Expand All @@ -859,7 +859,7 @@ impl<'a> Neg for &'a ExtendedPoint {
impl<'a> Neg for &'a ProjectiveNielsPoint {
type Output = ProjectiveNielsPoint;

#[inline]
#[inline(always)]
fn neg(self) -> ProjectiveNielsPoint {
ProjectiveNielsPoint{
Y_plus_X: self.Y_minus_X,
Expand All @@ -874,7 +874,7 @@ impl<'a> Neg for &'a ProjectiveNielsPoint {
impl<'a> Neg for &'a AffineNielsPoint {
type Output = AffineNielsPoint;

#[inline]
#[inline(always)]
fn neg(self) -> AffineNielsPoint {
AffineNielsPoint{
y_plus_x: self.y_minus_x,
Expand All @@ -889,7 +889,7 @@ impl<'a> Neg for &'a AffineNielsPoint {
// ------------------------------------------------------------------------

impl<'b> MulAssign<&'b Scalar> for ExtendedPoint {
#[inline]
#[inline(always)]
fn mul_assign(&mut self, scalar: &'b Scalar) {
let result = (self as &ExtendedPoint) * scalar;
*self = result;
Expand All @@ -905,7 +905,7 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a ExtendedPoint {
///
/// Uses a window of size 4. Note: for scalar multiplication of
/// the basepoint, `basepoint_mult` is approximately 4x faster.
#[inline]
#[inline(always)]
fn mul(self, scalar: &'b Scalar) -> ExtendedPoint {
let A = self.to_projective_niels();
let mut As: [ProjectiveNielsPoint; 8] = [A; 8];
Expand All @@ -931,7 +931,7 @@ impl<'a, 'b> Mul<&'b ExtendedPoint> for &'a Scalar {
///
/// Uses a window of size 4. Note: for scalar multiplication of
/// the basepoint, `basepoint_mult` is approximately 4x faster.
#[inline]
#[inline(always)]
fn mul(self, point: &'b ExtendedPoint) -> ExtendedPoint {
point * &self
}
Expand Down Expand Up @@ -972,7 +972,7 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a EdwardsBasepointTable {
/// We then use the `select_precomputed_point` function, which
/// takes `-8 ≤ x < 8` and `[16^2i * B, ..., 8 * 16^2i * B]`,
/// and returns `x * 16^2i * B` in constant time.
#[inline]
#[inline(always)]
fn mul(self, scalar: &'b Scalar) -> ExtendedPoint {
let e = scalar.to_radix_16();
let mut h = ExtendedPoint::identity();
Expand Down Expand Up @@ -1024,7 +1024,7 @@ impl<'a, 'b> Mul<&'a EdwardsBasepointTable> for &'b Scalar {
/// We then use the `select_precomputed_point` function, which
/// takes `-8 ≤ x < 8` and `[16^2i * B, ..., 8 * 16^2i * B]`,
/// and returns `x * 16^2i * B` in constant time.
#[inline]
#[inline(always)]
fn mul(self, basepoint_table: &'a EdwardsBasepointTable) -> ExtendedPoint {
basepoint_table * &self
}
Expand Down Expand Up @@ -1063,14 +1063,14 @@ impl ExtendedPoint {
/// Multiply by the cofactor: compute `8 * self`.
///
/// Convenience wrapper around `mult_by_pow_2`.
#[inline]
#[inline(always)]
pub fn mult_by_cofactor(&self) -> ExtendedPoint {
self.mult_by_pow_2(3)
}

/// Compute `2^k * self` by successive doublings.
/// Requires `k > 0`.
#[inline]
#[inline(always)]
pub fn mult_by_pow_2(&self, k: u32) -> ExtendedPoint {
let mut r: CompletedPoint;
let mut s = self.to_projective();
Expand Down
18 changes: 9 additions & 9 deletions src/decaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,14 +528,14 @@ impl<'a, 'b> Add<&'b DecafPoint> for &'a DecafPoint {
sub_impl!(DecafPoint, DecafPoint, DecafPoint);

impl<'b> AddAssign<&'b DecafPoint> for DecafPoint {
#[inline]
#[inline(always)]
fn add_assign(&mut self, _rhs: &DecafPoint) {
*self = (self as &DecafPoint) + _rhs;
}
}

impl<'a, 'b> Sub<&'b DecafPoint> for &'a DecafPoint {
#[inline]
#[inline(always)]
type Output = DecafPoint;

fn sub(self, other: &'b DecafPoint) -> DecafPoint {
Expand All @@ -546,7 +546,7 @@ impl<'a, 'b> Sub<&'b DecafPoint> for &'a DecafPoint {
neg_impl!(DecafPoint, DecafPoint);

impl<'b> SubAssign<&'b DecafPoint> for DecafPoint {
#[inline]
#[inline(always)]
fn sub_assign(&mut self, _rhs: &DecafPoint) {
*self = (self as &DecafPoint) - _rhs;
}
Expand All @@ -555,14 +555,14 @@ impl<'b> SubAssign<&'b DecafPoint> for DecafPoint {
impl<'a> Neg for &'a DecafPoint {
type Output = DecafPoint;

#[inline]
#[inline(always)]
fn neg(self) -> DecafPoint {
DecafPoint(-&self.0)
}
}

impl<'b> MulAssign<&'b Scalar> for DecafPoint {
#[inline]
#[inline(always)]
fn mul_assign(&mut self, scalar: &'b Scalar) {
let result = (self as &DecafPoint) * scalar;
*self = result;
Expand All @@ -572,7 +572,7 @@ impl<'b> MulAssign<&'b Scalar> for DecafPoint {
impl<'a, 'b> Mul<&'b Scalar> for &'a DecafPoint {
type Output = DecafPoint;
/// Scalar multiplication: compute `scalar * self`.
#[inline]
#[inline(always)]
fn mul(self, scalar: &'b Scalar) -> DecafPoint {
DecafPoint(&self.0 * scalar)
}
Expand All @@ -582,7 +582,7 @@ impl<'a, 'b> Mul<&'b DecafPoint> for &'a Scalar {
type Output = DecafPoint;

/// Scalar multiplication: compute `self * scalar`.
#[inline]
#[inline(always)]
fn mul(self, point: &'b DecafPoint) -> DecafPoint {
DecafPoint(self * &point.0)
}
Expand All @@ -596,7 +596,7 @@ pub struct DecafBasepointTable(pub EdwardsBasepointTable);
impl<'a, 'b> Mul<&'b Scalar> for &'a DecafBasepointTable {
type Output = DecafPoint;

#[inline]
#[inline(always)]
fn mul(self, scalar: &'b Scalar) -> DecafPoint {
DecafPoint(&self.0 * scalar)
}
Expand All @@ -605,7 +605,7 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a DecafBasepointTable {
impl<'a, 'b> Mul<&'a DecafBasepointTable> for &'b Scalar {
type Output = DecafPoint;

#[inline]
#[inline(always)]
fn mul(self, basepoint_table: &'a DecafBasepointTable) -> DecafPoint {
DecafPoint(self * &basepoint_table.0)
}
Expand Down
2 changes: 1 addition & 1 deletion src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<'a, 'b> Sub<&'b FieldElement> for &'a FieldElement {
}

impl<'b> MulAssign<&'b FieldElement> for FieldElement {
#[inline]
#[inline(always)]
fn mul_assign(&mut self, _rhs: &'b FieldElement) {
let result = (self as &FieldElement) * _rhs;
self.0 = result.0;
Expand Down
14 changes: 7 additions & 7 deletions src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl IndexMut<usize> for Scalar {
}

impl<'b> MulAssign<&'b Scalar> for Scalar {
#[inline]
#[inline(always)]
fn mul_assign(&mut self, _rhs: &'b Scalar) {
let result = (self as &Scalar) * _rhs;
self.0 = result.0;
Expand All @@ -115,14 +115,14 @@ impl<'b> MulAssign<&'b Scalar> for Scalar {

impl<'a, 'b> Mul<&'b Scalar> for &'a Scalar {
type Output = Scalar;
#[inline]
#[inline(always)]
fn mul(self, _rhs: &'b Scalar) -> Scalar {
Scalar::multiply_add(self, _rhs, &Scalar::zero())
}
}

impl<'b> AddAssign<&'b Scalar> for Scalar {
#[inline]
#[inline(always)]
fn add_assign(&mut self, _rhs: &'b Scalar) {
*self = Scalar::multiply_add(&Scalar::one(), self, _rhs);
}
Expand All @@ -132,14 +132,14 @@ add_impl!(Scalar, Scalar, Scalar);

impl<'a, 'b> Add<&'b Scalar> for &'a Scalar {
type Output = Scalar;
#[inline]
#[inline(always)]
fn add(self, _rhs: &'b Scalar) -> Scalar {
Scalar::multiply_add(&Scalar::one(), self, _rhs)
}
}

impl<'b> SubAssign<&'b Scalar> for Scalar {
#[inline]
#[inline(always)]
fn sub_assign(&mut self, _rhs: &'b Scalar) {
// (l-1)*_rhs + self = self - _rhs
*self = Scalar::multiply_add(&constants::l_minus_1, _rhs, self);
Expand All @@ -150,7 +150,7 @@ sub_impl!(Scalar, Scalar, Scalar);

impl<'a, 'b> Sub<&'b Scalar> for &'a Scalar {
type Output = Scalar;
#[inline]
#[inline(always)]
fn sub(self, _rhs: &'b Scalar) -> Scalar {
// (l-1)*_rhs + self = self - _rhs
Scalar::multiply_add(&constants::l_minus_1, _rhs, self)
Expand All @@ -161,7 +161,7 @@ neg_impl!(Scalar, Scalar);

impl<'a> Neg for &'a Scalar {
type Output = Scalar;
#[inline]
#[inline(always)]
fn neg(self) -> Scalar {
self * &constants::l_minus_1
}
Expand Down

0 comments on commit 156c92d

Please sign in to comment.