Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would be the best way to initialize a Bundle Register to all 1s in Chisel?

Tags:

chisel

I'm wondering how can I initialize a Bundle register to all 1s. Let's say I have the bundle:

class MyBundle(val w: Int) extends Bundle {
  val a = UInt(w.W)
  val b = UInt(w.W)
  val x = Bool()
  val y = Bool()
}

I'm trying something like:

val myReg = RegInit(-1.S.asTypeOf(new MyBundle(32)))

However, this assumes width of the signed literal to be just 1, and initializes only the LSB of the bundle to 1. What comes to mind is:

val myReg = RegInit(-1.S(new MyBundle(32).asSInt().getWidth).asTypeOf(new MyBundle(32)))

But this does not seem to work at all.

How can I accomplish this?

like image 416
josecm Avatar asked Jan 20 '26 05:01

josecm


1 Answers

You could set the width explicitly based on the width of that Bundle. You're on the right track. Try:

val myReg = RegInit(-1.S(new MyBundle(32).getWidth.W).asTypeOf(new MyBundle(32)))

Also note that if you've already constructed MyBundle you can refer to that directly as opposed to constructing new objects, e.g.:

val foo = Wire(new MyBundle(32))
val myReg = RegInit(-1.S(foo.getWidth.W).asTypeOf(foo))
like image 143
seldridge Avatar answered Jan 21 '26 19:01

seldridge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!