Generates and "multiple sources"

A

Andy Peters

Here's a weird one. I have a boolean generic, say FOO, that is
determines how some logic is generated. When analyzing with ModelSim
XE 6.3c, I get a warning that says, "non-resolved signal 'bar' may
have multiple sources."

The idea is that I have a terminal count value, bar, of type natural.
Depending on the value of FOO, bar is assigned either a constant, or
the contents of a register which the user can change. The thinking is
I can save a few gates by making bar a constant in one circumstance.

Here's the skeleton, which gives the idea.

signal bar : natural range 0 to 127;
signal loadthis : natural range 0 to 127;
constant bletch : natural range 0 to 127 := 127;

FOO_Is_True : if (FOO) generate
begin
bar <= bletch;
end generate FOO_Is_True;

FOO_Is_False : if (not FOO) generate
begin
bar <= loadthis;
end generate FOO_Is_False;

I've done this sort of thing before, although with std_logic and not
natural. So obviously bar (of type natural) is not a resolved type
whereas std_logic is, which is why I've never seen this warning
before.

So I guess my question is: is ModelSim right to be this picky? I
suppose it is. When synthesized (or at least elaborated), the generic
(which has a default) will select the right case, and as long as I'm
smart enough not to actually do a multiple assignment, all is well.

Is there a better way to do this?

-a
 
K

Kevin Neilson

Andy said:
Here's a weird one. I have a boolean generic, say FOO, that is
determines how some logic is generated. When analyzing with ModelSim
XE 6.3c, I get a warning that says, "non-resolved signal 'bar' may
have multiple sources."

The idea is that I have a terminal count value, bar, of type natural.
Depending on the value of FOO, bar is assigned either a constant, or
the contents of a register which the user can change. The thinking is
I can save a few gates by making bar a constant in one circumstance.

Here's the skeleton, which gives the idea.

signal bar : natural range 0 to 127;
signal loadthis : natural range 0 to 127;
constant bletch : natural range 0 to 127 := 127;

FOO_Is_True : if (FOO) generate
begin
bar <= bletch;
end generate FOO_Is_True;

FOO_Is_False : if (not FOO) generate
begin
bar <= loadthis;
end generate FOO_Is_False;

I've done this sort of thing before, although with std_logic and not
natural. So obviously bar (of type natural) is not a resolved type
whereas std_logic is, which is why I've never seen this warning
before.

So I guess my question is: is ModelSim right to be this picky? I
suppose it is. When synthesized (or at least elaborated), the generic
(which has a default) will select the right case, and as long as I'm
smart enough not to actually do a multiple assignment, all is well.

Is there a better way to do this?

-a
This might not be a direct answer, but you can get the same effect
without the generate using what I call parameterizable mux-based
collapsing. A synthesizer will collapse the mux implied by an if-clause
if the condition is a constant. That is, you should get the same
synthesis results with:

if (FOO) then bar <= bletch;
else bar <= loadthis; end

You can check this, but just about any synthesizer is smart enough to
prune out a mux that has the select line tied to a constant. The only
drawback is that simulation speed is slowed somewhat, because the
if-clause is checked during simulation, whereas with a generate the IF
is only checked during compilaton. -Kevin
 
M

Mark McDougall

Kevin said:
if (FOO) then bar <= bletch;
else bar <= loadthis; end

I've used both techniques myself, and haven't seen any warnings - at least
none that I've noticed! :O

Regards,
 
T

Tricky

Here's a weird one. I have a boolean generic, say FOO,  that is
determines how some logic is generated. When analyzing with ModelSim
XE 6.3c, I get a warning that says, "non-resolved signal 'bar' may
have multiple sources."

This has come about because Modelsim has no way of knowing the value
of FOO at compile time, even if it is given a default value. The
problem with generates is that you cannot force them to be mutually
exclusive - ie. they dont support if-then-else. Because of this, the
compiler assumes that both generate statements are possible, and
because it sees bar assigned from 2 sources, it throws a warning.
There will not be a problem when you actually run the simulation or
synthesis because the full implementation of the generates will give
the correct connection. If it did try to connect it to two sources, as
it is non-resolved it would throw an error.

Does what Mark suggested would remove the warning and still work fine,
and should synthesize in the same way.
If FOO was declared as a constant instead of a generic, some compilers
may completly ignore the non-generated portion of code, the the point
where they even ignore syntax errors (I know this was true of
ActiveHDL a couple of years ago. Not true of modelsim now.)
 
K

KJ

Andy Peters said:
Here's a weird one. I have a boolean generic, say FOO, that is
determines how some logic is generated. When analyzing with ModelSim
XE 6.3c, I get a warning that says, "non-resolved signal 'bar' may
have multiple sources."

The key words here are 'may'...and that it's a 'warning'. Good to question
and peruse all warnings as you're doing, but they will not prevent you from
simulating.
I've done this sort of thing before, although with std_logic and not
natural. So obviously bar (of type natural) is not a resolved type
whereas std_logic is, which is why I've never seen this warning
before.
Is there a better way to do this?

bar <= sel(FOO, bletch, loadthis);

where 'sel' is a function (that you write) that takes three operators, the
first being some form of 'condition' that selects the second argument or the
third argument. After writing this once for the data types you have, you'll
probably see that providing additional function overrides to handle all of
the usual data types for the second and third arguments (std_logic,
std_logic_vector, real, time, etc.) is also useful...as is being able to use
either a boolean or std_logic type for the first argument.

No errors, no warnings.

KJ
 
A

Andy Peters

The key words here are 'may'...and that it's a 'warning'.  Good to question
and peruse all warnings as you're doing, but they will not prevent you from
simulating.





bar <= sel(FOO, bletch, loadthis);

where 'sel' is a function (that you write) that takes three operators, the
first being some form of 'condition' that selects the second argument or the
third argument.  After writing this once for the data types you have, you'll
probably see that providing additional function overrides to handle all of
the usual data types for the second and third arguments (std_logic,
std_logic_vector, real, time, etc.) is also useful...as is being able to use
either a boolean or std_logic type for the first argument.

No errors, no warnings.

KJ

I like it!

I agree with everyone; the tools should be smart enough to optimize
properly.

-a
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top