Visible to Intel only — GUID: gll1605571270557
Ixiasoft
1. Intel® HLS Compiler Pro Edition Best Practices Guide
2. Best Practices for Coding and Compiling Your Component
3. FPGA Concepts
4. Interface Best Practices
5. Loop Best Practices
6. fMAX Bottleneck Best Practices
7. Memory Architecture Best Practices
8. System of Tasks Best Practices
9. Datatype Best Practices
10. Advanced Troubleshooting
A. Intel® HLS Compiler Pro Edition Best Practices Guide Archives
B. Document Revision History for Intel® HLS Compiler Pro Edition Best Practices Guide
5.1. Reuse Hardware By Calling It In a Loop
5.2. Parallelize Loops
5.3. Construct Well-Formed Loops
5.4. Minimize Loop-Carried Dependencies
5.5. Avoid Complex Loop-Exit Conditions
5.6. Convert Nested Loops into a Single Loop
5.7. Place if-Statements in the Lowest Possible Scope in a Loop Nest
5.8. Declare Variables in the Deepest Scope Possible
5.9. Raise Loop II to Increase fMAX
5.10. Control Loop Interleaving
Visible to Intel only — GUID: gll1605571270557
Ixiasoft
5.7. Place if-Statements in the Lowest Possible Scope in a Loop Nest
If you have a nests of loops, avoid placing loops within conditional statements.
These conditions can cause the outer loop to take different paths (divergent loops), which can reduce the QoR of your component because these condition prevent the Intel® HLS Compiler from pipelining the loops.
For example, the following code example results in divergent loops:
for (int row = 0; row < outerTripCount; row++) { if (loopCondition) { for (int col = 0; col < innerTripCount; col++) { foo(); } } else { for (int col = 0; col < innerTripCount; col++) { bar(); } } }
This code example is better rewritten as follows:
for (int row = 0; row < outerTripCount; row++) { for (int col = 0; col < innerTripCount; col++) { if (loopCondition) { foo(); } else { bar(); } } }
For more details, review the divergent loops tutorial available in the following location:
<quartus_installdir>/hls/examples/tutorials/best_practices/divergent_loops