york-lava-0.2: A library for digital circuit description.

Lava.Prelude

Contents

Description

The beginnings of a Prelude of commonly-used circuits. By no means exhaustive, but a useful start.

Synopsis

Bit-vectors

type Word n = Vec n BitSource

Notably, an instance of the Num class.

Generalised primitives

andG :: Generic a => a -> BitSource

Logical AND of all bits in a structure.

orG :: Generic a => a -> BitSource

Logical OR of all bits in a structure.

delay :: Generic a => a -> a -> aSource

Generic register, with initialiser.

delayEn :: Generic a => a -> Bit -> a -> aSource

Generic register, with initialiser, with input-enable.

(?) :: Generic a => Bit -> (a, a) -> aSource

Generic two-way multiplexer.

nameList :: Int -> String -> [Bit]Source

Returns a list of N named bits with a given prefix.

nameWord :: N n => String -> Word nSource

Returns a vector of N named bits with a given prefix.

Multiplexing

select :: [Bit] -> [[Bit]] -> [Bit]Source

N-way multiplexer, with one-hot address.

selectG :: Generic a => [Bit] -> [a] -> aSource

Generic select.

pick :: [(Bit, [Bit])] -> [Bit]Source

Like select, but with zipped arguments.

pickG :: Generic a => [(Bit, a)] -> aSource

Generic pick.

Encoding and decoding

decode :: [Bit] -> [Bit]Source

Binary to one-hot decoder.

decodeTwos :: [Bit] -> [Bit]Source

Two's complement version of decode.

encode :: [Bit] -> [Bit]Source

One-hot to binary encoder.

tally :: [Bit] -> [Bit]Source

Binary to tally converter.

oneHot :: N n => Int -> Word nSource

Convert a Haskell Int to a one-hot bit-vector.

tal :: [Bit] -> [Bit]Source

One-hot to tally converter.

tal' :: [Bit] -> [Bit]Source

Like tal; specifically tal' n = tal (n+1).

Rotation

rotr :: [Bit] -> [Bit] -> [Bit]Source

Rotate b by a places to the right; a is a one-hot number.

rotateRight :: [Bit] -> [[Bit]] -> [[Bit]]Source

Like rotr, but lifted to a list of bit-lists.

rotl :: [Bit] -> [Bit] -> [Bit]Source

Like rotr, except rotation is to the left.

rotateLeft :: [Bit] -> [[Bit]] -> [[Bit]]Source

Like rotateRight except rotation is to the left.

dot :: [Bit] -> [Bit] -> BitSource

Dot product over bit-lists.

RAMs

data RamInputs n m Source

Constructors

RamInputs 

Fields

ramData :: Word n
 
ramAddress :: Word m
 
ramWrite :: Bit
 

ram :: (N n, N m) => [Integer] -> RamAlgorithm -> RamInputs n m -> Word nSource

RAM of any width and size, with intialiser.

dualRam :: (N n, N m) => [Integer] -> RamAlgorithm -> (RamInputs n m, RamInputs n m) -> (Word n, Word n)Source

Dual-port RAM of any width and size, with intialiser.

Arithmetic

type Unsigned n = Word nSource

Unsigned bit-vectors.

newtype Signed n Source

Signed bit-vectors.

Constructors

Signed (Vec n Bit) 

Instances

Eq (Signed n) 
N n => Num (Signed n) 
Show (Signed n) 
Generic (Signed n) 
Ordered (Signed n) 

natSub :: N n => Word n -> Word n -> Word nSource

Subtracts b from a, but if b is larger than a then result is 0.

complement :: [Bit] -> [Bit]Source

Two's complement of a bit-list.

bitPlus :: Bit -> [Bit] -> [Bit]Source

Addition of a single bit to a bit-list.

wordToInt :: Integral a => Word n -> aSource

Convert bit-vector to an integer.

extend :: N n => Vec (S m) c -> Vec n cSource

Sign-extend a bit-vector.

Comparators

(===) :: Generic a => a -> a -> BitSource

Generic equality.

(=/=) :: Generic a => a -> a -> BitSource

Generic diseqaulity.

class Ordered a whereSource

Methods

(|<=|) :: a -> a -> BitSource

(|<|) :: a -> a -> BitSource

(|>=|) :: a -> a -> BitSource

(|>|) :: a -> a -> BitSource

Instances

Polymorphic functions over lists

tree1 :: (a -> a -> a) -> [a] -> aSource

Parallel reduce for a commutative an associative operator. Input list must be non-empty.

tree :: (a -> a -> a) -> a -> [a] -> aSource

Like tree1, but input list may be empty, in which case the zero element is returned.

groupN :: Int -> [a] -> [[a]]Source

Split a list into sub-lists of maximum length N.

halve :: [a] -> ([a], [a])Source

Split a list in two.