EDAboard.com | EDAboard.eu | EDAboard.de | EDAboard.co.uk | RTV forum PL | NewsGroups PL

Another syntax question

Ask a question - edaboard.com

elektroda.net NewsGroups Forum Index - Verilog Language - Another syntax question

Daku
Guest

Mon Jan 23, 2012 9:43 am   



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
Guest

Mon Jan 23, 2012 1:36 pm   



Daku <dakupoto_at_gmail.com> wrote:

Quote:
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.


Quote:
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
Guest

Mon Jan 23, 2012 9:29 pm   



glen herrmannsfeldt wrote:
Quote:
Daku <dakupoto_at_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

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

elektroda.net NewsGroups Forum Index - Verilog Language - Another syntax question

Ask a question - edaboard.com

Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
RTV map EDAboard.com map News map EDAboard.eu map EDAboard.de map EDAboard.co.uk map Opony