Home    Bloggers    Messages    Webinars    Resources   
Tw  |  Fb  |  In  |  Rss
Mike Field

Hamster Ponders Variables in VHDL

Mike Field
Page 1 / 14   >   >>
JezmoSSL
JezmoSSL
2/2/2013 4:58:49 AM
User Rank
Blogger
Re: it depends
Andy I think you assume too much about what we were taught, what we know and what we think.

50%
50%
aj1s
aj1s
2/2/2013 12:46:49 AM
User Rank
Guru
Re: it depends
It seems to me that the confusion with using varaibles for synthesis stems from how most of us are taught about how synthesis works.

Generally, we are taught that processes that can run at any time, produce outputs at any time, which should be combinatorial (with the occasional latch). Similarly, structural approaches to avoiding latches emphasized "an else for every if" as the the preferred solution for avoiding latches. Makes sense...

We are also taught that processes that were constrained to execute on a clock edge would produce registered values, presumably because just like a register, the only time they can update their value is on the clock edge. This makes sense too...

Both of these approaches to creating and avoiding storage elements (registers and latches) miss the boat entirely. 

Storage is inferred from the requirement to remember a previous value. If your code requires remembering a previous value, then the synthesis tool will infer a storage element to remember the previous value, whether you use a signal or a variable.

Failure to teach this basic principle leads to the inaccurate conclusion that it is the signal assignment that makes the assigned signal a register. Not true. It is the fact that any reference to a signal assigned in a clocked process, is a reference to the previous value from some previous clock cycle, and thus a register is inferred. When interpretted this way, it is much easier to consider how one variable can represent both combinatorial logic and/or registered logic. It is the references to the variable that determine whether the referenced value will be a registered or combinatorial value. 

If we were taught that in the first place, there would be far less confusion about variables, and all of us would be more comfortable with using them (as would our employers and co-workers who review or maintain our code, or who write approve and enforce coding/design standards).

Similarly, we would understand that a more effective means of avoiding latches (besides avoiding combinatorial processes!) is to employ default assignments for every signal at top of the process, so that remembering a previous value is not possible. Not surprisingly, this is also the best way to avoid an unintended register from a variable in a clocked process.

In most engineering disciplines, we are taught the theory first, then the simplifications that make applying the theory more practical. Why are we not taught logic synthesis the same way? There are times when a "cookbook" approach to teaching leads to roadblocks that impede a more complete understanding of the subject matter.

I believe synthesis should first be taught using variables to illustrate the truth about storage inference. Then the "shortcuts" of signal assignments in clocked processes can be presented. That way, students have the knowledge necessary to apply both to maximum benefit.

Andy

100%
0%
hash.era
hash.era
12/31/2012 3:27:48 AM
User Rank
Clever Clogs
Re: A software point of view
Obviously since then if so it will be an endless loop for sure.

50%
50%
Brian Davis
Brian Davis
12/13/2012 7:58:50 PM
User Rank
Clever Clogs
Re: A software point of view
@JezmoSSL: "If you want to count the number of bits set in a vector, why not cut to the chase and use a look-up table ?"

For small tables that's a perfectly reasonable method.

And once you've written the bit count function, wrapping it in another function that loops through the look-up table address range would allow initialization, at declaration, of a bit counting table of any size and width, _without_ typing out case statements or table entries.

----

The list of links I posted up-thread included an optimized one in which the smallest leaf adders were converted to LUT's:

"Hybrid, lookup tables + adder
"
https://groups.google.com/group/comp.lang.vhdl/msg/410a3b0c2e7c2402

The synthesis results were within a LUT or two of the other methods for a 32 bit input vector when using Synplicity.

50%
50%
jandecaluwe
jandecaluwe
12/13/2012 5:25:46 PM
User Rank
Blogger
Re: A software point of view
@rfrisbee "I was also referring to JesmoSSL's blog post "Toiling with Testbenches" but did not make that clear in my comment"

Good - happy to hear that we are in agreement about the need to correct that particular post. (I would like to hear you own analysis (beyond sensitivity list issues) because it seems you also know what you are talking about :-)). 

50%
50%
rfrisbee
rfrisbee
12/13/2012 1:48:04 PM
User Rank
Clever Clogs
Re: A software point of view
I should also apologise - I was also referring to JesmoSSL's blog post "Toiling with Testbenches" but did not make that clear in my comment.

Something else I've noticed quite a bit is clocked processes with signals in addition to the clock in their sensitivity list. While I doubt this does any harm, I'd imagine it might slow down simulation with processes having to be reevaluated more frequently than strictly necessary. That's another feature of using the "wait until rising_edge(clk)" statement: such processes can't legally have sensitivity lists and the tools will throw an error if one is present.

 

50%
50%
jandecaluwe
jandecaluwe
12/13/2012 1:11:17 PM
User Rank
Blogger
Re: A software point of view
@JezmoSSL "you can write some combinatorial logic to count the set bits in a vector of say 8 bits and run it in parallel for vectors larger than 8 bits adding the results, so if you have a vector of 8 bits its quite easy to write a combinartorial bit of logic to output the number of bits set."

All kind of approaches are possible, but I assume you are not going to write a lookup case with 256 entries for an 8-bit vector manually. Surely, you would use a program or script to generate this automatically and without bugs - and that program surely would use variables.

The HDL version would be very similar - and I suspect there wouldn't be big difference in synthesis results for this relatively small input size.

Therefore, the choice is between an "external" and an "internal" function. Fine with me, but I fail to see why something which is just fine externally would become confusing internally. On the contrary, from the flattened lookup table it would certainly be harder to see what's going on than from the function.

50%
50%
JezmoSSL
JezmoSSL
12/13/2012 12:44:09 PM
User Rank
Blogger
Re: A software point of view
Yeah ive never really fancied a unicycle

track racing is scary, 40 miles an hour. only way to brake is to put back pressure on the pedals and you have 18 mm wide tyres on wood, and you are 2-3 inches behind the guy in front, and youve got to stay exactly on the right line. and it hurts like hell

50%
50%
JezmoSSL
JezmoSSL
12/13/2012 12:16:46 PM
User Rank
Blogger
Re: A software point of view
 

Oh no the server went down there a bit.

anyway

there are two approaches to the problem you can write a function to go through the size of the vector and count the '1's or you can write some combinatorial logic to count the set bits in a vector of say 8 bits and run it in parallel for vectors larger than 8 bits adding the results, so if you have a vector of 8 bits its quite easy to write a combinartorial bit of logic to output the number of bits set. you know something like
case input
when "0000"=> count<=0;
when "0001" =>count<=1;
when "0011" =>count<=2;

and so on

if you have an ickle vector, say 6 bits, then it all fits into a LUT

50%
50%
jandecaluwe
jandecaluwe
12/13/2012 11:08:29 AM
User Rank
Blogger
Re: A software point of view
@Jezmo "If you want to count the number of bits set in a vector, why not cut to the chase and use a look-up table?"

I nearly missed it, but obviously you're joking again.

50%
50%
Page 1 / 14   >   >>
More Blogs from Mike Field
Over the past few days I have managed to create quite a few designs using the Xilinx Memory Interface Generator (MIG) and they all seem to work.
If I were an evil genius working on a plan for world domination (with regard to enterprise-level data storage solutions) I would be seriously considering building my design around a Zynq All Programmable SoC.
I would like to present to fellow readers of All Programmable Planet a new technique that I have invented to serialize data within the FPGA's main fabric at 1.5Gb/s.
It's time to look at the receiver portion of the link. After a few false starts, Mike Field has found what looks to be a workable design.
As with most things, my feeling is that there is no better way to understand high-speed serial links than to implement one from the ground up, so that is what I've set out to do.
flash poll
follow us on twitter
follow Xilinx on twitter
like us on facebook
like Xilinx on facebook
All Programmable Planet     About Us     Contact Us     Help     Register     Twitter     Facebook     RSS