【问题标题】:Syntax about chisel :Vec & Wire关于凿子的语法:Vec & Wire
【发布时间】:2016-11-26 08:22:02
【问题描述】:

我正在学习 Chisel3。

我对代码有一些疑问。

val myVec = Wire(Vec(5, SInt(width = 23)))  // Vector of 5 23-bit signed integers.

我想如果我声明一个向量,我需要写“Wire”,但是当我看到这些代码时我错了。

class BigBundle extends Bundle {


 val myVec = Vec(5, SInt(width = 23))  // Vector of 5 23-bit signed integers.

 val flag  = Bool()
 // Previously defined bundle.

 val f     = new MyFloat

}

它突然打在我脸上,所以我想知道我什么时候使用“Wire”?

提前致谢。

【问题讨论】:

    标签: chisel


    【解决方案1】:

    这里的关键是 Chisel3 中“类型”和“值”之间的区别。

    VecBundleUIntSIntBool 是“类型”的示例。

    WireRegInputOutputMem 是“值”的示例。

    上面有BigBundle

    class BigBundle extends Bundle {
      val myVec = Vec(5, SInt(23.W)) // Vector of 5 23-bit signed integers.
      val flag = Bool()
      val f = new MyFloat // Previously defined bundle.
    }
    

    BigBundle 是一个“类型”,就像Vec(5, SInt(23.W)) 是一个“类型”一样。

    如果您希望使用这些类型,您可以创建其中一种类型的 Wire,例如。

    val myVecWire = Wire(Vec(5, SInt(23.W)))
    val myBundleWire = Wire(new BigBundle)
    

    编辑:更新为现代 chisel3 风格

    【讨论】:

    • 能否举例说明如何对myBundleWire进行操作?可以让我更明白。
    • 您可以使用点符号访问 BigBundle 类型的 Wire(或其他值)的字段,并使用连接运算符 := 连接到它们。因此,如果您想将 myBundleWire 的标志字段连接到 false,您可以编写以下内容:myBundleWire.flag := false.B
    • 谢谢,我完全明白了。
    【解决方案2】:

    您可以将Wire 用于您可能为其重新分配值的任何 Chisel 节点。

    val a = Wire(Bool())
    a := Bool(false)
    ...
    

    【讨论】:

      猜你喜欢
      • 2021-11-25
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多