gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:32:05 25 4
gpt4 key购买 nike

作为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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com