asUint vs U

109 views
Skip to first unread message

Martin Schoeberl

unread,
Jan 19, 2022, 4:08:21 PM1/19/22
to chisel...@googlegroups.com
Hi all,

as I am working on an update of my Chisel book, I am wondering what is the (real) difference between .U an .asUInt. Following code shows that they are almost identical:

class UIntVsU extends Module {
val io = IO(new Bundle() {
val values = Output(Vec(5, UInt(3.W)))
})

val v = io.values

v(0) := 7.U
v(1) := 7.asUInt
val scalaInt = 7
v(2) := scalaInt.U
v(3) := scalaInt.asUInt
val signed = WireDefault(-1.S(3.W))
v(4) := signed.asUInt
}


Just the SInt (and probably Bundle and Vec) cannot be converted to an UInt with .U

Is there any best practice which one to use? .U is for sure less typing.

Cheers,
MArtin

Kevin Laeufer

unread,
Jan 19, 2022, 4:09:51 PM1/19/22
to chisel...@googlegroups.com
I only use `.U` when I want to convert a Scala Int/BigInt to a Chisel UInt.

Kevin
> --
> You received this message because you are subscribed to the Google
> Groups "chisel-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to chisel-users...@googlegroups.com
> <mailto:chisel-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/chisel-users/B2D395D2-C52D-4798-ACF2-50F4A66254BD%40jopdesign.com
> <https://groups.google.com/d/msgid/chisel-users/B2D395D2-C52D-4798-ACF2-50F4A66254BD%40jopdesign.com?utm_medium=email&utm_source=footer>.

Richard Lin

unread,
Jan 19, 2022, 4:27:12 PM1/19/22
to chisel...@googlegroups.com, Kevin Laeufer
If I remember correctly, when these were first introduced, the idea was
to use .U for numeric literals (eg, 7.U) and .asUInt for variables (eg,
myScalaVariable.asUInt). I don't think there is a difference in
behavior, it's mostly a stylistic recommendation.
Reply all
Reply to author
Forward
0 new messages