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 is not inferring the correct width of register

See original GitHub issue

Hi,

I have experienced some issues in trying to have Chisel inferring the correct number of widths for a register.

In particular, the register should be 6-bits, but instead, a 1-bit register is defined in the Verilog.

I tried to create an example code to reproduce the issue:

class width_error extends Module{
  val io = IO(new Bundle{
    val p1 = new HMC_port()
  })

  val regTag = Reg(init = 0.U)
  val readCounter = Counter(100)

  when(readCounter.value < 50.U){
    io.p1.cmd.bits.tag := regTag
    regTag := regTag + 1.U
    readCounter.inc()
  }

}

where HMC_port is defined as follows

class HMC_port extends Bundle{

  val cmd = Decoupled(new HMCCommand)
  val wr = DecoupledIO(UInt(128.W))
  val rd = Decoupled(new HMCResponseChannel).flip

  override def cloneType = {new HMC_port().asInstanceOf[this.type ]}
}


class HMCCommand extends Bundle{
  val addr = UInt(34.W)
  val size = UInt(4.W)
  val tag = UInt(6.W)
  val cmd = UInt(4.W)

  override def cloneType = { new HMCCommand().asInstanceOf[this.type] }
}

class HMCResponseChannel extends Bundle{
  val data = UInt(128.W)
  val errstat = UInt(7.W)
  val dinv = UInt(1.W)
  val tag = UInt(6.W)

  override def cloneType = { new HMCResponseChannel().asInstanceOf[this.type ]}
}

I attach also a version of the Verilog that is produced from this code.

width_error.v.zip

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
cceliocommented, Jul 20, 2017

Thanks @lorenzoditucci, I have opened an issue #650 to help us track adding the proper documentation for this behavior.

1reaction
sbeamercommented, Jul 20, 2017

Following up on the point made by @lorenzoditucci, how might a warning have made this less unintuitive?

Could this particular case (register declared without width and width of input to it is unknown) be detected?

Additionally, the IO assignment io.p1.cmd.bits.tag := regTag leaving 5 bits unassigned is also troubling. I don’t want to reignite the debate about warnings for unconnected IOs, but perhaps in this special case where the unconnected IOs are due to width inference, this could be also be detected.

Either way, this should be cleared up in the docs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chisel is not inferring the correct width of register #649 - GitHub
Hi, I have experienced some issues in trying to have Chisel inferring the correct number of widths for a register.
Read more >
Width Inference - Chisel/FIRRTL
Chisel provides bit width inference to reduce design effort. Users are encouraged to manually specify widths of ports and registers to prevent any...
Read more >
Bit width inference issue - Stack Overflow
Verilog actually is being generated but it appears that the chisel-testers Verilator backend is trying to get the width of the Chisel objects ......
Read more >
Getting Started with Chisel
register assignment, you do not need to do this as. Chisel will infer the type and width from the type and width of...
Read more >
Chisel Basic Operations - GitHub
Automatic bit width inference ... Chisel data types are different from Scala builtin types ... Bitwise NOT, AND, OR, and XOR.
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