#[cfg(any(
feature = "zz32",
all(
not(feature = "zz64"),
target_arch = "aarch64")))]
mod zz32;
#[cfg(any(
feature = "zz32",
all(
not(feature = "zz64"),
target_arch = "aarch64")))]
pub use zz32::{Zu128, Zu256, Zu384};
#[cfg(any(
feature = "zz64",
all(
not(feature = "zz32"),
not(target_arch = "aarch64"))))]
mod zz;
#[cfg(any(
feature = "zz64",
all(
not(feature = "zz32"),
not(target_arch = "aarch64"))))]
pub use zz::{Zu128, Zu256, Zu384};
#[cfg(all(
feature = "gf255_m51",
feature = "gf255_m64",
))]
compile_error!("cannot use m51 and m64 GF255 implementations simultaneously");
#[cfg(all(
any(
feature = "gf255",
feature = "gf255e",
feature = "gf255s",
feature = "gf25519"),
not(feature = "gf255_m51"),
any(
feature = "gf255_m64",
not(target_arch = "riscv64")),
))]
pub mod gf255_m64;
#[cfg(all(
any(
feature = "gf255",
feature = "gf255e",
feature = "gf255s",
feature = "gf25519"),
not(feature = "gf255_m51"),
any(
feature = "gf255_m64",
not(target_arch = "riscv64")),
))]
pub use gf255_m64::GF255;
#[cfg(all(
any(
feature = "gf255",
feature = "gf255e",
feature = "gf255s",
feature = "gf25519"),
not(feature = "gf255_m64"),
any(
feature = "gf255_m51",
target_arch = "riscv64"),
))]
pub mod gf255_m51;
#[cfg(all(
any(
feature = "gf255",
feature = "gf255e",
feature = "gf255s",
feature = "gf25519"),
not(feature = "gf255_m64"),
any(
feature = "gf255_m51",
target_arch = "riscv64"),
))]
pub use gf255_m51::GF255;
#[cfg(feature = "gf255e")]
pub type GF255e = GF255<18651>;
#[cfg(feature = "gf255s")]
pub type GF255s = GF255<3957>;
#[cfg(feature = "gf25519")]
pub type GF25519 = GF255<19>;
#[cfg(any(
feature = "modint256",
feature = "gfp256",
))]
pub mod modint;
#[cfg(feature = "modint256")]
pub use modint::ModInt256;
#[cfg(all(
feature = "modint256",
not(target_arch = "aarch64")))]
pub type ModInt256ct<const M0: u64, const M1: u64, const M2: u64, const M3: u64> = ModInt256<M0, M1, M2, M3>;
#[cfg(all(
feature = "modint256",
target_arch = "aarch64"))]
pub mod modint32;
#[cfg(all(
feature = "modint256",
target_arch = "aarch64"))]
pub use modint32::ModInt256ct;
#[cfg(feature = "gfp256")]
pub type GFp256 = modint::ModInt256<
0xFFFFFFFFFFFFFFFF, 0x00000000FFFFFFFF,
0x0000000000000000, 0xFFFFFFFF00000001>;
#[cfg(feature = "gfp256")]
impl GFp256 {
pub fn encode(self) -> [u8; 32] {
self.encode32()
}
}
#[cfg(feature = "secp256k1")]
pub mod gfsecp256k1;
#[cfg(feature = "secp256k1")]
pub use gfsecp256k1::GFsecp256k1;
#[cfg(feature = "gf448")]
pub mod gf448;
#[cfg(feature = "gf448")]
pub use gf448::GF448;
pub mod lagrange;
#[cfg(feature = "gfgen")]
pub mod gfgen;
#[cfg(all(
feature = "gfb254",
not(any(
feature = "gfb254_m64",
feature = "gfb254_arm64pmull")),
any(
feature = "gfb254_x86clmul",
all(
target_arch = "x86_64",
target_feature = "sse4.1",
target_feature = "pclmulqdq"))))]
pub mod gfb254_x86clmul;
#[cfg(all(
feature = "gfb254",
not(any(
feature = "gfb254_m64",
feature = "gfb254_arm64pmull")),
any(
feature = "gfb254_x86clmul",
all(
target_arch = "x86_64",
target_feature = "sse4.1",
target_feature = "pclmulqdq"))))]
pub use gfb254_x86clmul::{GFb127, GFb254};
#[cfg(all(
feature = "gfb254",
not(any(
feature = "gfb254_x86clmul",
feature = "gfb254_m64")),
any(
feature = "gfb254_arm64pmull",
all(
target_arch = "aarch64",
target_feature = "aes"))))]
pub mod gfb254_arm64pmull;
#[cfg(all(
feature = "gfb254",
not(any(
feature = "gfb254_x86clmul",
feature = "gfb254_m64")),
any(
feature = "gfb254_arm64pmull",
all(
target_arch = "aarch64",
target_feature = "aes"))))]
pub use gfb254_arm64pmull::{GFb127, GFb254};
#[cfg(all(
feature = "gfb254",
not(any(
feature = "gfb254_x86clmul",
feature = "gfb254_arm64pmull")),
any(
feature = "gfb254_m64",
not(any(
all(
target_arch = "x86_64",
target_feature = "sse4.1",
target_feature = "pclmulqdq"),
all(
target_arch = "aarch64",
target_feature = "aes"))))))]
pub mod gfb254_m64;
#[cfg(all(
feature = "gfb254",
not(any(
feature = "gfb254_x86clmul",
feature = "gfb254_arm64pmull")),
any(
feature = "gfb254_m64",
not(any(
all(
target_arch = "x86_64",
target_feature = "sse4.1",
target_feature = "pclmulqdq"),
all(
target_arch = "aarch64",
target_feature = "aes"))))))]
pub use gfb254_m64::{GFb127, GFb254};
pub(crate) mod util32;
#[cfg(target_arch = "x86_64")]
#[allow(dead_code)]
#[inline(always)]
pub(crate) fn addcarry_u64(x: u64, y: u64, c: u8) -> (u64, u8) {
use core::arch::x86_64::_addcarry_u64;
unsafe {
let mut d = 0u64;
let cc = _addcarry_u64(c, x, y, &mut d);
(d, cc)
}
}
#[cfg(not(target_arch = "x86_64"))]
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn addcarry_u64(x: u64, y: u64, c: u8) -> (u64, u8) {
let z = (x as u128).wrapping_add(y as u128).wrapping_add(c as u128);
(z as u64, (z >> 64) as u8)
}
#[cfg(target_arch = "x86_64")]
#[allow(dead_code)]
#[inline(always)]
pub(crate) fn subborrow_u64(x: u64, y: u64, c: u8) -> (u64, u8) {
use core::arch::x86_64::_subborrow_u64;
unsafe {
let mut d = 0u64;
let cc = _subborrow_u64(c, x, y, &mut d);
(d, cc)
}
}
#[cfg(not(target_arch = "x86_64"))]
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn subborrow_u64(x: u64, y: u64, c: u8) -> (u64, u8) {
let z = (x as u128).wrapping_sub(y as u128).wrapping_sub(c as u128);
(z as u64, (z >> 127) as u8)
}
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn umull(x: u64, y: u64) -> (u64, u64) {
let z = (x as u128) * (y as u128);
(z as u64, (z >> 64) as u64)
}
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn umull_add(x: u64, y: u64, z: u64) -> (u64, u64) {
let t = ((x as u128) * (y as u128)).wrapping_add(z as u128);
(t as u64, (t >> 64) as u64)
}
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn umull_add2(x: u64, y: u64, z1: u64, z2: u64) -> (u64, u64) {
let t = ((x as u128) * (y as u128))
.wrapping_add(z1 as u128).wrapping_add(z2 as u128);
(t as u64, (t >> 64) as u64)
}
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn umull_x2(x1: u64, y1: u64, x2: u64, y2: u64) -> (u64, u64) {
let z1 = (x1 as u128) * (y1 as u128);
let z2 = (x2 as u128) * (y2 as u128);
let z = z1.wrapping_add(z2);
(z as u64, (z >> 64) as u64)
}
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn umull_x2_add(x1: u64, y1: u64, x2: u64, y2: u64, z3: u64) -> (u64, u64) {
let z1 = (x1 as u128) * (y1 as u128);
let z2 = (x2 as u128) * (y2 as u128);
let z = z1.wrapping_add(z2).wrapping_add(z3 as u128);
(z as u64, (z >> 64) as u64)
}
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn sgnw(x: u64) -> u64 {
((x as i64) >> 63) as u64
}
#[cfg(any(
all(target_arch = "x86_64", target_feature = "lzcnt"),
target_arch = "aarch64",
))]
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn lzcnt(x: u64) -> u32 {
x.leading_zeros()
}
#[cfg(not(any(
all(target_arch = "x86_64", target_feature = "lzcnt"),
target_arch = "aarch64",
)))]
#[allow(dead_code)]
pub(crate) const fn lzcnt(x: u64) -> u32 {
let m = sgnw((x >> 32).wrapping_sub(1));
let s = m & 32;
let x = (x >> 32) ^ (m & (x ^ (x >> 32)));
let m = sgnw((x >> 16).wrapping_sub(1));
let s = s | (m & 16);
let x = (x >> 16) ^ (m & (x ^ (x >> 16)));
let m = sgnw((x >> 8).wrapping_sub(1));
let s = s | (m & 8);
let x = (x >> 8) ^ (m & (x ^ (x >> 8)));
let m = sgnw((x >> 4).wrapping_sub(1));
let s = s | (m & 4);
let x = (x >> 4) ^ (m & (x ^ (x >> 4)));
let m = sgnw((x >> 2).wrapping_sub(1));
let s = s | (m & 2);
let x = (x >> 2) ^ (m & (x ^ (x >> 2)));
let s = s.wrapping_add(2u64.wrapping_sub(x) & ((x.wrapping_sub(3) >> 2)));
s as u32
}