1
1
//! Macro definitions which are a part of the public API.
2
2
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
+
3
21
/// Internal implementation detail of [`const_assert_eq`] and [`const_assert_ne`].
4
22
#[ doc( hidden) ]
5
23
#[ macro_export]
@@ -22,11 +40,11 @@ macro_rules! const_assert_n {
22
40
///
23
41
/// The first/leftmost operand MUST be a `usize` constant.
24
42
///
25
- /// ```
43
+ /// ```ignore
26
44
/// const N: usize = 0;
27
45
/// const _: () = crypto_bigint::const_assert_eq!(N, 0, "zero equals zero");
28
46
/// ```
29
- #[ macro_export ]
47
+ #[ allow ( unused_macros ) ] // TODO(tarcieri): not ready for external use
30
48
macro_rules! const_assert_eq {
31
49
( $left: ident, $right: expr $( , ) ?) => (
32
50
$crate:: const_assert_n!( $left, $left == $right)
@@ -40,11 +58,10 @@ macro_rules! const_assert_eq {
40
58
///
41
59
/// The first/leftmost operand MUST be a `usize` constant.
42
60
///
43
- /// ```
61
+ /// ```ignore
44
62
/// const N: usize = 0;
45
63
/// const _: () = crypto_bigint::const_assert_ne!(N, 1, "zero is NOT equal to one");
46
64
/// ```
47
- #[ macro_export]
48
65
macro_rules! const_assert_ne {
49
66
( $left: ident, $right: expr $( , ) ?) => (
50
67
$crate:: const_assert_n!( $left, $left != $right)
@@ -54,24 +71,6 @@ macro_rules! const_assert_ne {
54
71
) ;
55
72
}
56
73
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
-
75
74
#[ cfg( test) ]
76
75
mod tests {
77
76
#[ cfg( target_pointer_width = "32" ) ]
0 commit comments