From 72930b2566b35306099cbaea2550e1f7f135a6b1 Mon Sep 17 00:00:00 2001 From: NoCtrlZ Date: Thu, 27 Jan 2022 09:34:24 +0900 Subject: [PATCH] add x86_64 target --- src/bn256/fq.rs | 18 +++++++++--------- src/bn256/fr.rs | 14 +++++++------- src/bn256/mod.rs | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/bn256/fq.rs b/src/bn256/fq.rs index 4fd2ecf..e6afe38 100644 --- a/src/bn256/fq.rs +++ b/src/bn256/fq.rs @@ -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)] @@ -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 { @@ -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]; @@ -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] @@ -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]; @@ -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) diff --git a/src/bn256/fr.rs b/src/bn256/fr.rs index 9d10662..5a821ab 100644 --- a/src/bn256/fr.rs +++ b/src/bn256/fr.rs @@ -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)] @@ -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 { @@ -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] @@ -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]; @@ -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) diff --git a/src/bn256/mod.rs b/src/bn256/mod.rs index b31e18b..c6c9467 100644 --- a/src/bn256/mod.rs +++ b/src/bn256/mod.rs @@ -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::*;