- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法确定使用新的 ChiselTest 框架将 signed int 转换为 unsigned int 以进行单元测试的正确方法。
这是我一直用来对 ALU 进行单元测试的方法(例如 16 位),问题是它不可扩展:
test(new ALU) { c =>
...
/* Sub */
c.io.ctl.poke(Control.ALU_SUB)
c.io.src0.poke(4321.U)
c.io.src1.poke(1234.U)
c.io.out.expect(3087.U)
c.io.src0.poke(1234.U)
c.io.src1.poke(4321.U)
c.io.out.expect("b_1111_0011_1111_0001".U) /* 2's compliment */
}
此方法的问题是,当我生成一个 32 位 ALU(输出一个无符号整数)时,单元测试将失败,因为使用上面的 hacky 字符串方法,字符串将零扩展到 32 位...
我想像这样重写测试:
test(new ALU) { c =>
/* Sub */
c.io.ctl.poke(Control.ALU_SUB)
c.io.src0.poke(4321.U)
c.io.src1.poke(1234.U)
c.io.out.expect(3087.U)
c.io.src0.poke(1234.U)
c.io.src1.poke(4321.U)
c.io.out.expect(-3087.S.asUInt)
}
但是,尽管设计确实很精细,但我收到以下错误:
[error] (run-main-9) chisel3.internal.ChiselException: Error: Not in a UserModule. Likely cause: Missed Module() wrap, bare chisel API call, or attempting to construct hardware inside a BlackBox.
[error] chisel3.internal.ChiselException: Error: Not in a UserModule. Likely cause: Missed Module() wrap, bare chisel API call, or attempting to construct hardware inside a BlackBox.
[error] at chisel3.internal.throwException$.apply(Error.scala:85)
[error] at chisel3.internal.Builder$.forcedUserModule(Builder.scala:298)
[error] at chisel3.internal.Builder$.pushOp(Builder.scala:336)
[error] at chisel3.SInt.do_asUInt(Bits.scala:925)
[error] at cpu.alu$.$anonfun$new$2(Main.scala:26)
[error] at cpu.alu$.$anonfun$new$2$adapted(Main.scala:18)
[error] at chiseltest.backends.treadle.TreadleBackend.$anonfun$run$1(TreadleBackend.scala:144)
[error] at chiseltest.internal.ThreadedBackend$TesterThread$$anon$1.$anonfun$run$1(ThreadedBackend.scala:453)
[error] at chiseltest.backends.treadle.TreadleBackend.doTimescope(TreadleBackend.scala:103)
[error] at chiseltest.internal.ThreadedBackend$TesterThread$$anon$1.run(ThreadedBackend.scala:453)
[error] at java.lang.Thread.run(Thread.java:748)
[error] stack trace is suppressed; run last Test / bgRunMain for the full output
[error] Nonzero exit code: 1
[error] (Test / runMain) Nonzero exit code: 1
我想不出解决这个问题的正确方法。任何帮助将不胜感激。
作为引用,ALU 非常简单,这是 ALU 类:
class ALU extends Module {
val io = IO(new Bundle {
val ctl = Input(UInt(Control.ALU_BITWIDTH))
val src0 = Input(UInt(Instructions.WORD_SIZE.W))
val src1 = Input(UInt(Instructions.WORD_SIZE.W))
val out = Output(UInt(Instructions.WORD_SIZE.W))
})
val shift = io.src1(3,0).asUInt
/* Lookup the operation to execute */
io.out := MuxLookup(io.ctl, 0.U, Seq(
Control.ALU_ADD -> (io.src0 + io.src1),
Control.ALU_SUB -> (io.src0 - io.src1),
Control.ALU_AND -> (io.src0 & io.src1),
Control.ALU_OR -> (io.src0 | io.src1),
Control.ALU_XOR -> (io.src0 ^ io.src1),
Control.ALU_NOT -> (~io.src0),
Control.ALU_SLL -> (io.src0 << shift),
Control.ALU_SRL -> (io.src0 >> shift),
))
}
最佳答案
这感觉有点恶心,但至少它是可扩展的(也许是一个可能的解决方案?)...我仍然对在测试框架中将 SInt 转换为 UInt 的最佳方式感兴趣。
/* Sub */
c.io.ctl.poke(Control.ALU_SUB)
c.io.src0.poke(4321.U)
c.io.src1.poke(1234.U)
c.io.out.expect(3087.U)
c.io.src0.poke(1234.U)
c.io.src1.poke(4321.U)
def bitwidth = 16 // for example
def max = scala.math.pow(2,bitwidth).toInt
c.io.out.expect((max-3087).U)
关于scala - 凿子测试 : Cast a signed int to unsigned int for an expected value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66294784/
时钟门控对于降低功耗很重要。我们如何在 Chisel 中指定时钟门控? 时钟门控是逻辑信号确定特定寄存器的时钟是否被触发的地方。当逻辑信号无效时,时钟保持稳定不变。只有当使能有效时,时钟信号才会切换,
我最近将我的一个大项目的 Chisel 版本从 3.1.1 更新到 3.4.0;但是,我得到了一堆 firrtl.passes.CheckHighFormLike$DefnameDifferentPo
是否有可能在 Chisel“switch”语句中使用类似于 Verilog“默认”情况的 Chisel“is”条件?这是为了防止从 FSM 推断出组合输出的锁存器。 Verilog 示例: mod
我是一名优秀的程序员,十分优秀!