clash-prelude-0.99.2: CAES Language for Synchronous Hardware - Prelude library

Copyright(C) 2013-2016 University of Twente
2016-2017 Myrtle Software Ltd
LicenseBSD2 (see the file LICENSE)
MaintainerChristiaan Baaij <christiaan.baaij@gmail.com>
Safe HaskellTrustworthy
LanguageHaskell2010
Extensions
  • Cpp
  • UndecidableInstances
  • MonoLocalBinds
  • ScopedTypeVariables
  • TypeFamilies
  • ViewPatterns
  • DataKinds
  • DefaultSignatures
  • FlexibleContexts
  • MagicHash
  • KindSignatures
  • TypeOperators
  • ExplicitNamespaces
  • ExplicitForAll

Clash.Class.BitPack

Description

 
Synopsis

Documentation

class BitPack a where #

Convert to and from a BitVector

Associated Types

type BitSize a :: Nat #

Number of Bits needed to represents elements of type a

Can be derived using Generics:

{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}

import Clash.Prelude
import GHC.Generics

data MyProductType = MyProductType { a :: Int, b :: Bool }
  deriving (Generic, BitPack)

Methods

pack :: a -> BitVector (BitSize a) #

Convert element of type a to a BitVector

>>> pack (-5 :: Signed 6)
11_1011

pack :: (Generic a, GBitPack (Rep a), GBitSize (Rep a) ~ BitSize a) => a -> BitVector (BitSize a) #

Convert element of type a to a BitVector

>>> pack (-5 :: Signed 6)
11_1011

unpack :: BitVector (BitSize a) -> a #

Convert a BitVector to an element of type a

>>> pack (-5 :: Signed 6)
11_1011
>>> let x = pack (-5 :: Signed 6)
>>> unpack x :: Unsigned 6
59
>>> pack (59 :: Unsigned 6)
11_1011

unpack :: (Generic a, GBitPack (Rep a), GBitSize (Rep a) ~ BitSize a) => BitVector (BitSize a) -> a #

Convert a BitVector to an element of type a

>>> pack (-5 :: Signed 6)
11_1011
>>> let x = pack (-5 :: Signed 6)
>>> unpack x :: Unsigned 6
59
>>> pack (59 :: Unsigned 6)
11_1011
Instances
BitPack Bool # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Bool :: Nat #

BitPack Double # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Double :: Nat #

BitPack Float # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Float :: Nat #

BitPack Int # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Int :: Nat #

BitPack Int8 # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Int8 :: Nat #

BitPack Int16 # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Int16 :: Nat #

BitPack Int32 # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Int32 :: Nat #

BitPack Int64 # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Int64 :: Nat #

BitPack Word # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Word :: Nat #

BitPack Word8 # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Word8 :: Nat #

BitPack Word16 # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Word16 :: Nat #

BitPack Word32 # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Word32 :: Nat #

BitPack Word64 # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Word64 :: Nat #

BitPack () # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize () :: Nat #

Methods

pack :: () -> BitVector (BitSize ()) #

unpack :: BitVector (BitSize ()) -> () #

BitPack CUShort # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize CUShort :: Nat #

BitPack Half # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Half :: Nat #

BitPack Bit # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize Bit :: Nat #

(BitPack a, KnownNat (BitSize a)) => BitPack (Maybe a) # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize (Maybe a) :: Nat #

Methods

pack :: Maybe a -> BitVector (BitSize (Maybe a)) #

unpack :: BitVector (BitSize (Maybe a)) -> Maybe a #

BitPack (BitVector n) # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize (BitVector n) :: Nat #

KnownNat n => BitPack (Index n) # 
Instance details

Defined in Clash.Sized.Internal.Index

Associated Types

type BitSize (Index n) :: Nat #

Methods

pack :: Index n -> BitVector (BitSize (Index n)) #

unpack :: BitVector (BitSize (Index n)) -> Index n #

BitPack (Unsigned n) # 
Instance details

Defined in Clash.Sized.Internal.Unsigned

Associated Types

type BitSize (Unsigned n) :: Nat #

KnownNat n => BitPack (Signed n) # 
Instance details

Defined in Clash.Sized.Internal.Signed

Associated Types

type BitSize (Signed n) :: Nat #

(KnownNat (BitSize b), BitPack a, BitPack b) => BitPack (a, b) # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize (a, b) :: Nat #

Methods

pack :: (a, b) -> BitVector (BitSize (a, b)) #

unpack :: BitVector (BitSize (a, b)) -> (a, b) #

(KnownNat n, KnownNat (BitSize a), BitPack a) => BitPack (Vec n a) # 
Instance details

Defined in Clash.Sized.Vector

Associated Types

type BitSize (Vec n a) :: Nat #

Methods

pack :: Vec n a -> BitVector (BitSize (Vec n a)) #

unpack :: BitVector (BitSize (Vec n a)) -> Vec n a #

(KnownNat d, KnownNat (BitSize a), BitPack a) => BitPack (RTree d a) # 
Instance details

Defined in Clash.Sized.RTree

Associated Types

type BitSize (RTree d a) :: Nat #

Methods

pack :: RTree d a -> BitVector (BitSize (RTree d a)) #

unpack :: BitVector (BitSize (RTree d a)) -> RTree d a #

(KnownNat (BitSize c), BitPack (a, b), BitPack c) => BitPack (a, b, c) # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize (a, b, c) :: Nat #

Methods

pack :: (a, b, c) -> BitVector (BitSize (a, b, c)) #

unpack :: BitVector (BitSize (a, b, c)) -> (a, b, c) #

BitPack (rep (int + frac)) => BitPack (Fixed rep int frac) # 
Instance details

Defined in Clash.Sized.Fixed

Associated Types

type BitSize (Fixed rep int frac) :: Nat #

Methods

pack :: Fixed rep int frac -> BitVector (BitSize (Fixed rep int frac)) #

unpack :: BitVector (BitSize (Fixed rep int frac)) -> Fixed rep int frac #

(KnownNat (BitSize d), BitPack (a, b, c), BitPack d) => BitPack (a, b, c, d) # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize (a, b, c, d) :: Nat #

Methods

pack :: (a, b, c, d) -> BitVector (BitSize (a, b, c, d)) #

unpack :: BitVector (BitSize (a, b, c, d)) -> (a, b, c, d) #

(KnownNat (BitSize e), BitPack (a, b, c, d), BitPack e) => BitPack (a, b, c, d, e) # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize (a, b, c, d, e) :: Nat #

Methods

pack :: (a, b, c, d, e) -> BitVector (BitSize (a, b, c, d, e)) #

unpack :: BitVector (BitSize (a, b, c, d, e)) -> (a, b, c, d, e) #

(KnownNat (BitSize f), BitPack (a, b, c, d, e), BitPack f) => BitPack (a, b, c, d, e, f) # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize (a, b, c, d, e, f) :: Nat #

Methods

pack :: (a, b, c, d, e, f) -> BitVector (BitSize (a, b, c, d, e, f)) #

unpack :: BitVector (BitSize (a, b, c, d, e, f)) -> (a, b, c, d, e, f) #

(KnownNat (BitSize g), BitPack (a, b, c, d, e, f), BitPack g) => BitPack (a, b, c, d, e, f, g) # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize (a, b, c, d, e, f, g) :: Nat #

Methods

pack :: (a, b, c, d, e, f, g) -> BitVector (BitSize (a, b, c, d, e, f, g)) #

unpack :: BitVector (BitSize (a, b, c, d, e, f, g)) -> (a, b, c, d, e, f, g) #

(KnownNat (BitSize h), BitPack (a, b, c, d, e, f, g), BitPack h) => BitPack (a, b, c, d, e, f, g, h) # 
Instance details

Defined in Clash.Class.BitPack

Associated Types

type BitSize (a, b, c, d, e, f, g, h) :: Nat #

Methods

pack :: (a, b, c, d, e, f, g, h) -> BitVector (BitSize (a, b, c, d, e, f, g, h)) #

unpack :: BitVector (BitSize (a, b, c, d, e, f, g, h)) -> (a, b, c, d, e, f, g, h) #

bitCoerce :: (BitPack a, BitPack b, BitSize a ~ BitSize b) => a -> b #

Coerce a value from one type to another through its bit representation.

>>> pack (-5 :: Signed 6)
11_1011
>>> bitCoerce (-5 :: Signed 6) :: Unsigned 6
59
>>> pack (59 :: Unsigned 6)
11_1011

boolToBV :: KnownNat n => Bool -> BitVector (n + 1) #

Zero-extend a Boolean value to a BitVector of the appropriate size.

>>> boolToBV True :: BitVector 6
00_0001
>>> boolToBV False :: BitVector 6
00_0000

boolToBit :: Bool -> Bit #

Convert a Bool to a Bit

bitToBool :: Bit -> Bool #

Convert a Bool to a Bit