[firrtl] Hardware with nested direction generates failing firrtl with Reg / RegNext
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 50/100
Research direction
Reproduce the issue with the Foo.scala example, starting at RegNext(io.in), Reg(chiselTypeOf(io.in)), and ChiselStage execution with --target verilog. Trace how the nested direction is represented in the generated FIRRTL and how firtool validates the firrtl.reg type. Done means the example generates valid Verilog without the firtool passive-type error.
Written by the indexing model from the issue text.
Description
Type of issue: Bug Report
Please provide the steps to reproduce the problem:
Create an empty Chisel project, then add Foo.scala below:
package foo
import chisel3._
import chisel3.util._
// This is a bundle with nested direction
class BundleWithDirection extends Bundle {
val a = Input(UInt(3.W))
}
class Foo extends Module {
val io = IO(new Bundle{
// And I'd like to make it an input for this module
// For now this works smoothly
val in = new BundleWithDirection
val out = Output(UInt(3.W))
})
// In this example we'll simply delay the input for 1 cycle
val buffer = RegNext(io.in)
io.out := buffer.a
}
Then generate verilog code using (new ChiselStage).execute( ... ) with argument --target verilog
What is the current behavior?
firtool will throw the following error:
src/main/scala/Foo.scala:18:25: error: 'firrtl.reg' op result #0 must be a passive non-'const' base type that does not contain analog, but got '!firrtl.bundle<a flip: uint<3>>'
val buffer = RegNext(io.in)
^
src/main/scala/Foo.scala:18:25: note: see current operation: %3 = "firrtl.reg"(%arg0) <{annotations = [], name = "buffer", nameKind = #firrtl<name_kind interesting_name>}> : (!firrtl.clock) -> !firrtl.bundle<a flip: uint<3>>
What is the expected behavior?
The BundleWithDirection bundle only contains Input signal, so RegNext(io.in) should be able to generate verilog code like
reg [2:0] buffer_a; // src/main/scala/Foo.scala:18:25
always @(posedge clock) // src/main/scala/Foo.scala:12:7
buffer_a <= io_in_a; // src/main/scala/Foo.scala:18:25
assign io_out = buffer_a; // src/main/scala/Foo.scala:12:7, :18:25
Please tell us about your environment:
- version: 7.7.0
- OS: Linux <hostname> 6.8.0-124-generic #124~22.04.1-Ubuntu SMP x86_64 GNU/Linux
Other Information
The Chisel code above could generate fir code with --target chirrtl:
FIRRTL version 6.0.0
circuit Foo :%[[
{
"class":"firrtl.transforms.DedupGroupAnnotation",
"target":"~|Foo",
"group":"Foo"
}
]]
layer Verification, bind, "verification" :
layer Assert, bind, "verification/assert" :
layer Temporal, inline :
layer Assume, bind, "verification/assume" :
layer Temporal, inline :
layer Cover, bind, "verification/cover" :
layer Temporal, inline :
public module Foo : @[src/main/scala/Foo.scala 12:7]
input clock : Clock @[src/main/scala/Foo.scala 12:7]
input reset : UInt<1> @[src/main/scala/Foo.scala 12:7]
output io : { in : { flip a : UInt<3>}, out : UInt<3>} @[src/main/scala/Foo.scala 13:16]
reg buffer : { flip a : UInt<3>}, clock @[src/main/scala/Foo.scala 18:25]
connect buffer.a, io.in.a @[src/main/scala/Foo.scala 18:25]
connect io.out, buffer.a @[src/main/scala/Foo.scala 19:12]
It seems that the Input in Chisel code is interpeted as output io : { in : { flip a : UInt<3>}, ...}, and the RegNext clones the type flip a: UInt<3>, which is considered a non-passive signal by firtool, causing it unable to connect buffer.a with io.in.a
This problem persists with val buffer = Reg(chiselTypeOf(io.in))
When removing the flip in reg buffer : { flip a : UInt<3>}, clock, the firtool is able to generate the correct verilog code, indicating that this issue might be fixed by removing the direction notation in fir reg.
What is the use case for changing the behavior?
Bundles with nested direction works well for grouping signals with similar functionalities together, e.g. gathering all the signals that connects to another specific module, so that they're easy to find, and can be connected using one line of source <> dest.
When a bundle consists of signal with the same direction, it should be able to use with RegNext or Reg for convenient buffering.
- Dominant language
- Scala
- Stars
- 4.8k
- Forks
- 669
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 25
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from chipsalliance/chisel
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
chipsalliance/chisel#5570 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
chipsalliance/chisel#5499 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 54/100
chipsalliance/chisel#5430 · 2 comments ·
Maintainers usually reply within 1 day
-
MultiClockSpec chiselTest fails with recent Verilator versionPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 68/100
chipsalliance/chisel#5418 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
chipsalliance/chisel#5407 · 1 comment ·
Maintainers usually reply within 1 day
All issues in chipsalliance/chisel
Similar issues
-
[Bug][NewCSR] vsstatus.SDT latches writes while DTE=0, exposing illegal (vsstatus.SDT=1 && vsstatus.SIE=1)Possibly taken @docluka77 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
OpenXiangShan/XiangShan#7134 ·
Maintainers usually reply within 2 days
-
Module - Core
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 Under an hour Newbie friendliness 83/100
rchillyard/TableParser#230 ·
Maintainers usually reply within 1 day
-
AI Generated CI/CD ⚒️ Flaky-tests 🐦 python 🐍
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
valkey-io/valkey-glide#8012 ·
Maintainers usually reply within 2 days
-
Agent Workspace Python guidance: the agent can choose an interpreter without magda-python-runtime planPossibly taken @chandrasahith claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
magda-io/magda#4007 · 2 comments ·
Maintainers usually reply within 1 day