asUint vs U

Skip to first unread message

Martin Schoeberl

Jan 19, 2022, 4:08:21 PMJan 19
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.


Kevin Laeufer

Jan 19, 2022, 4:09:51 PMJan 19
I only use `.U` when I want to convert a Scala Int/BigInt to a Chisel UInt.

> --
> 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
> <>.
> To view this discussion on the web visit
> <>.

Richard Lin

Jan 19, 2022, 4:27:12 PMJan 19
to, 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
0 new messages