-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved Storage out of BitWidth into its own module. refactored dependi…
…ng code. decoupled Width trait verifications and assertions into an own trait.
- Loading branch information
Showing
9 changed files
with
113 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters