1

我是 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"
4

1 回答 1

1

根据凿子代码SFix 似乎已被弃用,应使用 Fixed 代替。我修改了您的代码以使用它,但是 poke and 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)
                }
        }
}
于 2016-09-16T07:37:02.570 回答