packages feed

bv-sized 1.0.3 → 1.0.4

raw patch · 7 files changed

+51/−8 lines, 7 filesdep ~basedep ~bytestringPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, bytestring

API changes (from Hackage documentation)

+ Data.BitVector.Sized: sresize :: 1 <= w => NatRepr w -> NatRepr w' -> BV w -> BV w'
+ Data.BitVector.Sized: zresize :: NatRepr w' -> BV w -> BV w'

Files

bv-sized.cabal view
@@ -1,5 +1,5 @@ name:                bv-sized-version:             1.0.3+version:             1.0.4 category:            Bit Vectors synopsis:            a bitvector datatype that is parameterized by the vector width description:@@ -26,9 +26,9 @@                        Data.BitVector.Sized.Overflow   other-modules:       Data.BitVector.Sized.Internal                        Data.BitVector.Sized.Panic-  build-depends:       base >= 4.10 && <5,+  build-depends:       base >= 4.11 && <5,                        bitwise >= 1.0.0 && < 1.1,-                       bytestring >= 0.10 && < 0.11,+                       bytestring >= 0.10 && < 0.12,                        deepseq >= 1.4.0 && < 1.5.0,                        panic >= 0.4.0 && < 0.5,                        parameterized-utils >= 2.0.2 && < 2.2,
changelog.md view
@@ -1,5 +1,11 @@ # Changelog for [`bv-sized` package](http://hackage.haskell.org/package/bv-sized) +## 1.0.4 *March 2022*++* Deprecates trunc' and adds two alternatives, sresize and zresize+* Support for GHC 9.2+* BV is now a newtype+ ## 1.0.3 *April 2021*  * New instances (`NFData`, `Random`)
src/Data/BitVector/Sized.hs view
@@ -89,6 +89,8 @@   , zext   , sext   , trunc, trunc'+  , zresize+  , sresize   , mulWide     -- * Enum operations   , succUnsigned, succSigned
src/Data/BitVector/Sized/Internal.hs view
@@ -87,7 +87,7 @@ -- BitVector data type definitions  -- | Bitvector datatype, parameterized by width.-data BV (w :: Nat) :: Type where+newtype BV (w :: Nat) :: Type where   -- | We store the value as an 'Integer' rather than a 'Natural',   -- since many of the operations on bitvectors rely on a two's   -- complement representation. However, an invariant on the value is@@ -856,6 +856,26 @@        -- ^ Bitvector to truncate        -> BV w' trunc' w' (BV x) = mkBV w' x+{-# DEPRECATED trunc' "Use zresize instead" #-}++-- | Resizes a bitvector. If @w' > w@, perform a zero extension.+zresize :: NatRepr w'+        -- ^ Desired output width+        -> BV w+        -- ^ Bitvector to resize+        -> BV w'+zresize w' (BV x) = mkBV w' x++-- | Resizes a bitvector. If @w' > w@, perform a signed extension.+sresize :: 1 <= w+        => NatRepr w+        -- ^ Width of input vector+        -> NatRepr w'+        -- ^ Desired output width+        -> BV w+        -- ^ Bitvector to resize+        -> BV w'+sresize w w' bv = mkBV w' (asSigned w bv)  -- | Wide multiply of two bitvectors. mulWide :: NatRepr w -> NatRepr w' -> BV w -> BV w' -> BV (w+w')
src/Data/BitVector/Sized/Signed.hs view
@@ -34,8 +34,8 @@ import Data.Bits (Bits(..), FiniteBits(..)) import Data.Ix import GHC.Generics-import GHC.TypeLits-import Numeric.Natural+import GHC.TypeLits (KnownNat)+import Numeric.Natural (Natural) import System.Random import System.Random.Stateful 
src/Data/BitVector/Sized/Unsigned.hs view
@@ -98,7 +98,7 @@  instance KnownNat w => Enum (UnsignedBV w) where   toEnum = UnsignedBV . mkBV knownNat . checkInt-    where checkInt i | 0 <= i && toInteger i <= (maxUnsigned (knownNat @w)) = toInteger i+    where checkInt i | 0 <= i && toInteger i <= maxUnsigned (knownNat @w) = toInteger i                      | otherwise = panic "Data.BitVector.Sized.Unsigned"                                    ["toEnum: bad argument"] @@ -106,7 +106,7 @@  instance KnownNat w => Ix (UnsignedBV w) where   range (UnsignedBV loBV, UnsignedBV hiBV) =-    (UnsignedBV . mkBV knownNat) <$>+    UnsignedBV . mkBV knownNat <$>     [BV.asUnsigned loBV .. BV.asUnsigned hiBV]   index (UnsignedBV loBV, UnsignedBV hiBV) (UnsignedBV ixBV) =     index ( BV.asUnsigned loBV,
test/Main.hs view
@@ -624,6 +624,21 @@        let BV.BV x = BV.trunc' w' bv       checkBounds x w'+  , testProperty "zresize" $ property $ do+      Some w <- forAll anyWidth+      Some w' <- forAll anyWidth+      bv <- BV.mkBV w <$> forAll (unsigned w)++      let BV.BV x = BV.zresize w' bv+      checkBounds x w'+  , testProperty "sresize" $ property $ do+      Some w <- forAll anyPosWidth+      Just LeqProof <- return $ isPosNat w+      Some w' <- forAll anyWidth+      bv <- BV.mkBV w <$> forAll (unsigned w)++      let BV.BV x = BV.sresize w w' bv+      checkBounds x w'   , testProperty "mulWide" $ property $ do       Some w <- forAll anyWidth       Some w' <- forAll anyWidth