是否有一种简单的方法来检查Chisel中的1-hot总线编码?
我当前的解决方案似乎有点丑陋。我可以做得更好吗?
val range = Output (Vec (num, Bool()))
val outSum = io.range map ( p => if ( p == true.B ) 1.U else 0.U ) reduceleft (_ + _)
// This is $onehot0
assert (outSum <= 1.U, "One-hot0 bus encoding failed")
// This is $onehot
assert (outSum == 1.U, "One-hot bus encoding failed")
答案 0 :(得分:3)
您可以使用PopCount
import chisel3._
import chisel3.util.PopCount
...
val io = IO(new Bundle {
val range = Output(Vec(num, Bool()))
})
val outSum = PopCount(io.range)
// assertions...