1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use digit;
use bitwidth::BitWidth;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub(crate) enum Storage { Inl, Ext }
impl<W> From<W> for Storage
where W: Into<BitWidth>
{
#[inline]
fn from(width: W) -> Storage {
let width = width.into();
if Storage::is_inline(width) {
Storage::Inl
}
else {
Storage::Ext
}
}
}
impl Storage {
/// Returns `true` if the given `BitWidth` is small enough to be stored inline.
///
/// Note: Inline storage in the context of `ApInt` means that it is space-optimized
/// similar to the well-known small-string optimization.
#[inline]
fn is_inline(width: BitWidth) -> bool {
width.to_usize() <= digit::BITS
}
/// Returns `true` if the given `BitWidth` is large enough to require it to be stored externally.
///
/// Note: External storage in the context of `ApInt` means that it is **not** space-optimized
/// and thus stored on the heap with indirect access via pointer-to-data.
#[inline]
fn is_extern(width: BitWidth) -> bool {
!Storage::is_inline(width)
}
}