Giter Site home page Giter Site logo

Using Chisel types in peek about chiseltest HOT 7 CLOSED

ucb-bar avatar ucb-bar commented on May 23, 2024
Using Chisel types in peek

from chiseltest.

Comments (7)

ducky64 avatar ducky64 commented on May 23, 2024

Yes, this is currently the case, literals are Chisel objects (hardware nodes) so you need to extract the Scala-land value before doing a compare.

In theory we can do more constant propagation in Chisel (eg, 1.U + 2.U could evaluate to 3.U instead of just generating the add node) and might clean up the literals syntax used in testers2, but it would also have significant limitations and result in duplication of code with FIRRTL. Duplication is highly undesirable, as there have been subtle differences in behavior which are hard to fix because the fix changes behavior, even if it's bad and unituitive.

Using Chisel literals as the testers2 API allows us to re-use the same literal constructors (like the string-based binary/hex constructor and the literals constructor; in the future also Vec constructors), though it does make the syntax for getting values back into Scala more verbose.

Suggestions about how we can make working with literal values easier are appreciated, though within the constraints above.

from chiseltest.

schoeberl avatar schoeberl commented on May 23, 2024

from chiseltest.

ducky64 avatar ducky64 commented on May 23, 2024

So the main practical problem with the former is that it doesn't handle Bundle types or Vector types - what should be returned in those cases? While Vector might return an Array or Seq, for Bundles we generally have tried to avoid indexing with untyped strings, which would be difficult without returning the Chisel type.

I am definitely interested into finding ways to make the returned object more usable, so clever solutions are welcome...

from chiseltest.

ducky64 avatar ducky64 commented on May 23, 2024

Resolution from today's meeting:
We considered doing literal evaluation with chisel types, eg

3.U === 3.U => (some FIRRTL node essentially equal to true.B)
3.U == 3.U => true
3.U == 4.U => false
io.peek() == 3.U => true  // for io.peek() returning 3.U
io.peek() == 3 => assert out  // don't allow implicit promotion of Scala numbers to Chisel lits
3.U + 3.U == 6.U => assert out  // don't allow evaluation on non-literal types, you probably meant to do ===

but decided against it.
(separately, we might make == on Chisel nodes assert out, since it almost always doesn't do what you think it should do - and you should use the referential equality eq for advanced metaprogramming)

In a separate discussion, there was talk about implicitly promoting Scala numbers to literals, which while not completely offensive for Int -> UInt, causes problems (with the above antifeature) for Boolean -> Bool. So that's a no-go.

We thought it would be reasonable to have a simpler literal extract operator, eg io.peek().asInt, instead of the somewhat cumbersome and maybe not at all intuitive .litToValue()

from chiseltest.

schoeberl avatar schoeberl commented on May 23, 2024

Another (similar) consequence: you cannot really compute anything with Chisel types, I get a " Not in a UserModule." error when I do following:

val data = (i << 16).U + dut.io.cycCnt.peek

I need to first convert to Scala land and then back into Chisel land:

val data = ((i << 16) + dut.io.cycCnt.peek.litValue().toInt).U

This is quite a long expression just to add a value. Maybe using BigInt for UInt and SInt would make live easier?

+1 for the above io.peek.asInt and io.peek.asBigInt

Cheers,
Martin, the tester2 tester ;-)

from chiseltest.

oharboe avatar oharboe commented on May 23, 2024

My main concern about this is that it is brittle.

There's no compilation error, or runtime error, there's just a failure in operation.

This can be quite tricky to track down and it makes the process of porting to tester2 brittle.

Example:

while (dut.io.someBool.peek() == false)

Compiles but doesn't work.

Instead I had to do:

while (dut.io.someBool.peek().litValue == 0)

To me the best fix is not something convenient, but something that gives a compilation error message if it is not done correctly. I'll settle for a run-time error, but compilation error would be fantastic.

from chiseltest.

carlosedp avatar carlosedp commented on May 23, 2024

I think this has been addressed in #480.

from chiseltest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.