凿子UInt负值错误 [英] Chisel UInt negative value error

查看:272
本文介绍了凿子UInt负值错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始在scala工作,需要创建 MD5 的实现. .据我了解,MD5需要未签名的类型,而scala并不附带此类型.很快我将开始学习具有无符号类型的Chisel,因此我决定实现其库.到目前为止,一切似乎都很好,除非执行以下按位操作时,我的F值变为-271733879,这将导致错误由于:java.lang.IllegalArgumentException:要求失败:UInt文字-271733879为负",因为UInt无法执行是负面的.

I have recently started work in scala, and am required to create an implementation of MD5. It is my understanding that MD5 requires unsigned types, which scala does not come with. As I will soon begin Chisel, which does have unsigned types, I decided to implement its library. Everything appears good so far, except when doing the below bitwise operations, my F value becomes -271733879, which causes an error "Caused by: java.lang.IllegalArgumentException: requirement failed: UInt literal -271733879 is negative" as UInts can't be negative.

if(i<16){
      F = ((B & C) | ((~B) & D))
      g = i
}

错误消息还有很多,但是由于此错误而导致错误的只是不同库和类的跟踪列表,因此我没有发布它,因为我认为这并不重要.如果是这样,我可以对其进行编辑并将其全部发布.

There is more to the error message, but it is just the trace list of different libraries and classes that had an error because of this error, and thus I did not post it because I didn't think it was important. If it was, I can edit this and post it all.

我的B,C和D值等于下面列出的小写字母,这是第一次通过for循环,因此它们尚未更新.

My B, C, and D values are equal to the lower case equivalents listed below, and it is the first time through the for loop so they have not yet updated.

var a0 : UInt = UInt(0x67452301)
var b0 : UInt = UInt(0xefcdab89)
var c0 : UInt = UInt(0x98badcfe)
var d0 : UInt = UInt(0x10325476)

任何帮助将不胜感激.

推荐答案

为了我的回答,我使用Chisel 3首选的123.U样式指定文字,而不是Chisel 2 UInt(123)样式,但这答案对任何一个都有效.

For the sake of my answer, I am using the Chisel 3 preferred 123.U style for specifying literals rather than the Chisel 2 UInt(123) style, but this answer works for either.

您可以通过多种方式执行此操作:

There are several ways you could do this:

  • 使用Scala Long(在文字末尾放置L)
    • val myUInt = 0x98badcfeL.U
    • 这显然不适用于64位以上的计算机
    • Use Scala Long (put L at end of literal)
      • val myUInt = 0x98badcfeL.U
      • This obviously won't work for larger than 64-bit
      • val myUInt = BigInt("98badcfe", 16).U
      • val myUInt = "x98badcfe".U
      • hex = x | h,dec = d,oct = o,bin = b

      这篇关于凿子UInt负值错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆