0 bit wide integers

27 views
Skip to first unread message

Øyvind Harboe

unread,
Jan 27, 2022, 9:36:44 AMJan 27
to chisel-users
I'm curious, why doesn't Chisel support 0.U(0.W)?

Just like empty lists, 0.U(0.W) can be useful when expressing some things, like concatening a list of UInt's where some of those can be empty...

Øyvind Harboe

unread,
Jan 28, 2022, 6:01:39 AMJan 28
to chisel-users
So here's my use-case. I want to replace some bits within an UInt. UInt's are immutable(which is good!), so I have to create a new UInt from the old UInt.

In this case, what I want to express half open intervals(https://en.wikipedia.org/wiki/Interval_(mathematics) that can be empty.

When I try to do this with UInt's that can't express zero width integers, I get iffy (lots of conditional code) code...

      offset - offset of bits to replace. [0, width>
      width - width of bits to replace. [1, width]

            // not iffy, but it's a bit of an eyesore with the VecInit()...
val s = bits.asBools()
bits = VecInit(
(s.slice(0, offset) ++
data(i)
.asBools() ++
s.slice(offset + width, bits.getWidth))
).asUInt()


The above code is sloooow to elaborate... I tried with 1024 bits and it times out...

Jack Koenig

unread,
Jan 28, 2022, 8:04:38 PMJan 28
to chisel...@googlegroups.com
You're absolutely right that Chisel3 should support "Zero-width Wires", it really is just a lack of engineering time to implement it.
There is partial support internally for zero-width wires to deal with them when they crop up, but we don't let users instantiate them directly.

It's true that this does result in lots of annoying conditional code. I'm sorry about that. 

Even with the limitation, I would still recommend sticking to word-level logic when you can (even with annoying conditional guards), something like https://scastie.scala-lang.org/OIr9yfuQSiO5UivV8VEuYQ.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/chisel-users/204bd429-bf8c-4bc5-a963-2360ff8d9079n%40googlegroups.com.

Øyvind Harboe

unread,
Jan 29, 2022, 3:09:42 AMJan 29
to chisel-users
That's good to hear! Looking forward to this feature :-)

The problem with not having zero width integers can't be fixed by me doing something.

The problem is not writing code, but me writing code that can fail because I don't realize that I'm relying on zero width integers for it to be fully general....

Once the code fails, I have to debug it and then add in some code or other to work around the problem. Debugging and fixing the code isn't the problem, the problem is that it fails.
Reply all
Reply to author
Forward
0 new messages