Skip to content

Instantly share code, notes, and snippets.

@christiaanb
Last active October 15, 2015 15:00
Show Gist options
  • Save christiaanb/d114231c02f8ed90b428 to your computer and use it in GitHub Desktop.
Save christiaanb/d114231c02f8ed90b428 to your computer and use it in GitHub Desktop.
{-# 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
v :: Vec (n+1) Bit
v = unpack bv
topEntity :: BitVector 16 -> Index 17
topEntity = popCnt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment