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

Discussion in 'VHDL' started by alb, Aug 8, 2013.

  1. alb

    alb Guest

    Hi everyone,

    my Modelsim version is:
    and I get the following warning when compiling my code:
    A reduced snippet of my code is here:


    I've seen in this post somebody else had a similar issue:!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

    alb, Aug 8, 2013
    1. Advertisements

  2. alb

    Jim Lewis Guest

    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,
    every primary in the expression is a locally static primary, where a locally static primary is defined to be one
    of the following:"

    Jim Lewis, Aug 8, 2013
    1. Advertisements

  3. alb

    Andy Guest

    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, Aug 9, 2013
  4. alb

    alb Guest

    Hi Jim,

    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.
    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?
    alb, Aug 10, 2013
  5. alb

    alb Guest

    it doesn't seem to be the case, it compiles without warnings.
    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.
    That is quite more attractive indeed. And having the constants as
    integers will bu much more readable than what we currently have.
    alb, Aug 10, 2013
  6. alb

    Andy Guest

    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, Aug 10, 2013
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.