Skip to content

Commit

Permalink
Use intrinsics in add_nocarry/sub_noborrow
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Chuang <[email protected]>
  • Loading branch information
Pratyush and jon-chuang committed Feb 5, 2021
1 parent 8179812 commit 4e79b1f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
22 changes: 20 additions & 2 deletions ff/src/biginteger/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ff/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 4e79b1f

Please sign in to comment.