clash-lang / clash-compiler

Haskell to VHDL/Verilog/SystemVerilog compiler
https://clash-lang.org/
Other
1.44k stars 153 forks source link

Proposal: leverage BitVector in `Clash.Annotations.BitRepresentation` #1752

Open martijnbastiaan opened 3 years ago

martijnbastiaan commented 3 years ago

A ConstrRepr uses two fields to encode a mask and a value to encode constructor bits. For example:

ConstrRepr 'A 0b110011 0b1010 []

which would mean: take the four bits indicated by the first binary value. If the value corresponds to 1010 it's constructor A. This is confusing in multiple ways:

Perhaps we could fix this by leveraging the ability to set undefined bits on BitVector. For example:

ConstrRepr 'A (bLit "10..10") []

The Python programmer in me says we could even use OverloadedStrings and do:

ConstrRepr 'A "0b10..10" []

but that's a topic for another day..


Relevant documentation: http://hackage.haskell.org/package/clash-prelude-1.4.0/docs/Clash-Annotations-BitRepresentation.html#g:1

JvWesterveld commented 3 years ago

+1! Perhaps to serve your point: I believe your description of how this currently works is wrong. Bitpacking A would rather result in 0b00..10. The mask and value are matched bit by bit, and the bits of the value for which the corresponding mask bits are zero are ignored.

martijnbastiaan commented 3 years ago

Thanks @JvWesterveld. And yeah, I think that definitely proves my point then :-)