Chisel hdl 上的定点支持

fixed point support on Chisel hdl

我是 Chisel HDL 的新手,我发现 Chisel HDL 确实提供定点表示。 (我发现这个 link: Fixed Point Arithmetic in Chisel HDL)

当我在 chisel 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"

根据 Chisel code SFix 似乎已被弃用,应改用 Fixed。 我修改了你的代码来使用它,但是 poke 和 expect 有问题。 poke和expect好像还不支持Fixed

import Chisel._

class Toy extends Module {
        val io = new Bundle {
                val in0 = Fixed(INPUT, 4, 12)
                val in1 = Fixed(INPUT, 4, 12)
                val out = Fixed(OUTPUT, 8, 24)
                val oraw = Bits(OUTPUT, width=128)
        }
        val int_result = -io.in0 * (io.in0 + io.in1)
        io.out := int_result
        io.oraw := int_result.asUInt()
}

class ToyTest(c: Toy) extends Tester(c) {
        for (i <- 0 until 20) {
                val i0 = Fixed(0.5, 4, 12)
                val i1 = Fixed(0.25, 4, 12)
                c.io.in0 := i0
                c.io.in1 := i1
                //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)
                }
        }
}