Skip to content

Commit

Permalink
Drop the use_addcarry build config
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed May 4, 2024
1 parent f34e079 commit 5fbade7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
6 changes: 0 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,5 @@ fn main() {
println!("cargo:rustc-cfg=u64_digit");
}

if let Ok(arch) = env::var("CARGO_CFG_TARGET_ARCH") {
if arch == "x86_64" || arch == "x86" {
println!("cargo:rustc-cfg=use_addcarry");
}
}

println!("cargo:rerun-if-changed=build.rs");
}
16 changes: 5 additions & 11 deletions src/biguint/addition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,25 @@ use core::iter::Sum;
use core::ops::{Add, AddAssign};
use num_traits::CheckedAdd;

#[cfg(all(use_addcarry, target_arch = "x86_64"))]
use core::arch::x86_64 as arch;

#[cfg(all(use_addcarry, target_arch = "x86"))]
use core::arch::x86 as arch;

// Add with carry:
#[cfg(all(use_addcarry, u64_digit))]
#[cfg(target_arch = "x86_64")]
#[inline]
fn adc(carry: u8, a: u64, b: u64, out: &mut u64) -> u8 {
// Safety: There are absolutely no safety concerns with calling `_addcarry_u64`.
// It's just unsafe for API consistency with other intrinsics.
unsafe { arch::_addcarry_u64(carry, a, b, out) }
unsafe { core::arch::x86_64::_addcarry_u64(carry, a, b, out) }
}

#[cfg(all(use_addcarry, not(u64_digit)))]
#[cfg(target_arch = "x86")]
#[inline]
fn adc(carry: u8, a: u32, b: u32, out: &mut u32) -> u8 {
// Safety: There are absolutely no safety concerns with calling `_addcarry_u32`.
// It's just unsafe for API consistency with other intrinsics.
unsafe { arch::_addcarry_u32(carry, a, b, out) }
unsafe { core::arch::x86::_addcarry_u32(carry, a, b, out) }
}

// fallback for environments where we don't have an addcarry intrinsic
#[cfg(not(use_addcarry))]
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
#[inline]
fn adc(carry: u8, a: BigDigit, b: BigDigit, out: &mut BigDigit) -> u8 {
use crate::big_digit::DoubleBigDigit;
Expand Down
16 changes: 5 additions & 11 deletions src/biguint/subtraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,25 @@ use core::cmp::Ordering::{Equal, Greater, Less};
use core::ops::{Sub, SubAssign};
use num_traits::CheckedSub;

#[cfg(all(use_addcarry, target_arch = "x86_64"))]
use core::arch::x86_64 as arch;

#[cfg(all(use_addcarry, target_arch = "x86"))]
use core::arch::x86 as arch;

// Subtract with borrow:
#[cfg(all(use_addcarry, u64_digit))]
#[cfg(target_arch = "x86_64")]
#[inline]
fn sbb(borrow: u8, a: u64, b: u64, out: &mut u64) -> u8 {
// Safety: There are absolutely no safety concerns with calling `_subborrow_u64`.
// It's just unsafe for API consistency with other intrinsics.
unsafe { arch::_subborrow_u64(borrow, a, b, out) }
unsafe { core::arch::x86_64::_subborrow_u64(borrow, a, b, out) }
}

#[cfg(all(use_addcarry, not(u64_digit)))]
#[cfg(target_arch = "x86")]
#[inline]
fn sbb(borrow: u8, a: u32, b: u32, out: &mut u32) -> u8 {
// Safety: There are absolutely no safety concerns with calling `_subborrow_u32`.
// It's just unsafe for API consistency with other intrinsics.
unsafe { arch::_subborrow_u32(borrow, a, b, out) }
unsafe { core::arch::x86::_subborrow_u32(borrow, a, b, out) }
}

// fallback for environments where we don't have a subborrow intrinsic
#[cfg(not(use_addcarry))]
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
#[inline]
fn sbb(borrow: u8, a: BigDigit, b: BigDigit, out: &mut BigDigit) -> u8 {
use crate::big_digit::SignedDoubleBigDigit;
Expand Down

0 comments on commit 5fbade7

Please sign in to comment.