Skip to content

Instantly share code, notes, and snippets.

View christiaanb's full-sized avatar

Christiaan Baaij christiaanb

  • QBayLogic
  • Enschede, The Netherlands
View GitHub Profile
{-# LANGUAGE Arrows, GADTs, TypeFamilies, NoImplicitPrelude, RankNTypes #-}
module ArrTest where
import Unsafe.Coerce
import CLaSH.Prelude hiding (id,(.))
import Control.Arrow
import Control.Category
import Data.Proxy
type family En a
import Data.List
indices [] ix2 = ix2
indices ix1 [] = ix1
indices ((l1,r1):ix1) ((l2,r2):ix2)
| r1 < r2 = (l1,r1) : indices ix1 ((r1+1,r2):ix2)
| r1 == r2 = (l1,r1) : indices ix1 ix2
| r1 > r2 = (l2,r2) : indices ((r2+1,r1):ix1) ix2
module Test.Delayed
where
import CLaSH.Prelude
import CLaSH.Prelude.Explicit
import Data.Functor
import Clocks
import Delayed
module CPUD where
import CLaSH.Prelude
import qualified Data.List as L
type InstrAddr = Unsigned 8
type MemAddr = Unsigned 5
type Value = Signed 8
, { "BlackBox" :
{ "name" : "CLaSH.Sized.Vector.fold"
, "type" : "fold :: (a -> a -> a) -> Vec (n+1) a -> a"
, "comment" : "THIS ONLY WORKS FOR POWER OF TWO LENGTH VECTORS"
, "templateD" :
"-- fold begin
fold_~SYM[0] : block
function pow2Index (d,n : in natural) return natural is
begin
return (2 ** d - 2 ** n);
{-# LANGUAGE ScopedTypeVariables #-}
module BitPalindrome where
import CLaSH.Prelude
-- Not used anywhere, but using (!) is more idiomatic than "slice x x"
sl8 :: BitVector 8 -> (Bit, Bit, Bit, Bit, Bit, Bit, Bit, Bit)
sl8 a = (a ! 0, a ! 1, a ! 2, a ! 3, a ! 4, a ! 5, a ! 6, a ! 7)
{-# LANGUAGE ScopedTypeVariables #-}
module PopulationCount where
import CLaSH.Prelude
popCnt :: forall n . (KnownNat (n+1), KnownNat (n + 2))
=> BitVector (n+1)
-> Index (n+2)
popCnt bv = sum (map fromIntegral v)
where
module BitPalindrome2 where
-- import Control.Arrow (second)
import CLaSH.Prelude
-- This function will be in `clash-prelude-0.10.1`
bv2v :: KnownNat n => BitVector n -> Vec n Bit
bv2v = unpack
evenPalindrome :: (Eq a,KnownNat m)
module BitPalindrome3 where
import CLaSH.Prelude
-- evenPalindrome :: (Eq a, KnownNat m) => Vec (m + m) a -> Bool
evenPalindrome v = l == reverse r
where
(l,r) = splitAtI v
-- unevenPalindrome :: (Eq a, KnownNat m) => Vec (m + (m + 1)) a -> Bool
{-# LANGUAGE GADTs, KindSignatures, ScopedTypeVariables, Rank2Types,
UndecidableInstances, MultiParamTypeClasses #-}
module PopCount2 where
import CLaSH.Prelude
import CLaSH.Sized.Internal.Index
import Data.Proxy (Proxy (..))
import Data.Singletons.Prelude
import qualified Data.List as L