Al said:
Is that means synthesizer will always get to the same point, based on time
estimation?
'Time estimation' has nothing to do with it. Logic that is equivalent will
almost without exception synthesize to the exact same thing.
I've always believed (maybe erroneously and most probably because never
gone into details) that differences like "if" statements and "case"
statements will turn out in different resources inferred.
Only if they are not logically equivalent. Try writing the code for
something like an address decoder where you decode specific addresses and do
so using only a case statement. Then translate that code into the
equivalent if/elsif form. Synthesize and target to the same device and, if
you translated correctly, you'll get the same result.
case Address is
when C1 => -- Do something
when C2 => -- Do something else
when C3 => -- Do some more
when others => -- Do something different
end case
If written as an if statement should come out as
elsif Address = C1 then -- Do something
elsif Address = C2 then -- Do something else
elsif Address = C3 then -- Do some more
else -- Do something different
end if;
Based on what Andy explained, I then assume that there is no meaning
giving priority to a signal instead of another to synchronously set a
Flip-Flop, because the synthesizer, based on time estimation, may revert
the logic. But shouldn't it estimate time starting from the point that the
code has a priority?
I'm not quite sure what point Andy was trying to make. The synthesis
process translates your code into boolean equations. Next it tries come up
with an implementation of that set of boolean equations that meets any
timing requirements. If it does not meet timing then it works with
alternate equivaent forms of that same set of boolean equations that does
meet the requirement.
I know that my first question was just a case of study, but then I would
really like to understand if this is a more general problem of coding
style.
Equivalent logic will synthesize to the same output. It usually has nothing
to do with 'coding style', if you have a complicated algorithm to implement
it will usually be a complicated structure. Where you get the most bang for
the buck is having an understanding of how high level language structure get
translated into boolean equations and what implications get implied and
seeing if there is an alternative representation that implements the same
functionality.
As an example, from a 'coding style' perspective you might not like to see
10 nested 'if' statements of the form....
if s1 then
if s2 then
if s3 then
....
end if;
end if;
end if;
But this structure is exactly equivalent to
if s1 and s2 and s2 .... then
end if;
and will produce the exact same synthesis result. So don't let dogma about
how many nested if statements drive how the code gets written, let the
driving force be how clear the code is to understand and map back to the
requirements since, in this example, the number of NESTED if statements is
irrelevant.
But now if some (or all) of those if statements have 'else' branches now you
look a bit harder. If s1 is a single signal than not(s1) (i.e. the path
taken for the 'else' of "if s1 then" is pretty easy, but if s1 is the
comparison of let's say an 8 bit address to a constant then not(s1) becomes
quite a bit more complex. What if s1 is the comparison of an 8 bit address
to something that is not constant? Now those nested 'if statements' quickly
turn into a lot of logic and probably slow timing paths. But is that a
problem? If your implementation of the the algorithm looks just like the
algorithm specification and you meet timing, then the answer is 'no'. There
is great value in being able to look at the algorithm specification (i.e.
your functional requirements) and your implementation of that algorithm and
being able to see that one to one correspondance. If that direct
translation does NOT meet timing requirements than you have to come up with
an alternative, that's where skill and experience will kick in and be the
important determinant in getting the implementation completed correctly.
The best way to get this innate 'feel' is to try writing some benchmark
examples and see what pops out of the final synthesized result for the final
boolean equations. Once you've mastered this you'll gain the ability to
glance at code and know what things to look for that will make things
difficult to implement in terms of either logic resources or timing
performance. Their are no shortcuts to study and learn, just like doing
homework in school has you doing specific problems to gain mastery over the
topic so you can tackle new things.
KJ