Chisel hdl上的定点支持

时间:2016-09-15 18:09:49

标签: fixed-point chisel

我是Chisel HDL的新手,我发现Chisel HDL确实提供了定点表示。 (我发现这个链接: Fixed Point Arithmetic in 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)
                }
        }
}

产生以下错误: enter image description here

在我的build.sbt文件中,我选择了最新发布的凿子:

libraryDependencies += "edu.berkeley.cs" %% "chisel" % "latest.release"

1 个答案:

答案 0 :(得分:1)

根据Chisel code SFix似乎已被弃用,应该使用Fixed。 我修改了你的代码以使用它,但是poke和expect存在问题。似乎固定不受支持和预期支持。

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)
                }
        }
}