Skip to content

Add option to change internal bit representation of Clash types #572

Open
@martijnbastiaan

Description

@martijnbastiaan

Consider the following data type:

data A
  = A (Unsigned 4)
  | B (Unsigned 4) (Unsigned 4)
  deriving (Generic, BitPack)

Right now:

>>> pack (A 2)
10010....

where the .s are indicating undefined. This behavior matches what Clash will generate in the HDL: whenever it converts the data type to a std_logic_vector-like. While this is completely fine in terms of functionality, interoperability between tools might suffer. For example, BlueSpec uses the following:

>>> pack (A 2)
1....0010

Other tooling might use "one-hot" constructors, like so:

>>> pack (A 2)
10....0010
>>> pack (B 2 2)
0100100010

Integrating with these tools thus requires the user to manually write these conversions. Pretty annoying!

Ideally, Clash would offer the option to configure this behavior. The easiest way would probably be a Cabal flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions