question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chisel does not generate error if size argument is not .W in RegInit

See original GitHub issue

Type of issue: bug report Impact: no functional change Development Phase: request

What is the current behavior? If I instantiate a register this way :

val sizeFrame = 30
val writeFrame = RegInit(0.U(sizeFrame))

Chisel compile without problem. But the size of writeFrame register will be 1.

I think it’s a chisel bug, because width parameter must be suffixed by ‘.W’.

What is the expected behavior? In my opinion, the correct way to instantiate my register is :

val sizeFrame = 30
val writeFrame = RegInit(0.U(sizeFrame.W))

And the declaration given at the begining should generate an error.

Please tell us about your environment: - version: 3.1.8 - OS: Linux Debian 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1+deb9u5 (2019-08-11) x86_64 GNU/Linux

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

2reactions
jackkoenigcommented, Jan 28, 2021

8.U(3) is a huge wart that merits fixing. Removing indexing with Int would fix it but is a pretty draconian change that would require updating a lot of code (indexing Wires, Regs and the like). There are a couple of other approaches we could do:

2reactions
ducky64commented, Jan 18, 2020

From the example in #871

val foo = 0.U // declare a UInt whose value is 0
val bar = foo(sz) // extract bit sz from foo

Basically, from a Scala operations point of view, it looks like a literal chained with a bit extract, which is legal and apparently in use - and which is why it’s so hard to fix.

One solution might be the use of macros (or a linter) to detect and warn on style-based anti-patterns like this. Or we might define a .U(int) function that is deprecated / errors and requires users to introduce parens to make chained literal - bit extract operations explicit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove implicit width truncation / Don't repeat Verilog's ...
This is one of the worst issues in Verilog and modern synthesize tools should ... Chisel does not generate error if size argument...
Read more >
freechipsproject/chisel3 - Gitter
I was generating random inputs based on the bit width of the input rin . The port is defined as UInt(12.W) and it's...
Read more >
How to init a register with a parametrized value - Stack Overflow
When I tried the above, I got 3 errors: [error] /Users/jack/work/chisel3-raw/src/main/scala/RegInit.scala:10:13: inferred type arguments ...
Read more >
Advanced Chisel Topics
PriorityEncoder – returns the bit position of the trailing 1 in the input vector with the assumption that multiple bits of the input...
Read more >
RegInit - chisel3
The single argument form uses the argument to specify both the type and reset value. For non-literal Bits, the width of the Reg...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found