chisel - 如何在 Chisel3 中将 UInt 转换为 SInt 值?

标签 chisel

作为tile,如何在Chisel3中以正确的方式将UInt转换为SInt值? IG:

val opC    = RegInit(0.U(64.W))
val result = RegInit(0.U(64.W))
result := Mux(opC.toSInt > 0.S, opC, 0.U)

最佳答案

这取决于您是否想要重新解释为 SInt(相同宽度),或者实际转换(即转换 8 位 UInt 会产生 9 位 SInt)。

您应该通过在 UInt 上调用 .asSInt 将 UInt 重新解释为 SInt。例如。 opC.asSInt,结果将具有相同的宽度。

您应该通过调用 UInt 上的 .zext 将 UInt 强制转换为 SInt。例如。 opC.zext,结果将加宽 1 位,最高位为零。

关于chisel - 如何在 Chisel3 中将 UInt 转换为 SInt 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49081218/

相关文章:

scala - bool Scala/Chisel 的选项方法

scala - 为什么 chisel UInt(32.W) 不能取 bit[32] 恰好为 1 的无符号数?

scala - 使用 MixedVec 在 chisel 中使用动态参数创建 IO 包

Chisel 测试台 : controlling multiple ports independently

chisel - 如何在Chisel中使用参数化模块生成Verilog代码?

Chisel 语言如何最好地使用队列?

scala - 凿子测试 : Cast a signed int to unsigned int for an expected value

scala - 如何在 expect() 中看到错误值时生成 [error] 而不是 [info]

chisel - 在 Chisel 中将 Bundle Register 初始化为全 1 的最佳方法是什么?