clash-prelude-1.8.4: Clash: a functional hardware description language - Prelude library

Safe Haskell | None
Language | Haskell2010

Clash.Class.Counter.Internal

Synopsis

- class Counter a where
  - countMin :: a
  - countMax :: a
  - countSuccOverflow :: a -> (Bool, a)
  - countPredOverflow :: a -> (Bool, a)

# Documentation

    >>> import Clash.Class.Counter
    >>> import Clash.Sized.BitVector (BitVector)
    >>> import Clash.Sized.Index (Index)
    >>> import Clash.Sized.Signed (Signed)
    >>> import Clash.Sized.Unsigned (Unsigned)

class Counter a where Source #

`Counter` is a class that composes multiple counters into a single one. It is similar to odometers found in olds cars, once all counters reach their maximum they reset to zero - i.e. odometer rollover. See `countSucc` and `countPred` for API usage examples.

Example use case: when driving a monitor through VGA you would like to keep track at least two counters: one counting a horizontal position, and one vertical. Perhaps a fancy VGA driver would also like to keep track of the number of drawn frames. To do so, the three counters are setup with different types. On each round of the horizontal counter the vertical counter should be increased. On each round of the vertical counter the frame counter should be increased. With this class you could simply use the type:

    (FrameCount, VerticalCount, HorizontalCount)

and have `countSucc` work as described.

Minimal complete definition

Nothing

Methods

countMin :: a Source #

Value counter wraps around to on a `countSuccOverflow` overflow

default countMin :: Bounded a => a Source #

countMax :: a Source #

Value counter wraps around to on a `countPredOverflow` overflow

default countMax :: Bounded a => a Source #

countSuccOverflow :: a -> (Bool, a) Source #

Gets the successor of `a`. If it overflows, the first part of the tuple will be set to True and the second part wraps around to `countMin`.

default countSuccOverflow :: (Eq a, Enum a, Bounded a) => a -> (Bool, a) Source #

countPredOverflow :: a -> (Bool, a) Source #

Gets the predecessor of `a`. If it underflows, the first part of the tuple will be set to True and the second part wraps around to `countMax`.

default countPredOverflow :: (Eq a, Enum a, Bounded a) => a -> (Bool, a) Source #

#### Instances

Instances details

Counter Bit Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Bit Source # countMax :: Bit Source # countSuccOverflow :: Bit -> (Bool, Bit) Source # countPredOverflow :: Bit -> (Bool, Bit) Source #
Counter Int16 Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Int16 Source # countMax :: Int16 Source # countSuccOverflow :: Int16 -> (Bool, Int16) Source # countPredOverflow :: Int16 -> (Bool, Int16) Source #
Counter Int32 Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Int32 Source # countMax :: Int32 Source # countSuccOverflow :: Int32 -> (Bool, Int32) Source # countPredOverflow :: Int32 -> (Bool, Int32) Source #
Counter Int64 Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Int64 Source # countMax :: Int64 Source # countSuccOverflow :: Int64 -> (Bool, Int64) Source # countPredOverflow :: Int64 -> (Bool, Int64) Source #
Counter Int8 Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Int8 Source # countMax :: Int8 Source # countSuccOverflow :: Int8 -> (Bool, Int8) Source # countPredOverflow :: Int8 -> (Bool, Int8) Source #
Counter Word16 Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Word16 Source # countMax :: Word16 Source # countSuccOverflow :: Word16 -> (Bool, Word16) Source # countPredOverflow :: Word16 -> (Bool, Word16) Source #
Counter Word32 Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Word32 Source # countMax :: Word32 Source # countSuccOverflow :: Word32 -> (Bool, Word32) Source # countPredOverflow :: Word32 -> (Bool, Word32) Source #
Counter Word64 Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Word64 Source # countMax :: Word64 Source # countSuccOverflow :: Word64 -> (Bool, Word64) Source # countPredOverflow :: Word64 -> (Bool, Word64) Source #
Counter Word8 Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Word8 Source # countMax :: Word8 Source # countSuccOverflow :: Word8 -> (Bool, Word8) Source # countPredOverflow :: Word8 -> (Bool, Word8) Source #
Counter Bool Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Bool Source # countMax :: Bool Source # countSuccOverflow :: Bool -> (Bool, Bool) Source # countPredOverflow :: Bool -> (Bool, Bool) Source #
Counter Int Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Int Source # countMax :: Int Source # countSuccOverflow :: Int -> (Bool, Int) Source # countPredOverflow :: Int -> (Bool, Int) Source #
Counter Word Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Word Source # countMax :: Word Source # countSuccOverflow :: Word -> (Bool, Word) Source # countPredOverflow :: Word -> (Bool, Word) Source #
KnownNat n => Counter (BitVector n) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: BitVector n Source # countMax :: BitVector n Source # countSuccOverflow :: BitVector n -> (Bool, BitVector n) Source # countPredOverflow :: BitVector n -> (Bool, BitVector n) Source #
(1 <= n, KnownNat n) => Counter (Index n) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Index n Source # countMax :: Index n Source # countSuccOverflow :: Index n -> (Bool, Index n) Source # countPredOverflow :: Index n -> (Bool, Index n) Source #
KnownNat n => Counter (Signed n) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Signed n Source # countMax :: Signed n Source # countSuccOverflow :: Signed n -> (Bool, Signed n) Source # countPredOverflow :: Signed n -> (Bool, Signed n) Source #
KnownNat n => Counter (Unsigned n) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Unsigned n Source # countMax :: Unsigned n Source # countSuccOverflow :: Unsigned n -> (Bool, Unsigned n) Source # countPredOverflow :: Unsigned n -> (Bool, Unsigned n) Source #
Counter a => Counter (Identity a) Source # | Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Identity a Source # countMax :: Identity a Source # countSuccOverflow :: Identity a -> (Bool, Identity a) Source # countPredOverflow :: Identity a -> (Bool, Identity a) Source #
Counter a => Counter (Maybe a) Source # | `Nothing` is considered the minimum value, while ``Just` `countMax`` is considered the maximum value. Since: 1.8.2
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Maybe a Source # countMax :: Maybe a Source # countSuccOverflow :: Maybe a -> (Bool, Maybe a) Source # countPredOverflow :: Maybe a -> (Bool, Maybe a) Source #

(Counter a, Counter b) => Counter (Either a b) Source #

Counter instance that flip-flops between `Left` and `Right`. Examples:

    >>> type T = Either (Index 2) (Unsigned 2)
    >>> countSucc @T (Left 0)
    Left 1
    >>> countSucc @T (Left 1)
    Right 0
    >>> countSucc @T (Right 0)
    Right 1

Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Either a b Source # countMax :: Either a b Source # countSuccOverflow :: Either a b -> (Bool, Either a b) Source # countPredOverflow :: Either a b -> (Bool, Either a b) Source #

(Counter a0, Counter a1) => Counter (a0, a1) Source #

Counters on tuples increment from right-to-left. This makes sense from the perspective of LSB/MSB; MSB is on the left-hand-side and LSB is on the right-hand-side in other Clash types.

    >>> type T = (Unsigned 2, Index 2, Index 2)
    >>> countSucc @T (0, 0, 0)
    (0,0,1)
    >>> countSucc @T (0, 0, 1)
    (0,1,0)
    >>> countSucc @T (0, 1, 0)
    (0,1,1)
    >>> countSucc @T (0, 1, 1)
    (1,0,0)

NB: The documentation only shows the instances up to 3-tuples. By default, instances up to and including 12-tuples will exist. If the flag `large-tuples` is set instances up to the GHC imposed limit will exist. The GHC imposed limit is either 62 or 64 depending on the GHC version.

Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: (a0, a1) Source # countMax :: (a0, a1) Source # countSuccOverflow :: (a0, a1) -> (Bool, (a0, a1)) Source # countPredOverflow :: (a0, a1) -> (Bool, (a0, a1)) Source #
(Counter a0, Counter a1, Counter a2) => Counter (a0, a1, a2) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: (a0, a1, a2) Source # countMax :: (a0, a1, a2) Source # countSuccOverflow :: (a0, a1, a2) -> (Bool, (a0, a1, a2)) Source # countPredOverflow :: (a0, a1, a2) -> (Bool, (a0, a1, a2)) Source #
(Counter a0, Counter a1, Counter a2, Counter a3) => Counter (a0, a1, a2, a3) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: (a0, a1, a2, a3) Source # countMax :: (a0, a1, a2, a3) Source # countSuccOverflow :: (a0, a1, a2, a3) -> (Bool, (a0, a1, a2, a3)) Source # countPredOverflow :: (a0, a1, a2, a3) -> (Bool, (a0, a1, a2, a3)) Source #
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4) => Counter (a0, a1, a2, a3, a4) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: (a0, a1, a2, a3, a4) Source # countMax :: (a0, a1, a2, a3, a4) Source # countSuccOverflow :: (a0, a1, a2, a3, a4) -> (Bool, (a0, a1, a2, a3, a4)) Source # countPredOverflow :: (a0, a1, a2, a3, a4) -> (Bool, (a0, a1, a2, a3, a4)) Source #
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5) => Counter (a0, a1, a2, a3, a4, a5) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: (a0, a1, a2, a3, a4, a5) Source # countMax :: (a0, a1, a2, a3, a4, a5) Source # countSuccOverflow :: (a0, a1, a2, a3, a4, a5) -> (Bool, (a0, a1, a2, a3, a4, a5)) Source # countPredOverflow :: (a0, a1, a2, a3, a4, a5) -> (Bool, (a0, a1, a2, a3, a4, a5)) Source #
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6) => Counter (a0, a1, a2, a3, a4, a5, a6) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: (a0, a1, a2, a3, a4, a5, a6) Source # countMax :: (a0, a1, a2, a3, a4, a5, a6) Source # countSuccOverflow :: (a0, a1, a2, a3, a4, a5, a6) -> (Bool, (a0, a1, a2, a3, a4, a5, a6)) Source # countPredOverflow :: (a0, a1, a2, a3, a4, a5, a6) -> (Bool, (a0, a1, a2, a3, a4, a5, a6)) Source #
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6, Counter a7) => Counter (a0, a1, a2, a3, a4, a5, a6, a7) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: (a0, a1, a2, a3, a4, a5, a6, a7) Source # countMax :: (a0, a1, a2, a3, a4, a5, a6, a7) Source # countSuccOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7)) Source # countPredOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7)) Source #
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6, Counter a7, Counter a8) => Counter (a0, a1, a2, a3, a4, a5, a6, a7, a8) Source # |

Instance details

Defined in Clash.Class.Counter.Internal

Methods

countMin :: (a0, a1, a2, a3, a4, a5, a6, a7, a8) Source #

countMax :: (a0, a1, a2, a3, a4, a5, a6, a7, a8) Source #

countSuccOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8)) Source #

countPredOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8)) Source #

(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6, Counter a7, Counter a8, Counter a9) => Counter (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) Source # |

Instance details

Defined in Clash.Class.Counter.Internal

Methods

countMin :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) Source #

countMax :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) Source #

countSuccOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)) Source #

countPredOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)) Source #

(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6, Counter a7, Counter a8, Counter a9, Counter a10) => Counter (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) Source # |

Instance details

Defined in Clash.Class.Counter.Internal

Methods

countMin :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) Source #

countMax :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) Source #

countSuccOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)) Source #

countPredOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)) Source #

(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6, Counter a7, Counter a8, Counter a9, Counter a10, Counter a11) => Counter (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) Source # |

Instance details

Defined in Clash.Class.Counter.Internal

Methods

countMin :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) Source #

countMax :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) Source #

countSuccOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)) Source #

countPredOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)) Source #