Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Case statement illusions ?

Reply
Thread Tools

Case statement illusions ?

 
 
Neo
Guest
Posts: n/a
 
      05-02-2005
Info,
The code above given by you for onehot did sysnthesize differently. the
"case" version systhesized to 3 LUT's involving only OR gates and didnt
infer priority structure infact it optimized as you have mentioned to a
series of OR gates. But the "if" version systhesiszed to 6 LUT's and
inferred a priority structure. Leonardo was used for the systhesis.

 
Reply With Quote
 
 
 
 
backhus
Guest
Posts: n/a
 
      05-02-2005
Hi Symon,
for (most) of the given examples case and if-elsif will give the same result.
Why?
Because in both cases your selector is fully covered (uses all of the bits of a vector or whatever you use as a
selector). Your if-elsif collapses into a parallel structure, because there is no priority of one value over the other
possible.

but how about this:

Selector <= A&B&C; -- I MUST do this for a case statement !
case Selector is
when "001" => Output <= Input1;
when "010" => Output <= Input2;
when "100" => Output <= Input2;
when others => Output <= (others => 'Z');
end case;

vs.

If C = '1' then
Output <= Input1;
elsif B= '1' then
Output <= Input2;
elsif C= '1' then
Output <= Input3;
else
Output <= (others => 'Z');
end if;

NOW the case produces a parallel multiplexer structure that is sensitive for the given code of Selector.
The if-elsif does something different. Whenever C becomes '1' (No matter how unlikely or unneccesary this might be in
your particular design) it switches Input1 to the output. Here we have the always cited priority encoder.

To get the same functionality with a case you have to write a different code:

Selector <= A&B&C; -- I MUST do this for a case statement !
case Selector is
when "--1" => Output <= Input1;
when "-10" => Output <= Input2;
when "100" => Output <= Input2;
when others => Output <= (others => 'Z');
end case;

Now the first >when< hits whenever C becomes '1'.
This code might produce something more "parallel" than the if-elsif, but who knows about the tricks of modern synthesis
tools.

Have a nice synthesis

Eilert



 
Reply With Quote
 
 
 
 
info_
Guest
Posts: n/a
 
      05-04-2005
Neo wrote:
> Info,
> The code above given by you for onehot did sysnthesize differently. the
> "case" version systhesized to 3 LUT's involving only OR gates and didnt
> infer priority structure infact it optimized as you have mentioned to a
> series of OR gates. But the "if" version systhesiszed to 6 LUT's and
> inferred a priority structure. Leonardo was used for the systhesis.
>

Yes my point exactly. Not all tools do this correctly. Leoanrdo is right.
Just try Precision Synthesis (or other tools) if you can and compare
the results.

The if .. elsif is a priority encoder which has a well defined behavior
for the overlapping cases (more than one 1 in the vector), and this
requires more logic than the "pure one hot". This edscription is
more predictible acroos tools.


Bert
 
Reply With Quote
 
info_
Guest
Posts: n/a
 
      05-04-2005
backhus wrote:

> Hi Symon,
> for (most) of the given examples case and if-elsif will give the same
> result.
> Why?
> Because in both cases your selector is fully covered (uses all of
> the bits of a vector or whatever you use as a selector). Your if-elsif
> collapses into a parallel structure, because there is no priority of one
> value over the other possible.
>
> but how about this:
>
> Selector <= A&B&C; -- I MUST do this for a case statement !
> case Selector is
> when "001" => Output <= Input1;
> when "010" => Output <= Input2;
> when "100" => Output <= Input2;
> when others => Output <= (others => 'Z');
> end case;
>
> vs.
>
> If C = '1' then
> Output <= Input1;
> elsif B= '1' then
> Output <= Input2;
> elsif C= '1' then
> Output <= Input3;
> else
> Output <= (others => 'Z');
> end if;
>
> NOW the case produces a parallel multiplexer structure that is sensitive
> for the given code of Selector.
> The if-elsif does something different. Whenever C becomes '1' (No matter
> how unlikely or unneccesary this might be in your particular design) it
> switches Input1 to the output. Here we have the always cited priority
> encoder.
>
> To get the same functionality with a case you have to write a different
> code:
>
> Selector <= A&B&C; -- I MUST do this for a case statement !
> case Selector is
> when "--1" => Output <= Input1;
> when "-10" => Output <= Input2;
> when "100" => Output <= Input2;
> when others => Output <= (others => 'Z');
> end case;
>
> Now the first >when< hits whenever C becomes '1'.
> This code might produce something more "parallel" than the if-elsif, but
> who knows about the tricks of modern synthesis tools.
>
> Have a nice synthesis
>
> Eilert


Just a few errors :

1. you can in fact qualify the expression and not use a signal.
A variable is usually preferable if you want one (otherwise,
you must add Selector in your sensitivity list, and this slows down
the simulation without usefulness).

case SLV3'(A&B&C) is -- with subtype SLV3 is std_logic_vector (3 downto 0);

2.
output <= 'Z' infers a tristate, nothing to do with a don't care!
A don't care '-' does eliminate C from the result.

3. case ... is when "--1" is wrong !
Comparing anything (but a '-') to '-' produces a false.
Comparing with '-' (to ignore the comparison) requires the use
of std_match (not usable in case statement).


VHDL is not always intuitive...


Bert Cuzeau
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Interactive Optical Illusions - Explore & Train Your Vision System ASCII Digital Photography 2 03-28-2011 09:53 AM
Melting Ice, Inconvenient Truth, Shattered Illusions Global Warming Digital Photography 4 01-29-2008 05:06 AM
(update) If all were just illusions ? Daniel Rocha Digital Photography 1 02-06-2006 08:25 PM
if statement that, when false, skips first statement in its block, executes second? Jay McGavren Java 11 01-16-2006 05:49 PM
How do I do a conditional statement in a constant statement? tkvhdl@gmail.com VHDL 3 12-16-2005 06:13 PM



Advertisments