Skip to content

Instantly share code, notes, and snippets.

@thoughtpolice
Created December 8, 2017 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoughtpolice/7384c09ddc7efbfe075069d3036e8328 to your computer and use it in GitHub Desktop.
Save thoughtpolice/7384c09ddc7efbfe075069d3036e8328 to your computer and use it in GitHub Desktop.
clash example
module Test where
import Clash.Prelude
-- this just puts zeros in front of the bit vector
f :: KnownNat a => BitVector a -> BitVector (a + 1)
f bv = zeroExtend bv
-- this gets the length of a bit vector, as an SNat
g :: KnownNat a => BitVector a -> SNat a
g _ = SNat
-- this gets the length of *any* 'thing with known size that can become
-- a bitvector'
h :: (BitPack a, BitSize a ~ n, KnownNat n) => a -> SNat n
h _ = SNat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment