I seem to have missed some articles in this thread, as there are some
things being reference that I can't having seen. However, I would
like to respond to some of the last comments I've seen.
Reza Naima wrote:
> It seems my biggest problem was that I though that HDL would give me
> the ability to write behavioral code and the software would be able
> to make it work...
Yes, that is always the hitch--in every area where we have automated
tools: synthesizers, parser generators (my area of expertise), 4GL
lanugages, natural language translators, et al. There is some level
of behavioral code that tools will be able translate. However, they
will never reach the "holy grail". This is no "dwim" (do what I mean)
instruction and cannot be. What we have are idioms that tools can
understand and paraphrase. If you learn the idioms (dialect) the tool
can speak, you can make it do quite a bit.
Here is some very specific advice about what idioms that synthesizers
understand.
Jan Decaluwe wrote:
> My advice: for implementation-oriented modeling, you only need 2
> templates: the synchronous always block (sensitive to a clock
> edge and possibly a reset edge), and the combinatorial always
> block (sensitive to the input signal levels).
This is the essence of a digital design course. Laying down
combinatorial logic that is fed into (or driven by) a set of
flip-flops that are clocked at an appropriate time. At some very deep
level all synchronous digital design is about designing an FSM (finite
state machine) which is merely a collection of gates around
flip-flops.
J> To a large extent, you can concentrate on getting the behavior
> right (hard enough), and rely on the synthesis tool to give you a good
> implementation.
This is true. If you build everything, out of the two blocks
described, you will have designed a circuit that a synthesizer can
build. There are still timing issues and other things to worry about.
However, the synthesizer will be able to lay down a set of gates that
does what your model does. This is the technology that the
syntehsizer writers' have, a way of translating those two idioms into
circuitry. Those are probably about the only two universal idioms,
because they represent things that are present in all forms
(implementations) of Boolean logic.
Things like tri-state drivers are not universal, because they are not
purely parts of Boolean logic and some implementations will have them
and others may not. Moreover, they may work "differently" in varying
implementations, because the underlying mechanism may work
"differently", and that may require specifying them differently at the
source level, to give a better interpretation of the semantics of the
implementation.
J> In contrast to what many people will tell you (and sometimes shout
> at you), there's no need to try to visualize the exact hardware that
> will come out. Believe me, they can't either.
Here I will disagree to some extent. Jan is correct in that I can't
predict exactly what gates will be infered by a synchronous always
block I write. However, I do have a reasonable expectation, that it
will be some combinatorial logic feeding some flip-flops and some
combinatorial logic leading away from the flip-flops. Moreover, when
I've written a synchronous always block, I have a pretty code idea
what signal is going to be driving the clock pins of the flip-flops in
that block. Now, if I want something different, say a tri-state bus
with some keeper that has a specific decay on it, I will write
different Verilog code. I will be really surprised if a synthesizer
writes out a tri-state bus when I've written a synchronous always
block--the synchronous always block is not the idiom used to create a
tri-state bus.
This is what I mean, by think hardware. Learn the idioms and what
they translate to. There aren't many of them. I think I know about
5: combinatorial code, synchronous (clocked) always block, tri-state
driver, priority encoder, and mux. Once you've learned the idioms,
then you know when you want something that works like x, you pick the
idiom that generates an x. Now, you may not know all the hardware the
synthesizer will generate to lay down an x (and the synthesizer may
even be more clever than you are and know that a y will work in the
given context and substitute a y), but you'll have basic concepts of
what the synthesizer can do for you and you will design circuits which
the synthesizer can lay down. When I want to design something, I
think how I can build it using those basic concepts, and once I know
that I can build it out of those things, then I have a rough design.
If I want something that I can't map to those concepts, then I don't
know how to build it (and I don't know what to tell the synthesizer
either).
Not to beat a dead horse, but I have one final comment on the topic
of "thinking in hardware". It has to do with for-loops. There are
some for loops that can be synthesized, but many (most) cannot. In
general for-loops that search cannot by synthesized. Nor can ones
that do sorting. For-loops that simply iterate over each bit of a
resigter can. If one lays down an unsynthesizable for-loop in an
otherwise synthesizable always block, the result is unsynthesizable.
The whole point of "thinking in terms of hardware" is avoiding writing
that kind of code.
Finally, I don't have a good answer to:
R> - There have been several replies indicating that the order of the
> statment has to do with priorities, and an async reset has a higher
> priority. Why is this? Is this just how flipflops are physically
> built?
It's probably more likely an artifact of the synthesizer. As I said
previoiusly, the synthesizer works by matching your code to its
templates. Those templates have some assumptions built into them.
Now, there are some variations in the templates the synthesizer can
handle (and better synthesizers generally can handle more variation).
However, at some level, when you've strayed too far from the
templates, the synthesizer writer cannot legitimately infer what you
"meant" and the writer chooses instead to give you an error telling
you to change your code into something that better matches the
templates (rather than instantiating something that is wrong).
Hope this helps,
-Chris
*****************************************************************************
Chris Clark Internet : compres@world.std.com
Compiler Resources, Inc. Web Site : http://world.std.com/~compres
23 Bailey Rd voice : (508) 435-5016
Berlin, MA 01503 USA fax : (978) 838-0263 (24 hours)
------------------------------------------------------------------------------