Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
add x86_64 target
Browse files Browse the repository at this point in the history
  • Loading branch information
ashWhiteHat committed Jan 27, 2022
1 parent a1f8f2e commit 72930b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/bn256/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rand::RngCore;
use std::io::{self, Read, Write};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

#[cfg(feature = "asm")]
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
use super::assembly::assembly_field;

#[derive(Clone, Copy, Eq)]
Expand Down Expand Up @@ -214,7 +214,7 @@ impl<'a, 'b> Mul<&'b Fq> for &'a Fq {
impl_binops_additive!(Fq, Fq);
impl_binops_multiplicative!(Fq, Fq);

#[cfg(feature = "asm")]
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
assembly_field!(Fq, MODULUS, INV);

impl Fq {
Expand Down Expand Up @@ -254,10 +254,10 @@ impl Fq {
pub fn to_bytes(&self) -> [u8; 32] {
// Turn into canonical form by computing
// (a.R) / R = a
#[cfg(feature = "asm")]
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
let tmp = Fq::montgomery_reduce(&[self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0]);

#[cfg(not(feature = "asm"))]
#[cfg(any(not(feature = "asm"), not(target_arch = "x86_64")))]
let tmp = Fq::montgomery_reduce(self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0);

let mut res = [0; 32];
Expand Down Expand Up @@ -289,7 +289,7 @@ impl Fq {
}
}

#[cfg(not(feature = "asm"))]
#[cfg(any(not(feature = "asm"), not(target_arch = "x86_64")))]
impl Fq {
/// Returns zero, the additive identity.
#[inline]
Expand Down Expand Up @@ -598,11 +598,11 @@ impl ff::PrimeField for Fq {
fn to_repr(&self) -> Self::Repr {
// Turn into canonical form by computing
// (a.R) / R = a
#[cfg(feature = "asm")]
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
let tmp =
Self::montgomery_reduce(&[self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0]);

#[cfg(not(feature = "asm"))]
#[cfg(any(not(feature = "asm"), not(target_arch = "x86_64")))]
let tmp = Self::montgomery_reduce(self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0);

let mut res = [0; 32];
Expand Down Expand Up @@ -690,10 +690,10 @@ impl FieldExt for Fq {
/// Gets the lower 128 bits of this field element when expressed
/// canonically.
fn get_lower_128(&self) -> u128 {
#[cfg(feature = "asm")]
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
let tmp = Fq::montgomery_reduce(&[self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0]);

#[cfg(not(feature = "asm"))]
#[cfg(any(not(feature = "asm"), not(target_arch = "x86_64")))]
let tmp = Fq::montgomery_reduce(self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0);

u128::from(tmp.0[0]) | (u128::from(tmp.0[1]) << 64)
Expand Down
14 changes: 7 additions & 7 deletions src/bn256/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

use crate::arithmetic::{adc, mac, sbb, BaseExt, FieldExt, Group};

#[cfg(feature = "asm")]
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
use super::assembly::assembly_field;

#[derive(Clone, Copy, Eq, Hash)]
Expand Down Expand Up @@ -222,7 +222,7 @@ impl<'a, 'b> Mul<&'b Fr> for &'a Fr {
impl_binops_additive!(Fr, Fr);
impl_binops_multiplicative!(Fr, Fr);

#[cfg(feature = "asm")]
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
assembly_field!(Fr, MODULUS, INV);

impl Fr {
Expand All @@ -231,7 +231,7 @@ impl Fr {
}
}

#[cfg(not(feature = "asm"))]
#[cfg(any(not(feature = "asm"), not(target_arch = "x86_64")))]
impl Fr {
/// Returns zero, the additive identity.
#[inline]
Expand Down Expand Up @@ -538,10 +538,10 @@ impl ff::PrimeField for Fr {
fn to_repr(&self) -> Self::Repr {
// Turn into canonical form by computing
// (a.R) / R = a
#[cfg(feature = "asm")]
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
let tmp = Fr::montgomery_reduce(&[self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0]);

#[cfg(not(feature = "asm"))]
#[cfg(any(not(feature = "asm"), not(target_arch = "x86_64")))]
let tmp = Fr::montgomery_reduce(self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0);

let mut res = [0; 32];
Expand Down Expand Up @@ -672,10 +672,10 @@ impl FieldExt for Fr {
/// Gets the lower 128 bits of this field element when expressed
/// canonically.
fn get_lower_128(&self) -> u128 {
#[cfg(feature = "asm")]
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
let tmp = Fr::montgomery_reduce(&[self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0]);

#[cfg(not(feature = "asm"))]
#[cfg(any(not(feature = "asm"), not(target_arch = "x86_64")))]
let tmp = Fr::montgomery_reduce(self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0);

u128::from(tmp.0[0]) | (u128::from(tmp.0[1]) << 64)
Expand Down
2 changes: 1 addition & 1 deletion src/bn256/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod fq6;
mod fr;
mod g;

#[cfg(feature = "asm")]
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
mod assembly;

pub use engine::*;
Expand Down

0 comments on commit 72930b2

Please sign in to comment.