Hello Farhad,
> Thanks for your answer and explanation. In this LUT module, I just
> want to store tangent values, so as you said it contains a list of
> constant values of tangent theta and I want to use these values in
> another module called "update" which I attached it as well.
> getTan :: Unsigned 10 -> Signed 16
> getTan n = reverse $(listToVecTH(lut 10)) ! n
Ah! This should already work just fine, both in simulation and in
hardware. The $(...) construct is Template Haskell, which can do
term-level computation and then use the result as part of the syntax
tree of the program to be compiled. So here, you compute, at
compile-time, the constant vector with the constants generated by `lut`.
This compilation stage is just standard Haskell where you're free to use
lists.
The only thing preventing the code to compile right now is that you
defined `lut` as [Int] whereas here it should be [Signed 16]. Also, (!)
is the wrong indexing function, you want (!!). I would also put the
reverse inside the Template Haskell; it's not necessary, but why compute
a vector at compile time and then reverse it at runtime?
So
getTan :: Unsigned 10 -> Signed 16
getTan n = $(listToVecTH . reverse $ lut 10) !! n
Also, I see you wrote
tanv = getTan (unpack (reverse ds))
but `unpack` expects a BitVector, not a Vec n Bit. They're
different :-). You mean
tanv = getTan (bitCoerce (reverse ds))
(bitCoerce is just (unpack . pack) )
I also wonder if you actually need to specify ds as a `Vec 10 Bit` or it
would be better to immediately declare it `Unsigned 10`. In the
generated HDL, they might very well be the exact same thing. You should
verify the bit endianness though; you might end up using the
`Vec 10 Bit` anyway to reverse endianness if that is necessary.
I hope this gives you enough to work with, feel free to ask more
questions.
Oh, one final thing. You might hit compilation speed issues with long
vectors. I actually just needed to use a lookup ROM construction myself
because Clash would stumble on the length of my vector. Your `getTan`
lends itself perfectly to that construction, and while the solution is a
bit hacky, it has no trouble with long vectors. So if you need that, I
can show you how to work around it.
HTH,
Peter.