]>
Commit | Line | Data |
---|---|---|
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] | |
4 | macro_rules! nlimbs { | |
5 | ($bits:expr) => { | |
49aad941 | 6 | $bits / $crate::Limb::BITS |
0a29b90c FG |
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 | } |