packages feed

hw-bits 0.1.0.1 → 0.2.0.0

raw patch · 7 files changed

+55/−47 lines, 7 filesdep ~hw-prim

Dependency ranges changed: hw-prim

Files

bench/Main.hs view
@@ -7,7 +7,6 @@ import           HaskellWorks.Data.Bits.PopCount.PopCount1 import           HaskellWorks.Data.Bits.Types.Broadword import           HaskellWorks.Data.Bits.Types.Builtin-import           HaskellWorks.Data.Positioning  setupEnvVector :: Int -> IO (DVS.Vector Word64) setupEnvVector n = return $ DVS.fromList (take n (cycle [maxBound, 0]))@@ -15,14 +14,14 @@ benchPopCount1 :: [Benchmark] benchPopCount1 =   [ env (setupEnvVector 1000000) $ \bv -> bgroup "PopCount0"-    [ bench "Broadword" (nf (map (\n -> getCount (popCount0 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Broadword Word64)))))) [0, 1000..100000])-    , bench "Builtin"   (nf (map (\n -> getCount (popCount0 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Builtin   Word64)))))) [0, 1000..100000])-    , bench "Default"   (nf (map (\n -> getCount (popCount0 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector            Word64 ))))) [0, 1000..100000])+    [ bench "Broadword" (nf (map (\n -> popCount0 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Broadword Word64))))) [0, 1000..100000])+    , bench "Builtin"   (nf (map (\n -> popCount0 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Builtin   Word64))))) [0, 1000..100000])+    , bench "Default"   (nf (map (\n -> popCount0 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector            Word64 )))) [0, 1000..100000])     ]   , env (setupEnvVector 1000000) $ \bv -> bgroup "PopCount1"-    [ bench "Broadword" (nf (map (\n -> getCount (popCount1 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Broadword Word64)))))) [0, 1000..100000])-    , bench "Builtin"   (nf (map (\n -> getCount (popCount1 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Builtin   Word64)))))) [0, 1000..100000])-    , bench "Default"   (nf (map (\n -> getCount (popCount1 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector            Word64 ))))) [0, 1000..100000])+    [ bench "Broadword" (nf (map (\n -> popCount1 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Broadword Word64))))) [0, 1000..100000])+    , bench "Builtin"   (nf (map (\n -> popCount1 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Builtin   Word64))))) [0, 1000..100000])+    , bench "Default"   (nf (map (\n -> popCount1 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector            Word64 )))) [0, 1000..100000])     ]   ] 
hw-bits.cabal view
@@ -1,5 +1,5 @@ name:                   hw-bits-version:                0.1.0.1+version:                0.2.0.0 synopsis:               Conduits for tokenizing streams. description:            Please see README.md homepage:               http://github.com/haskell-works/hw-bits#readme@@ -54,7 +54,7 @@                       , HaskellWorks.Data.Bits.Word   build-depends:        base                          >= 4          && < 5                       , bytestring-                      , hw-prim                       >= 0.1.0.0+                      , hw-prim                       >= 0.3.0.0                       , parsec                       , safe                       , vector@@ -77,7 +77,7 @@                       , bytestring                       , hspec                       , hw-bits-                      , hw-prim                       >= 0.1.0.0+                      , hw-prim                       >= 0.3.0.0                       , QuickCheck                       , vector   ghc-options:          -threaded -rtsopts -with-rtsopts=-N -Wall@@ -96,5 +96,5 @@     Build-Depends:      base                          >= 4          && < 5                       , criterion                       , hw-bits-                      , hw-prim                       >= 0.1.0.0+                      , hw-prim                       >= 0.3.0.0                       , vector
src/HaskellWorks/Data/Bits/BitLength.hs view
@@ -17,27 +17,27 @@ import qualified Data.Vector                         as DV import qualified Data.Vector.Storable                as DVS import           Data.Word-import           HaskellWorks.Data.IndexedSeq+import           HaskellWorks.Data.AtIndex import           HaskellWorks.Data.Naive import           HaskellWorks.Data.Positioning-import           Prelude                             as P+import           Prelude hiding (length)  -- | Number of bits in a value including ones and zeros. class BitLength v where   bitLength :: v -> Count    endPosition :: v -> Position-  endPosition = Position . fromIntegral . getCount . bitLength+  endPosition = toPosition . bitLength   {-# INLINE endPosition #-}  -------------------------------------------------------------------------------- -- Functions -elemBitLength :: (IndexedSeq v, BitLength (Elem v)) => v -> Count+elemBitLength :: (AtIndex v, BitLength (Elem v)) => v -> Count elemBitLength v = bitLength (v !!! 0) {-# INLINE elemBitLength #-} -elemBitEnd :: (IndexedSeq v, BitLength (Elem v)) => v -> Position+elemBitEnd :: (AtIndex v, BitLength (Elem v)) => v -> Position elemBitEnd v = endPosition (v !!! 0) {-# INLINE elemBitEnd #-} @@ -49,7 +49,7 @@   {-# INLINE bitLength #-}  instance BitLength [Bool] where-  bitLength = fromIntegral . P.length+  bitLength = fromIntegral . length   {-# INLINE bitLength #-}  instance BitLength Word8 where@@ -85,49 +85,49 @@   {-# INLINE bitLength #-}  instance BitLength [Word8] where-  bitLength v = fromIntegral (P.length v) * bitLength (head v)+  bitLength v = fromIntegral (length v) * bitLength (head v)   {-# INLINE bitLength #-}  instance BitLength [Word16] where-  bitLength v = fromIntegral (P.length v) * bitLength (head v)+  bitLength v = fromIntegral (length v) * bitLength (head v)   {-# INLINE bitLength #-}  instance BitLength [Word32] where-  bitLength v = fromIntegral (P.length v) * bitLength (head v)+  bitLength v = fromIntegral (length v) * bitLength (head v)   {-# INLINE bitLength #-}  instance BitLength [Word64] where-  bitLength v = fromIntegral (P.length v) * bitLength (head v)+  bitLength v = fromIntegral (length v) * bitLength (head v)   {-# INLINE bitLength #-}  instance BitLength (DV.Vector Word8) where-  bitLength v = vLength v * bitLength (v !!! 0)+  bitLength v = length v * bitLength (v !!! 0)   {-# INLINE bitLength #-}  instance BitLength (DV.Vector Word16) where-  bitLength v = vLength v * bitLength (v !!! 0)+  bitLength v = length v * bitLength (v !!! 0)   {-# INLINE bitLength #-}  instance BitLength (DV.Vector Word32) where-  bitLength v = vLength v * bitLength (v !!! 0)+  bitLength v = length v * bitLength (v !!! 0)   {-# INLINE bitLength #-}  instance BitLength (DV.Vector Word64) where-  bitLength v = vLength v * bitLength (v !!! 0)+  bitLength v = length v * bitLength (v !!! 0)   {-# INLINE bitLength #-}  instance BitLength (DVS.Vector Word8) where-  bitLength v = vLength v * bitLength (v !!! 0)+  bitLength v = length v * bitLength (v !!! 0)   {-# INLINE bitLength #-}  instance BitLength (DVS.Vector Word16) where-  bitLength v = vLength v * bitLength (v !!! 0)+  bitLength v = length v * bitLength (v !!! 0)   {-# INLINE bitLength #-}  instance BitLength (DVS.Vector Word32) where-  bitLength v = vLength v * bitLength (v !!! 0)+  bitLength v = length v * bitLength (v !!! 0)   {-# INLINE bitLength #-}  instance BitLength (DVS.Vector Word64) where-  bitLength v = vLength v * bitLength (v !!! 0)+  bitLength v = length v * bitLength (v !!! 0)   {-# INLINE bitLength #-}
src/HaskellWorks/Data/Bits/BitWise.hs view
@@ -18,8 +18,8 @@ import qualified Data.Vector                         as DV import qualified Data.Vector.Storable                as DVS import           Data.Word+import           HaskellWorks.Data.AtIndex import           HaskellWorks.Data.Bits.BitLength-import           HaskellWorks.Data.IndexedSeq        as IS import           HaskellWorks.Data.Naive import           HaskellWorks.Data.Positioning import           Prelude                             as P@@ -74,39 +74,39 @@   {-# INLINE (.?.) #-}  instance TestBit Int where-  (.?.) w n = B.testBit w (fromIntegral (getPosition n))+  (.?.) w n = B.testBit w (fromIntegral n)   {-# INLINE (.?.) #-}  instance TestBit Word8 where-  (.?.) w n = B.testBit w (fromIntegral (getPosition n))+  (.?.) w n = B.testBit w (fromIntegral n)   {-# INLINE (.?.) #-}  instance TestBit Word16 where-  (.?.) w n = B.testBit w (fromIntegral (getPosition n))+  (.?.) w n = B.testBit w (fromIntegral n)   {-# INLINE (.?.) #-}  instance TestBit Word32 where-  (.?.) w n = B.testBit w (fromIntegral (getPosition n))+  (.?.) w n = B.testBit w (fromIntegral n)   {-# INLINE (.?.) #-}  instance TestBit Word64 where-  (.?.) w n = B.testBit w (fromIntegral (getPosition n))+  (.?.) w n = B.testBit w (fromIntegral n)   {-# INLINE (.?.) #-}  instance TestBit (Naive Word8) where-  (.?.) w n = B.testBit (naive w) (fromIntegral (getPosition n))+  (.?.) w n = B.testBit (naive w) (fromIntegral n)   {-# INLINE (.?.) #-}  instance TestBit (Naive Word16) where-  (.?.) w n = B.testBit (naive w) (fromIntegral (getPosition n))+  (.?.) w n = B.testBit (naive w) (fromIntegral n)   {-# INLINE (.?.) #-}  instance TestBit (Naive Word32) where-  (.?.) w n = B.testBit (naive w) (fromIntegral (getPosition n))+  (.?.) w n = B.testBit (naive w) (fromIntegral n)   {-# INLINE (.?.) #-}  instance TestBit (Naive Word64) where-  (.?.) w n = B.testBit (naive w) (fromIntegral (getPosition n))+  (.?.) w n = B.testBit (naive w) (fromIntegral n)   {-# INLINE (.?.) #-}  instance TestBit (DV.Vector Word8) where
src/HaskellWorks/Data/Bits/Log2.hs view
@@ -4,8 +4,8 @@  import qualified Data.Vector.Storable as DVS import           Data.Word+import           HaskellWorks.Data.AtIndex import           HaskellWorks.Data.Bits.BitWise-import           HaskellWorks.Data.IndexedSeq  class Log2 a where   log2 :: a -> Int
src/HaskellWorks/Data/Bits/PopCount/PopCount1.hs view
@@ -17,6 +17,7 @@ import           HaskellWorks.Data.Bits.Types.Broadword import           HaskellWorks.Data.Bits.Types.Builtin import           HaskellWorks.Data.Positioning+import           HaskellWorks.Data.Widen.Widen64 import           Prelude                                as P  type FastWord a = Builtin a@@ -35,7 +36,7 @@   {-# INLINE popCount1 #-}  instance PopCount1 (Broadword Word8) where-  popCount1 (Broadword x0) = Count (fromIntegral x3)+  popCount1 (Broadword x0) = widen64 x3     where       x1 = x0 - ((x0 .&. 0xaa) .>. 1)       x2 = (x1 .&. 0x33) + ((x1 .>. 2) .&. 0x33)@@ -43,7 +44,7 @@   {-# INLINE popCount1 #-}  instance PopCount1 (Broadword Word16) where-  popCount1 (Broadword x0) = Count (fromIntegral ((x3 * 0x0101) .>. 8))+  popCount1 (Broadword x0) = widen64 ((x3 * 0x0101) .>. 8)     where       x1 = x0 - ((x0 .&. 0xaaaa) .>. 1)       x2 = (x1 .&. 0x3333) + ((x1 .>. 2) .&. 0x3333)@@ -51,7 +52,7 @@   {-# INLINE popCount1 #-}  instance PopCount1 (Broadword Word32) where-  popCount1 (Broadword x0) = Count (fromIntegral ((x3 * 0x01010101) .>. 24))+  popCount1 (Broadword x0) = widen64 ((x3 * 0x01010101) .>. 24)     where       x1 = x0 - ((x0 .&. 0xaaaaaaaa) .>. 1)       x2 = (x1 .&. 0x33333333) + ((x1 .>. 2) .&. 0x33333333)@@ -59,7 +60,7 @@   {-# INLINE popCount1 #-}  instance PopCount1 (Broadword Word64) where-  popCount1 (Broadword x0) = Count ((x3 * 0x0101010101010101) .>. 56)+  popCount1 (Broadword x0) = widen64 (x3 * 0x0101010101010101) .>. 56     where       x1 = x0 - ((x0 .&. 0xaaaaaaaaaaaaaaaa) .>. 1)       x2 = (x1 .&. 0x3333333333333333) + ((x1 .>. 2) .&. 0x3333333333333333)
src/HaskellWorks/Data/Bits/SubWord64Vector.hs view
@@ -10,17 +10,25 @@  data SubWord64Vector = SubWord64Vector     { swBuffer      :: !(DVS.Vector Word64)-    , swSize        :: !Word+    , swBitSize     :: !Word     , swBufferLen   :: !Int     } deriving (Eq, Show) +-- empty :: SubWord64Vector+-- empty =+--   SubWord64Vector+--   { swBuffer    = DVS.empty+--   , swBufferLen = 0+--   , swBitSize   = 1+--   }+-- fromList :: Int -> [Word64] -> SubWord64Vector fromList wl ws =   SubWord64Vector   { swBuffer    = DVS.fromList (packBits wl ws)   , swBufferLen = fromIntegral (length ws)-  , swSize      = fromIntegral wl+  , swBitSize   = fromIntegral wl   }  toList :: SubWord64Vector -> [Word64]-toList v = unpackBits (swBufferLen v) (fromIntegral (swSize v)) (DVS.toList (swBuffer v))+toList v = unpackBits (swBufferLen v) (fromIntegral (swBitSize v)) (DVS.toList (swBuffer v))