提问人:Shubha 提问时间:7/20/2018 最后编辑:Shubha 更新时间:7/26/2018 访问量:1400
凿子串联错误
Chisel Concatenation Error
问:
class CC extends Module {
val io = IO(new Bundle {
val in1 = Input(Vec(5, UInt(3.W)))
val in2 = Input(Vec(5, UInt(3.W)))
val out = Output(Vec(9, UInt(3.W)))
})
val L = 5
val ml = 4
var y = 0
for (i <- 0 until ml) {
when (io.in2(i) === io.in1(L - ml + i))
y = y + 1
}
when (y === ml) {
io.out := Cat(io.in1(0) ,io.in2)
}
io.out := io.in1
}
这是在检查两个字符串是否匹配后连接它们的代码。例如,如果 in1 为 1001,in2 为 0010,则它必须连接并返回 10010
另外,我有几个问题
1)我们可以连接向量吗?
2) '===' 运算符对向量有效吗?
3) 我们可以比较两个向量吗?
我遇到的错误
1)
inferred type arguments [chisel3.core.Data] do not conform to method apply's type parameter bounds [T <: chisel3.Bits] [error] io.out := Cat(io.in1(0) ,io.in2)
2)
value === is not a member of Int [error] when (y === ml)
3)
type mismatch; [error] found : chisel3.core.UInt [error] required: T [error] io.out := Cat(io.in1(0) ,io.in2)
有人可以指导我吗?谢谢!
答:
2赞
FabienM
7/20/2018
#1
这段代码中有很多混淆。
第一个 'y' 应该是 Chisel 寄存器,而不是 scala Int 变量。
val y = RegInit(0.asUInt(8.W))
Scala for 循环在 VHDL 中用作 Generate,用于“复制”一些代码行。
然后,据我了解,这个循环:
for (i <- 0 until ml){
when (io.in2(i) === io.in1(L.U - ml.U + i))
y = y + 1
}
事实上,值 'y' 应该是一个向量:
val y = RegInit(VecInit(Seq.fill(m1)(0.asUInt(8.W))))
你的循环应该看起来像这样:
for (i <- 0 until ml){
when (io.in2(i) === io.in1(L - ml + i)){
y(i) := y(i) + 1.U
}
io.out(i) := 0.U
when (y(i) === ml){
io.out(i) := io.in2(i)
}
}
io.out(m1+1) := io.in1(0)
io.out 的 Vec 大小应为 6 而不是 9:
val out = Output(Vec(6, UInt(3.W)))
评论
0赞
Shubha
7/20/2018
非常感谢。但我仍然发现错误 1) 和 2)value asUint is not a member of Int [error] val y = RegInit(VecInit(Seq.fill(ml)(0.asUint(8.W))))
inferred type arguments [chisel3.core.Data] do not conform to method apply's type parameter bounds [T <: chisel3.Bits] [error] io.out := Cat(io.in1(0) ,io.in2)
0赞
FabienM
7/20/2018
我的错误,是 asUInt()(我大写)
0赞
Shubha
7/20/2018
我仍然在连接行中遇到错误inferred type arguments [chisel3.core.Data] do not conform to method apply's type parameter bounds [T <: chisel3.Bits] [error] io.out := Cat(io.in1(0) ,io.in2) [error] ^
1赞
FabienM
7/20/2018
嗯,听起来 Cat 函数不返回 Vec() 而是返回 UInt:github.com/freechipsproject/chisel3/blob/master/src/main/scala/......事实上,你不应该以这种方式返回。(我编辑了回复)
0赞
Shubha
7/23/2018
它仍然显示相同的错误type arguments [chisel3.core.Data] do not conform to method apply's type parameter bounds [T <: chisel3.Bits] [error] io.out(i) := Cat(io.in1(0) ,io.in2)
上一个:如何知道分配了哪个功能?
下一个:类之间的自定义相等性
评论