在 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/