pub struct BitVec { /* private fields */ }Expand description
Implementation of the Lean BitVec in Rust. The Lean version is a wrapper around a Fin,
a finite natural number that is guaranteed to be less than 2^width. In our implementation
we use a BigUint and enforce the invariant that it is less than 2^width. Trying to
create a bit-vector from a value greater than 2^width will truncate the value.
Implementations§
Source§impl BitVec
impl BitVec
Sourcepub fn extract_bits(&self, low: u32, high: u32) -> Result<Self, BitVecError>
pub fn extract_bits(&self, low: u32, high: u32) -> Result<Self, BitVecError>
Returns an integer representing the extracted bits from low to high, inclusive.
low and/or high may be 0 without causing errors. However, we must
have low <= high < self.width, else we’ll get Err (not panic).
Sourcepub fn signed_min(n: Width) -> Int
pub fn signed_min(n: Width) -> Int
Returns (as Int) the minimum signed value that fits in the given bit-width.
Compare to int_min(), which returns the minimum signed value as a BitVec.
Sourcepub fn signed_max(n: Width) -> Int
pub fn signed_max(n: Width) -> Int
Returns the maximum signed value that fits in the given bit-width.
Sourcepub fn int_min(width: Width) -> Self
pub fn int_min(width: Width) -> Self
Minimum signed value of the given bit-width, encoded as a BitVec.
Compare to signed_min(), which returns the minimum signed value as an Int.
Sourcepub fn slt(lhs: &Self, rhs: &Self) -> Result<bool, BitVecError>
pub fn slt(lhs: &Self, rhs: &Self) -> Result<bool, BitVecError>
Bit-vector signed less-than.
Sourcepub fn sle(lhs: &Self, rhs: &Self) -> Result<bool, BitVecError>
pub fn sle(lhs: &Self, rhs: &Self) -> Result<bool, BitVecError>
Bit-vector signed less-than-or-equal.
Sourcepub fn ule(lhs: &Self, rhs: &Self) -> Result<bool, BitVecError>
pub fn ule(lhs: &Self, rhs: &Self) -> Result<bool, BitVecError>
Bit-vector unsigned less-than-or-equal.
Sourcepub fn ult(lhs: &Self, rhs: &Self) -> Result<bool, BitVecError>
pub fn ult(lhs: &Self, rhs: &Self) -> Result<bool, BitVecError>
Bit-vector unsigned less-than.
Sourcepub fn add(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
pub fn add(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
Bit-vector addition.
Only returns Err if the lhs and rhs widths mismatch.
In particular, overflow is not an Err.
Sourcepub fn sub(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
pub fn sub(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
Bit-vector subtraction.
Only returns Err if the lhs and rhs widths mismatch.
In particular, overflow is not an Err.
Sourcepub fn mul(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
pub fn mul(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
Bit-vector multiplication.
Only returns Err if the lhs and rhs widths mismatch.
In particular, overflow is not an Err.
Sourcepub fn udiv(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
pub fn udiv(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
Bit-vector unsigned division.
Semantics to match SMT bit-vector theory here: https://smt-lib.org/theories-FixedSizeBitVectors.shtml
Only returns Err if the lhs and rhs widths mismatch.
In particular, overflow is not an Err.
Sourcepub fn urem(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
pub fn urem(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
Bit-vector unsigned remainder.
Semantics to match SMT bit-vector theory here: https://smt-lib.org/theories-FixedSizeBitVectors.shtml
Only returns Err if the lhs and rhs widths mismatch.
In particular, overflow is not an Err.
Sourcepub fn sdiv(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
pub fn sdiv(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
Bit-vector signed division.
Semantics to match SMT bit-vector logic here: https://smt-lib.org/logics-all.shtml
Only returns Err if the lhs and rhs widths mismatch.
In particular, overflow is not an Err.
Sourcepub fn srem(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
pub fn srem(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
Bit-vector signed remainder.
Semantics to match SMT bit-vector logic here: https://smt-lib.org/logics-all.shtml
Only returns Err if the lhs and rhs widths mismatch.
In particular, overflow is not an Err.
Sourcepub fn smod(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
pub fn smod(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
Bit-vector signed modulus.
Semantics to match SMT bit-vector logic here: https://smt-lib.org/logics-all.shtml
Only returns Err if the lhs and rhs widths mismatch.
In particular, overflow is not an Err.
Sourcepub fn shl(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
pub fn shl(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
Bit-vector left shift.
Returns Err if the lhs and rhs widths mismatch, or if the shift
amount does not fit in a u32.
Sourcepub fn lshr(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
pub fn lshr(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
Bit-vector logical right shift.
Returns Err if the lhs and rhs widths mismatch, or if the shift
amount does not fit in a u32.
Sourcepub fn concat(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
pub fn concat(lhs: &Self, rhs: &Self) -> Result<Self, BitVecError>
Bit-vector concatenation.
Panics if the total width exceeds u32::MAX. As of this writing, we shouldn’t ever construct any bitvector longer than 128, which is an extremely long way from u32::MAX.
Sourcepub fn zero_extend(bv: &Self, n: Width) -> Self
pub fn zero_extend(bv: &Self, n: Width) -> Self
Bit-vector unsigned (zero) extension.
This matches the Lean implementation that just adjusts the length of the bit-vector to match n (and not the SMT-LIB implementation that zero extends the bit-vector by n bits). If n is less than the current bit-width it will truncate
Trait Implementations§
impl Eq for BitVec
Source§impl Ord for BitVec
impl Ord for BitVec
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for BitVec
impl PartialOrd for BitVec
impl StructuralPartialEq for BitVec
Auto Trait Implementations§
impl Freeze for BitVec
impl RefUnwindSafe for BitVec
impl Send for BitVec
impl Sync for BitVec
impl Unpin for BitVec
impl UnsafeUnpin for BitVec
impl UnwindSafe for BitVec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more