-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathQueens.hs
38 lines (27 loc) · 922 Bytes
/
Queens.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Queens where
import Clash.Prelude
import Data.Maybe
mem <~ (i,x) = replace i x mem
type Word3 = Unsigned 3
type MbWord3 = Maybe Word3
type Din = Vec 8 (MbWord3)
type Dout = Vec 8 Word3
din :: Din
din = $(listToVecTH [ Nothing :: Maybe (Unsigned 3), Just 1, Nothing, Nothing, Just 4, Nothing, Just 6, Just 7 ])
dout0 :: Dout
dout0 = 0 :> 0 :> 0 :> 0 :> 0 :> 0 :> 0 :> 0 :> Nil :: Dout
ind0 :: Word3
ind0 = 0
mbfilter (dout,ind) din = ((dout',ind'), low)
where
f (dout,ind) v = case v of
Just x -> (dout<~(ind,x), ind+1)
Nothing -> (dout, ind)
(dout',ind') = foldl f (dout0,ind0) din
topEntity
:: Clock System
-> Reset System
-> Enable System
-> Signal System Din
-> Signal System Bit
topEntity = exposeClockResetEnable (mbfilter `mealy` (dout0, ind0))