Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Another syntax question

14 views
Skip to first unread message

Daku

unread,
Jan 23, 2012, 2:43:17 AM1/23/12
to
Please pardon me if this is a very stupid question. My Verilog
is rusty. Could some Verilog guru please explain what the
following means ? I have seen it before, and it seems very
complicated. Does it mean that if sum[25] == true, normalshift is
assigned 0, and so on down the chain.
Thanks for your help.


assign normalshift =

sum[25] ? 0 :

sum[24] ? 1 :

sum[23] ? 2 :

sum[22] ? 3 :

sum[21] ? 4 :

sum[20] ? 5 :

sum[19] ? 6 :

sum[18] ? 7 :

sum[17] ? 8 :

sum[16] ? 9 :

sum[15] ? 10 :

sum[14] ? 11 :

sum[13] ? 12 :

sum[12] ? 13 :

sum[11] ? 14 :

sum[10] ? 15 :

sum[9] ? 16 :

sum[8] ? 17 :

sum[7] ? 18 :

sum[6] ? 19 :

sum[5] ? 20 :

sum[4] ? 21 :

sum[3] ? 22 :

sum[2] ? 23 :

sum[1] ? 24 : 25;

glen herrmannsfeldt

unread,
Jan 23, 2012, 6:36:39 AM1/23/12
to
Daku <daku...@gmail.com> wrote:

> Please pardon me if this is a very stupid question. My Verilog
> is rusty. Could some Verilog guru please explain what the
> following means ? I have seen it before, and it seems very
> complicated. Does it mean that if sum[25] == true, normalshift is
> assigned 0, and so on down the chain.
> Thanks for your help.


> assign normalshift =
> sum[25] ? 0 :
> sum[24] ? 1 :
> sum[23] ? 2 :

(snip)

This is the conditional operator that came from C. (At least that
is where I first knew it in this form.)

So, yes, if sum[25] is true the value is zero (the left side of the : ),
otherwise it has the value of the expression on the right side of the :.

Whether that is a good way to implement a priority encoder, I don't
know.

The logic, as written, would be very slow, propagating all the way
through in the low sum[], high return value cases. The tools are very
good at optimizing much logic, and reasonably likely this one, too.

Even so, I probably wouldn't write it this way.

-- glen

Gabor

unread,
Jan 23, 2012, 3:29:15 PM1/23/12
to
Because the ? operator can be used in a continuous assignment it is
often used to generate multiplexers and encoders. The alternative
is to use a reg instead of a wire, and then in an always @* block
use a case statement. Normally I would not use the ? operator
for building very large encoders or multiplexers, however it is likely
that the synthesis tool will build the same hardware as if you
used a reg and a case statement.

I think this is more a matter of style than substance. Some people
like to keep combinatorial equations in continuous assigns rather
than using always @*, and may go to extreme lengths to make it happen
as you can see here. Still, once you know how it works, the code
is readable enough, I guess...

-- Gabor
0 new messages