Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 测试:为期望值将有符号整数强制转换为无符号整数_Scala_Chisel - Fatal编程技术网

Scala 测试:为期望值将有符号整数强制转换为无符号整数

Scala 测试:为期望值将有符号整数强制转换为无符号整数,scala,chisel,Scala,Chisel,在使用新的测试框架进行单元测试时,我很难确定将有符号int转换为无符号int的正确方法 下面是我用来单元测试ALU的方法(示例为16位),问题是它不可伸缩: test(新ALU){c=> ... /*潜艇*/ c、 io.ctl.poke(控制模块) 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、

在使用新的测试框架进行单元测试时,我很难确定将有符号int转换为无符号int的正确方法

下面是我用来单元测试ALU的方法(示例为16位),问题是它不可伸缩:

test(新ALU){c=>
...
/*潜艇*/
c、 io.ctl.poke(控制模块)
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的赞美*/
}
这个方法的问题是,当我生成一个32位ALU(它输出一个无符号int)时,单元测试将失败,因为使用上面的hacky string方法,字符串将零扩展到32位

我想这样重写测试:

test(新ALU){c=>
/*潜艇*/
c、 io.ctl.poke(控制模块)
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)凿毛3.internal.凿毛异常:错误:不在用户模块中。可能的原因:缺少Module()包装、裸凿API调用或试图在黑盒中构造硬件。
[错误]凿子3.internal.凿子异常:错误:不在UserModule中。可能的原因:缺少Module()包装、裸凿API调用或试图在黑盒中构造硬件。
[error]位于3.internal.throweexception$.apply(error.scala:85)
[错误]位于3.internal.Builder$.forcedUserModule(Builder.scala:298)
[错误]位于3.internal.Builder$.pushOp(Builder.scala:336)
凿子3.SInt.do_asUInt处的[错误](位scala:925)
[错误]位于cpu.alu$.$anonfun$new$2(Main.scala:26)
[错误]位于cpu.alu$.$anonfun$new$2$adapted(Main.scala:18)
[错误]在测试时。后端。踏板。踏板靠背。$anonfun$run$1(踏板靠背。scala:144)
[错误]位于.test.internal.ThreadedBackend$tester读取$$anon$1.$anonfun$run$1(ThreadedBackend.scala:453)
[错误]在测试时。后端。踏板。踏板后端。doTimescope(踏板后端。scala:103)
[error]位于kivetest.internal.ThreadedBackend$testerRead$$anon$1.run(ThreadedBackend.scala:453)
java.lang.Thread.run(Thread.java:748)处的[error]
[错误]堆栈跟踪被抑制;运行最后一个测试/bgRunMain以获得完整输出
[错误]非零退出代码:1
[错误](测试/运行主机)非零退出代码:1
我想不出解决这个问题的正确方法。任何帮助都将不胜感激

作为参考,ALU非常简单,下面是ALU类:

类ALU扩展模块{ val io=io(新捆绑){ val ctl=输入(UInt(Control.ALU_BITWIDTH)) val src0=输入(UInt(Instructions.WORD\u SIZE.W)) val src1=输入(UInt(Instructions.WORD\u SIZE.W)) val out=输出(UInt(Instructions.WORD_SIZE.W)) }) val shift=io.src1(3,0).asUInt /*查找要执行的操作*/ io.out:=MuxLookup(io.ctl,0.U,序列( Control.ALU_ADD->(io.src0+io.src1), Control.ALU_SUB->(io.src0-io.src1), Control.ALU_和->(io.src0和io.src1), Control.ALU_或->(io.src0 | io.src1), Control.ALU_XOR->(io.src0^io.src1), Control.ALU_NOT->(~io.src0), Control.ALU_SLL->(io.src0(io.src0>>移位), )) }
这感觉有点恶心,但至少它是可伸缩的(可能是一个可能的解决方案?)。我仍然对在测试框架中将SInt转换为UInt的最佳方法感兴趣

/*Sub*/
c、 io.ctl.poke(控制模块)
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//例如
def max=scala.math.pow(2,位宽).toInt
c、 io.out.expect((max-3087.U)

基于@tonysamaritano的解决方案进行了一些改进。 编写一个独立的Scala函数,使其看起来更好

ToSInt(x: Int): Int = scala.math.pow(2, bitwidth).toInt - x

顺便说一句,我的ScreetTest版本配置为
“ScreetTest”->“0.2.1+”
,这更美观,可读性更强,这是一个很好的建议。