掩码如何用于凿子中的聚合内存?

How the mask can be used in aggregate memory in chisel?

我想在 chisel 中使用聚合内存。

根据 github、https://github.com/ucb-bar/chisel3-wiki/blob/master/Chisel-Memories.md

中的建议

我的代码如下所示:

class Interface(val w:Int) extends Bundle{
  val a: UInt = UInt(w.W)
  val b: UInt = UInt(w.W)
  val c: UInt = UInt(w.W)
}

val mem = Mem(16,new Interface(4))

然后我使用掩码如下:

mem.write(io.addr, inter, mask)

其中'inter'的类型是Interface,'mask'的类型是Vec[Bool]

报错如下:

Cannot prove that mytest.Interface <:< chisel3.Vec[_].

我搜索了一下,发现mask只能在内存定义为Vec时使用

有什么解决方案可以使这项工作正常进行吗?

如您所见,mask只能在内存的数据类型为Vec时使用。

您没有描述您希望 mask 与接口对应的具体程度,但我假设您有一个大小为 3 的 Vec,每个接口对应一位abc

最简单的解决方案就是使用 Vec(3, UInt(4.W)):

val mem = Mem(16, Vec(3, UInt(4.W)))

如果你想像真正由 Interface 构成一样进行读写,你可以转换:

mem.write(io.addr, inter.asTypeOf(Vec(3, UInt(4.W)), mask)

这些转换有点冗长,您可以创建类型别名以使代码更简洁和可维护:

val w = 4
val memType = Vec(3, UInt(w.W))
val intfType = new Interface(w)

val mem = Mem(16, memType)
mem.write(io.addr, inter.asTypeOf(memType), mask)

val read: Interface = mem.read(io.addr).asTypeOf(intfType)