Description
Sometimes C/C++ code is written with a sequence of operations, resulting in a long chain of operations in RTL. With a small clock period, this can increase the latency in the design. By default, the Vitis HLS tool rearranges the operations using associative and commutative properties. This rearrangement creates a balanced tree that can shorten the chain, potentially reducing latency in the design at the cost of extra hardware.
Expression balancing rearranges operators to construct a balanced tree and reduce latency.
- For integer operations expression balancing is on by default but may be disabled.
- For floating-point operations, expression balancing is off by default but may be enabled.
The EXPRESSION_BALANCE pragma allows this expression balancing to be disabled, or to be expressly enabled, within a specified scope.
Syntax
Place the pragma in the C source within the boundaries of the required location.
#pragma HLS expression_balance off
Where:
-
off
- Turns off expression balancing at this location.
Example 1
Disables expression balancing within function my_Func
.
void my_func(char inval, char incr) {
#pragma HLS expression_balance off
Example 2
This example explicitly enables expression balancing in function my_Func
.
void my_func(char inval, char incr) {
#pragma HLS expression_balance