Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Discrete range in CASE

Reply
Thread Tools

Discrete range in CASE

 
 
hssig
Guest
Posts: n/a
 
      01-04-2010
Hi,

I have the following VHDL case structure:

signal numa : unsigned(2 downto 0);

constant cA : unsigned(2 downto 0) := "000";
constant cB : unsigned(2 downto 0) := "001";
constant cC : unsigned(2 downto 0) := "100";

process(rstn, clk)
begin
if rstn='0' then
numa <= "000";

elsif rising_edge(clk) then
...

case to_integer(numa) is
when to_integer(cA) => ...
when to_integer(cB) to to_integer(cC) => ...
when others => ...
end case;

end if;

end process;


When trying to insert a (Lattice) Reveal core I get the following
error message:

"ERROR: case choice must be a locally static expression (VHDL-143"

How can I make use of the discrete range choice without violating the
static expression rule ?
Thank you for your opinion.


Cheers,
hssig



 
Reply With Quote
 
 
 
 
Jonathan Bromley
Guest
Posts: n/a
 
      01-04-2010
On Mon, 4 Jan 2010 03:03:25 -0800 (PST), hssig wrote:

>signal numa : unsigned(2 downto 0);
>
>constant cA : unsigned(2 downto 0) := "000";
>constant cB : unsigned(2 downto 0) := "001";
>constant cC : unsigned(2 downto 0) := "100";
>
>process(rstn, clk)
>begin
> if rstn='0' then
> numa <= "000";
>
> elsif rising_edge(clk) then
> ...
>
> case to_integer(numa) is
> when to_integer(cA) => ...
> when to_integer(cB) to to_integer(cC) => ...
> when others => ...
> end case;
>
> end if;
>
>end process;


>"ERROR: case choice must be a locally static expression (VHDL-143"
>
>How can I make use of the discrete range choice without violating the
>static expression rule ?


"Locally static" in VHDL is a very aggressive restriction and
there's not much you can do about it. Function call in the
case choice is a no-no, sorry.

I suggest you re-cast your code so that the original constants
are integers:

--- Useful bits and pieces
subtype u3 is unsigned(2 downto 0);
subtype i3 is integer range 0 to (2**u3'length - 1);
function to_u3(n: i3) return u3 is begin
return to_unsigned(n, u3'length);
end;

--- Your constants as proper integers
constant nA : i3 := 0;
constant nB : i3 := 1;
constant nC : i3 := 4;

--- Your unsigned signals and constants,
--- derived from the original integers
signal numa: u3;
constant cA: u3 := to_u3(nA);
constant cB: u3 := to_u3(nB);
constant cC: u3 := to_u3(nC);

--- Now the case statement should be OK,
--- as well as being easier to read:
case to_integer(numa) is
when nA => ...
when nB to nC => ...
when others => ...
end case;

Hope this helps
--
Jonathan Bromley
 
Reply With Quote
 
 
 
 
Andy
Guest
Posts: n/a
 
      01-04-2010
On Jan 4, 6:43*am, Brian Drummond <(E-Mail Removed)>
wrote:
> On Mon, 4 Jan 2010 03:03:25 -0800 (PST), hssig <(E-Mail Removed)> wrote:
> >Hi,

>
> >I have the following VHDL case structure:

>
> >signal numa : unsigned(2 downto 0);
> >constant cA : unsigned(2 downto 0) := "000";
> >constant cB : unsigned(2 downto 0) := "001";
> >constant cC : unsigned(2 downto 0) := "100";

>
> ...
>
> > * * * * case to_integer(numa) is
> > * * * * * *when to_integer(cA) => ...
> > * * * * * *when to_integer(cB) to to_integer(cC) => ...
> > * * * * * *when others => *...
> > * * * * end case;
> >"ERROR: case choice must be a locally static expression (VHDL-143"

>
> >How can I make use of the discrete range choice without violating the
> >static expression rule ?

>
> The number of type conversions here suggest you are fighting the type system
> instead of using it... that's often a hint that the design can be improved.
>
> Assuming you need to write the constant values in binary for clarity, one way is
> to keep them in integer form, and write
>
> subtype numaRange is
> constant cA : natural range 0 to 7 := 2#000#;
> subtype BtoC is natural range 2#
> and
> * * * * *case to_integer(numa) is
> * * * * * * * * when cA => ...
> * * * * * * * * when BtoC => ...
>
> Much less clutter. And it avoids functions in the case arm branches, which is
> the likely cause of the error...
>
> The meaning of "to_integer" is not locally defined; since it is a function
> declared somewhere else, it may not even have been written yet!
>
> Thinking hardware, a case statement typically generates a multiplexer.
>
> So while a function call in the case variable is allowed (you can select a
> different multiplexer input depending on external conditions), a function call
> in a case arm would change the shape of the hardware implementation if the
> function evaluated differently ... it's not surprising that isn't allowed..
>
> The fact that it is a standard function from a standard library is known to you,
> but not to me, or the compiler. *From the code you posted (no use clauses) I
> can't tell if you are using the "real" unsigned, (from numeric_std), or an
> impostor (from the Synopsis libraries) or even your own implementation.
>
> VHDL doesn't cheat and impose special case meanings on your code - even at the
> level of assuming '1' = true and '0' = false. That decision is (IMO, correctly)
> kept outside the language, in the libraries. So you could implement negative
> logic systems simply by replacing std_logic_1164 and numeric_std with their
> negative logit equivalents. (If ECL ever comes back into fashion, this could be
> a big win for VHDL over that other language, but I'm not holding my breath!)
>
> You do have to be explicit about what you mean - in your case, simply using
> integer ranges will do. IMO the result is cleaner - and easier for the next guy
> to read and understand..
>
> - Brian


IINM, the reason for the locally static restriction on choice
expressions is because the case statement choices must be evaluated at
analysis time (before elaboration) to determine that they are complete
and mutually exclusive. Non-locally static function calls cannot be
evaluated at analysis time, and therefore the set of choices cannot be
evaluated for completeness and mutual exclusivity.

Andy
 
Reply With Quote
 
hssig
Guest
Posts: n/a
 
      01-04-2010
Hi,

thank you for your answers.

@Brian:
I use "std_logic_arith" and "numeric_std".

The constant definition "constant cA : natural range 0 to 7 :=
2#000#;"
is clear to me. But how do you use the proposed subtypes

subtype numaRange is
subtype BtoC is natural range 2#

? What is their purpose ?


Cheers,
hssig
 
Reply With Quote
 
hssig
Guest
Posts: n/a
 
      01-04-2010
Sorry, I mean:
"std_logic_1164" and "numeric_std"

Cheers,
hssig
 
Reply With Quote
 
Mike Treseler
Guest
Posts: n/a
 
      01-05-2010
hssig wrote:

> How can I make use of the discrete range choice without violating the
> static expression rule ?


I like to use cases of enumerated types, but ...

If I couldn't change your declarations, I would use
if, elsif, elsif, ..., else
You will get no such errors,
the conditions can be whatever you like,
and it won't cost any gates unless you really need them.

-- Mike Treseler

 
Reply With Quote
 
Jonathan Bromley
Guest
Posts: n/a
 
      01-05-2010
On Tue, 05 Jan 2010 00:18:34 +0000, Brian Drummond wrote:

>And when you extend the design, hopefully you only need to change the subtype
>and maybe constant declarations:
> subtype u3 is unsigned(4 downto 0);
> -- oops! hence in my opinion: name it after its purpose, not its size!
> subtype numaRange is unsigned(4 downto 0);


Yes, of course Brian is completely right about this -
unless, as occasionally happens, the size is an essential
part of the nature of the thing. Apologies for the
illiterate programming.[*]
[*] If Brian can use Knuth as a stick to beat me with,
there's no reason why I shouldn't do so myself
--
Jonathan Bromley
 
Reply With Quote
 
hssig
Guest
Posts: n/a
 
      01-06-2010
Thank you.

Cheers,
hssig
 
Reply With Quote
 
JimLewis
Guest
Posts: n/a
 
      01-07-2010
Hssig,
In VHDL-2008, array types and functions in std_logic_1164 and
numeric_std became locally static.

Does lattice have a language switch for VHDL-2008? If not submit the
issue as a bug since it is supported in the current revision of the
language - approved by IEEE in September 2008 and approved by
Accellera as a trial standard in July 2006, so vendors really don't
have an excuse for not having implemented it at this point.

Best,
Jim
SynthWorks
 
Reply With Quote
 
HT-Lab
Guest
Posts: n/a
 
      01-08-2010

"JimLewis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hssig,
> In VHDL-2008, array types and functions in std_logic_1164 and
> numeric_std became locally static.
>
> Does lattice have a language switch for VHDL-2008? If not submit the
> issue as a bug since it is supported in the current revision of the
> language - approved by IEEE in September 2008 and approved by
> Accellera as a trial standard in July 2006, so vendors really don't
> have an excuse for not having implemented it at this point.


Unfortunately the excuse they gave me is that not many users are asking for it!
I find this very frustrating since there are some very basic language
enhancements which can make your code a lot cleaner, examples are:

1) Reading output ports
2) Case statement with don't care support
3) Expressions in port maps
4) Process(all)
5) Generic on packages

So have a look at the new language features and then send an email to your
vendor, it shouldn't take long!

Hans
www.ht-lab.com


>
> Best,
> Jim
> SynthWorks



 
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
static discrete range in generate statements SameerDS VHDL 4 03-24-2010 04:33 PM
VHDL For-Loop Index .. can it be of discrete range ? omara007 VHDL 0 05-05-2009 11:56 PM
error "choice must be discrete range" with CASE Manfred Balik VHDL 3 04-30-2005 11:18 AM
Is there already a discrete range class? Sim Nanda C++ 3 10-06-2003 04:18 PM
where to have discrete color prints made? Beowulf Digital Photography 14 08-30-2003 06:44 PM



Advertisments