Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How expensive is data type conversion vs. bit array manipulation in VHDL?

Tags:

vhdl

fpga

In VHDL, if you want to increment a std_logic_vector that represents a real number by one, I have come across a few options.

1) Use typecasting datatype conversion functions to change the std_logic vector to a signed or unsigned value, then convert it to an integer, add one to that integer, and convert it back to a std_logic_vector the opposite way than before. The chart below is handy when trying to do this.

Number to Vector Conversion Chart

2) Check to see the value of the LSB. If it is a '0', make it a '1'. If it is a '1', do a "shift left" and concatenate a '0' to the LSB. Ex: (For a 16 bit vector) vector(15 downto 1) & '0';

In an FPGA, as compared to a microprocessor, physical hardware resources seem to be the limiting factor instead of actual processing time. There is always the risk that you could run out of physical gates.

So my real question is this: which one of these implementations is "more expensive" in an FPGA and why? Are the compilers robust enough to implement the same physical representation?

like image 336
Ben Schoeler Avatar asked Dec 10 '14 14:12

Ben Schoeler


1 Answers

None of the type conversions cost.

The different types are purely about expressing the design as clearly as possible - not only to other readers (or yourself, next year:-) but also to the compiler, letting it catch as many errors as possible (such as, this integer value is out of range)

Type conversions are your way of telling the compiler "yes, I meant to do that".

Use the type that best expresses the design intent.

If you're using too many type conversions, that usually means something has been declared as the wrong type; stop and think about the design for a bit and it will often simplify nicely. If you want to increment a std_logic_vector, it should probably be an unsigned, or even a natural.

Then convert when you have to : often at top level ports or other people's IP.

Conversions may infinitesimally slow down simulations, but that's another matter.

As for your option 2 : low level detailed descriptions are not only harder to understand than a <= a + 1; but they are no easier for synth tools to translate, and more likely to contain bugs.

like image 165
user_1818839 Avatar answered Nov 15 '22 11:11

user_1818839