From 04a32fb4435f747572bf5e86b19a6c1a881e8a99 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Mon, 4 Dec 2017 21:47:45 -0700 Subject: [PATCH 1/2] Introduce `expose-arith` unstable feature for exposing arithmetic functions downstream. --- Cargo.toml | 3 ++- src/lib.rs | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f0fe6aa..df9bd52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ byteorder = "1" clippy = { version = "0.0.174", optional = true } [features] -unstable-features = [] +unstable-features = ["expose-arith"] +expose-arith = [] u128-support = [] default = [] diff --git a/src/lib.rs b/src/lib.rs index 29c82be..b61fbc7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -613,14 +613,18 @@ fn test_bit_iterator() { assert!(a.next().is_none()); } -use self::arith::*; +#[cfg(not(feature = "expose-arith"))] +use self::arith_impl::*; + +#[cfg(feature = "expose-arith")] +pub use self::arith_impl::*; #[cfg(feature = "u128-support")] -mod arith { +mod arith_impl { /// Calculate a - b - borrow, returning the result and modifying /// the borrow value. #[inline(always)] - pub(crate) fn sbb(a: u64, b: u64, borrow: &mut u64) -> u64 { + pub fn sbb(a: u64, b: u64, borrow: &mut u64) -> u64 { let tmp = (1u128 << 64) + u128::from(a) - u128::from(b) - u128::from(*borrow); *borrow = if tmp >> 64 == 0 { 1 } else { 0 }; @@ -631,7 +635,7 @@ mod arith { /// Calculate a + b + carry, returning the sum and modifying the /// carry value. #[inline(always)] - pub(crate) fn adc(a: u64, b: u64, carry: &mut u64) -> u64 { + pub fn adc(a: u64, b: u64, carry: &mut u64) -> u64 { let tmp = u128::from(a) + u128::from(b) + u128::from(*carry); *carry = (tmp >> 64) as u64; @@ -642,7 +646,7 @@ mod arith { /// Calculate a + (b * c) + carry, returning the least significant digit /// and setting carry to the most significant digit. #[inline(always)] - pub(crate) fn mac_with_carry(a: u64, b: u64, c: u64, carry: &mut u64) -> u64 { + pub fn mac_with_carry(a: u64, b: u64, c: u64, carry: &mut u64) -> u64 { let tmp = (u128::from(a)) + u128::from(b) * u128::from(c) + u128::from(*carry); *carry = (tmp >> 64) as u64; @@ -652,7 +656,7 @@ mod arith { } #[cfg(not(feature = "u128-support"))] -mod arith { +mod arith_impl { #[inline(always)] fn split_u64(i: u64) -> (u64, u64) { (i >> 32, i & 0xFFFFFFFF) @@ -663,8 +667,10 @@ mod arith { (hi << 32) | lo } + /// Calculate a - b - borrow, returning the result and modifying + /// the borrow value. #[inline(always)] - pub(crate) fn sbb(a: u64, b: u64, borrow: &mut u64) -> u64 { + pub fn sbb(a: u64, b: u64, borrow: &mut u64) -> u64 { let (a_hi, a_lo) = split_u64(a); let (b_hi, b_lo) = split_u64(b); let (b, r0) = split_u64((1 << 32) + a_lo - b_lo - *borrow); @@ -675,8 +681,10 @@ mod arith { combine_u64(r1, r0) } + /// Calculate a + b + carry, returning the sum and modifying the + /// carry value. #[inline(always)] - pub(crate) fn adc(a: u64, b: u64, carry: &mut u64) -> u64 { + pub fn adc(a: u64, b: u64, carry: &mut u64) -> u64 { let (a_hi, a_lo) = split_u64(a); let (b_hi, b_lo) = split_u64(b); let (carry_hi, carry_lo) = split_u64(*carry); @@ -689,8 +697,10 @@ mod arith { combine_u64(r1, r0) } + /// Calculate a + (b * c) + carry, returning the least significant digit + /// and setting carry to the most significant digit. #[inline(always)] - pub(crate) fn mac_with_carry(a: u64, b: u64, c: u64, carry: &mut u64) -> u64 { + pub fn mac_with_carry(a: u64, b: u64, c: u64, carry: &mut u64) -> u64 { /* [ b_hi | b_lo ] [ c_hi | c_lo ] * From fb679470dbbdf4cf6931b37d0da17a29947bd5e8 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Mon, 4 Dec 2017 21:48:22 -0700 Subject: [PATCH 2/2] Bump version. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index df9bd52..80d0b05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "pairing" # Remember to change version string in README.md. -version = "0.13.1" +version = "0.13.2" authors = ["Sean Bowe "] license = "MIT/Apache-2.0"