Comments (7)
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.
from chiseltest.
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.
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.
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.
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.
I think this has been addressed in #480.
from chiseltest.
Related Issues (20)
- Generate waveform file in real-time HOT 1
- chiseltest gets the signal name wrong when trying to peek, poke, or expect an OpaqueType HOT 3
- Solver Chosen Constants for Formal Verification HOT 3
- scala.NotImplementedError: TODO: convert ThrowOnFirstErrorAnnotation HOT 3
- Bundle literal construction outside test() is not allowed in Chiseltest 5.0.0 (works in 0.5.4) HOT 2
- assertion failed: The Chisel compiler plugin is now required for compiling Chisel code HOT 1
- The waveform doesn't reflect changes in the input port until io.clock.peek HOT 1
- scala.NotImplementedError: TODO: convert DecodeTableAnnotatio HOT 7
- Will there be a chiseltest 6.0.0? HOT 16
- Frequent crash on macOS with the threaded Verilator backend HOT 6
- AXI4RAM test failed on chiseltest 5.0.2 HOT 2
- Cant ```import chiseltest._``` HOT 1
- Bitwuzla has changed it's command line argument format HOT 1
- [WARNING] Unsupported annotation: SRAMAnnotation
- [Help]A TLRAM test failed log HOT 8
- What are the future use cases of ChiselTest if it is replaced by ChiselSim? HOT 4
- Who is the copyright holder of chiseltest and what is the license? HOT 1
- one step takes extremely long time to complete HOT 2
- Cover is not yet implemented for Chiseltest HOT 3
- Implement SytemVerilog style Sequences HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chiseltest.