Reputation: 27636
I have the following CLaSH function:
toBCD :: Word8 -> Vec 3 Word8
toBCD x =
x `div` 100 :>
(x `div` 10) `mod` 10 :>
x `mod` 10 :>
Nil
Of course, the resulting HDL module is unsynthesizable because of the division by a non-power of 2 constant. So I would like to turn it into a lookup table instead, and put it into a small asynchronous ROM.
At first, I thought it would be enough to do something like
romBCD :: Word8 -> Vec 3 Word8
romBCD = asyncROM $ fmap toBCD $ iterate d256 succ 0
but the resulting VHDL still contains the formula to calculate toBCD 0
, toBCD 1
, etc. What I would like instead, is to get VHDL which simply contains the precomputed values in a 256x24 table.
One workaround I found was to calculate romBCD
's contents via Template Haskell:
romBCD = asyncRom $(listToVecTH $ fmap toBCD [minBound .. maxBound])
but that then forces the definition of romBCD
to be in a separate module than toBCD
.
Upvotes: 3
Views: 346