chisel2-deprecated icon indicating copy to clipboard operation
chisel2-deprecated copied to clipboard

Vec clone method incorrect

Open sdtwigg opened this issue 10 years ago • 1 comments

class Toy extends Module {
  val io = new Bundle {
    val in1    = UInt(width= 2).asInput
    val in2    = UInt(width=16).asInput
    val select = UInt(width= 2).asInput
    val out1   = UInt(width=32).asOutput
  }
  val myVec = Vec(Seq(io.in1,UInt(10),UInt(20),io.in2))
  val myReg = Reg(next=myVec)

  io.out1 := myReg(io.select)
}

The corresponding myReg consists of elements that all have width 2. This is because the Reg needs to clone Vec and the clone method for Vec reconstructs all constituent elements by using the cloning the head element. There is a family of similar bugs that can be demonstrated using these methods (e.g. turning a Vec of various Data types to a single type).

The best solution is, I think, to drop the gen constructor argument and adjust the Vec clone method to reconstruct all constituent elements via map i.e.

override def clone(): this.type = Vec(elts.map(_.clone)).asInstanceOf[this.type]

However, further testing on this fix is needed.

sdtwigg avatar Apr 01 '15 11:04 sdtwigg

cloneType should be modified to:

override def cloneType: this.type = Vec(elts.map(_.cloneType)).asInstanceOf[this.type]

Was running into similar problems earlier (widths of subsequent elements being too small b/c the first element had a small width). Another hard to catch "bug"...

shunshou avatar Mar 06 '16 08:03 shunshou