diff --git a/ff/src/biginteger/macros.rs b/ff/src/biginteger/macros.rs index 138b05af6..ce2bed4de 100644 --- a/ff/src/biginteger/macros.rs +++ b/ff/src/biginteger/macros.rs @@ -17,7 +17,16 @@ macro_rules! bigint_impl { let mut carry = 0; for i in 0..$num_limbs { - self.0[i] = adc!(self.0[i], other.0[i], &mut carry); + #[cfg(all(target_arch = "x86_64", feature = "asm"))] + #[cfg_attr(all(target_arch = "x86_64", feature = "asm"), allow(unsafe_code))] + unsafe { + carry = core::arch::x86_64::_addcarry_u64(carry, self.0[i], other.0[i], &mut self.0[i]) + }; + + #[cfg(not(feature = "asm"))] + { + self.0[i] = adc!(self.0[i], other.0[i], &mut carry); + } } carry != 0 @@ -28,7 +37,16 @@ macro_rules! bigint_impl { let mut borrow = 0; for i in 0..$num_limbs { - self.0[i] = sbb!(self.0[i], other.0[i], &mut borrow); + #[cfg(all(target_arch = "x86_64", feature = "asm"))] + #[cfg_attr(all(target_arch = "x86_64", feature = "asm"), allow(unsafe_code))] + unsafe { + borrow = core::arch::x86_64::_subborrow_u64(borrow, self.0[i], other.0[i], &mut self.0[i]) + }; + + #[cfg(not(feature = "asm"))] + { + self.0[i] = sbb!(self.0[i], other.0[i], &mut borrow); + } } borrow != 0 diff --git a/ff/src/lib.rs b/ff/src/lib.rs index db280fa90..72ec5669d 100644 --- a/ff/src/lib.rs +++ b/ff/src/lib.rs @@ -1,9 +1,9 @@ #![cfg_attr(not(feature = "std"), no_std)] #![warn(unused, future_incompatible, nonstandard_style, rust_2018_idioms)] #![allow(clippy::op_ref, clippy::suspicious_op_assign_impl)] -#![cfg_attr(not(use_asm), forbid(unsafe_code))] +#![cfg_attr(not(feature = "asm"), forbid(unsafe_code))] #![cfg_attr(use_asm, feature(llvm_asm))] -#![cfg_attr(use_asm, deny(unsafe_code))] +#![cfg_attr(feature = "asm", deny(unsafe_code))] #[macro_use] extern crate ark_std;