User manual

Tutorial: Handel-C and VGA graphics output
6.1.3 Macro procedures vs. functions
The main difference between a macro proc and a function in Handel-C is the number of hardware
copies that result. Placing a block of frequently used code in a function means that one copy of the code
will exist in the hardware and every time the function is called this single copy of the code will be used. A
macro procedure builds a fresh copy of the code every time it is called. This means that if the code block
needs to be called several times in parallel, a single function can not be used as multiple copies of the
code are required. To cater for this situation, arrays of functions can be declared to build a specified
number of copies which can then be called in parallel. However, a further consideration is that multiple
sequential calls to a single function will result in complex circuitry at the entry and exit points of the
function, leading to the following trade-offs:
a function may take up less space than a
macro proc.
using a
macro proc will generally result in a higher clock rate
Overall, the best practice is to use macro procedures by default, as they are easier to design with and
result in higher performance. If there is a particularly large (in hardware terms) block of code that is used
infrequently but in several places, it may be a candidate for implementation in function. Another
alternative is to implement a client-server architecture, as described in the Advanced Optimization
tutorial.
6.1.4 Static initialization
For a variable to be initialized in Handel-C it must either be declared as global or static. As assigning a
value directly to a variable takes a clock cycle, static initialization can be used to save cycles and
increase the performance in a design.
Ï
always be initialized before use, as their values can not be assumed to be Variables should
zero at startup.
6.2 Loops and control code
The following sections illustrate how to code efficient loops and other control structures in Handel-C,
optimizi
age 75)
(see page 76)
Nested control (see page 77)
s an
ng for both area and timing efficiency.
Clock-cycle efficiency of loops (see page 74)
Timing efficiency of loops and control code (see p
Avoiding combinatorial loops
6.2.1 Clock-cycle efficiency of loops
As Handel-C is very close to C, it is common to port code directly from C to Handel-C, modifying it to add
parallelism. There are several areas where common coding styles in C will not produce the most efficient
hardware design in Handel-C. In the area of control statements it is the
for() loop which is not ideal.
for() loops are supported by Handel-C. Because the control portion of the loop typically contain
assignment, it must use a clock cycle. This is because the Handel-C timing model requires every
www.celoxica.com
Page 74