Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implicit pack/unpack + custom Bits instance can result in extraneous logic. #731

Open
rossc719g opened this issue Aug 20, 2024 · 1 comment

Comments

@rossc719g
Copy link
Contributor

The compiler inserts an implicit unpack when reading a port/register, and an implicit pack when writing. For "standard" types like "UInt" or "Bit", these are effectively no-ops. But when using a type with a custom Bits instance, they can generate extraneous logic. Given that the source and destination are both packed, these could be elided, and remove the extraneous logic that is generated.

See https://github.com/rossc719g/bsc_examples/blob/main/pack_unpack/README.md for a full example.

The example includes a workaround using a wrapper type.

@krame505
Copy link
Contributor

I think a fix for this would be to introduce some primitives:

primitive primPack :: (a - > Bit n) -> a -> Bit n
primitive primUnpack :: (Bit n -> a) -> Bit n -> a

and use these as wrappers around pack and unpack at synthesis boundaries. The evaluator would permit these to cancel each other out as a special case, otherwise it would just use the wrapped functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants