Description
Slow in simulation implementation:
-- | Reverse bitvector
reverseBV :: KnownNat n => BitVector n -> BitVector n
reverseBV = v2bv . reverse . bv2v
Originally mentioned by @christiaanb in #2694 (comment)
- add this function to
clash-prelude
and- make something with better time complexity such as https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
Originally posted by @DigitalBrains1 in #2694 (comment)
Hah I had noted this too, but didn't comment on it. I think I didn't even write it down for myself, which was dumb. Anyway...... the current implementation is fine in hardware, and a quick implementation would probably need a primitive. Unless you use
clashSimulation
fromClash.Magic
to use the quick implementation in simulation but usev2bv . reverse . bv2v
when generating HDL. That will write your primitive for you (but like a usual primitive, it's still up to you to make sure simulation and HDL match in behaviour).
[edit]
The quick implementation should probably deconstruct the bitvector and construct it again at the end because logical operations on bitvector are needlessly expensive for this application, in this PR I achieved a roughly threefold speedup of logical operations that way.
[/edit]
[edit 2]
I read this wrong: I read this as that Rowan was going to do the implementation. Once the issue is raised, I'll copy-paste the essence of the above to that issue.
[/edit 2]