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:

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

    <code>
    > 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

    --
    A: Because it fouls the order in which people normally read text.
    Q: Why is top-posting such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    alb, Aug 8, 2013
    #1
    1. Advertising

  2. alb

    Jim Lewis Guest

    Re: ModelSim ** Warning: <foo.vhd> Choice in CASE statementalternative must be locally static.

    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
    Jim Lewis, Aug 8, 2013
    #2
    1. Advertising

  3. alb

    Andy Guest

    Re: ModelSim ** Warning: <foo.vhd> Choice in CASE statementalternative must be locally static.

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

    alb Guest

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

    Hi Jim,

    On 08/08/2013 21:40, Jim Lewis wrote:
    > 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?
    alb, Aug 10, 2013
    #4
  5. alb

    alb Guest

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

    On 09/08/2013 01:31, Andy wrote:
    > 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.
    alb, Aug 10, 2013
    #5
  6. alb

    Andy Guest

    Re: ModelSim ** Warning: <foo.vhd> Choice in CASE statementalternative must be locally static.

    On Friday, August 9, 2013 7:05:40 PM UTC-5, alb wrote:
    > 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
    Andy, Aug 10, 2013
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kenneth Johansson
    Replies:
    9
    Views:
    8,779
    Mike Treseler
    May 9, 2005
  2. Replies:
    3
    Views:
    371
    John Roth
    Jul 29, 2005
  3. .rhavin grobert

    vector: Foo[5] == ((foo*)Foo) + 5 ?

    .rhavin grobert, Sep 23, 2008, in forum: C++
    Replies:
    4
    Views:
    377
    JaredGrubb
    Sep 24, 2008
  4. Peter
    Replies:
    9
    Views:
    4,593
    Peter
    Feb 21, 2011
  5. Replies:
    4
    Views:
    130
    Thomas 'PointedEars' Lahn
    Dec 23, 2007
Loading...

Share This Page