Chisel3 : Vec indexWhere expected Bool, 实际 任意

标签 chisel

在 Chisel 中,我有一个 Bool 的 Vec 进入一个模块。我想知道发生的第一个 False 的索引。
为了获得这个,我尝试使用以下内容:

val faultIndex = Wire(UInt)

faultIndex := comparison.indexWhere(x:Bool => x === false.B)
当我把它放进去时,一个错误被突出显示:
Unspecified value parameters: from: Int
Type mismatch, expected Bool => Bool, actual: Bool => Any
Type mismatch, expected Bool => Boolean, actual: Bool => Any
Cannot resolve symbol x
Cannot resolve symbol x
使用此功能的正确方法是什么?

最佳答案

这里有两个小的语法问题:

val faultIndex = Wire(UInt())
注意 ()UInt 之后.您可以将其视为构造一个新类型对象,而不是指向名为 UInt 的静态对象。 .indexWhere有几种表达方式:
faultIndex := comparison.indexWhere((x: Bool) => x === false.B) // Note parentheses
// or
faultIndex := comparison.indexWhere(x => x === false.B) // Type is inferred
// or
faultIndex := comparison.indexWhere(_ === false.B) // underscore shorthand
// alternatively
faultIndex := comparison.indexWhere(x => !x) // !x is equivalent to x === false.B
// or
faultIndex := comparison.indexWhere(!_)      // More underscore shorthand

可执行示例:https://scastie.scala-lang.org/uHCX5wxgSzu6wXqa9OJdRA

关于Chisel3 : Vec indexWhere expected Bool, 实际 任意,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63160229/

相关文章:

chisel - 值不是 chisel3.Bundle 的成员

riscv - 如何在 Chisel 中做出断言只是警告而不是停止模拟

chisel - 关于凿子 :Vec & Wire 的语法

凿子同步

Chisel 测试台 : controlling multiple ports independently

scala - 如何在 Chisel 中将状态机拆分为多个类或特征?

riscv - Chisel 中的 Queue() 函数有什么作用?

凿子3 : False Combinational Loop in Fixed Priority Arbiter

scala - 如何将一些 Bundles 作为模块参数传递?