pub struct BitVec { /* private fields */ }Expand description
An exact W-bit value, W in 1..=512.
Implementations§
Source§impl BitVec
impl BitVec
Sourcepub fn from_u64(width: Width, v: u64) -> Result<Self, ValueError>
pub fn from_u64(width: Width, v: u64) -> Result<Self, ValueError>
v, which must fit in width bits as an unsigned value.
Sourcepub fn from_u128(width: Width, v: u128) -> Result<Self, ValueError>
pub fn from_u128(width: Width, v: u128) -> Result<Self, ValueError>
v, which must fit in width bits as an unsigned value.
Sourcepub fn from_i128(width: Width, v: i128) -> Result<Self, ValueError>
pub fn from_i128(width: Width, v: i128) -> Result<Self, ValueError>
v, which must be representable as a width-bit signed value.
Sourcepub fn wrapping_from_u64(width: Width, v: u64) -> Self
pub fn wrapping_from_u64(width: Width, v: u64) -> Self
v truncated to width bits.
Sourcepub fn wrapping_from_u128(width: Width, v: u128) -> Self
pub fn wrapping_from_u128(width: Width, v: u128) -> Self
v truncated to width bits.
Sourcepub fn wrapping_from_i128(width: Width, v: i128) -> Self
pub fn wrapping_from_i128(width: Width, v: i128) -> Self
v in two’s complement, sign-extended or truncated to width bits.
Sourcepub fn from_limbs(width: Width, limbs: &[u64]) -> Result<Self, ValueError>
pub fn from_limbs(width: Width, limbs: &[u64]) -> Result<Self, ValueError>
Little-endian limbs, which must not have bits set at or above width.
Sourcepub fn wrapping_from_limbs(width: Width, limbs: &[u64]) -> Self
pub fn wrapping_from_limbs(width: Width, limbs: &[u64]) -> Self
Little-endian limbs truncated to width bits.
Sourcepub fn to_i128(&self) -> Option<i128>
pub fn to_i128(&self) -> Option<i128>
The signed (two’s-complement) value, if it fits in an i128.
Sourcepub fn apply_un(op: UnOp, a: &BitVec) -> Result<BitVec, WidthError>
pub fn apply_un(op: UnOp, a: &BitVec) -> Result<BitVec, WidthError>
Applies a unary operator. The only error is Bswap at a width that is not a multiple
of 8.
Sourcepub fn apply_bin(
op: BinOp,
a: &BitVec,
b: &BitVec,
) -> Result<BitVec, WidthError>
pub fn apply_bin( op: BinOp, a: &BitVec, b: &BitVec, ) -> Result<BitVec, WidthError>
Applies a binary operator. Both operands must have the same width.
Sourcepub fn apply_cmp(
op: impl Into<CmpOpExt>,
a: &BitVec,
b: &BitVec,
) -> Result<bool, WidthError>
pub fn apply_cmp( op: impl Into<CmpOpExt>, a: &BitVec, b: &BitVec, ) -> Result<bool, WidthError>
Evaluates a comparison. Both operands must have the same width.
Sourcepub fn zext(&self, to: Width) -> Result<BitVec, WidthError>
pub fn zext(&self, to: Width) -> Result<BitVec, WidthError>
Zero extension to to, which must be at least as wide (equal width is the identity).
Sourcepub fn sext(&self, to: Width) -> Result<BitVec, WidthError>
pub fn sext(&self, to: Width) -> Result<BitVec, WidthError>
Sign extension to to, which must be at least as wide (equal width is the identity).
Sourcepub fn trunc(&self, to: Width) -> Result<BitVec, WidthError>
pub fn trunc(&self, to: Width) -> Result<BitVec, WidthError>
The low to bits (to must not exceed the width).
Sourcepub fn concat(hi: &BitVec, lo: &BitVec) -> Result<BitVec, WidthError>
pub fn concat(hi: &BitVec, lo: &BitVec) -> Result<BitVec, WidthError>
hi in the high bits and lo in the low bits.
Sourcepub fn select(c: &BitVec, t: &BitVec, f: &BitVec) -> Result<BitVec, WidthError>
pub fn select(c: &BitVec, t: &BitVec, f: &BitVec) -> Result<BitVec, WidthError>
if c { t } else { f } for a 1-bit condition.
Sourcepub fn parse(s: &str) -> Result<BitVec, ParseError>
pub fn parse(s: &str) -> Result<BitVec, ParseError>
Parses <digits>:<width>, where digits are decimal (optionally negative), 0x hex or
0b binary, or the Verilog form <width>'h<hex> / 'd / 'b.
use bitwright::{BitVec, Width};
assert_eq!(BitVec::parse("0xff:8").unwrap(), BitVec::ones(Width::W8));
assert_eq!(BitVec::parse("-1:32").unwrap(), BitVec::ones(Width::W32));
assert_eq!(BitVec::parse("8'h80").unwrap(), BitVec::smin(Width::W8));Trait Implementations§
impl Copy for BitVec
impl Eq for BitVec
Source§impl Ord for BitVec
impl Ord for BitVec
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
By width, then by unsigned value. (A total order for sorting and canonical keys; use
BitVec::apply_cmp for signed or unsigned comparison of same-width values.)