by wyager · 10y ago · 0 comments
The best thing I've found so far is Clash. It translates Haskell code to (System)Verilog or VHDL. It works remarkably well, and is way easier to write and test than writing VHDL or Verilog directly. You can compile it to a plain old program for testing and debugging, which means you can use things like QuickCheck for aggressive testing. If you're really serious, you can use something like LiquidHaskell for really aggressive formal verification. There's also Lambda-CCC, which looks a bit more theoretically rigorous, but I couldn't get that working when I tried it.
The key here is that non-strict lambda calculus maps remarkably well to hardware, which means that it's actually relatively straightforward to translate a program to an exactly equivalent hardware representation. The only exception is unbounded recursion (at the function or data level), because obviously you can't represent infinite stuff in hardware.
I've written a few FPGA projects using Clash that I never would have had the patience to finish if I had used a traditional HDL. There's usually a bit of a performance hit over hand-optimized HDL, but (as with using e.g. Python over assembly) there are many cases where developer time is more expensive than a small efficiency loss.
When performance matters - and it does or you wouldn't bother to design hardware - everything gets heavily pipelined with very short logic between pipes stages. Will Clash be any more readable than Verilog then?
A few advantages include: sensible language design, strong types, ADTs, easier and much faster testing/debugging, easier formal verification, easier, more powerful, and safer parametrization, etc.
And yes, even if your clash degenerates to basically copying verilog (which it usually doesn't, in my experience) it's still much easier to read thanks to the richer types and ADTs.