4

I have the following code:

constant HALF_RANGE: unsigned(RANGE_WIDTH-1 downto 0) := (RANGE_WIDTH-1 => '1', others=>'0');

where RANGE_WIDTH is a generic of type integer. It does exactly what is should: Generate a constant where the first bit is 1 and the others 0. The only problem is: It generates a waring using Questa Sim:

(vcom-1073) Non-locally static choice (association #1, choice #1) is allowed only if it is the only choice of the only association.

What does this warning mean? What would be the right way to define such a constant?

Botnic
  • 2,245
  • 2
  • 19
  • 33
  • 1
    "RANGE_WIDTH is a generic integer" - where did you declare it? – Bruce Abbott Oct 30 '17 at 16:34
  • 1
    The others choice in an aggregate is limited when there are choices that are not locally static. The idea here is that you generate object code during analysis (compiling), not during elaboration (linking). You could write a function and use it to return (the same) constant's value during elaboration or use another form of expression. –  Oct 30 '17 at 18:33
  • @BruceAbbott: RANGE_WIDTH has been declared in the entity. – Botnic Oct 31 '17 at 07:59

1 Answers1

6

Just in case the comments weren't clear: the warning means that you cannot use more than one choice in an array aggregate if you're using a non-static value (a generic or something derived from a generic) to define the ranges or positions. I don't know, however, why the restriction exists.

There is a simple workaround to defining such constants. Just break the constant into smaller pieces that can be defined with an aggregate with only one choice and then concatenate them. Useful for simple cases like this:

constant HALF_RANGE: unsigned(RANGE_WIDTH - 1 downto 0) := '1'&(RANGE_WIDTH - 2 downto 0 => '0');

I'm not sure if a better solution exists since whatever you derive from a generic becomes non-static, but I'm not an expert.

  • Oh, in this particular case you could also convert an integer to std_logic_vector (didn't test though): std_logic_vector(to_unsigned(2**(RANGE_WIDTH - 1), RANGE_WIDTH)) – Miloš Ljubotina Aug 02 '18 at 13:04