我是 Chisel HDL 的新手,我发现 Chisel HDL 确实提供了定点表示。(我找到了这个链接: Chisel HDL 中的定点算术)
当我在凿子 hdl 中尝试它时,它实际上不起作用:
import Chisel._
class Toy extends Module {
val io = new Bundle {
val in0 = SFix(4, 12).asInput
val in1 = SFix(4, 12).asInput
val out = SFix(4, 16).asOutput
val oraw = Bits(OUTPUT, width=128)
}
val int_result = -io.in0 * (io.in0 + io.in1)
io.out := int_result
io.oraw := int_result.raw
}
class ToyTest(c: Toy) extends Tester(c) {
for (i <- 0 until 20) {
val i0 = 0.5
val i1 = 0.25
poke(c.io.in0, i0)
poke(c.io.in1, i1)
val res = -i0 * (i0+i1)
step(1)
expect(c.io.out, res)
}
}
object Toy {
def main(args: Array[String]): Unit = {
val tutArgs = args.slice(1, args.length)
chiselMainTest(tutArgs, () => Module(new Toy())) {
c => new ToyTest(c)
}
}
}
在我的 build.sbt 文件中,我通过以下方式选择最新版本的凿子:
libraryDependencies += "edu.berkeley.cs" %% "chisel" % "latest.release"