Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chisel invert Vec[Bool] one-liner

Tags:

chisel

Is there a one-liner that takes a Vec[Bool] and creates an inverted version of it?

Here is an example of taking 37 bits, inverting them, then doing an OR reduction across all of them. Is there a one-liner that can replace the assignment of inv_a?

class MyModule extends Module {
  val io = IO(new Bundle {
    val a = Input(Vec(37, Bool()))
    val b = Output(Bool())
  })

  val inv_a = Wire(Vec(37, Bool()))
  for (i <- 0 until 37) {
    inv_a(i) := ~io.a(i)
  }

  io.b := inv_a.reduce((a, b) => (a | b))
}
like image 201
nic Avatar asked Feb 27 '26 14:02

nic


1 Answers

I think this does what you want.

val inv_a = (~ io.a.asUInt).asBools()
like image 115
Chick Markley Avatar answered Mar 02 '26 15:03

Chick Markley



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!