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

Make reinterpret cast conversions (fromBits / asUInt / etc) consistent #433

Closed
ducky64 opened this issue Jan 10, 2017 · 3 comments
Closed
Assignees
Milestone

Comments

@ducky64
Copy link
Contributor

ducky64 commented Jan 10, 2017

Split of the discussion from #424. I think we want to do the temporary fix first while we discuss how to improve the API.

@sdtwigg 's approach was:

Our approach was the following:

  1. asUInt or from[blah] on a Clock is a runtime-exception (iirc FIRRTL doesn't support this at all anyway)
  2. Instead of fromBits, Data has an "asTypeOf[T <: Data](model: T): T" since most commonly people were using fromBits to perform a cast and this made all casts look like as[blah]. This also made asTypeOf invert itself. (There are potentially some odd cases when unknown-width SInts are involved; however, it was generally advised to use only known width things under threat of emitting errors later.)
  3. asTypeOf uses connectFromUInt(target: UInt) for each element, which basically acts like your proposed fromBits (but without having to worry about which Bits it is). connectFromUInt also doesn't create any wires.

So a concrete (API change) proposal would be:

  1. Implement asTypeOf(model) for the fromBits conversions.
  2. Deprecate fromBits. It didn't really have an intuitive API.
@ducky64
Copy link
Contributor Author

ducky64 commented Jan 19, 2017

We will deprecate fromBits and replace with Data.asTypeOf(model) as per Stephen's approach.

@ducky64
Copy link
Contributor Author

ducky64 commented Apr 11, 2017

So the new asTypeOf API has been around for a while, though fromBits hasn't been deprecated yet.

Since fromBits is a Data method, deprecation in chisel3._ only (and not in Chisel._) will likely be difficult. Options include:

  • Deprecate fromBits across the board. Legacy users will receive deprecation warnings.
  • Remove fromBits from Data._, and use implicit casts (PML pattern) to support fromBits with different implementations in chisel3._ and Chisel._. This will also be the only option to support fromBits in Chisel._ if we want to remove it completely from chisel3._.

@ducky64 ducky64 added this to the 3.0.0 milestone Apr 18, 2017
@ducky64
Copy link
Contributor Author

ducky64 commented Apr 18, 2017

We will try #2 (PML to like FromBits-able) and manually fix up any instances where it breaks existing code.

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

1 participant