]> git.proxmox.com Git - rustc.git/blob - vendor/crypto-bigint/src/nlimbs.rs
New upstream version 1.75.0+dfsg1
[rustc.git] / vendor / crypto-bigint / src / nlimbs.rs
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]
4 macro_rules! nlimbs {
5 ($bits:expr) => {
6 $bits / $crate::Limb::BITS
7 };
8 }
9
10 #[cfg(test)]
11 mod 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 }