Clash.Promoted.Nat: exported symbols usage examples

Symbols

  • addBNat No usage example found for this symbol :( Collapse [-]
    addSNat No usage example found for this symbol :( Collapse [-]
    addUNat No usage example found for this symbol :( Collapse [-]
    clogBaseSNat No usage example found for this symbol :( Collapse [-]
    div2BNat No usage example found for this symbol :( Collapse [-]
    div2Sub1BNat No usage example found for this symbol :( Collapse [-]
    divSNat No usage example found for this symbol :( Collapse [-]
    flogBaseSNat No usage example found for this symbol :( Collapse [-]
    fromBNat No usage example found for this symbol :( Collapse [-]
    fromUNat No usage example found for this symbol :( Collapse [-]
    leToPlus See 9 Occurences [+] Collapse [-]
    Found in Clash.Sized.Vector from the package clash-prelude
    instance (KnownNat n, 1 <= n) => F.Foldable (Vec n) where
      fold a      = leToPlus @1 (Flip a) (fold mappend . runFlip)
      foldMap f a = leToPlus @1 (Flip (map f a)) (fold mappend . runFlip)
      foldr       = foldr
      foldl       = foldl
      foldr1 f a  = leToPlus @1 (Flip a) (foldr1 f . runFlip)
      foldl1 f a  = leToPlus @1 (Flip a) (foldl1 f . runFlip)
      toList      = toList
      null _      = False
      length      = length
      maximum a   = leToPlus @1 (Flip a) (fold (\x y -> if x >= y then x else y) . runFlip)
      minimum a   = leToPlus @1 (Flip a) (fold (\x y -> if x <= y then x else y) . runFlip)
      sum a       = leToPlus @1 (Flip a) (fold (+) . runFlip)
      product a   = leToPlus @1 (Flip a) (fold (*) . runFlip)
    
    instance Functor (Vec n) where
      fmap = map
    
    instance (KnownNat n, 1 <= n) => Traversable (Vec n) where
    

    Found in Clash.Sized.Vector from the package clash-prelude
      fs <*> xs = zipWith ($) fs xs
    
    instance (KnownNat n, 1 <= n) => F.Foldable (Vec n) where
      fold a      = leToPlus @1 (Flip a) (fold mappend . runFlip)
      foldMap f a = leToPlus @1 (Flip (map f a)) (fold mappend . runFlip)
      foldr       = foldr
      foldl       = foldl
      foldr1 f a  = leToPlus @1 (Flip a) (foldr1 f . runFlip)
      foldl1 f a  = leToPlus @1 (Flip a) (foldl1 f . runFlip)
      toList      = toList
      null _      = False
      length      = length
      maximum a   = leToPlus @1 (Flip a) (fold (\x y -> if x >= y then x else y) . runFlip)
      minimum a   = leToPlus @1 (Flip a) (fold (\x y -> if x <= y then x else y) . runFlip)
      sum a       = leToPlus @1 (Flip a) (fold (+) . runFlip)
      product a   = leToPlus @1 (Flip a) (fold (*) . runFlip)
    
    instance Functor (Vec n) where
      fmap = map
    

    Found in Clash.Sized.Vector from the package clash-prelude
      pure      = repeat
      fs <*> xs = zipWith ($) fs xs
    
    instance (KnownNat n, 1 <= n) => F.Foldable (Vec n) where
      fold a      = leToPlus @1 (Flip a) (fold mappend . runFlip)
      foldMap f a = leToPlus @1 (Flip (map f a)) (fold mappend . runFlip)
      foldr       = foldr
      foldl       = foldl
      foldr1 f a  = leToPlus @1 (Flip a) (foldr1 f . runFlip)
      foldl1 f a  = leToPlus @1 (Flip a) (foldl1 f . runFlip)
      toList      = toList
      null _      = False
      length      = length
      maximum a   = leToPlus @1 (Flip a) (fold (\x y -> if x >= y then x else y) . runFlip)
      minimum a   = leToPlus @1 (Flip a) (fold (\x y -> if x <= y then x else y) . runFlip)
      sum a       = leToPlus @1 (Flip a) (fold (+) . runFlip)
      product a   = leToPlus @1 (Flip a) (fold (*) . runFlip)
    
    instance Functor (Vec n) where
      fmap = map
    

    Found in Clash.Sized.Vector from the package clash-prelude
    instance KnownNat n => Applicative (Vec n) where
      pure      = repeat
      fs <*> xs = zipWith ($) fs xs
    
    instance (KnownNat n, 1 <= n) => F.Foldable (Vec n) where
      fold a      = leToPlus @1 (Flip a) (fold mappend . runFlip)
      foldMap f a = leToPlus @1 (Flip (map f a)) (fold mappend . runFlip)
      foldr       = foldr
      foldl       = foldl
      foldr1 f a  = leToPlus @1 (Flip a) (foldr1 f . runFlip)
      foldl1 f a  = leToPlus @1 (Flip a) (foldl1 f . runFlip)
      toList      = toList
      null _      = False
      length      = length
      maximum a   = leToPlus @1 (Flip a) (fold (\x y -> if x >= y then x else y) . runFlip)
      minimum a   = leToPlus @1 (Flip a) (fold (\x y -> if x <= y then x else y) . runFlip)
      sum a       = leToPlus @1 (Flip a) (fold (+) . runFlip)
      product a   = leToPlus @1 (Flip a) (fold (*) . runFlip)
    
    instance Functor (Vec n) where
    

    Found in Clash.Sized.Vector from the package clash-prelude
      compare x y = foldr f EQ $ zipWith compare x y
        where f EQ   keepGoing = keepGoing
              f done _         = done
    
    instance KnownNat n => Applicative (Vec n) where
      pure      = repeat
      fs <*> xs = zipWith ($) fs xs
    
    instance (KnownNat n, 1 <= n) => F.Foldable (Vec n) where
      fold a      = leToPlus @1 (Flip a) (fold mappend . runFlip)
      foldMap f a = leToPlus @1 (Flip (map f a)) (fold mappend . runFlip)
      foldr       = foldr
      foldl       = foldl
      foldr1 f a  = leToPlus @1 (Flip a) (foldr1 f . runFlip)
      foldl1 f a  = leToPlus @1 (Flip a) (foldl1 f . runFlip)
      toList      = toList
      null _      = False
      length      = length
      maximum a   = leToPlus @1 (Flip a) (fold (\x y -> if x >= y then x else y) . runFlip)
      minimum a   = leToPlus @1 (Flip a) (fold (\x y -> if x <= y then x else y) . runFlip)
    

    Found in Clash.Sized.Vector from the package clash-prelude
    instance (KnownNat n, Ord a) => Ord (Vec n a) where
      compare x y = foldr f EQ $ zipWith compare x y
        where f EQ   keepGoing = keepGoing
              f done _         = done
    
    instance KnownNat n => Applicative (Vec n) where
      pure      = repeat
      fs <*> xs = zipWith ($) fs xs
    
    instance (KnownNat n, 1 <= n) => F.Foldable (Vec n) where
      fold a      = leToPlus @1 (Flip a) (fold mappend . runFlip)
      foldMap f a = leToPlus @1 (Flip (map f a)) (fold mappend . runFlip)
      foldr       = foldr
      foldl       = foldl
      foldr1 f a  = leToPlus @1 (Flip a) (foldr1 f . runFlip)
      foldl1 f a  = leToPlus @1 (Flip a) (foldl1 f . runFlip)
      toList      = toList
      null _      = False
      length      = length
      maximum a   = leToPlus @1 (Flip a) (fold (\x y -> if x >= y then x else y) . runFlip)
    

    Found in Clash.Sized.Vector from the package clash-prelude
      --
      -- But the Clash compiler currently fails on that definition.
    
    instance (KnownNat n, Ord a) => Ord (Vec n a) where
      compare x y = foldr f EQ $ zipWith compare x y
        where f EQ   keepGoing = keepGoing
              f done _         = done
    
    instance KnownNat n => Applicative (Vec n) where
      pure      = repeat
      fs <*> xs = zipWith ($) fs xs
    
    instance (KnownNat n, 1 <= n) => F.Foldable (Vec n) where
      fold a      = leToPlus @1 (Flip a) (fold mappend . runFlip)
      foldMap f a = leToPlus @1 (Flip (map f a)) (fold mappend . runFlip)
      foldr       = foldr
      foldl       = foldl
      foldr1 f a  = leToPlus @1 (Flip a) (foldr1 f . runFlip)
      foldl1 f a  = leToPlus @1 (Flip a) (foldl1 f . runFlip)
      toList      = toList
    

    Found in Clash.Sized.Vector from the package clash-prelude
      -- (==) v1@(Cons _ _) v2 = fold (&&) (zipWith (==) v1 v2)
      --
      -- But the Clash compiler currently fails on that definition.
    
    instance (KnownNat n, Ord a) => Ord (Vec n a) where
      compare x y = foldr f EQ $ zipWith compare x y
        where f EQ   keepGoing = keepGoing
              f done _         = done
    
    instance KnownNat n => Applicative (Vec n) where
      pure      = repeat
      fs <*> xs = zipWith ($) fs xs
    
    instance (KnownNat n, 1 <= n) => F.Foldable (Vec n) where
      fold a      = leToPlus @1 (Flip a) (fold mappend . runFlip)
      foldMap f a = leToPlus @1 (Flip (map f a)) (fold mappend . runFlip)
      foldr       = foldr
      foldl       = foldl
      foldr1 f a  = leToPlus @1 (Flip a) (foldr1 f . runFlip)
      foldl1 f a  = leToPlus @1 (Flip a) (foldl1 f . runFlip)
    

    Found in Clash.Sized.Vector from the package clash-prelude
    import GHC.Prim                   ((==#),(<#),(-#))
    import Language.Haskell.TH        (ExpQ)
    import Language.Haskell.TH.Syntax (Lift(..))
    import Prelude                    hiding ((++), (!!), concat, drop, foldl,
                                              foldl1, foldr, foldr1, head, init,
                                              iterate, last, length, map, repeat,
                                              replicate, reverse, scanl, scanr,
                                              splitAt, tail, take, unzip, unzip3,
                                              zip, zip3, zipWith, zipWith3)
    import qualified Prelude          as P
    import Test.QuickCheck            (Arbitrary (..), CoArbitrary (..))
    import Unsafe.Coerce              (unsafeCoerce)
    
    import Clash.Promoted.Nat
      (SNat (..), UNat (..), leToPlus, pow2SNat, snatProxy, snatToInteger, subSNat,
       withSNat, toUNat)
    import Clash.Promoted.Nat.Literals (d1)
    import Clash.Sized.Internal.BitVector (Bit, BitVector, (++#), split#)
    import Clash.Sized.Index          (Index)
    

    leToPlusKN See 13 Occurences [+] Collapse [-]
    Found in Clash.Sized.Internal.Index from the package clash-prelude
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
      satMult SatZero a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> fromInteger# 0
            z -> resize# z
      satMult _ a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> maxBound#
            z -> resize# z
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
      satMult SatZero a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> fromInteger# 0
            z -> resize# z
      satMult _ a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> maxBound#
            z -> resize# z
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
      satMin _ a b =
        if lt# a b
           then fromInteger# 0
           else a -# b
    
      satMult SatWrap a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
      satMult SatZero a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> fromInteger# 0
            z -> resize# z
      satMult _ a b =
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
      satMin _ a b =
        if lt# a b
           then fromInteger# 0
           else a -# b
    
      satMult SatWrap a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
      satMult SatZero a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> fromInteger# 0
            z -> resize# z
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
            z -> resize# z
    
      satMin SatWrap a b =
        if lt# a b
           then maxBound -# (b -# a) +# 1
           else a -# b
    
      satMin _ a b =
        if lt# a b
           then fromInteger# 0
           else a -# b
    
      satMult SatWrap a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
      satMult SatZero a b =
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
              , z >= m -> maxBound#
            z -> resize# z
    
      satMin SatWrap a b =
        if lt# a b
           then maxBound -# (b -# a) +# 1
           else a -# b
    
      satMin _ a b =
        if lt# a b
           then fromInteger# 0
           else a -# b
    
      satMult SatWrap a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case times# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
      satPlus SatZero a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> fromInteger# 0
            z -> resize# z
      satPlus _ a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> maxBound#
            z -> resize# z
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
      satPlus SatZero a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> fromInteger# 0
            z -> resize# z
      satPlus _ a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> maxBound#
            z -> resize# z
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
    {-# NOINLINE times# #-}
    times# :: Index m -> Index n -> Index (((m - 1) * (n - 1)) + 1)
    times# (I a) (I b) = I (a * b)
    
    instance (KnownNat n, 1 <= n) => SaturatingNum (Index n) where
      satPlus SatWrap a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
      satPlus SatZero a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> fromInteger# 0
            z -> resize# z
      satPlus _ a b =
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
    {-# NOINLINE times# #-}
    times# :: Index m -> Index n -> Index (((m - 1) * (n - 1)) + 1)
    times# (I a) (I b) = I (a * b)
    
    instance (KnownNat n, 1 <= n) => SaturatingNum (Index n) where
      satPlus SatWrap a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
      satPlus SatZero a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> fromInteger# 0
            z -> resize# z
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
    minus# (I a) (I b) =
      let z   = a - b
          err = error ("Clash.Sized.Index.minus: result " ++ show z ++
                       " is smaller than 0")
          res = if z < 0 then err else I z
      in  res
    
    {-# NOINLINE times# #-}
    times# :: Index m -> Index n -> Index (((m - 1) * (n - 1)) + 1)
    times# (I a) (I b) = I (a * b)
    
    instance (KnownNat n, 1 <= n) => SaturatingNum (Index n) where
      satPlus SatWrap a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
      satPlus SatZero a b =
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
    {-# NOINLINE minus# #-}
    minus# (I a) (I b) =
      let z   = a - b
          err = error ("Clash.Sized.Index.minus: result " ++ show z ++
                       " is smaller than 0")
          res = if z < 0 then err else I z
      in  res
    
    {-# NOINLINE times# #-}
    times# :: Index m -> Index n -> Index (((m - 1) * (n - 1)) + 1)
    times# (I a) (I b) = I (a * b)
    
    instance (KnownNat n, 1 <= n) => SaturatingNum (Index n) where
      satPlus SatWrap a b =
        leToPlusKN @1 a $ \a' ->
        leToPlusKN @1 b $ \b' ->
          case plus# a' b' of
            z | let m = fromInteger# (natVal (Proxy @ n))
              , z >= m -> resize# (z - m)
            z -> resize# z
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
    import Language.Haskell.TH        (TypeQ, appT, conT, litT, numTyLit, sigE)
    import Language.Haskell.TH.Syntax (Lift(..))
    import GHC.TypeLits               (CmpNat, KnownNat, Nat, type (+), type (-),
                                       type (*), type (<=), natVal)
    import GHC.TypeLits.Extra         (CLog)
    import Test.QuickCheck.Arbitrary  (Arbitrary (..), CoArbitrary (..),
                                       arbitraryBoundedIntegral,
                                       coarbitraryIntegral, shrinkIntegral)
    
    import Clash.Class.BitPack        (BitPack (..))
    import Clash.Class.Num            (ExtendingNum (..), SaturatingNum (..),
                                       SaturationMode (..))
    import Clash.Class.Resize         (Resize (..))
    import {-# SOURCE #-} Clash.Sized.Internal.BitVector (BitVector (BV))
    import Clash.Promoted.Nat         (SNat, snatToNum, leToPlusKN)
    import Clash.XException           (ShowX (..), showsPrecXWith)
    
    -- | Arbitrary-bounded unsigned integer represented by @ceil(log_2(n))@ bits.
    --
    -- Given an upper bound @n@, an 'Index' @n@ number has a range of: [0 .. @n@-1]
    

    log2BNat No usage example found for this symbol :( Collapse [-]
    logBaseSNat No usage example found for this symbol :( Collapse [-]
    modSNat No usage example found for this symbol :( Collapse [-]
    mulBNat No usage example found for this symbol :( Collapse [-]
    mulSNat No usage example found for this symbol :( Collapse [-]
    mulUNat No usage example found for this symbol :( Collapse [-]
    plusToLe No usage example found for this symbol :( Collapse [-]
    plusToLeKN No usage example found for this symbol :( Collapse [-]
    pow2SNat See 15 Occurences [+] Collapse [-]
    Found in Clash.Explicit.BlockRam.File from the package clash-prelude
    -- own data files.
    blockRamFilePow2
      :: forall dom gated n m
       . (KnownNat m, KnownNat n, HasCallStack)
      => Clock dom gated
      -- ^ 'Clock' to synchronize to
      -> FilePath
      -- ^ File describing the initial content of the blockRAM
      -> Signal dom (Unsigned n)  -- ^ Read address @r@
      -> Signal dom (Maybe (Unsigned n, BitVector m))
      -- ^ (write address @w@, value to write)
      -> Signal dom (BitVector m)
      -- ^ Value of the @blockRAM@ at address @r@ from the previous clock cycle
    blockRamFilePow2 = \clk file rd wrM -> withFrozenCallStack
      (blockRamFile clk (pow2SNat (SNat @ n)) file rd wrM)
    {-# INLINE blockRamFilePow2 #-}
    
    -- | Create a blockRAM with space for @n@ elements
    --
    -- * __NB__: Read value is delayed by 1 cycle
    

    Found in Clash.Explicit.BlockRam.File from the package clash-prelude
        -- * Internal
      , blockRamFile#
      , initMem
      )
    where
    
    import Data.Char             (digitToInt)
    import Data.Maybe            (fromJust, isJust, listToMaybe)
    import qualified Data.Vector as V
    import GHC.Stack             (HasCallStack, withFrozenCallStack)
    import GHC.TypeLits          (KnownNat)
    import Numeric               (readInt)
    import System.IO.Unsafe      (unsafePerformIO)
    
    import Clash.Promoted.Nat    (SNat (..), pow2SNat)
    import Clash.Sized.BitVector (BitVector)
    import Clash.Signal.Internal (Clock, Signal (..), (.&&.), clockEnable)
    import Clash.Signal.Bundle   (unbundle)
    import Clash.Sized.Unsigned  (Unsigned)
    import Clash.XException      (errorX, maybeX, seqX)
    

    Found in Clash.Explicit.RAM from the package clash-prelude
    asyncRamPow2
      :: forall wdom rdom wgated rgated n a
       . (KnownNat n, HasCallStack)
      => Clock wdom wgated
      -- ^ 'Clock' to which to synchronise the write port of the RAM
      -> Clock rdom rgated
      -- ^ 'Clock' to which the read address signal, @r@, is synchronised
      -> Signal rdom (Unsigned n)
      -- ^ Read address @r@
      -> Signal wdom (Maybe (Unsigned n, a))
      -- ^ (write address @w@, value to write)
      -> Signal rdom a
      -- ^ Value of the @RAM@ at address @r@
    asyncRamPow2 = \wclk rclk rd wrM -> withFrozenCallStack
      (asyncRam wclk rclk (pow2SNat (SNat @ n)) rd wrM)
    {-# INLINE asyncRamPow2 #-}
    
    
    -- | Create a RAM with space for @n@ elements
    --
    

    Found in Clash.Explicit.RAM from the package clash-prelude
      ( -- * RAM synchronised to an arbitrary clock
        asyncRam
      , asyncRamPow2
        -- * Internal
      , asyncRam#
      )
    where
    
    import Data.Maybe            (fromJust, isJust)
    import GHC.Stack             (HasCallStack, withFrozenCallStack)
    import GHC.TypeLits          (KnownNat)
    import qualified Data.Vector as V
    
    import Clash.Explicit.Signal ((.&&.), unbundle, unsafeSynchronizer)
    import Clash.Promoted.Nat    (SNat (..), snatToNum, pow2SNat)
    import Clash.Signal.Internal (Clock (..), Signal (..), clockEnable)
    import Clash.Sized.Unsigned  (Unsigned)
    import Clash.XException      (errorX, maybeX)
    
    -- | Create a RAM with space for 2^@n@ elements
    

    Found in Clash.Explicit.ROM.File from the package clash-prelude
    --
    -- * See "Clash.Explicit.ROM.File#usingromfiles" for more information on how
    -- to instantiate a ROM with the contents of a data file.
    -- * See "Clash.Sized.Fixed#creatingdatafiles" for ideas on how to create your
    -- own data files.
    romFilePow2
      :: forall domain gated n m
       . (KnownNat m, KnownNat n)
      => Clock domain gated        -- ^ 'Clock' to synchronize to
      -> FilePath                  -- ^ File describing the content of
                                   -- the ROM
      -> Signal domain (Unsigned n)  -- ^ Read address @rd@
      -> Signal domain (BitVector m)
      -- ^ The value of the ROM at address @rd@ from the previous clock cycle
    romFilePow2 = \clk -> romFile clk (pow2SNat (SNat @ n))
    {-# INLINE romFilePow2 #-}
    
    -- | A ROM with a synchronous read port, with space for @n@ elements
    --
    -- * __NB__: Read value is delayed by 1 cycle
    

    Found in Clash.Explicit.ROM.File from the package clash-prelude
    module Clash.Explicit.ROM.File
      ( -- * Synchronous ROM synchronised to an arbitrary clock
        romFile
      , romFilePow2
        -- * Internal
      , romFile#
      )
    where
    
    import Data.Array                   (listArray,(!))
    import GHC.TypeLits                 (KnownNat)
    import System.IO.Unsafe             (unsafePerformIO)
    --
    import Clash.Explicit.BlockRam.File (initMem)
    import Clash.Promoted.Nat           (SNat (..), pow2SNat, snatToNum)
    import Clash.Sized.BitVector        (BitVector)
    import Clash.Explicit.Signal        (Clock, Signal, delay)
    import Clash.Sized.Unsigned         (Unsigned)
    

    Found in Clash.Explicit.Synchronizer from the package clash-prelude
      register clk2 rst i . register clk2 rst i . unsafeSynchronizer clk1 clk2
    
    -- * Asynchronous FIFO synchronizer
    
    fifoMem
      :: Clock wdomain wgated
      -> Clock rdomain rgated
      -> SNat addrSize
      -> Signal wdomain Bool
      -> Signal rdomain (BitVector addrSize)
      -> Signal wdomain (Maybe (BitVector addrSize, a))
      -> Signal rdomain a
    fifoMem wclk rclk addrSize@SNat full raddr writeM =
      asyncRam wclk rclk
               (pow2SNat addrSize)
               raddr
               (mux full (pure Nothing) writeM)
    
    ptrCompareT :: SNat addrSize
                -> (BitVector (addrSize + 1) -> BitVector (addrSize + 1) -> Bool)
    

    Found in Clash.Explicit.Synchronizer from the package clash-prelude
    import Data.Constraint.Nat         (leTrans)
    #else
    import Unsafe.Coerce
    #endif
    import Data.Maybe                  (isJust)
    import GHC.TypeLits                (type (+), type (-), type (<=))
    
    import Clash.Class.BitPack         (boolToBV)
    import Clash.Class.Resize          (truncateB)
    import Clash.Prelude.BitIndex      (slice)
    import Clash.Explicit.Mealy        (mealyB)
    import Clash.Explicit.RAM          (asyncRam)
    import Clash.Explicit.Signal
      (Clock, Reset, Signal, register, unsafeSynchronizer)
    import Clash.Promoted.Nat          (SNat (..), pow2SNat)
    import Clash.Promoted.Nat.Literals (d0)
    import Clash.Signal                (mux)
    import Clash.Sized.BitVector       (BitVector, (++#))
    
    -- * Dual flip-flop synchronizer
    

    Found in Clash.Prelude.ROM.File from the package clash-prelude
    --     @
    --
    --     you __should__ give it a /monomorphic/ type signature:
    --
    --     @
    --     myRomData :: Unsigned 9 -> BitVector 16
    --     myRomData = asyncRomFilePow2 "memory.bin"
    --     @
    asyncRomFilePow2
      :: forall n m
       . (KnownNat m, KnownNat n)
      => FilePath    -- ^ File describing the content of the ROM
      -> Unsigned n  -- ^ Read address @rd@
      -> BitVector m -- ^ The value of the ROM at address @rd@
    asyncRomFilePow2 = asyncRomFile (pow2SNat (SNat @ n))
    {-# INLINE asyncRomFilePow2 #-}
    
    -- | asyncROMFile primitive
    asyncRomFile#
      :: KnownNat m
    

    Found in Clash.Prelude.ROM.File from the package clash-prelude
        -- * Synchronous ROM synchronised to an arbitrary clock
      , romFile
      , romFilePow2
        -- * Internal
      , asyncRomFile#
      )
    where
    
    import           Data.Array                   (listArray,(!))
    import           GHC.TypeLits                 (KnownNat)
    import           System.IO.Unsafe             (unsafePerformIO)
    
    import           Clash.Explicit.BlockRam.File (initMem)
    import qualified Clash.Explicit.ROM.File      as E
    import           Clash.Promoted.Nat           (SNat (..), pow2SNat, snatToNum)
    import           Clash.Signal
    import           Clash.Sized.BitVector        (BitVector)
    import           Clash.Sized.Unsigned         (Unsigned)
    
    -- | An asynchronous/combinational ROM with space for @n@ elements
    

    Found in Clash.Sized.Index from the package clash-prelude
    {-# LANGUAGE Trustworthy #-}
    
    {-# OPTIONS_GHC -fplugin GHC.TypeLits.Extra.Solver -fplugin GHC.TypeLits.KnownNat.Solver #-}
    {-# OPTIONS_GHC -fno-warn-unused-imports #-}
    {-# OPTIONS_HADDOCK show-extensions #-}
    
    module Clash.Sized.Index
      (Index, bv2i)
    where
    
    import GHC.TypeLits               (KnownNat, type (^))
    import GHC.TypeLits.Extra         (CLog) -- documentation only
    
    import Clash.Promoted.Nat         (SNat (..), pow2SNat)
    import Clash.Sized.BitVector      (BitVector)
    import Clash.Sized.Internal.Index
    
    -- | An alternative implementation of 'Clash.Class.BitPack.unpack' for the
    -- 'Index' data type; for when you know the size of the 'BitVector' and want
    

    Found in Clash.Sized.RTree from the package clash-prelude
    -- i.e.,
    --
    -- > tmap f (BR (LR a) (LR b)) == BR (LR (f a)) (LR (f b))
    tmap :: forall d a b . KnownNat d => (a -> b) -> RTree d a -> RTree d b
    tmap f = tdfold (Proxy @(MapTree b)) (LR . f) (\_ l r -> BR l r)
    
    -- | Generate a tree of indices, where the depth of the tree is determined by
    -- the context.
    --
    -- >>> tindices :: RTree 3 (Index 8)
    -- <<<0,1>,<2,3>>,<<4,5>,<6,7>>>
    tindices :: forall d . KnownNat d => RTree d (Index (2^d))
    tindices =
      tdfold (Proxy @(MapTree (Index (2^d)))) LR
             (\s@SNat l r -> BR l (tmap (+(snatToNum (pow2SNat s))) r))
             (treplicate SNat 0)
    
    data V2TTree (a :: *) (f :: TyFun Nat *) :: *
    type instance Apply (V2TTree a) d = RTree d a
    

    Found in Clash.Sized.RTree from the package clash-prelude
    import Control.Applicative         (liftA2)
    import qualified Control.Lens      as Lens
    import Data.Default                (Default (..))
    import Data.Foldable               (toList)
    import Data.Singletons.Prelude     (Apply, TyFun, type (@@))
    import Data.Proxy                  (Proxy (..))
    import GHC.TypeLits                (KnownNat, Nat, type (+), type (^), type (*))
    import Language.Haskell.TH.Syntax  (Lift(..))
    import qualified Prelude           as P
    import Prelude                     hiding ((++), (!!))
    import Test.QuickCheck             (Arbitrary (..), CoArbitrary (..))
    
    import Clash.Class.BitPack         (BitPack (..))
    import Clash.Promoted.Nat          (SNat (..), UNat (..), pow2SNat, snatToNum,
                                        subSNat, toUNat)
    import Clash.Promoted.Nat.Literals (d1)
    import Clash.Sized.Index           (Index)
    import Clash.Sized.Vector          (Vec (..), (!!), (++), dtfold, replace)
    import Clash.XException            (ShowX (..), showsX, showsPrecXWith)
    

    Found in Clash.Sized.Vector from the package clash-prelude
           -- tree that is created by applying this function. The leafs of the tree
           -- have depth\/height /0/, and the root of the tree has height /k/.
           -> Vec (2^k) a
           -- ^ Vector to fold over.
           --
           -- __NB__: Must have a length that is a power of 2.
           -> (p @@ k)
    dtfold _ f g = go (SNat :: SNat k)
      where
        go :: forall n . SNat n -> Vec (2^n) a -> (p @@ n)
        go _  (x `Cons` Nil) = f x
        go sn xs@(Cons _ (Cons _ _)) =
          let sn' :: SNat (n - 1)
              sn'       = sn `subSNat` d1
              (xsL,xsR) = splitAt (pow2SNat sn') xs
          in  g sn' (go sn' xsL) (go sn' xsR)
    {-# NOINLINE dtfold #-}
    
    -- | To be used as the motive /p/ for 'dfold', when the /f/ in \"'dfold' @p f@\"
    -- is a variation on (':>'), e.g.:
    

    Found in Clash.Sized.Vector from the package clash-prelude
    import GHC.Prim                   ((==#),(<#),(-#))
    import Language.Haskell.TH        (ExpQ)
    import Language.Haskell.TH.Syntax (Lift(..))
    import Prelude                    hiding ((++), (!!), concat, drop, foldl,
                                              foldl1, foldr, foldr1, head, init,
                                              iterate, last, length, map, repeat,
                                              replicate, reverse, scanl, scanr,
                                              splitAt, tail, take, unzip, unzip3,
                                              zip, zip3, zipWith, zipWith3)
    import qualified Prelude          as P
    import Test.QuickCheck            (Arbitrary (..), CoArbitrary (..))
    import Unsafe.Coerce              (unsafeCoerce)
    
    import Clash.Promoted.Nat
      (SNat (..), UNat (..), leToPlus, pow2SNat, snatProxy, snatToInteger, subSNat,
       withSNat, toUNat)
    import Clash.Promoted.Nat.Literals (d1)
    import Clash.Sized.Internal.BitVector (Bit, BitVector, (++#), split#)
    import Clash.Sized.Index          (Index)
    

    powBNat No usage example found for this symbol :( Collapse [-]
    powSNat No usage example found for this symbol :( Collapse [-]
    powUNat No usage example found for this symbol :( Collapse [-]
    predBNat No usage example found for this symbol :( Collapse [-]
    predUNat No usage example found for this symbol :( Collapse [-]
    showBNat No usage example found for this symbol :( Collapse [-]
    snatProxy See 4 Occurences [+] Collapse [-]
    Found in Clash.Promoted.Nat.Unsafe from the package clash-prelude
    {-# LANGUAGE Unsafe #-}
    
    module Clash.Promoted.Nat.Unsafe
      (unsafeSNat)
    where
    
    import Data.Reflection    (reifyNat)
    import Unsafe.Coerce      (unsafeCoerce)
    
    import Clash.Promoted.Nat (SNat, snatProxy)
    
    -- | I hope you know what you're doing
    unsafeSNat :: Integer -> SNat k
    unsafeSNat i = reifyNat i $ (\p -> unsafeCoerce (snatProxy p))
    {-# NOINLINE unsafeSNat #-}
    

    Found in Clash.Promoted.Nat.Unsafe from the package clash-prelude
    Copyright  :  (C) 2015-2016, University of Twente
    License    :  BSD2 (see the file LICENSE)
    Maintainer :  Christiaan Baaij <christiaan.baaij@gmail.com>
    -}
    
    {-# LANGUAGE Unsafe #-}
    
    module Clash.Promoted.Nat.Unsafe
      (unsafeSNat)
    where
    
    import Data.Reflection    (reifyNat)
    import Unsafe.Coerce      (unsafeCoerce)
    
    import Clash.Promoted.Nat (SNat, snatProxy)
    
    -- | I hope you know what you're doing
    unsafeSNat :: Integer -> SNat k
    unsafeSNat i = reifyNat i $ (\p -> unsafeCoerce (snatProxy p))
    {-# NOINLINE unsafeSNat #-}
    

    Found in Clash.Sized.Vector from the package clash-prelude
    -- __NB__: \"@'dfold' m f z xs@\" creates a linear structure, which has a depth,
    -- or delay, of O(@'length' xs@). Look at 'dtfold' for a /dependently/ typed
    -- fold that produces a structure with a depth of O(log_2(@'length' xs@)).
    dfold :: forall p k a . KnownNat k
          => Proxy (p :: TyFun Nat * -> *) -- ^ The /motive/
          -> (forall l . SNat l -> a -> (p @@ l) -> (p @@ (l + 1)))
          -- ^ Function to fold.
          --
          -- __NB__: The @SNat l@ is __not__ the index (see (`!!`)) to the
          -- element /a/. @SNat l@ is the number of elements that occur to the
          -- right of /a/.
          -> (p @@ 0) -- ^ Initial element
          -> Vec k a -- ^ Vector to fold over
          -> (p @@ k)
    dfold _ f z xs = go (snatProxy (asNatProxy xs)) xs
      where
        go :: SNat n -> Vec n a -> (p @@ n)
        go _ Nil                        = z
        go s (y `Cons` (ys :: Vec z a)) =
          let s' = s `subSNat` d1
    

    Found in Clash.Sized.Vector from the package clash-prelude
    import GHC.Prim                   ((==#),(<#),(-#))
    import Language.Haskell.TH        (ExpQ)
    import Language.Haskell.TH.Syntax (Lift(..))
    import Prelude                    hiding ((++), (!!), concat, drop, foldl,
                                              foldl1, foldr, foldr1, head, init,
                                              iterate, last, length, map, repeat,
                                              replicate, reverse, scanl, scanr,
                                              splitAt, tail, take, unzip, unzip3,
                                              zip, zip3, zipWith, zipWith3)
    import qualified Prelude          as P
    import Test.QuickCheck            (Arbitrary (..), CoArbitrary (..))
    import Unsafe.Coerce              (unsafeCoerce)
    
    import Clash.Promoted.Nat
      (SNat (..), UNat (..), leToPlus, pow2SNat, snatProxy, snatToInteger, subSNat,
       withSNat, toUNat)
    import Clash.Promoted.Nat.Literals (d1)
    import Clash.Sized.Internal.BitVector (Bit, BitVector, (++#), split#)
    import Clash.Sized.Index          (Index)
    

    snatToInteger See 10 Occurences [+] Collapse [-]
    Found in Clash.Signal.Internal from the package clash-prelude
      -> a
    clockPeriod (Clock _ period)        = snatToNum period
    clockPeriod (GatedClock _ period _) = snatToNum period
    
    -- | If the clock is gated, return 'Just' the /enable/ signal, 'Nothing'
    -- otherwise
    clockEnable
      :: Clock domain gated
      -> Maybe (Signal domain Bool)
    clockEnable Clock {}            = Nothing
    clockEnable (GatedClock _ _ en) = Just en
    
    instance Show (Clock domain gated) where
      show (Clock      nm period)   = show nm ++ show (snatToInteger period)
      show (GatedClock nm period _) = show nm ++ show (snatToInteger period)
    
    -- | Clock gating primitive
    clockGate :: Clock domain gated -> Signal domain Bool -> Clock domain 'Gated
    clockGate (Clock nm rt)         en  = GatedClock nm rt en
    clockGate (GatedClock nm rt en) en' = GatedClock nm rt (en .&&. en')
    

    Found in Clash.Signal.Internal from the package clash-prelude
      => Clock domain gated
      -> a
    clockPeriod (Clock _ period)        = snatToNum period
    clockPeriod (GatedClock _ period _) = snatToNum period
    
    -- | If the clock is gated, return 'Just' the /enable/ signal, 'Nothing'
    -- otherwise
    clockEnable
      :: Clock domain gated
      -> Maybe (Signal domain Bool)
    clockEnable Clock {}            = Nothing
    clockEnable (GatedClock _ _ en) = Just en
    
    instance Show (Clock domain gated) where
      show (Clock      nm period)   = show nm ++ show (snatToInteger period)
      show (GatedClock nm period _) = show nm ++ show (snatToInteger period)
    
    -- | Clock gating primitive
    clockGate :: Clock domain gated -> Signal domain Bool -> Clock domain 'Gated
    clockGate (Clock nm rt)         en  = GatedClock nm rt en
    

    Found in Clash.Signal.Internal from the package clash-prelude
    where
    
    import Control.Applicative        (liftA2, liftA3)
    import Control.DeepSeq            (NFData, force)
    import Control.Exception          (catch, evaluate, throw)
    import Data.Default               (Default (..))
    import GHC.Generics               (Generic)
    import GHC.Stack                  (HasCallStack, withFrozenCallStack)
    import GHC.TypeLits               (KnownNat, KnownSymbol, Nat, Symbol)
    import Language.Haskell.TH.Syntax (Lift (..))
    import System.IO.Unsafe           (unsafeDupablePerformIO)
    import Test.QuickCheck            (Arbitrary (..), CoArbitrary(..), Property,
                                       property)
    
    import Clash.Promoted.Nat         (SNat (..), snatToInteger, snatToNum)
    import Clash.Promoted.Symbol      (SSymbol (..))
    import Clash.XException           (XException, errorX, seqX)
    
    {- $setup
    >>> :set -XDataKinds
    

    Found in Clash.Sized.Vector from the package clash-prelude
        go n (y `Cons` ys) = go (n-1) (ys :< y)
    {-# NOINLINE rotateLeftS #-}
    
    -- | /Statically/ rotate a 'Vec'tor to the right:
    --
    -- >>> let xs = 1 :> 2 :> 3 :> 4 :> Nil
    -- >>> rotateRightS xs d1
    -- <4,1,2,3>
    --
    -- __NB:__ use `rotateRight` if you want to rotate right by a /dynamic/ amount.
    rotateRightS :: KnownNat n
                 => Vec n a
                 -> SNat d
                 -> Vec n a
    rotateRightS xs d = go (snatToInteger d `mod` natVal (asNatProxy xs)) xs
      where
        go _ Nil            = Nil
        go 0 ys             = ys
        go n ys@(Cons _ _)  = go (n-1) (last ys :> init ys)
    {-# NOINLINE rotateRightS #-}
    

    Found in Clash.Sized.Vector from the package clash-prelude
        len = length xs
    {-# INLINE rotateRight #-}
    
    -- | /Statically/ rotate a 'Vec'tor to the left:
    --
    -- >>> let xs = 1 :> 2 :> 3 :> 4 :> Nil
    -- >>> rotateLeftS xs d1
    -- <2,3,4,1>
    --
    -- __NB:__ use `rotateLeft` if you want to rotate left by a /dynamic/ amount.
    rotateLeftS :: KnownNat n
                => Vec n a
                -> SNat d
                -> Vec n a
    rotateLeftS xs d = go (snatToInteger d `mod` natVal (asNatProxy xs)) xs
      where
        go :: Integer -> Vec k a -> Vec k a
        go _ Nil           = Nil
        go 0 ys            = ys
        go n (y `Cons` ys) = go (n-1) (ys :< y)
    

    Found in Clash.Sized.Vector from the package clash-prelude
    import GHC.Prim                   ((==#),(<#),(-#))
    import Language.Haskell.TH        (ExpQ)
    import Language.Haskell.TH.Syntax (Lift(..))
    import Prelude                    hiding ((++), (!!), concat, drop, foldl,
                                              foldl1, foldr, foldr1, head, init,
                                              iterate, last, length, map, repeat,
                                              replicate, reverse, scanl, scanr,
                                              splitAt, tail, take, unzip, unzip3,
                                              zip, zip3, zipWith, zipWith3)
    import qualified Prelude          as P
    import Test.QuickCheck            (Arbitrary (..), CoArbitrary (..))
    import Unsafe.Coerce              (unsafeCoerce)
    
    import Clash.Promoted.Nat
      (SNat (..), UNat (..), leToPlus, pow2SNat, snatProxy, snatToInteger, subSNat,
       withSNat, toUNat)
    import Clash.Promoted.Nat.Literals (d1)
    import Clash.Sized.Internal.BitVector (Bit, BitVector, (++#), split#)
    import Clash.Sized.Index          (Index)
    

    Found in Clash.Sized.Internal.BitVector from the package clash-prelude
        sz   = fromInteger (natVal bv)
        err  = error $ concat [ "replaceBit: "
                              , show i
                              , " is out of range ["
                              , show (sz - 1)
                              , "..0]"
                              ]
    
    {-# NOINLINE setSlice# #-}
    setSlice# :: BitVector (m + 1 + i) -> SNat m -> SNat n -> BitVector (m + 1 - n)
              -> BitVector (m + 1 + i)
    setSlice# (BV i) m n (BV j) = BV ((i .&. mask) .|. j')
      where
        m' = snatToInteger m
        n' = snatToInteger n
    
        j'   = shiftL j (fromInteger n')
        mask = complement ((2 ^ (m' + 1) - 1) `xor` (2 ^ n' - 1))
    
    {-# NOINLINE split# #-}
    

    Found in Clash.Sized.Internal.BitVector from the package clash-prelude
      where
        sz   = fromInteger (natVal bv)
        err  = error $ concat [ "replaceBit: "
                              , show i
                              , " is out of range ["
                              , show (sz - 1)
                              , "..0]"
                              ]
    
    {-# NOINLINE setSlice# #-}
    setSlice# :: BitVector (m + 1 + i) -> SNat m -> SNat n -> BitVector (m + 1 - n)
              -> BitVector (m + 1 + i)
    setSlice# (BV i) m n (BV j) = BV ((i .&. mask) .|. j')
      where
        m' = snatToInteger m
        n' = snatToInteger n
    
        j'   = shiftL j (fromInteger n')
        mask = complement ((2 ^ (m' + 1) - 1) `xor` (2 ^ n' - 1))
    

    Found in Clash.Sized.Internal.BitVector from the package clash-prelude
    msb# :: forall n . KnownNat n => BitVector n -> Bit
    msb# (BV v)
      = let i = fromInteger (natVal (Proxy @n) - 1)
        in  Bit (smallInteger (dataToTag# (testBit v i)))
    
    {-# NOINLINE lsb# #-}
    -- | LSB
    lsb# :: BitVector n -> Bit
    lsb# (BV v) = Bit (smallInteger (dataToTag# (testBit v 0)))
    
    {-# NOINLINE slice# #-}
    slice# :: BitVector (m + 1 + i) -> SNat m -> SNat n -> BitVector (m + 1 - n)
    slice# (BV i) m n = BV (shiftR (i .&. mask) n')
      where
        m' = snatToInteger m
        n' = snatToNum n
    
        mask = 2 ^ (m' + 1) - 1
    
    -- * Constructions
    

    Found in Clash.Sized.Internal.BitVector from the package clash-prelude
    import GHC.Integer                (smallInteger)
    import GHC.Prim                   (dataToTag#)
    import GHC.TypeLits               (KnownNat, Nat, type (+), type (-), natVal)
    import GHC.TypeLits.Extra         (Max)
    import Language.Haskell.TH        (Q, TExp, TypeQ, appT, conT, litT, numTyLit, sigE)
    import Language.Haskell.TH.Syntax (Lift(..))
    import Numeric                    (readInt)
    import Test.QuickCheck.Arbitrary  (Arbitrary (..), CoArbitrary (..),
                                       arbitraryBoundedIntegral,
                                       coarbitraryIntegral, shrinkIntegral)
    
    import Clash.Class.Num            (ExtendingNum (..), SaturatingNum (..),
                                       SaturationMode (..))
    import Clash.Class.Resize         (Resize (..))
    import Clash.Promoted.Nat         (SNat, snatToInteger, snatToNum)
    import Clash.XException           (ShowX (..), showsPrecXWith)
    
    import {-# SOURCE #-} qualified Clash.Sized.Vector         as V
    import {-# SOURCE #-} qualified Clash.Sized.Internal.Index as I
    

    snatToNum See 15 Occurences [+] Collapse [-]
    Found in Clash.Explicit.RAM from the package clash-prelude
      -- ^ 'Clock' to which to synchronise the write port of the RAM
      -> Clock rdom rgated
      -- ^ 'Clock' to which the read address signal, @r@, is synchronised
      -> SNat n            -- ^ Size @n@ of the RAM
      -> Signal rdom Int  -- ^ Read address @r@
      -> Signal wdom Bool -- ^ Write enable
      -> Signal wdom Int  -- ^ Write address @w@
      -> Signal wdom a    -- ^ Value to write (at address @w@)
      -> Signal rdom a    -- ^ Value of the @RAM@ at address @r@
    asyncRam# wclk rclk sz rd en wr din =
        unsafeSynchronizer wclk rclk dout
      where
        rd'  = unsafeSynchronizer rclk wclk rd
        ramI = V.replicate
                  (snatToNum sz)
                  (withFrozenCallStack (errorX "asyncRam#: initial value undefined"))
        en'  = case clockEnable wclk of
                 Nothing  -> en
                 Just wgt -> wgt .&&. en
        dout = go ramI rd' en' wr din
    

    Found in Clash.Explicit.RAM from the package clash-prelude
      ( -- * RAM synchronised to an arbitrary clock
        asyncRam
      , asyncRamPow2
        -- * Internal
      , asyncRam#
      )
    where
    
    import Data.Maybe            (fromJust, isJust)
    import GHC.Stack             (HasCallStack, withFrozenCallStack)
    import GHC.TypeLits          (KnownNat)
    import qualified Data.Vector as V
    
    import Clash.Explicit.Signal ((.&&.), unbundle, unsafeSynchronizer)
    import Clash.Promoted.Nat    (SNat (..), snatToNum, pow2SNat)
    import Clash.Signal.Internal (Clock (..), Signal (..), clockEnable)
    import Clash.Sized.Unsigned  (Unsigned)
    import Clash.XException      (errorX, maybeX)
    
    -- | Create a RAM with space for 2^@n@ elements
    

    Found in Clash.Explicit.ROM.File from the package clash-prelude
      => Clock domain gated
      -- ^ 'Clock' to synchronize to
      -> SNat n
      -- ^ Size of the ROM
      -> FilePath
      -- ^ File describing the content of the ROM
      -> Signal domain Int
      -- ^ Read address @rd@
      -> Signal domain (BitVector m)
      -- ^ The value of the ROM at address @rd@ from the previous clock cycle
    romFile# clk sz file rd = delay clk ((content !) <$> rd)
      where
        mem     = unsafePerformIO (initMem file)
        content = listArray (0,szI-1) mem
        szI     = snatToNum sz
    {-# NOINLINE romFile# #-}
    

    Found in Clash.Explicit.ROM.File from the package clash-prelude
    module Clash.Explicit.ROM.File
      ( -- * Synchronous ROM synchronised to an arbitrary clock
        romFile
      , romFilePow2
        -- * Internal
      , romFile#
      )
    where
    
    import Data.Array                   (listArray,(!))
    import GHC.TypeLits                 (KnownNat)
    import System.IO.Unsafe             (unsafePerformIO)
    --
    import Clash.Explicit.BlockRam.File (initMem)
    import Clash.Promoted.Nat           (SNat (..), pow2SNat, snatToNum)
    import Clash.Sized.BitVector        (BitVector)
    import Clash.Explicit.Signal        (Clock, Signal, delay)
    import Clash.Sized.Unsigned         (Unsigned)
    

    Found in Clash.Prelude.ROM.File from the package clash-prelude
    asyncRomFilePow2 = asyncRomFile (pow2SNat (SNat @ n))
    {-# INLINE asyncRomFilePow2 #-}
    
    -- | asyncROMFile primitive
    asyncRomFile#
      :: KnownNat m
      => SNat n       -- ^ Size of the ROM
      -> FilePath     -- ^ File describing the content of the ROM
      -> Int          -- ^ Read address @rd@
      -> BitVector m  -- ^ The value of the ROM at address @rd@
    asyncRomFile# sz file = (content !) -- Leave "(content !)" eta-reduced, see
      where                             -- Note [Eta-reduction and unsafePerformIO initMem]
        mem     = unsafePerformIO (initMem file)
        content = listArray (0,szI-1) mem
        szI     = snatToNum sz
    {-# NOINLINE asyncRomFile# #-}
    
    -- | A ROM with a synchronous read port, with space for @n@ elements
    --
    -- * __NB__: Read value is delayed by 1 cycle
    

    Found in Clash.Prelude.ROM.File from the package clash-prelude
        -- * Synchronous ROM synchronised to an arbitrary clock
      , romFile
      , romFilePow2
        -- * Internal
      , asyncRomFile#
      )
    where
    
    import           Data.Array                   (listArray,(!))
    import           GHC.TypeLits                 (KnownNat)
    import           System.IO.Unsafe             (unsafePerformIO)
    
    import           Clash.Explicit.BlockRam.File (initMem)
    import qualified Clash.Explicit.ROM.File      as E
    import           Clash.Promoted.Nat           (SNat (..), pow2SNat, snatToNum)
    import           Clash.Signal
    import           Clash.Sized.BitVector        (BitVector)
    import           Clash.Sized.Unsigned         (Unsigned)
    
    -- | An asynchronous/combinational ROM with space for @n@ elements
    

    Found in Clash.Signal.Internal from the package clash-prelude
        -> Clock domain 'Source
      GatedClock
        :: (domain ~ ('Dom name period))
        => SSymbol name
        -> SNat    period
        -> Signal domain Bool
        -> Clock  domain 'Gated
    
    -- | Get the clock period of a 'Clock' (in /ps/) as a 'Num'
    clockPeriod
      :: Num a
      => Clock domain gated
      -> a
    clockPeriod (Clock _ period)        = snatToNum period
    clockPeriod (GatedClock _ period _) = snatToNum period
    
    -- | If the clock is gated, return 'Just' the /enable/ signal, 'Nothing'
    -- otherwise
    clockEnable
      :: Clock domain gated
    

    Found in Clash.Signal.Internal from the package clash-prelude
        -> SNat    period
        -> Clock domain 'Source
      GatedClock
        :: (domain ~ ('Dom name period))
        => SSymbol name
        -> SNat    period
        -> Signal domain Bool
        -> Clock  domain 'Gated
    
    -- | Get the clock period of a 'Clock' (in /ps/) as a 'Num'
    clockPeriod
      :: Num a
      => Clock domain gated
      -> a
    clockPeriod (Clock _ period)        = snatToNum period
    clockPeriod (GatedClock _ period _) = snatToNum period
    
    -- | If the clock is gated, return 'Just' the /enable/ signal, 'Nothing'
    -- otherwise
    clockEnable
    

    Found in Clash.Signal.Internal from the package clash-prelude
    where
    
    import Control.Applicative        (liftA2, liftA3)
    import Control.DeepSeq            (NFData, force)
    import Control.Exception          (catch, evaluate, throw)
    import Data.Default               (Default (..))
    import GHC.Generics               (Generic)
    import GHC.Stack                  (HasCallStack, withFrozenCallStack)
    import GHC.TypeLits               (KnownNat, KnownSymbol, Nat, Symbol)
    import Language.Haskell.TH.Syntax (Lift (..))
    import System.IO.Unsafe           (unsafeDupablePerformIO)
    import Test.QuickCheck            (Arbitrary (..), CoArbitrary(..), Property,
                                       property)
    
    import Clash.Promoted.Nat         (SNat (..), snatToInteger, snatToNum)
    import Clash.Promoted.Symbol      (SSymbol (..))
    import Clash.XException           (XException, errorX, seqX)
    
    {- $setup
    >>> :set -XDataKinds
    

    Found in Clash.Sized.RTree from the package clash-prelude
    -- i.e.,
    --
    -- > tmap f (BR (LR a) (LR b)) == BR (LR (f a)) (LR (f b))
    tmap :: forall d a b . KnownNat d => (a -> b) -> RTree d a -> RTree d b
    tmap f = tdfold (Proxy @(MapTree b)) (LR . f) (\_ l r -> BR l r)
    
    -- | Generate a tree of indices, where the depth of the tree is determined by
    -- the context.
    --
    -- >>> tindices :: RTree 3 (Index 8)
    -- <<<0,1>,<2,3>>,<<4,5>,<6,7>>>
    tindices :: forall d . KnownNat d => RTree d (Index (2^d))
    tindices =
      tdfold (Proxy @(MapTree (Index (2^d)))) LR
             (\s@SNat l r -> BR l (tmap (+(snatToNum (pow2SNat s))) r))
             (treplicate SNat 0)
    
    data V2TTree (a :: *) (f :: TyFun Nat *) :: *
    type instance Apply (V2TTree a) d = RTree d a
    

    Found in Clash.Sized.RTree from the package clash-prelude
    import Control.Applicative         (liftA2)
    import qualified Control.Lens      as Lens
    import Data.Default                (Default (..))
    import Data.Foldable               (toList)
    import Data.Singletons.Prelude     (Apply, TyFun, type (@@))
    import Data.Proxy                  (Proxy (..))
    import GHC.TypeLits                (KnownNat, Nat, type (+), type (^), type (*))
    import Language.Haskell.TH.Syntax  (Lift(..))
    import qualified Prelude           as P
    import Prelude                     hiding ((++), (!!))
    import Test.QuickCheck             (Arbitrary (..), CoArbitrary (..))
    
    import Clash.Class.BitPack         (BitPack (..))
    import Clash.Promoted.Nat          (SNat (..), UNat (..), pow2SNat, snatToNum,
                                        subSNat, toUNat)
    import Clash.Promoted.Nat.Literals (d1)
    import Clash.Sized.Index           (Index)
    import Clash.Sized.Vector          (Vec (..), (!!), (++), dtfold, replace)
    import Clash.XException            (ShowX (..), showsX, showsPrecXWith)
    

    Found in Clash.Sized.Internal.BitVector from the package clash-prelude
    msb# (BV v)
      = let i = fromInteger (natVal (Proxy @n) - 1)
        in  Bit (smallInteger (dataToTag# (testBit v i)))
    
    {-# NOINLINE lsb# #-}
    -- | LSB
    lsb# :: BitVector n -> Bit
    lsb# (BV v) = Bit (smallInteger (dataToTag# (testBit v 0)))
    
    {-# NOINLINE slice# #-}
    slice# :: BitVector (m + 1 + i) -> SNat m -> SNat n -> BitVector (m + 1 - n)
    slice# (BV i) m n = BV (shiftR (i .&. mask) n')
      where
        m' = snatToInteger m
        n' = snatToNum n
    
        mask = 2 ^ (m' + 1) - 1
    
    -- * Constructions
    

    Found in Clash.Sized.Internal.BitVector from the package clash-prelude
    import GHC.Integer                (smallInteger)
    import GHC.Prim                   (dataToTag#)
    import GHC.TypeLits               (KnownNat, Nat, type (+), type (-), natVal)
    import GHC.TypeLits.Extra         (Max)
    import Language.Haskell.TH        (Q, TExp, TypeQ, appT, conT, litT, numTyLit, sigE)
    import Language.Haskell.TH.Syntax (Lift(..))
    import Numeric                    (readInt)
    import Test.QuickCheck.Arbitrary  (Arbitrary (..), CoArbitrary (..),
                                       arbitraryBoundedIntegral,
                                       coarbitraryIntegral, shrinkIntegral)
    
    import Clash.Class.Num            (ExtendingNum (..), SaturatingNum (..),
                                       SaturationMode (..))
    import Clash.Class.Resize         (Resize (..))
    import Clash.Promoted.Nat         (SNat, snatToInteger, snatToNum)
    import Clash.XException           (ShowX (..), showsPrecXWith)
    
    import {-# SOURCE #-} qualified Clash.Sized.Vector         as V
    import {-# SOURCE #-} qualified Clash.Sized.Internal.Index as I
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
    instance NFData (Index n) where
      rnf (I i) = rnf i `seq` ()
      {-# NOINLINE rnf #-}
      -- NOINLINE is needed so that Clash doesn't trip on the "Index ~# Integer"
      -- coercion
    
    instance KnownNat n => BitPack (Index n) where
      type BitSize (Index n) = CLog 2 n
      pack   = pack#
      unpack = unpack#
    
    -- | Safely convert an `SNat` value to an `Index`
    fromSNat :: (KnownNat m, CmpNat n m ~ 'LT) => SNat n -> Index m
    fromSNat = snatToNum
    
    {-# NOINLINE pack# #-}
    pack# :: Index n -> BitVector (CLog 2 n)
    pack# (I i) = BV i
    

    Found in Clash.Sized.Internal.Index from the package clash-prelude
    import Language.Haskell.TH        (TypeQ, appT, conT, litT, numTyLit, sigE)
    import Language.Haskell.TH.Syntax (Lift(..))
    import GHC.TypeLits               (CmpNat, KnownNat, Nat, type (+), type (-),
                                       type (*), type (<=), natVal)
    import GHC.TypeLits.Extra         (CLog)
    import Test.QuickCheck.Arbitrary  (Arbitrary (..), CoArbitrary (..),
                                       arbitraryBoundedIntegral,
                                       coarbitraryIntegral, shrinkIntegral)
    
    import Clash.Class.BitPack        (BitPack (..))
    import Clash.Class.Num            (ExtendingNum (..), SaturatingNum (..),
                                       SaturationMode (..))
    import Clash.Class.Resize         (Resize (..))
    import {-# SOURCE #-} Clash.Sized.Internal.BitVector (BitVector (BV))
    import Clash.Promoted.Nat         (SNat, snatToNum, leToPlusKN)
    import Clash.XException           (ShowX (..), showsPrecXWith)
    
    -- | Arbitrary-bounded unsigned integer represented by @ceil(log_2(n))@ bits.
    --
    -- Given an upper bound @n@, an 'Index' @n@ number has a range of: [0 .. @n@-1]
    

    stripZeros No usage example found for this symbol :( Collapse [-]
    subSNat See 5 Occurences [+] Collapse [-]
    Found in Clash.Sized.RTree from the package clash-prelude
    -- 3
    tdfold :: forall p k a . KnownNat k
           => Proxy (p :: TyFun Nat * -> *) -- ^ The /motive/
           -> (a -> (p @@ 0)) -- ^ Function to apply to the elements on the leafs
           -> (forall l . SNat l -> (p @@ l) -> (p @@ l) -> (p @@ (l+1)))
           -- ^ Function to fold the branches with.
           --
           -- __NB:__ @SNat l@ is the depth of the two sub-branches.
           -> RTree k a -- ^ Tree to fold over.
           -> (p @@ k)
    tdfold _ f g = go SNat
      where
        go :: SNat m -> RTree m a -> (p @@ m)
        go _  (LR_ a)   = f a
        go sn (BR_ l r) = let sn' = sn `subSNat` d1
                          in  g sn' (go sn' l) (go sn' r)
    {-# NOINLINE tdfold #-}
    
    data TfoldTree (a :: *) (f :: TyFun Nat *) :: *
    type instance Apply (TfoldTree a) d = a
    

    Found in Clash.Sized.RTree from the package clash-prelude
    import Control.Applicative         (liftA2)
    import qualified Control.Lens      as Lens
    import Data.Default                (Default (..))
    import Data.Foldable               (toList)
    import Data.Singletons.Prelude     (Apply, TyFun, type (@@))
    import Data.Proxy                  (Proxy (..))
    import GHC.TypeLits                (KnownNat, Nat, type (+), type (^), type (*))
    import Language.Haskell.TH.Syntax  (Lift(..))
    import qualified Prelude           as P
    import Prelude                     hiding ((++), (!!))
    import Test.QuickCheck             (Arbitrary (..), CoArbitrary (..))
    
    import Clash.Class.BitPack         (BitPack (..))
    import Clash.Promoted.Nat          (SNat (..), UNat (..), pow2SNat, snatToNum,
                                        subSNat, toUNat)
    import Clash.Promoted.Nat.Literals (d1)
    import Clash.Sized.Index           (Index)
    import Clash.Sized.Vector          (Vec (..), (!!), (++), dtfold, replace)
    import Clash.XException            (ShowX (..), showsX, showsPrecXWith)
    

    Found in Clash.Sized.Vector from the package clash-prelude
           -- __NB__: The @SNat l@ indicates the depth/height of the node in the
           -- tree that is created by applying this function. The leafs of the tree
           -- have depth\/height /0/, and the root of the tree has height /k/.
           -> Vec (2^k) a
           -- ^ Vector to fold over.
           --
           -- __NB__: Must have a length that is a power of 2.
           -> (p @@ k)
    dtfold _ f g = go (SNat :: SNat k)
      where
        go :: forall n . SNat n -> Vec (2^n) a -> (p @@ n)
        go _  (x `Cons` Nil) = f x
        go sn xs@(Cons _ (Cons _ _)) =
          let sn' :: SNat (n - 1)
              sn'       = sn `subSNat` d1
              (xsL,xsR) = splitAt (pow2SNat sn') xs
          in  g sn' (go sn' xsL) (go sn' xsR)
    {-# NOINLINE dtfold #-}
    
    -- | To be used as the motive /p/ for 'dfold', when the /f/ in \"'dfold' @p f@\"
    

    Found in Clash.Sized.Vector from the package clash-prelude
          -> (forall l . SNat l -> a -> (p @@ l) -> (p @@ (l + 1)))
          -- ^ Function to fold.
          --
          -- __NB__: The @SNat l@ is __not__ the index (see (`!!`)) to the
          -- element /a/. @SNat l@ is the number of elements that occur to the
          -- right of /a/.
          -> (p @@ 0) -- ^ Initial element
          -> Vec k a -- ^ Vector to fold over
          -> (p @@ k)
    dfold _ f z xs = go (snatProxy (asNatProxy xs)) xs
      where
        go :: SNat n -> Vec n a -> (p @@ n)
        go _ Nil                        = z
        go s (y `Cons` (ys :: Vec z a)) =
          let s' = s `subSNat` d1
          in  f s' y (go s' ys)
    {-# NOINLINE dfold #-}
    
    -- | A combination of 'dfold' and 'fold': a /dependently/ typed fold that
    -- reduces a vector in a tree-like structure.
    

    Found in Clash.Sized.Vector from the package clash-prelude
    import GHC.Prim                   ((==#),(<#),(-#))
    import Language.Haskell.TH        (ExpQ)
    import Language.Haskell.TH.Syntax (Lift(..))
    import Prelude                    hiding ((++), (!!), concat, drop, foldl,
                                              foldl1, foldr, foldr1, head, init,
                                              iterate, last, length, map, repeat,
                                              replicate, reverse, scanl, scanr,
                                              splitAt, tail, take, unzip, unzip3,
                                              zip, zip3, zipWith, zipWith3)
    import qualified Prelude          as P
    import Test.QuickCheck            (Arbitrary (..), CoArbitrary (..))
    import Unsafe.Coerce              (unsafeCoerce)
    
    import Clash.Promoted.Nat
      (SNat (..), UNat (..), leToPlus, pow2SNat, snatProxy, snatToInteger, subSNat,
       withSNat, toUNat)
    import Clash.Promoted.Nat.Literals (d1)
    import Clash.Sized.Internal.BitVector (Bit, BitVector, (++#), split#)
    import Clash.Sized.Index          (Index)
    

    subUNat No usage example found for this symbol :( Collapse [-]
    succBNat No usage example found for this symbol :( Collapse [-]
    toBNat No usage example found for this symbol :( Collapse [-]
    toUNat See 9 Occurences [+] Collapse [-]
    Found in Clash.Sized.RTree from the package clash-prelude
          -> (b -> b -> b) -- ^ Function to combine the results of the reduction
                           -- of two branches
          -> RTree d a -- ^ Tree to fold reduce
          -> b
    tfold f g = tdfold (Proxy @(TfoldTree b)) f (const g)
    
    -- | \"'treplicate' @d a@\" returns a tree of depth /d/, and has /2^d/ copies
    -- of /a/.
    --
    -- >>> treplicate (SNat :: SNat 3) 6
    -- <<<6,6>,<6,6>>,<<6,6>,<6,6>>>
    -- >>> treplicate d3 6
    -- <<<6,6>,<6,6>>,<<6,6>,<6,6>>>
    treplicate :: forall d a . SNat d -> a -> RTree d a
    treplicate sn a = go (toUNat sn)
      where
        go :: UNat n -> RTree n a
        go UZero      = LR a
        go (USucc un) = BR (go un) (go un)
    {-# NOINLINE treplicate #-}
    

    Found in Clash.Sized.RTree from the package clash-prelude
    import Control.Applicative         (liftA2)
    import qualified Control.Lens      as Lens
    import Data.Default                (Default (..))
    import Data.Foldable               (toList)
    import Data.Singletons.Prelude     (Apply, TyFun, type (@@))
    import Data.Proxy                  (Proxy (..))
    import GHC.TypeLits                (KnownNat, Nat, type (+), type (^), type (*))
    import Language.Haskell.TH.Syntax  (Lift(..))
    import qualified Prelude           as P
    import Prelude                     hiding ((++), (!!))
    import Test.QuickCheck             (Arbitrary (..), CoArbitrary (..))
    
    import Clash.Class.BitPack         (BitPack (..))
    import Clash.Promoted.Nat          (SNat (..), UNat (..), pow2SNat, snatToNum,
                                        subSNat, toUNat)
    import Clash.Promoted.Nat.Literals (d1)
    import Clash.Sized.Index           (Index)
    import Clash.Sized.Vector          (Vec (..), (!!), (++), dtfold, replace)
    import Clash.XException            (ShowX (..), showsX, showsPrecXWith)
    

    Found in Clash.Sized.Vector from the package clash-prelude
    concatBitVector#
      :: (KnownNat n, KnownNat m)
      => Vec n (BitVector m)
      -> BitVector (n * m)
    concatBitVector# Nil           = 0
    concatBitVector# (x `Cons` xs) = x ++# concatBitVector# xs
    {-# NOINLINE concatBitVector# #-}
    
    unconcatBitVector#
      :: forall n m
       . (KnownNat n, KnownNat m)
      => BitVector (n * m)
      -> Vec n (BitVector m)
    unconcatBitVector# = go (toUNat (SNat @ n))
      where
        go :: KnownNat x => UNat x -> BitVector (x * m) -> Vec x (BitVector m)
        go UZero     _  = Nil
        go (USucc n) bv = let (x :: BitVector m,bv') = split# bv
                          in  x :> go n bv'
    

    Found in Clash.Sized.Vector from the package clash-prelude
            => SNat f
            -> SNat s
            -> Vec (f + i) a
            -> Vec n a
    selectI f s xs = withSNat (\n -> select f s n xs)
    {-# INLINE selectI #-}
    
    -- | \"'replicate' @n a@\" returns a vector that has /n/ copies of /a/.
    --
    -- >>> replicate (SNat :: SNat 3) 6
    -- <6,6,6>
    -- >>> replicate d3 6
    -- <6,6,6>
    replicate :: SNat n -> a -> Vec n a
    replicate n a = replicateU (toUNat n) a
    {-# NOINLINE replicate #-}
    
    replicateU :: UNat n -> a -> Vec n a
    replicateU UZero     _ = Nil
    replicateU (USucc s) x = x `Cons` replicateU s x
    

    Found in Clash.Sized.Vector from the package clash-prelude
    -- | \"'select' @f s n xs@\" selects /n/ elements with step-size /s/ and
    -- offset @f@ from /xs/.
    --
    -- >>> select (SNat :: SNat 1) (SNat :: SNat 2) (SNat :: SNat 3) (1:>2:>3:>4:>5:>6:>7:>8:>Nil)
    -- <2,4,6>
    -- >>> select d1 d2 d3 (1:>2:>3:>4:>5:>6:>7:>8:>Nil)
    -- <2,4,6>
    select :: (CmpNat (i + s) (s * n) ~ 'GT)
           => SNat f
           -> SNat s
           -> SNat n
           -> Vec (f + i) a
           -> Vec n a
    select f s n xs = select' (toUNat n) $ drop f xs
      where
        select' :: UNat n -> Vec i a -> Vec n a
        select' UZero      _               = Nil
        select' (USucc n') vs@(x `Cons` _) = x `Cons`
                                             select' n' (drop s (unsafeCoerce vs))
    

    Found in Clash.Sized.Vector from the package clash-prelude
    --
    -- >>> concat ((1:>2:>3:>Nil) :> (4:>5:>6:>Nil) :> (7:>8:>9:>Nil) :> (10:>11:>12:>Nil) :> Nil)
    -- <1,2,3,4,5,6,7,8,9,10,11,12>
    concat :: Vec n (Vec m a) -> Vec (n * m) a
    concat Nil           = Nil
    concat (x `Cons` xs) = x ++ concat xs
    {-# NOINLINE concat #-}
    
    -- | Split a vector of \(n * m)\ elements into a vector of \"vectors of length
    -- /m/\", where the length /m/ is given.
    --
    -- >>> unconcat d4 (1:>2:>3:>4:>5:>6:>7:>8:>9:>10:>11:>12:>Nil)
    -- <<1,2,3,4>,<5,6,7,8>,<9,10,11,12>>
    unconcat :: KnownNat n => SNat m -> Vec (n * m) a -> Vec n (Vec m a)
    unconcat n xs = unconcatU (withSNat toUNat) (toUNat n) xs
    {-# NOINLINE unconcat #-}
    
    unconcatU :: UNat n -> UNat m -> Vec (n * m) a -> Vec n (Vec m a)
    unconcatU UZero      _ _  = Nil
    unconcatU (USucc n') m ys = let (as,bs) = splitAtU m ys
    

    Found in Clash.Sized.Vector from the package clash-prelude
    --
    -- >>> concat ((1:>2:>3:>Nil) :> (4:>5:>6:>Nil) :> (7:>8:>9:>Nil) :> (10:>11:>12:>Nil) :> Nil)
    -- <1,2,3,4,5,6,7,8,9,10,11,12>
    concat :: Vec n (Vec m a) -> Vec (n * m) a
    concat Nil           = Nil
    concat (x `Cons` xs) = x ++ concat xs
    {-# NOINLINE concat #-}
    
    -- | Split a vector of \(n * m)\ elements into a vector of \"vectors of length
    -- /m/\", where the length /m/ is given.
    --
    -- >>> unconcat d4 (1:>2:>3:>4:>5:>6:>7:>8:>9:>10:>11:>12:>Nil)
    -- <<1,2,3,4>,<5,6,7,8>,<9,10,11,12>>
    unconcat :: KnownNat n => SNat m -> Vec (n * m) a -> Vec n (Vec m a)
    unconcat n xs = unconcatU (withSNat toUNat) (toUNat n) xs
    {-# NOINLINE unconcat #-}
    
    unconcatU :: UNat n -> UNat m -> Vec (n * m) a -> Vec n (Vec m a)
    unconcatU UZero      _ _  = Nil
    unconcatU (USucc n') m ys = let (as,bs) = splitAtU m ys
    

    Found in Clash.Sized.Vector from the package clash-prelude
    -- >>> (1:>2:>3:>Nil) ++ (7:>8:>Nil)
    -- <1,2,3,7,8>
    (++) :: Vec n a -> Vec m a -> Vec (n + m) a
    Nil           ++ ys = ys
    (x `Cons` xs) ++ ys = x `Cons` xs ++ ys
    {-# NOINLINE (++) #-}
    
    -- | Split a vector into two vectors at the given point.
    --
    -- >>> splitAt (SNat :: SNat 3) (1:>2:>3:>7:>8:>Nil)
    -- (<1,2,3>,<7,8>)
    -- >>> splitAt d3 (1:>2:>3:>7:>8:>Nil)
    -- (<1,2,3>,<7,8>)
    splitAt :: SNat m -> Vec (m + n) a -> (Vec m a, Vec n a)
    splitAt n xs = splitAtU (toUNat n) xs
    {-# NOINLINE splitAt #-}
    
    splitAtU :: UNat m -> Vec (m + n) a -> (Vec m a, Vec n a)
    splitAtU UZero     ys            = (Nil,ys)
    splitAtU (USucc s) (y `Cons` ys) = let (as,bs) = splitAtU s ys
    

    Found in Clash.Sized.Vector from the package clash-prelude
    import Language.Haskell.TH        (ExpQ)
    import Language.Haskell.TH.Syntax (Lift(..))
    import Prelude                    hiding ((++), (!!), concat, drop, foldl,
                                              foldl1, foldr, foldr1, head, init,
                                              iterate, last, length, map, repeat,
                                              replicate, reverse, scanl, scanr,
                                              splitAt, tail, take, unzip, unzip3,
                                              zip, zip3, zipWith, zipWith3)
    import qualified Prelude          as P
    import Test.QuickCheck            (Arbitrary (..), CoArbitrary (..))
    import Unsafe.Coerce              (unsafeCoerce)
    
    import Clash.Promoted.Nat
      (SNat (..), UNat (..), leToPlus, pow2SNat, snatProxy, snatToInteger, subSNat,
       withSNat, toUNat)
    import Clash.Promoted.Nat.Literals (d1)
    import Clash.Sized.Internal.BitVector (Bit, BitVector, (++#), split#)
    import Clash.Sized.Index          (Index)
    
    import Clash.Class.BitPack (BitPack (..))
    

    withSNat See 8 Occurences [+] Collapse [-]
    Found in Clash.Sized.Vector from the package clash-prelude
    replicate :: SNat n -> a -> Vec n a
    replicate n a = replicateU (toUNat n) a
    {-# NOINLINE replicate #-}
    
    replicateU :: UNat n -> a -> Vec n a
    replicateU UZero     _ = Nil
    replicateU (USucc s) x = x `Cons` replicateU s x
    
    -- | \"'repeat' @a@\" creates a vector with as many copies of /a/ as demanded
    -- by the context.
    --
    -- >>> repeat 6 :: Vec 5 Int
    -- <6,6,6,6,6>
    repeat :: KnownNat n => a -> Vec n a
    repeat = withSNat replicate
    {-# INLINE repeat #-}
    
    -- | \"'iterate' @n f x@\" returns a vector starting with /x/ followed by
    -- /n/ repeated applications of /f/ to /x/.
    --
    

    Found in Clash.Sized.Vector from the package clash-prelude
        select' (USucc n') vs@(x `Cons` _) = x `Cons`
                                             select' n' (drop s (unsafeCoerce vs))
    {-# NOINLINE select #-}
    
    -- | \"'selectI' @f s xs@\" selects as many elements as demanded by the context
    -- with step-size /s/ and offset /f/ from /xs/.
    --
    -- >>> selectI d1 d2 (1:>2:>3:>4:>5:>6:>7:>8:>Nil) :: Vec 2 Int
    -- <2,4>
    selectI :: (CmpNat (i + s) (s * n) ~ 'GT, KnownNat n)
            => SNat f
            -> SNat s
            -> Vec (f + i) a
            -> Vec n a
    selectI f s xs = withSNat (\n -> select f s n xs)
    {-# INLINE selectI #-}
    
    -- | \"'replicate' @n a@\" returns a vector that has /n/ copies of /a/.
    --
    -- >>> replicate (SNat :: SNat 3) 6
    

    Found in Clash.Sized.Vector from the package clash-prelude
    -- <interactive>:...
    --     • Couldn't match expected type ‘2’ with actual type ‘4 + n0’
    --       The type variable ‘n0’ is ambiguous
    --     • In the first argument of ‘print’, namely ‘it’
    --       In a stmt of an interactive GHCi command: print it
    drop :: SNat m -> Vec (m + n) a -> Vec n a
    drop n = snd . splitAt n
    {-# INLINE drop #-}
    
    -- | \"'dropI' @xs@\" returns the suffix of /xs/ as demanded by the context.
    --
    -- >>> dropI (1:>2:>3:>4:>5:>Nil) :: Vec 2 Int
    -- <4,5>
    dropI :: KnownNat m => Vec (m + n) a -> Vec n a
    dropI = withSNat drop
    {-# INLINE dropI #-}
    
    -- | \"'at' @n xs@\" returns /n/'th element of /xs/
    --
    -- __NB__: vector elements have an __ASCENDING__ subscript starting from 0 and
    

    Found in Clash.Sized.Vector from the package clash-prelude
    --         Actual type: Vec (1 + 1) a
    --       The type variable ‘n0’ is ambiguous
    --     • In the second argument of ‘take’, namely ‘(1 :> 2 :> Nil)’
    --       In the expression: take d4 (1 :> 2 :> Nil)
    --       In an equation for ‘it’: it = take d4 (1 :> 2 :> Nil)
    take :: SNat m -> Vec (m + n) a -> Vec m a
    take n = fst . splitAt n
    {-# INLINE take #-}
    
    -- | \"'takeI' @xs@\" returns the prefix of /xs/ as demanded by the context.
    --
    -- >>> takeI (1:>2:>3:>4:>5:>Nil) :: Vec 2 Int
    -- <1,2>
    takeI :: KnownNat m => Vec (m + n) a -> Vec m a
    takeI = withSNat take
    {-# INLINE takeI #-}
    
    -- | \"'drop' @n xs@\" returns the suffix of /xs/ after the first /n/ elements.
    --
    -- >>> drop (SNat :: SNat 3) (1:>2:>3:>4:>5:>Nil)
    

    Found in Clash.Sized.Vector from the package clash-prelude
    unconcat n xs = unconcatU (withSNat toUNat) (toUNat n) xs
    {-# NOINLINE unconcat #-}
    
    unconcatU :: UNat n -> UNat m -> Vec (n * m) a -> Vec n (Vec m a)
    unconcatU UZero      _ _  = Nil
    unconcatU (USucc n') m ys = let (as,bs) = splitAtU m ys
                                in  as `Cons` unconcatU n' m bs
    
    -- | Split a vector of /(n * m)/ elements into a vector of \"vectors of length
    -- /m/\", where the length /m/ is determined by the context.
    --
    -- >>> unconcatI (1:>2:>3:>4:>5:>6:>7:>8:>9:>10:>11:>12:>Nil) :: Vec 2 (Vec 6 Int)
    -- <<1,2,3,4,5,6>,<7,8,9,10,11,12>>
    unconcatI :: (KnownNat n, KnownNat m) => Vec (n * m) a -> Vec n (Vec m a)
    unconcatI = withSNat unconcat
    {-# INLINE unconcatI #-}
    
    -- | Merge two vectors, alternating their elements, i.e.,
    --
    -- >>> merge (1 :> 2 :> 3 :> 4 :> Nil) (5 :> 6 :> 7 :> 8 :> Nil)
    

    Found in Clash.Sized.Vector from the package clash-prelude
    --
    -- >>> concat ((1:>2:>3:>Nil) :> (4:>5:>6:>Nil) :> (7:>8:>9:>Nil) :> (10:>11:>12:>Nil) :> Nil)
    -- <1,2,3,4,5,6,7,8,9,10,11,12>
    concat :: Vec n (Vec m a) -> Vec (n * m) a
    concat Nil           = Nil
    concat (x `Cons` xs) = x ++ concat xs
    {-# NOINLINE concat #-}
    
    -- | Split a vector of \(n * m)\ elements into a vector of \"vectors of length
    -- /m/\", where the length /m/ is given.
    --
    -- >>> unconcat d4 (1:>2:>3:>4:>5:>6:>7:>8:>9:>10:>11:>12:>Nil)
    -- <<1,2,3,4>,<5,6,7,8>,<9,10,11,12>>
    unconcat :: KnownNat n => SNat m -> Vec (n * m) a -> Vec n (Vec m a)
    unconcat n xs = unconcatU (withSNat toUNat) (toUNat n) xs
    {-# NOINLINE unconcat #-}
    
    unconcatU :: UNat n -> UNat m -> Vec (n * m) a -> Vec n (Vec m a)
    unconcatU UZero      _ _  = Nil
    unconcatU (USucc n') m ys = let (as,bs) = splitAtU m ys
    

    Found in Clash.Sized.Vector from the package clash-prelude
    splitAt n xs = splitAtU (toUNat n) xs
    {-# NOINLINE splitAt #-}
    
    splitAtU :: UNat m -> Vec (m + n) a -> (Vec m a, Vec n a)
    splitAtU UZero     ys            = (Nil,ys)
    splitAtU (USucc s) (y `Cons` ys) = let (as,bs) = splitAtU s ys
                                       in  (y `Cons` as, bs)
    
    -- | Split a vector into two vectors where the length of the two is determined
    -- by the context.
    --
    -- >>> splitAtI (1:>2:>3:>7:>8:>Nil) :: (Vec 2 Int, Vec 3 Int)
    -- (<1,2>,<3,7,8>)
    splitAtI :: KnownNat m => Vec (m + n) a -> (Vec m a, Vec n a)
    splitAtI = withSNat splitAt
    {-# INLINE splitAtI #-}
    
    -- | Concatenate a vector of vectors.
    --
    -- >>> concat ((1:>2:>3:>Nil) :> (4:>5:>6:>Nil) :> (7:>8:>9:>Nil) :> (10:>11:>12:>Nil) :> Nil)
    

    Found in Clash.Sized.Vector from the package clash-prelude
    import Language.Haskell.TH        (ExpQ)
    import Language.Haskell.TH.Syntax (Lift(..))
    import Prelude                    hiding ((++), (!!), concat, drop, foldl,
                                              foldl1, foldr, foldr1, head, init,
                                              iterate, last, length, map, repeat,
                                              replicate, reverse, scanl, scanr,
                                              splitAt, tail, take, unzip, unzip3,
                                              zip, zip3, zipWith, zipWith3)
    import qualified Prelude          as P
    import Test.QuickCheck            (Arbitrary (..), CoArbitrary (..))
    import Unsafe.Coerce              (unsafeCoerce)
    
    import Clash.Promoted.Nat
      (SNat (..), UNat (..), leToPlus, pow2SNat, snatProxy, snatToInteger, subSNat,
       withSNat, toUNat)
    import Clash.Promoted.Nat.Literals (d1)
    import Clash.Sized.Internal.BitVector (Bit, BitVector, (++#), split#)
    import Clash.Sized.Index          (Index)
    
    import Clash.Class.BitPack (BitPack (..))
    

    BNat No usage example found for this symbol :( Collapse [-]
    SNat No usage example found for this symbol :( Collapse [-]
    UNat No usage example found for this symbol :( Collapse [-]