pub struct Tnum { /* private fields */ }Expand description
Tracking number
Tracks on a bit-by-bit level whether we know the value of a bit & what that value is (if known).
References:
- Linux’s production implementation: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/bpf/tnum.c
- Linux verifier documentation: https://docs.kernel.org/bpf/verifier.html#register-value-tracking
- https://bitmath.blogspot.com/2013/08/addition-in-bitfield-domain.html
- https://bitmath.blogspot.com/2014/02/addition-in-bitfield-domain-alternative.html
- “Abstract Domains for Bit-Level Machine Integer and Floating-point Operations” (paper)
- https://www.omnimaga.org/other-computer-languages-help/addition-in-the-bitfield-domain/
Implementations§
Source§impl Tnum
impl Tnum
Sourcepub const fn from_parts(value: u64, mask: u64) -> Self
pub const fn from_parts(value: u64, mask: u64) -> Self
Construct a tracking number from its known value and unknown-bit mask.
Value bits covered by the mask are cleared to maintain the canonical
value & mask == 0 representation.
pub const fn from_value(value: u64) -> Self
Sourcepub const fn parts(&self) -> Option<(u64, u64)>
pub const fn parts(&self) -> Option<(u64, u64)>
Return the canonical (known_value, unknown_mask) representation.
pub const fn is_const(&self) -> bool
pub const fn value(&self) -> Option<u64>
Sourcepub const fn contains_value(&self, value: u64) -> bool
pub const fn contains_value(&self, value: u64) -> bool
Whether this abstract value includes value.
Sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
Return the least tracking number containing both operands.
Sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
Return the values represented by both operands.
pub const fn is_defined(&self) -> bool
Sourcepub const fn contains(&self, other: Self) -> bool
pub const fn contains(&self, other: Self) -> bool
Whether this tracking number includes every value in other.
pub const fn has_value(&self) -> bool
pub const fn min_value(&self) -> Option<u64>
pub const fn max_value(&self) -> Option<u64>
pub const fn unsigned_bounds(&self) -> (u64, u64)
pub const fn signed_bounds(&self) -> (i64, i64)
pub const fn bit_not(self) -> Self
pub const fn bit_or(self, other: Self) -> Self
pub const fn bit_and(self, other: Self) -> Self
pub const fn bit_xor(self, other: Self) -> Self
pub const fn shift_left(self, shift: u8) -> Self
pub const fn shift_right(self, shift: u8) -> Self
pub const fn add(self, other: Self) -> Self
Trait Implementations§
impl Copy for Tnum
impl Eq for Tnum
impl StructuralPartialEq for Tnum
Auto Trait Implementations§
impl Freeze for Tnum
impl RefUnwindSafe for Tnum
impl Send for Tnum
impl Sync for Tnum
impl Unpin for Tnum
impl UnsafeUnpin for Tnum
impl UnwindSafe for Tnum
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
Mutably borrows from an owned value. Read more