我正在开发 Z 规模 RISCV 处理器,我已在数据路径中实现了新的功能和逻辑。我想知道是否存在一种简单的方法来“关闭”代码的某些部分而不使用一堆 if 循环?我希望能够轻松地在 Z 尺度处理器的常规实现和扩展实现之间进行切换。
我实现的新逻辑并没有取代数据路径的主要组件,而是扩展了功能。
最佳答案
这个问题确实触及了 Chisel 强大的核心。作为嵌入 Scala 中的 DSL,您可以使用面向对象和函数式编程语言的全部功能。
虽然我不确定你到底在做什么,但这似乎是使用继承的好地方。您可以创建一个新的模块类来扩展数据路径模块并添加附加功能。
一个玩具示例:
import Chisel._
class ParentIO extends Bundle {
val foo = UInt(width = 32).asInput
val bar = UInt(width = 32).asOutput
}
class Parent extends Module {
// Note the use of lazy val
// Due to Scala initialization order (http://docs.scala-lang.org/tutorials/FAQ/initialization-order.html)
// this cannot be a val
// Due to quirks of Chisel, this cannot be a def
lazy val io = new ParentIO
io.bar := io.foo
}
class ChildIO extends ParentIO {
val isOdd = Bool().asOutput
}
class Child extends Parent {
override lazy val io = new ChildIO
io.isOdd := io.foo(0)
}
// Note use of call-by-name for passing gen
// Chisel Modules must be constructed within a call to the Module(...) function
class Top(gen: => Parent) extends Module {
val dut = Module(gen)
val io = dut.io.cloneType
io <> dut.io
}
Module Top 由它实例化的模块类型参数化:父模块或子模块。因此,您可以有条件地实例化 Parent 或 Child,而不是区分它们的所有逻辑。如果您希望子级覆盖父级的某些功能,Chisel 的最后连接语义允许子级中的任何连接覆盖父级中的连接。
关于scala - 使用泛型类型关闭数据路径中的逻辑(Chisel),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40650510/