Skip to content

Commit 6862513

Browse files
authored
Support literals cast to aggregates as async reset reg init values (#1225) (#1247)
Accomplished by changing the code gen for casting literals to aggregates. Rather than connecting the literal to a wire that is then bit selected from, just bit select from the literal which saves the creation of an intermediate wire and matches FIRRTL's semantics for legal async reset initial values. (cherry picked from commit 92d88ff)
1 parent d33da44 commit 6862513

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

chiselFrontend/src/main/scala/chisel3/Aggregate.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ sealed abstract class Aggregate extends Data {
6565
private[chisel3] override def connectFromBits(that: Bits)(implicit sourceInfo: SourceInfo,
6666
compileOptions: CompileOptions): Unit = {
6767
var i = 0
68-
val bits = WireDefault(UInt(this.width), that) // handles width padding
68+
val bits = if (that.isLit) that else WireDefault(UInt(this.width), that) // handles width padding
6969
for (x <- flatten) {
7070
val fieldWidth = x.getWidth
7171
if (fieldWidth > 0) {

src/test/scala/chiselTests/AsyncResetSpec.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,36 @@ class AsyncResetSpec extends ChiselFlatSpec {
169169
assertTesterPasses(new AsyncResetQueueTester)
170170
}
171171

172+
it should "allow literals cast to Bundles as reset values" in {
173+
class MyBundle extends Bundle {
174+
val x = UInt(16.W)
175+
val y = UInt(16.W)
176+
}
177+
assertTesterPasses(new BasicTester {
178+
val reg = withReset(reset.asAsyncReset) {
179+
RegNext(0xbad0cad0L.U.asTypeOf(new MyBundle), 0xdeadbeefL.U.asTypeOf(new MyBundle))
180+
}
181+
val (count, done) = Counter(true.B, 4)
182+
when (count === 0.U) {
183+
chisel3.assert(reg.asUInt === 0xdeadbeefL.U)
184+
} .otherwise {
185+
chisel3.assert(reg.asUInt === 0xbad0cad0L.U)
186+
}
187+
when (done) { stop() }
188+
})
189+
}
190+
it should "allow literals cast to Vecs as reset values" in {
191+
assertTesterPasses(new BasicTester {
192+
val reg = withReset(reset.asAsyncReset) {
193+
RegNext(0xbad0cad0L.U.asTypeOf(Vec(4, UInt(8.W))), 0xdeadbeefL.U.asTypeOf(Vec(4, UInt(8.W))))
194+
}
195+
val (count, done) = Counter(true.B, 4)
196+
when (count === 0.U) {
197+
chisel3.assert(reg.asUInt === 0xdeadbeefL.U)
198+
} .otherwise {
199+
chisel3.assert(reg.asUInt === 0xbad0cad0L.U)
200+
}
201+
when (done) { stop() }
202+
})
203+
}
172204
}

0 commit comments

Comments
 (0)