]> git.proxmox.com Git - rustc.git/blame - vendor/crypto-bigint/src/nlimbs.rs
New upstream version 1.71.1+dfsg1
[rustc.git] / vendor / crypto-bigint / src / nlimbs.rs
CommitLineData
0a29b90c
FG
1/// Calculate the number of limbs required to represent the given number of bits.
2// TODO(tarcieri): replace with `generic_const_exprs` (rust-lang/rust#76560) when stable
3#[macro_export]
4macro_rules! nlimbs {
5 ($bits:expr) => {
49aad941 6 $bits / $crate::Limb::BITS
0a29b90c
FG
7 };
8}
9
10#[cfg(test)]
11mod tests {
12 #[cfg(target_pointer_width = "32")]
13 #[test]
14 fn nlimbs_for_bits_macro() {
15 assert_eq!(nlimbs!(64), 2);
16 assert_eq!(nlimbs!(128), 4);
17 assert_eq!(nlimbs!(192), 6);
18 assert_eq!(nlimbs!(256), 8);
19 }
20
21 #[cfg(target_pointer_width = "64")]
22 #[test]
23 fn nlimbs_for_bits_macro() {
24 assert_eq!(nlimbs!(64), 1);
25 assert_eq!(nlimbs!(128), 2);
26 assert_eq!(nlimbs!(192), 3);
27 assert_eq!(nlimbs!(256), 4);
28 }
29}