How to cast UInt to SInt value in Chisel3?

我是研究僧i 提交于 2020-01-04 03:50:21

问题


As tile, how to cast UInt to SInt value in Chisel3 in right way? ig:

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

回答1:


It depends on if you want to reinterpret as an SInt (same width), or actually cast (ie. casting an 8-bit UInt results in a 9-bit SInt).

You should reinterpret a UInt to an SInt by calling .asSInt on the UInt. eg. opC.asSInt, the result will be the same width.

You should cast a UInt to an SInt by calling .zext on the UInt. eg. opC.zext, the result will be 1-bit wider with a zero in the msb.



来源:https://stackoverflow.com/questions/49081218/how-to-cast-uint-to-sint-value-in-chisel3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!