| Copyright | (c) Galois Inc 2020 |
|---|---|
| License | BSD3 |
| Maintainer | huffman@galois.com |
| Safe Haskell | None |
| Language | Haskell2010 |
What4.Domains.BV.Bitwise
Description
Provides a bitwise implementation of bitvector abstract domains.
Synopsis
- data Domain (w :: Nat) = BVBitInterval !Integer !Integer !Integer
- bitle :: Integer -> Integer -> Bool
- proper :: forall (w :: Nat). NatRepr w -> Domain w -> Bool
- bvdMask :: forall (w :: Nat). Domain w -> Integer
- member :: forall (w :: Nat). Domain w -> Integer -> Bool
- pmember :: forall (n :: Nat). NatRepr n -> Domain n -> Integer -> Bool
- size :: forall (w :: Nat). Domain w -> Integer
- asSingleton :: forall (w :: Nat). Domain w -> Maybe Integer
- nonempty :: forall (w :: Nat). Domain w -> Bool
- eq :: forall (w :: Nat). Domain w -> Domain w -> Maybe Bool
- slt :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Maybe Bool
- ult :: forall (w :: Nat). Domain w -> Domain w -> Maybe Bool
- domainsOverlap :: forall (w :: Nat). Domain w -> Domain w -> Bool
- bitbounds :: forall (w :: Nat). Domain w -> (Integer, Integer)
- ubounds :: forall (w :: Nat). Domain w -> (Integer, Integer)
- sbounds :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> (Integer, Integer)
- top :: forall (w :: Nat). NatRepr w -> Domain w
- any :: forall (w :: Nat). NatRepr w -> Domain w
- bottom :: forall (w :: Nat). NatRepr w -> Domain w
- isBottom :: forall (w :: Nat). Domain w -> Bool
- join :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- union :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- meet :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- intersection :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- leq :: forall (w :: Nat). Domain w -> Domain w -> Bool
- singleton :: forall (w :: Nat). NatRepr w -> Integer -> Domain w
- range :: forall (w :: Nat). NatRepr w -> Integer -> Integer -> Domain w
- interval :: forall (w :: Nat). Integer -> Integer -> Integer -> Domain w
- concat :: forall (u :: Nat) (v :: Nat). NatRepr u -> Domain u -> NatRepr v -> Domain v -> Domain (u + v)
- select :: forall (n :: Natural) (i :: Natural) (w :: Natural). (1 <= n, (i + n) <= w) => NatRepr i -> NatRepr n -> Domain w -> Domain n
- zext :: forall (w :: Natural) (u :: Natural). (1 <= w, (w + 1) <= u) => Domain w -> NatRepr u -> Domain u
- sext :: forall (w :: Natural) (u :: Natural). (1 <= w, (w + 1) <= u) => NatRepr w -> Domain w -> NatRepr u -> Domain u
- testBit :: forall (w :: Nat). Domain w -> Natural -> Maybe Bool
- shl :: forall (w :: Nat). NatRepr w -> Domain w -> Integer -> Domain w
- lshr :: forall (w :: Nat). NatRepr w -> Domain w -> Integer -> Domain w
- ashr :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Integer -> Domain w
- rol :: forall (w :: Nat). NatRepr w -> Domain w -> Integer -> Domain w
- ror :: forall (w :: Nat). NatRepr w -> Domain w -> Integer -> Domain w
- shlAbstract :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w
- lshrAbstract :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w
- ashrAbstract :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w
- rolAbstract :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w
- rorAbstract :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w
- shlAbstractSpec :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w
- lshrAbstractSpec :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w
- ashrAbstractSpec :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w
- rolAbstractSpec :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w
- rorAbstractSpec :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w
- add :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- sub :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- negate :: forall (w :: Nat). Domain w -> Domain w
- scale :: forall (w :: Nat). Integer -> Domain w -> Domain w
- mul :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- mulPrecise :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- udiv :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- urem :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- sdiv :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w
- srem :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w
- udivPrecise :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w
- uremPrecise :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w
- udivSmtlib :: forall (w :: Natural). 1 <= w => Domain w -> Domain w -> Domain w
- uremSmtlib :: forall (w :: Natural). 1 <= w => Domain w -> Domain w -> Domain w
- sdivSmtlib :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w
- sremSmtlib :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w
- and :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- or :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- xor :: forall (w :: Nat). Domain w -> Domain w -> Domain w
- not :: forall (w :: Nat). Domain w -> Domain w
- genDomain :: forall (w :: Nat). NatRepr w -> Gen (Domain w)
- genElement :: forall (w :: Nat). Domain w -> Gen Integer
- genPair :: forall (w :: Nat). NatRepr w -> Gen (Domain w, Integer)
- correct_any :: forall (n :: Natural). 1 <= n => NatRepr n -> Integer -> Property
- correct_singleton :: forall (n :: Natural). 1 <= n => NatRepr n -> Integer -> Integer -> Property
- correct_overlap :: forall (n :: Nat). Domain n -> Domain n -> Integer -> Property
- correct_overlap_inv :: forall (n :: Nat). Domain n -> Domain n -> Property
- correct_asSingleton :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Property
- correct_union :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Integer -> Property
- correct_intersection :: forall (n :: Natural). 1 <= n => Domain n -> Domain n -> Integer -> Property
- correct_join :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Integer -> Property
- correct_meet :: forall (n :: Natural). 1 <= n => Domain n -> Domain n -> Integer -> Property
- precise_meet :: forall (n :: Natural). 1 <= n => Domain n -> Domain n -> Integer -> Property
- correct_leq :: forall (n :: Nat). Domain n -> Domain n -> Integer -> Property
- join_commutative :: forall (n :: Nat). Domain n -> Domain n -> Integer -> Property
- join_idempotent :: forall (n :: Nat). Domain n -> Integer -> Property
- meet_commutative :: forall (n :: Nat). Domain n -> Domain n -> Integer -> Property
- meet_idempotent :: forall (n :: Nat). Domain n -> Integer -> Property
- join_top :: forall (n :: Nat). NatRepr n -> Domain n -> Integer -> Property
- join_bottom :: forall (n :: Nat). NatRepr n -> Domain n -> Integer -> Property
- meet_top :: forall (n :: Nat). NatRepr n -> Domain n -> Integer -> Property
- meet_bottom :: forall (n :: Nat). NatRepr n -> Domain n -> Integer -> Property
- leq_reflexive :: forall (n :: Nat). Domain n -> Property
- leq_transitive :: forall (n :: Nat). Domain n -> Domain n -> Domain n -> Property
- meet_lower_bound :: forall (n :: Nat). Domain n -> Domain n -> Property
- join_upper_bound :: forall (n :: Nat). Domain n -> Domain n -> Property
- join_monotone :: forall (n :: Nat). Domain n -> Domain n -> Domain n -> Property
- meet_monotone :: forall (n :: Nat). Domain n -> Domain n -> Domain n -> Property
- join_associative :: forall (n :: Nat). Domain n -> Domain n -> Domain n -> Integer -> Property
- meet_associative :: forall (n :: Nat). Domain n -> Domain n -> Domain n -> Integer -> Property
- join_absorb :: forall (n :: Nat). Domain n -> Domain n -> Integer -> Property
- meet_absorb :: forall (n :: Nat). Domain n -> Domain n -> Integer -> Property
- join_proper :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property
- meet_proper :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property
- correct_zero_ext :: forall (w :: Natural) (u :: Natural). (1 <= w, (w + 1) <= u) => NatRepr w -> Domain w -> NatRepr u -> Integer -> Property
- correct_sign_ext :: forall (w :: Natural) (u :: Natural). (1 <= w, (w + 1) <= u) => NatRepr w -> Domain w -> NatRepr u -> Integer -> Property
- correct_concat :: forall (m :: Nat) (n :: Nat). NatRepr m -> (Domain m, Integer) -> NatRepr n -> (Domain n, Integer) -> Property
- correct_shrink :: forall (i :: Nat) (n :: Nat). NatRepr i -> NatRepr n -> (Domain (i + n), Integer) -> Property
- correct_trunc :: forall (n :: Nat) (w :: Nat). n <= w => NatRepr n -> (Domain w, Integer) -> Property
- correct_select :: forall (n :: Natural) (i :: Natural) (w :: Natural). (1 <= n, (i + n) <= w) => NatRepr i -> NatRepr n -> (Domain w, Integer) -> Property
- correct_shl :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Integer -> Property
- correct_lshr :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Integer -> Property
- correct_ashr :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Integer -> Property
- correct_rol :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Integer -> Property
- correct_ror :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Integer -> Property
- correct_shlAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_lshrAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_ashrAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_rolAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_rorAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_equiv_shlAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property
- correct_equiv_lshrAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property
- correct_equiv_ashrAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property
- correct_equiv_rolAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property
- correct_equiv_rorAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property
- correct_eq :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_ult :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_slt :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_ubounds :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Property
- correct_sbounds :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Property
- correct_add :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_sub :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_neg :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Property
- correct_scale :: forall (n :: Natural). 1 <= n => NatRepr n -> Integer -> (Domain n, Integer) -> Property
- correct_mul :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_mulPrecise :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_udiv :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_urem :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_sdiv :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_srem :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_udivPrecise :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_uremPrecise :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_udivSmtlib :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_uremSmtlib :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_sdivSmtlib :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_sremSmtlib :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_and :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_or :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_not :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Property
- correct_xor :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property
- correct_testBit :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Natural -> Property
Documentation
data Domain (w :: Nat) Source #
A bitwise interval domain, defined via a
bitwise upper and lower bound. The ordering
used here to construct the interval is the pointwise
ordering on bits. In particular x [= y iff x .|. y == y,
and a value x is in the set defined by the pair (lo,hi)
just when lo [= x && x [= hi.
Constructors
| BVBitInterval !Integer !Integer !Integer |
|
proper :: forall (w :: Nat). NatRepr w -> Domain w -> Bool Source #
O(w). Test if the domain satisfies its invariants.
bvdMask :: forall (w :: Nat). Domain w -> Integer Source #
O(1). Return the bitvector mask value from this domain.
member :: forall (w :: Nat). Domain w -> Integer -> Bool Source #
O(w). Test if the given integer value is a member of the abstract domain.
pmember :: forall (n :: Nat). NatRepr n -> Domain n -> Integer -> Bool Source #
Check that a domain is proper, and that the given value is a member
size :: forall (w :: Nat). Domain w -> Integer Source #
O(w). Compute how many concrete elements are in the abstract domain.
asSingleton :: forall (w :: Nat). Domain w -> Maybe Integer Source #
O(w). Test if this domain contains a single value, and return it if so.
nonempty :: forall (w :: Nat). Domain w -> Bool Source #
O(w). Returns true iff there is at least one element in this bitwise domain.
eq :: forall (w :: Nat). Domain w -> Domain w -> Maybe Bool Source #
O(w). Decide equality of two domains: 'Just True' if both are the same
singleton, 'Just False' if they're disjoint, Nothing otherwise.
slt :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Maybe Bool Source #
O(w). Check if all elements in one domain are signed-less-than all elements in the other.
ult :: forall (w :: Nat). Domain w -> Domain w -> Maybe Bool Source #
O(w). Check if all elements in one domain are unsigned-less-than all elements in the other.
domainsOverlap :: forall (w :: Nat). Domain w -> Domain w -> Bool Source #
O(w). Returns true iff the domains have some value in common.
bitbounds :: forall (w :: Nat). Domain w -> (Integer, Integer) Source #
O(1). Bitwise lower and upper bounds.
ubounds :: forall (w :: Nat). Domain w -> (Integer, Integer) Source #
O(1). Unsigned bounds for the domain. The low bit-pattern bound is also the unsigned minimum, and the high bit-pattern bound is also the unsigned maximum: setting unknown bits to 0 minimizes, setting them to 1 maximizes.
sbounds :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> (Integer, Integer) Source #
O(w). Signed bounds for the domain.
Lattice operations
top :: forall (w :: Nat). NatRepr w -> Domain w Source #
O(1). Top element of the lattice: represents all bitvectors of width w.
any :: forall (w :: Nat). NatRepr w -> Domain w Source #
Deprecated: Use top instead
O(w). Bitwise domain containing every bitvector value.
bottom :: forall (w :: Nat). NatRepr w -> Domain w Source #
O(1). Bottom element of the lattice: represents the empty set of bitvectors. This is an improper domain whose membership predicate is unsatisfiable.
join :: forall (w :: Nat). Domain w -> Domain w -> Domain w Source #
O(w). Lattice join: pointwise least upper bound on the bit-level bitle ordering.
meet :: forall (w :: Nat). Domain w -> Domain w -> Domain w Source #
O(w). Lattice meet: pointwise greatest lower bound on the bit-level bitle ordering.
If both inputs are proper (or bottom), so is the result.
intersection :: forall (w :: Nat). Domain w -> Domain w -> Domain w Source #
Deprecated: Use meet instead
leq :: forall (w :: Nat). Domain w -> Domain w -> Bool Source #
O(w). Lattice ordering: leq a b returns True if every concrete value
represented by a is also represented by b.
Operations
singleton :: forall (w :: Nat). NatRepr w -> Integer -> Domain w Source #
O(w). Return a domain containing just the given value.
range :: forall (w :: Nat). NatRepr w -> Integer -> Integer -> Domain w Source #
O(w). Construct a domain from bitwise lower and upper bounds.
interval :: forall (w :: Nat). Integer -> Integer -> Integer -> Domain w Source #
O(1). Unsafe constructor for internal use.
concat :: forall (u :: Nat) (v :: Nat). NatRepr u -> Domain u -> NatRepr v -> Domain v -> Domain (u + v) Source #
O(u + v). concat a y returns a domain where each element in a has
been concatenated with an element in y. The most-significant bits are
a, and the least significant bits are y.
select :: forall (n :: Natural) (i :: Natural) (w :: Natural). (1 <= n, (i + n) <= w) => NatRepr i -> NatRepr n -> Domain w -> Domain n Source #
O(w). select i n a selects n bits starting from index i from a.
zext :: forall (w :: Natural) (u :: Natural). (1 <= w, (w + 1) <= u) => Domain w -> NatRepr u -> Domain u Source #
O(w). Zero-extend a domain to a larger width.
sext :: forall (w :: Natural) (u :: Natural). (1 <= w, (w + 1) <= u) => NatRepr w -> Domain w -> NatRepr u -> Domain u Source #
O(w). Sign-extend a domain to a larger width.
testBit :: forall (w :: Nat). Domain w -> Natural -> Maybe Bool Source #
O(w). Test bit i of every value in the domain: 'Just True' if it is
set in every member, 'Just False' if clear in every member, Nothing if
it varies.
shifts and rotates
shl :: forall (w :: Nat). NatRepr w -> Domain w -> Integer -> Domain w Source #
O(w). Shift left by a known amount.
lshr :: forall (w :: Nat). NatRepr w -> Domain w -> Integer -> Domain w Source #
O(w). Logical (zero-fill) shift right by a known amount.
ashr :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Integer -> Domain w Source #
O(w). Arithmetic (sign-extending) shift right by a known amount.
rol :: forall (w :: Nat). NatRepr w -> Domain w -> Integer -> Domain w Source #
O(w). Rotate left by a known amount.
ror :: forall (w :: Nat). NatRepr w -> Domain w -> Integer -> Domain w Source #
O(w). Rotate right by a known amount.
shlAbstract :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w Source #
O(w²). Shift left by an amount drawn from the domain b. See
foldShifts for the algorithm.
More precisely, O(n · w) where w is the bitvector width and
n = min(bh − bl + 1, w + 1) is the number of candidate shift amounts
considered, with bl and bh the unsigned bounds of b.
lshrAbstract :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w Source #
O(w²). Logical (zero-fill) shift right by an amount drawn from
the domain b. See foldShifts for the algorithm.
More precisely, O(n · w) where w is the bitvector width and
n = min(bh − bl + 1, w + 1) is the number of candidate shift amounts
considered, with bl and bh the unsigned bounds of b.
ashrAbstract :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w Source #
O(w²). Arithmetic (sign-extending) shift right by an amount drawn
from the domain b. See foldShifts for the algorithm.
More precisely, O(n · w) where w is the bitvector width and
n = min(bh − bl + 1, w + 1) is the number of candidate shift amounts
considered, with bl and bh the unsigned bounds of b.
rolAbstract :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w Source #
O(w²). Rotate left by an amount drawn from the domain b. See
foldRotates for the algorithm.
More precisely, O(r · w) where w is the bitvector width and r is
the number of distinct residues mod w that are reachable from b
(at most w).
rorAbstract :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w Source #
O(w²). Rotate right by an amount drawn from the domain b.
Mirrors rolAbstract.
More precisely, O(r · w) where w is the bitvector width and r is
the number of distinct residues mod w that are reachable from b
(at most w).
shlAbstractSpec :: forall (w :: Nat). NatRepr w -> Domain w -> Domain w -> Domain w Source #
Declarative reference variant of shlAbstract: for every member
y of the shift-amount domain, compute the per-shift result and
union them all. Strictly slower; used to validate shlAbstract.
ashrAbstractSpec :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w Source #
arithmetic
sub :: forall (w :: Nat). Domain w -> Domain w -> Domain w Source #
O(w). Subtract: sub a b = add a (negate b).
negate :: forall (w :: Nat). Domain w -> Domain w Source #
O(w). Two's complement negation: negate a = not a + 1.
scale :: forall (w :: Nat). Integer -> Domain w -> Domain w Source #
O(w²). Multiply by a constant. Uses mulPrecise since the
shift-and-add algorithm gives bit-level precision when one operand
is concrete.
mul :: forall (w :: Nat). Domain w -> Domain w -> Domain w Source #
O(w). Multiply two bitwise domains via interval and trailing-zero
analysis. Captures known leading bits (both 0s and 1s) derived from
[aMin*bMin, aMax*bMax], plus known trailing zeros from the operands.
See mul for the algorithm. mulPrecise is strictly more
precise; this is the cheaper alternative when middle-bit precision
doesn't matter.
udiv :: forall (w :: Nat). Domain w -> Domain w -> Domain w Source #
O(w). Unsigned division via interval analysis on the quotient bounds. Assumes the divisor is nonzero.
Captures known leading bits (both 0s and 1s) derived from
[aMin `quot` bMax, aMax `quot` bMin]. When the divisor is a known
power of two, the result is exact (bit-level structure of the dividend
is preserved, e.g. udiv (any w) (singleton w (2^k)) has its top k
bits known zero). udivPrecise is strictly more precise; this is the
cheaper alternative when middle-bit precision doesn't matter.
urem :: forall (w :: Nat). Domain w -> Domain w -> Domain w Source #
O(w). Unsigned remainder via leading-zero analysis. Assumes the divisor is nonzero.
The result is bounded above by min(aMax, bMax - 1); bits above that are
known zero. (The remainder's lower bound is trivially 0, so the same
interval-agreement analysis used in udiv would not yield additional
leading bits here.) When the divisor is a known power of two,
urem a (singleton w (2^k)) is exactly the low k bits of a.
sdiv :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w Source #
O(w). Signed division (rounds toward zero). Assumes the divisor is nonzero.
Implemented by splitting each operand on its sign bit into a non-negative
"zero circle" and a negative "one circle", applying udiv to the
absolute values, fixing up the sign, and joining the resulting subcases.
srem :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w Source #
O(w). Signed remainder (sign of dividend). Assumes the divisor is nonzero.
Implemented like sdiv, except the result takes the sign of the dividend
rather than the XOR of the input signs. Additionally, leading bits of the
result are refined using magnitude bounds: if the dividend is non-negative,
the result has leading zeros from both the dividend and divisor magnitude;
if negative and nonzero, it has leading ones similarly.
udivPrecise :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w Source #
O(w²). Unsigned division combining abstract schoolbook long division
with the interval analysis of udiv. Assumes the divisor is nonzero.
Strictly at least as precise as udiv.
The result is the intersection of udiv (interval analysis on the
quotient bounds, plus an exact path for power-of-two divisors) and the
schoolbook result (which captures middle-bit structure that interval
analysis can't see, but joins through any undetermined comparison and so
loses on power-of-two divisors).
uremPrecise :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w Source #
arithmetic (SMT-LIB div-by-zero semantics)
udivSmtlib :: forall (w :: Natural). 1 <= w => Domain w -> Domain w -> Domain w Source #
O(w). Like udiv, but using the SMT-LIB FixedSizeBitVectors theory's
div-by-zero semantics: bvudiv s 0 is the all-ones bitvector. See Note
[SMT-LIB division] in What4.Interface for the design rationale.
uremSmtlib :: forall (w :: Natural). 1 <= w => Domain w -> Domain w -> Domain w Source #
O(w). Like urem, but using the SMT-LIB FixedSizeBitVectors theory's
div-by-zero semantics: bvurem s 0 is the dividend itself (s). See Note
[SMT-LIB division] in What4.Interface for the design rationale.
sdivSmtlib :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w Source #
O(w). Like sdiv, but using the SMT-LIB QF_BV logic's div-by-zero
convention: bvsdiv s 0 is all-ones when s is non-negative and 1 when
s is negative. See Note [SMT-LIB division] in What4.Interface for the
design rationale.
sremSmtlib :: forall (w :: Natural). 1 <= w => NatRepr w -> Domain w -> Domain w -> Domain w Source #
O(w). Like srem, but using the SMT-LIB QF_BV logic's div-by-zero
convention: bvsrem s 0 is the dividend itself (s). See Note [SMT-LIB
division] in What4.Interface for the design rationale.
bitwise logical
and :: forall (w :: Nat). Domain w -> Domain w -> Domain w Source #
O(w). Bitwise AND of two domains.
xor :: forall (w :: Nat). Domain w -> Domain w -> Domain w Source #
O(w). Bitwise XOR of two domains.
Correctness properties
genDomain :: forall (w :: Nat). NatRepr w -> Gen (Domain w) Source #
Random generator for domain values. We always generate nonempty domain values.
genPair :: forall (w :: Nat). NatRepr w -> Gen (Domain w, Integer) Source #
Generate a random nonempty domain and an element contained in that domain.
correct_singleton :: forall (n :: Natural). 1 <= n => NatRepr n -> Integer -> Integer -> Property Source #
correct_overlap_inv :: forall (n :: Nat). Domain n -> Domain n -> Property Source #
If domainsOverlap returns True, then a shared witness exists
at the bitwise OR of the two low masks.
correct_union :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Integer -> Property Source #
correct_intersection :: forall (n :: Natural). 1 <= n => Domain n -> Domain n -> Integer -> Property Source #
correct_join :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Integer -> Property Source #
correct_meet :: forall (n :: Natural). 1 <= n => Domain n -> Domain n -> Integer -> Property Source #
precise_meet :: forall (n :: Natural). 1 <= n => Domain n -> Domain n -> Integer -> Property Source #
Precision of meet: if x is a member of meet a b, then x is
a member of both a and b.
Lattice laws
join_associative :: forall (n :: Nat). Domain n -> Domain n -> Domain n -> Integer -> Property Source #
meet_associative :: forall (n :: Nat). Domain n -> Domain n -> Domain n -> Integer -> Property Source #
join_proper :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property Source #
meet_proper :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property Source #
correct_zero_ext :: forall (w :: Natural) (u :: Natural). (1 <= w, (w + 1) <= u) => NatRepr w -> Domain w -> NatRepr u -> Integer -> Property Source #
correct_sign_ext :: forall (w :: Natural) (u :: Natural). (1 <= w, (w + 1) <= u) => NatRepr w -> Domain w -> NatRepr u -> Integer -> Property Source #
correct_concat :: forall (m :: Nat) (n :: Nat). NatRepr m -> (Domain m, Integer) -> NatRepr n -> (Domain n, Integer) -> Property Source #
correct_shrink :: forall (i :: Nat) (n :: Nat). NatRepr i -> NatRepr n -> (Domain (i + n), Integer) -> Property Source #
correct_trunc :: forall (n :: Nat) (w :: Nat). n <= w => NatRepr n -> (Domain w, Integer) -> Property Source #
correct_select :: forall (n :: Natural) (i :: Natural) (w :: Natural). (1 <= n, (i + n) <= w) => NatRepr i -> NatRepr n -> (Domain w, Integer) -> Property Source #
correct_shl :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Integer -> Property Source #
correct_lshr :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Integer -> Property Source #
correct_ashr :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Integer -> Property Source #
correct_rol :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Integer -> Property Source #
correct_ror :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Integer -> Property Source #
correct_shlAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_lshrAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_ashrAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_rolAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_rorAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_equiv_shlAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property Source #
The optimized shlAbstract produces the same domain as the
declarative shlAbstractSpec. Together with correct_shlAbstract,
this proves shlAbstract is point-wise optimal at this domain.
correct_equiv_lshrAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property Source #
correct_equiv_ashrAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property Source #
correct_equiv_rolAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property Source #
correct_equiv_rorAbstract :: forall (n :: Natural). 1 <= n => NatRepr n -> Domain n -> Domain n -> Property Source #
correct_eq :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_ult :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_slt :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_ubounds :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Property Source #
correct_sbounds :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Property Source #
correct_add :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_sub :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_neg :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Property Source #
correct_scale :: forall (n :: Natural). 1 <= n => NatRepr n -> Integer -> (Domain n, Integer) -> Property Source #
correct_mul :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_mulPrecise :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_udiv :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_urem :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_sdiv :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_srem :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_udivPrecise :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_uremPrecise :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_udivSmtlib :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_uremSmtlib :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_sdivSmtlib :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_sremSmtlib :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_and :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_or :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> (Domain n, Integer) -> Property Source #
correct_not :: forall (n :: Natural). 1 <= n => NatRepr n -> (Domain n, Integer) -> Property Source #