在凿子中实施Verilog $ onehot任务

时间:2018-10-08 17:00:54

标签: scala one-hot-encoding chisel

是否有一种简单的方法来检查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")

1 个答案:

答案 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...