-
Notifications
You must be signed in to change notification settings - Fork 611
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
Semantic Inconsistency in Intermediate FIRRTL File During Compilation: Incorrect reg Emission Instead of node and Loss of Memory readUnderWrite Behavior #4526
Comments
For (1) and (2), are you sure that the FIRRTL being produced is incorrect? Those tests are written as When I created a single-file version of this, I don't see that: //> using scala "2.13.12"
//> using repository sonatype-s01:snapshots
//> using dep "org.chipsalliance::chisel::7.0.0-M2+160-d564445d-SNAPSHOT"
//> using plugin "org.chipsalliance:::chisel-plugin::7.0.0-M2+160-d564445d-SNAPSHOT"
//> using options "-unchecked", "-deprecation", "-language:reflectiveCalls", "-feature", "-Xcheckinit", "-Xfatal-warnings", "-Ywarn-dead-code", "-Ywarn-unused", "-Ymacro-annotations"
import chisel3._
import chisel3.util.{Counter, ShiftRegister}
import circt.stage.ChiselStage
class Foo(n: Int) extends Module {
val (cntVal, done) = Counter(true.B, n)
val start = 23.U
val sr = ShiftRegister(cntVal + start, n)
when(done) {
assert(sr === start)
stop()
}
}
object Main extends App {
println(
ChiselStage.emitCHIRRTL(
new Foo(0)
)
)
println(
ChiselStage.emitSystemVerilog(
new Foo(0),
firtoolOpts = Array(
"-strip-debug-info",
"-disable-all-randomization",
"-enable-layers=Verification,Verification.Assert,Verification.Assume,Verification.Cover"
)
)
)
} Running the above with FIRRTL version 4.0.0
circuit Foo :
layer Verification, bind, "Verification" :
layer Assert, bind, "Verification/Assert" :
layer Assume, bind, "Verification/Assume" :
layer Cover, bind, "Verification/Cover" :
public module Foo :
input clock : Clock
input reset : UInt<1>
wire cntVal : UInt
connect cntVal, UInt<1>(0h0)
wire done : UInt<1>
connect done, UInt<1>(0h0)
when UInt<1>(0h1) :
connect done, UInt<1>(0h1)
node _sr_T = add(cntVal, UInt<5>(0h17))
node sr = tail(_sr_T, 1)
when done :
node _T = eq(sr, UInt<5>(0h17))
node _T_1 = eq(reset, UInt<1>(0h0))
layerblock Verification :
layerblock Assert :
intrinsic(circt_chisel_ifelsefatal<format = "Assertion failed at 4526.scala:16\n", label = "chisel3_builtin">, clock, _T, _T_1)
layerblock Verification :
node _T_2 = eq(reset, UInt<1>(0h0))
when _T_2 :
stop(clock, UInt<1>(0h1), 0) : stop // Generated by CIRCT firtool-1.89.0
// Users can define 'STOP_COND' to add an extra gate to stop conditions.
`ifndef STOP_COND_
`ifdef STOP_COND
`define STOP_COND_ (`STOP_COND)
`else // STOP_COND
`define STOP_COND_ 1
`endif // STOP_COND
`endif // not def STOP_COND_
module Foo(
input clock,
reset
);
`ifndef SYNTHESIS
always
if ((`STOP_COND_) & ~reset)
$finish;
end // always
`endif // not def SYNTHESIS
endmodule That has For (3), this was a long-standing bug in that Chisel never emitted these attributes. That was fixed in chipsalliance/firrtl@d9da6b1. However, it looks like that never made a version of the Scala-based FIRRTL compiler (SFC) as I only see it on the 1.5.x branch (and not on a tag). Newer Chisel versions will emit this. However, there is a separate bug in CIRCT (the new FIRRTL compiler) where these attributes are ignored: llvm/circt#787 It was originally considered to just drop all behaviors other than undefined, however, this was rejected here: #2948 On Chisel Very high level, though, Chisel 3.5.6 is quite old at this point and the SFC is no longer receiving updates. (3) can get fixed on |
Thank you very much for your response. Regarding (3), I no longer have any doubts, but I am still confused about (1) and (2). In fact, I observed the bugs related to (1) and (2) on Chisel v3.5.6, not the latest CIRCT-based version (which seems to be the one you compiled). Regarding the issue of overwriting However, this is not important. I believe the inconsistency I mentioned earlier may not have been observed by you because you are not using Chisel v3.5.6. Below is the intermediate
As can be seen, |
Type of issue: Bug Report
Please provide the steps to reproduce the problem:
Chisel Version: v3.5.6
FIRRTL Version: v1.5.6
Treadle Version: v1.5.6
We ran the official tests for each of the following cases (without any modifications), and then examined the
.fir
files in thetest_run_dir
. We observed inconsistencies between the.fir
files and the source code. The details are provided below.src/test/scala/chiselTests/Reg.scala
, Line 54n = 0
, the registersr
should have a constant value, which should be compiled to anode
. (This is observable when emitting FIRRTL, where the translation results in anode
.) However, when emitting Verilog (which generates a.fir
file in the same directory), the registersr
is compiled to areg
, leading to an inconsistency with the source code. Initially, the value inreg sr
is either random or zero (depending on the settings), rather than the expected constant value.src/test/scala/chiselTests/Reg.scala
, Line 44src/test/scala/chiselTests/Mem.scala
, Line 37readUnderWrite
behavior is lost in the.fir
file generated in the same directory.What is the current behavior?
There are cases of semantic inconsistencies between the
.fir
intermediate files generated by Chisel'semit verilog
and the source code (including incorrect compilation and loss of semantic information).What is the expected behavior?
The semantic behavior of the
.fir
intermediate files generated by Chisel'semit verilog
is consistent with the source code.Please tell us about your environment:
v3.5.6
Ubuntu 24.04 LTS
Other Information
Use
emit verilog
to generate the.fir
in the same directory (test_run_dir
) instead of directly usingemit firrtl
. I observed that in the FIRRTL repository source code, insrc/main/scala/firrtl/ir/Serializer.scala
at Line 303, thereadUnderWrite
field is lost during the emission.What is the use case for changing the behavior?
I have mentioned it before: the official test code for
ShiftResetTester
,ShiftTester
, andSyncReadMemWriteCollisionTester
in the Chisel v3.5.6 repository.The text was updated successfully, but these errors were encountered: