Copyright | (c) Sirui Lu 2021-2023 |
---|---|
License | BSD-3-Clause (see the LICENSE file) |
Maintainer | siruilu@cs.washington.edu |
Stability | Experimental |
Portability | GHC only |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Synopsis
- class BV bv where
- bvExtract :: BV bv => Int -> Int -> bv -> bv
- class SizedBV bv where
- sizedBVConcat :: (KnownNat l, KnownNat r, 1 <= l, 1 <= r) => bv l -> bv r -> bv (l + r)
- sizedBVZext :: (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> bv l -> bv r
- sizedBVSext :: (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> bv l -> bv r
- sizedBVExt :: (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> bv l -> bv r
- sizedBVSelect :: (KnownNat n, KnownNat ix, KnownNat w, 1 <= n, 1 <= w, (ix + w) <= n) => p ix -> q w -> bv n -> bv w
- sizedBVExtract :: forall p i q j n bv. (SizedBV bv, KnownNat n, KnownNat i, KnownNat j, 1 <= n, (i + 1) <= n, j <= i) => p i -> q j -> bv n -> bv ((i - j) + 1)
- class BVSignConversion ubv sbv | ubv -> sbv, sbv -> ubv where
- toSigned :: ubv -> sbv
- toUnsigned :: sbv -> ubv
Bit vector operations
Bit vector operations. Including concatenation (bvConcat
),
extension (bvZext
, bvSext
, bvExt
), and selection
(bvSelect
).
bvConcat :: bv -> bv -> bv Source #
Concatenation of two bit vectors.
>>>
bvConcat (SomeSymWordN (0b101 :: SymWordN 3)) (SomeSymWordN (0b010 :: SymWordN 3))
0b101010
:: Int | Desired output length |
-> bv | Bit vector to extend |
-> bv |
Zero extension of a bit vector.
>>>
bvZext 6 (SomeSymWordN (0b101 :: SymWordN 3))
0b000101
:: Int | Desired output length |
-> bv | Bit vector to extend |
-> bv |
Sign extension of a bit vector.
>>>
bvSext 6 (SomeSymWordN (0b101 :: SymWordN 3))
0b111101
:: Int | Desired output length |
-> bv | Bit vector to extend |
-> bv |
Extension of a bit vector. Signedness is determined by the input bit vector type.
>>>
bvExt 6 (SomeSymIntN (0b101 :: SymIntN 3))
0b111101>>>
bvExt 6 (SomeSymIntN (0b001 :: SymIntN 3))
0b000001>>>
bvExt 6 (SomeSymWordN (0b101 :: SymWordN 3))
0b000101>>>
bvExt 6 (SomeSymWordN (0b001 :: SymWordN 3))
0b000001
:: Int | Index of the least significant bit of the slice |
-> Int | Desired output width, |
-> bv | Bit vector to select from |
-> bv |
Slicing out a smaller bit vector from a larger one,
selecting a slice with width w
starting from index ix
.
The least significant bit is indexed as 0.
>>>
bvSelect 1 3 (SomeSymIntN (0b001010 :: SymIntN 6))
0b101
Instances
BV SomeIntN Source # | |
BV SomeWordN Source # | |
BV SomeSymIntN Source # | |
Defined in Grisette.IR.SymPrim.Data.SymPrim bvConcat :: SomeSymIntN -> SomeSymIntN -> SomeSymIntN Source # bvZext :: Int -> SomeSymIntN -> SomeSymIntN Source # bvSext :: Int -> SomeSymIntN -> SomeSymIntN Source # bvExt :: Int -> SomeSymIntN -> SomeSymIntN Source # bvSelect :: Int -> Int -> SomeSymIntN -> SomeSymIntN Source # | |
BV SomeSymWordN Source # | |
Defined in Grisette.IR.SymPrim.Data.SymPrim bvConcat :: SomeSymWordN -> SomeSymWordN -> SomeSymWordN Source # bvZext :: Int -> SomeSymWordN -> SomeSymWordN Source # bvSext :: Int -> SomeSymWordN -> SomeSymWordN Source # bvExt :: Int -> SomeSymWordN -> SomeSymWordN Source # bvSelect :: Int -> Int -> SomeSymWordN -> SomeSymWordN Source # |
:: BV bv | |
=> Int | The start position to extract from, |
-> Int | The end position to extract from, |
-> bv | Bit vector to extract from |
-> bv |
Slicing out a smaller bit vector from a larger one, extract a slice from
bit i
down to j
.
The least significant bit is indexed as 0.
>>>
bvExtract 4 2 (SomeSymIntN (0b010100 :: SymIntN 6))
0b101
class SizedBV bv where Source #
Sized bit vector operations. Including concatenation (sizedBVConcat
),
extension (sizedBVZext
, sizedBVSext
, sizedBVExt
), and selection
(sizedBVSelect
).
sizedBVConcat :: (KnownNat l, KnownNat r, 1 <= l, 1 <= r) => bv l -> bv r -> bv (l + r) Source #
Concatenation of two bit vectors.
>>>
sizedBVConcat (0b101 :: SymIntN 3) (0b010 :: SymIntN 3)
0b101010
:: (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) | |
=> proxy r | Desired output width |
-> bv l | Bit vector to extend |
-> bv r |
Zero extension of a bit vector.
>>>
sizedBVZext (Proxy @6) (0b101 :: SymIntN 3)
0b000101
:: (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) | |
=> proxy r | Desired output width |
-> bv l | Bit vector to extend |
-> bv r |
Signed extension of a bit vector.
>>>
sizedBVSext (Proxy @6) (0b101 :: SymIntN 3)
0b111101
:: (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) | |
=> proxy r | Desired output width |
-> bv l | Bit vector to extend |
-> bv r |
Extension of a bit vector. Signedness is determined by the input bit vector type.
>>>
sizedBVExt (Proxy @6) (0b101 :: SymIntN 3)
0b111101>>>
sizedBVExt (Proxy @6) (0b001 :: SymIntN 3)
0b000001>>>
sizedBVExt (Proxy @6) (0b101 :: SymWordN 3)
0b000101>>>
sizedBVExt (Proxy @6) (0b001 :: SymWordN 3)
0b000001
:: (KnownNat n, KnownNat ix, KnownNat w, 1 <= n, 1 <= w, (ix + w) <= n) | |
=> p ix | Index of the least significant bit of the slice |
-> q w | Desired output width, |
-> bv n | Bit vector to select from |
-> bv w |
Slicing out a smaller bit vector from a larger one, selecting a slice with
width w
starting from index ix
.
The least significant bit is indexed as 0.
>>>
sizedBVSelect (Proxy @2) (Proxy @3) (con 0b010100 :: SymIntN 6)
0b101
Instances
SizedBV IntN Source # | |
Defined in Grisette.Core.Data.BV sizedBVConcat :: forall (l :: Nat) (r :: Nat). (KnownNat l, KnownNat r, 1 <= l, 1 <= r) => IntN l -> IntN r -> IntN (l + r) Source # sizedBVZext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> IntN l -> IntN r Source # sizedBVSext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> IntN l -> IntN r Source # sizedBVExt :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> IntN l -> IntN r Source # sizedBVSelect :: forall (n :: Nat) (ix :: Nat) (w :: Nat) p q. (KnownNat n, KnownNat ix, KnownNat w, 1 <= n, 1 <= w, (ix + w) <= n) => p ix -> q w -> IntN n -> IntN w Source # | |
SizedBV WordN Source # | |
Defined in Grisette.Core.Data.BV sizedBVConcat :: forall (l :: Nat) (r :: Nat). (KnownNat l, KnownNat r, 1 <= l, 1 <= r) => WordN l -> WordN r -> WordN (l + r) Source # sizedBVZext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> WordN l -> WordN r Source # sizedBVSext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> WordN l -> WordN r Source # sizedBVExt :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> WordN l -> WordN r Source # sizedBVSelect :: forall (n :: Nat) (ix :: Nat) (w :: Nat) p q. (KnownNat n, KnownNat ix, KnownNat w, 1 <= n, 1 <= w, (ix + w) <= n) => p ix -> q w -> WordN n -> WordN w Source # | |
SizedBV SymIntN Source # | |
Defined in Grisette.IR.SymPrim.Data.SymPrim sizedBVConcat :: forall (l :: Nat) (r :: Nat). (KnownNat l, KnownNat r, 1 <= l, 1 <= r) => SymIntN l -> SymIntN r -> SymIntN (l + r) Source # sizedBVZext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymIntN l -> SymIntN r Source # sizedBVSext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymIntN l -> SymIntN r Source # sizedBVExt :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymIntN l -> SymIntN r Source # sizedBVSelect :: forall (n :: Nat) (ix :: Nat) (w :: Nat) p q. (KnownNat n, KnownNat ix, KnownNat w, 1 <= n, 1 <= w, (ix + w) <= n) => p ix -> q w -> SymIntN n -> SymIntN w Source # | |
SizedBV SymWordN Source # | |
Defined in Grisette.IR.SymPrim.Data.SymPrim sizedBVConcat :: forall (l :: Nat) (r :: Nat). (KnownNat l, KnownNat r, 1 <= l, 1 <= r) => SymWordN l -> SymWordN r -> SymWordN (l + r) Source # sizedBVZext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymWordN l -> SymWordN r Source # sizedBVSext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymWordN l -> SymWordN r Source # sizedBVExt :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymWordN l -> SymWordN r Source # sizedBVSelect :: forall (n :: Nat) (ix :: Nat) (w :: Nat) p q. (KnownNat n, KnownNat ix, KnownNat w, 1 <= n, 1 <= w, (ix + w) <= n) => p ix -> q w -> SymWordN n -> SymWordN w Source # |
:: forall p i q j n bv. (SizedBV bv, KnownNat n, KnownNat i, KnownNat j, 1 <= n, (i + 1) <= n, j <= i) | |
=> p i | The start position to extract from, |
-> q j | The end position to extract from, |
-> bv n | Bit vector to extract from |
-> bv ((i - j) + 1) |
Slicing out a smaller bit vector from a larger one, extract a slice from
bit i
down to j
.
The least significant bit is indexed as 0.
>>>
sizedBVExtract (Proxy @4) (Proxy @2) (con 0b010100 :: SymIntN 6)
0b101
class BVSignConversion ubv sbv | ubv -> sbv, sbv -> ubv where Source #
Convert bitvectors from and to signed
toSigned :: ubv -> sbv Source #
Convert unsigned bitvector to signed
toUnsigned :: sbv -> ubv Source #
Convert signed bitvector to unsigned
Instances
BVSignConversion SomeWordN SomeIntN Source # | |
BVSignConversion SomeSymWordN SomeSymIntN Source # | |
Defined in Grisette.IR.SymPrim.Data.SymPrim toSigned :: SomeSymWordN -> SomeSymIntN Source # toUnsigned :: SomeSymIntN -> SomeSymWordN Source # | |
(KnownNat n, 1 <= n) => BVSignConversion (WordN n) (IntN n) Source # | |
(KnownNat n, 1 <= n) => BVSignConversion (SymWordN n) (SymIntN n) Source # | |