11//! Macro definitions which are a part of the public API.
22
3+ /// Calculate the number of limbs required to represent the given number of bits.
4+ // TODO(tarcieri): replace with `generic_const_exprs` (rust-lang/rust#76560) when stable
5+ #[ macro_export]
6+ macro_rules! nlimbs {
7+ ( $bits: expr) => {
8+ ( ( $bits + $crate:: Limb :: BITS - 1 ) / $crate:: Limb :: BITS ) as usize
9+ } ;
10+ }
11+
12+ /// Calculate the number of 62-bit unsaturated limbs required to represent the given number of bits when performing
13+ /// Bernstein-Yang inversions.
14+ // TODO(tarcieri): replace with `generic_const_exprs` (rust-lang/rust#76560) when stable
15+ macro_rules! bernstein_yang_nlimbs {
16+ ( $bits: expr) => {
17+ ( ( $bits / 64 ) + ( ( $bits / 64 ) * 2 ) . div_ceil( 64 ) + 1 )
18+ } ;
19+ }
20+
321/// Internal implementation detail of [`const_assert_eq`] and [`const_assert_ne`].
422#[ doc( hidden) ]
523#[ macro_export]
@@ -22,11 +40,11 @@ macro_rules! const_assert_n {
2240///
2341/// The first/leftmost operand MUST be a `usize` constant.
2442///
25- /// ```
43+ /// ```ignore
2644/// const N: usize = 0;
2745/// const _: () = crypto_bigint::const_assert_eq!(N, 0, "zero equals zero");
2846/// ```
29- #[ macro_export ]
47+ #[ allow ( unused_macros ) ] // TODO(tarcieri): not ready for external use
3048macro_rules! const_assert_eq {
3149 ( $left: ident, $right: expr $( , ) ?) => (
3250 $crate:: const_assert_n!( $left, $left == $right)
@@ -40,11 +58,10 @@ macro_rules! const_assert_eq {
4058///
4159/// The first/leftmost operand MUST be a `usize` constant.
4260///
43- /// ```
61+ /// ```ignore
4462/// const N: usize = 0;
4563/// const _: () = crypto_bigint::const_assert_ne!(N, 1, "zero is NOT equal to one");
4664/// ```
47- #[ macro_export]
4865macro_rules! const_assert_ne {
4966 ( $left: ident, $right: expr $( , ) ?) => (
5067 $crate:: const_assert_n!( $left, $left != $right)
@@ -54,24 +71,6 @@ macro_rules! const_assert_ne {
5471 ) ;
5572}
5673
57- /// Calculate the number of limbs required to represent the given number of bits.
58- // TODO(tarcieri): replace with `generic_const_exprs` (rust-lang/rust#76560) when stable
59- #[ macro_export]
60- macro_rules! nlimbs {
61- ( $bits: expr) => {
62- ( ( $bits + $crate:: Limb :: BITS - 1 ) / $crate:: Limb :: BITS ) as usize
63- } ;
64- }
65-
66- /// Calculate the number of 62-bit unsaturated limbs required to represent the given number of bits when performing
67- /// Bernstein-Yang inversions.
68- // TODO(tarcieri): replace with `generic_const_exprs` (rust-lang/rust#76560) when stable
69- macro_rules! bernstein_yang_nlimbs {
70- ( $bits: expr) => {
71- ( ( $bits / 64 ) + ( ( $bits / 64 ) * 2 ) . div_ceil( 64 ) + 1 )
72- } ;
73- }
74-
7574#[ cfg( test) ]
7675mod tests {
7776 #[ cfg( target_pointer_width = "32" ) ]
0 commit comments