ModelSim ** Warning: <foo.vhd> Choice in CASE statement alternativemust be locally static.

A

alb

Hi everyone,

my Modelsim version is:
pol@pcalb:firmware$ vsim -version
Model Technology ModelSim ACTEL vsim 10.1b Simulator 2012.04 Apr 27 2012

and I get the following warning when compiling my code:
** Warning: foo.vhd(123): Choice in CASE statement alternative must be locally static.

A reduced snippet of my code is here:

constant COMMAND_GET_EVENT : std_logic_vector(4 downto 0) := '0' & x"4";
state_machine : process(clk, rst)
begin

if (rst = '1') then
LVDS_STATE <= IDLE;
-- more stuff here ...
elsif rising_edge(clk) then
case LVDS_STATE is
when IDLE =>
-- some code here
when DECODE_COMMAND =>
case LVDS_DATA_IN_COMMAND(4 downto 0) is
when COMMAND_GET_EVENT => -- WARNING referring here!
-- some code here
</code>

I've seen in this post somebody else had a similar issue:
https://groups.google.com/forum/#!msg/comp.lang.vhdl/S9sRjLJbdqA/XUXdgnwY-c8J

but I do not have a to_unsigned function in my code and the constant
*is* locally static because is defined in the same architecture,
therefore I do not see the issue.

I will test with vhdl-2008 and report. But any clarification would be
appreciated.

Al
 
J

Jim Lewis

Prior to VHDL-2008, a locally static expression required the operands and result to be scalar. VHDL-2008 drops the scalar requirement and explicitly adds some IEEE packages (see text below). In short, it should work in VHDL-2008.

From VHDL-2002, 7.4.1 P113
"7.4.1 Locally static primaries
An expression is said to be locally static if and only if every operator in the expression denotes an implicitly
defined operator whose operands and result are _scalar_ and"

From VHDL-2008, 7.4.2, P139
"9.4.2 Locally static primaries
An expression is said to be locally static if and only if every operator in the expression denotes an implicitly
defined operator or an operator defined in one of the packages STD_LOGIC_1164, NUMERIC_BIT,
NUMERIC_STD, NUMERIC_BIT_UNSIGNED, or NUMERIC_STD_UNSIGNED in library IEEE, and if
every primary in the expression is a locally static primary, where a locally static primary is defined to be one
of the following:"

Jim
 
A

Andy

If your tools support vhdl-2008, it really helps. Modelsim's tools do support 2008, but 2008 has new reserved words that, if used in your pre-2008 written code, also cause a failure.

If for some reason you cannot use 2008, then you still have a couple of good options.

Initialize the constant with "00100" (not as readable)

Convert the case expression to an integer, and store it in a variable, then used that variable in the case statement. Then define your target expression constants as integers.

There are probably others...

Note that 2008 would also allow you to skip the variable for the converted case expression.

Andy
 
A

alb

Hi Jim,

Prior to VHDL-2008, a locally static expression required the operands
and result to be scalar. VHDL-2008 drops the scalar requirement and
explicitly adds some IEEE packages (see text below). In short, it
should work in VHDL-2008.

eheh, I had to look up the definition of a 'scalar type' in the LRM, I
didn't know an enumeration was a scalar... But I got your point.
From VHDL-2002, 7.4.1 P113 "7.4.1 Locally static primaries An
expression is said to be locally static if and only if every operator
in the expression denotes an implicitly defined operator whose
operands and result are _scalar_ and"

I wonder what was the reason for that... as long as it is a constant it
shouldn't really matter for a case statement, am I missing something?
 
A

alb

If your tools support vhdl-2008, it really helps. Modelsim's tools do
support 2008, but 2008 has new reserved words that, if used in your
pre-2008 written code, also cause a failure.

it doesn't seem to be the case, it compiles without warnings.
[]
Initialize the constant with "00100" (not as readable)

true, even though not so dramatic either. I guess I may specify the
constant as a wider signal (say 8 bits) and then do some gymnastic with
the ranges when comparing, but I guess that also won't improve readability.
Convert the case expression to an integer, and store it in a
variable, then used that variable in the case statement. Then define
your target expression constants as integers.

That is quite more attractive indeed. And having the constants as
integers will bu much more readable than what we currently have.
 
A

Andy

I wonder what was the reason for that... as long as
it is a constant it shouldn't really matter for a case
statement, am I missing something?

The idea is for the compiler to catch such errors at compile time, before elaboration has occurred. This allows a module to be compiled into a libraryand known to be good (WRT those things that had to be locally static) longbefore anyone had used it.

Things like unconstrained ports, deferred constants and generics get defined during elaboration, which is often transparent in today's tools. Synthesis usually combines compilation ("analysis" per LRM) and elaboration in one step. Most simulators combine elaboration and execution in one step. Some of Cadence's older simulators (NC and Leapfrog) separated the analysis, elaboration and execution into separate steps (I have no exprience with their later tools).

If an aspect of a module, such as the completeness and exclusiveness of a case statement, could be verified at compilation, then no matter how the module was instantiated or connected, it could not cause a future problem withthat aspect. This has been somewhat relaxed in 2008 with the allowance of the case expression (but not the target expressions!) to be globally static.. The resulting, reduced benefit of the target expressions being locally static is to ensure that no target expression values are repeated, whereas before they could also be ensured to be complete.

Hope this helps,

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top