Intel® High Level Synthesis Compiler Pro Edition: Best Practices Guide

ID 683152
Date 3/28/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

9. Datatype Best Practices

The datatypes in your component and possible conversions or casting that they might undergo can significantly affect the performance and FPGA area usage of your component. Review the datatype best practices for tips and guidance how best to control datatype sizes and conversions in your component.

After you optimize the algorithm bottlenecks of your design, you can fine-tune some datatypes in your component by using arbitrary precision datatypes to shrink data widths, which reduces FPGA area utilization. The Intel® HLS Compiler Pro Edition provides debug functionality so that you can easily detect overflows in arbitrary precision datatypes.

Because C++ automatically promotes smaller datatypes such as short or char to 32 bits for operations such as addition or bit-shifting, you must use the arbitrary precision datatypes if you want to create narrow datapaths in your component.

Tutorials Demonstrating Datatype Best Practices

The Intel® HLS Compiler Pro Edition comes with a number of tutorials that illustrate important Intel® HLS Compiler concepts and demonstrate good coding practices.

Review the following tutorials to learn about datatype best practices that might apply to your design:
Tutorial Description
You can find these tutorials in the following location on your Intel® Quartus® Prime system:
<quartus_installdir>/hls/examples/tutorials
best_practices/ac_datatypes Demonstrates the effect of using ac_int datatype instead of int datatype.
ac_datatypes/ac_fixed_constructor Demonstrates the use of the ac_fixed constructor where you can get a better QoR by using minor variations in coding style.
ac_datatypes/ac_int_basic_ops Demonstrates the operators available for the ac_int class.
ac_datatypes/ac_int_overflow Demonstrates the usage of the DEBUG_AC_INT_WARNING and DEBUG_AC_INT_ERROR keywords to help detect overflow during emulation runtime.
best_practices/single_vs_double_precision_math Demonstrates the effect of using single precision literals and functions instead of double precision literals and functions.
ac_datatypes/ ac_fixed_constructor Demonstrates the use of the ac_fixed math library functions.
hls_float/ 1_reduced_double Demonstrates how your applications can benefit from changing the underlying type from double to hls_float<11,44> (reduced double).
hls_float/ 2_explicit_arithmetic Demonstrates how to use explicit versions of hls_float binary operations to perform floating-point arithmetic operations based on your needs.
hls_float/ 3_conversions Demonstrates when conversions appear in designs that use the hls_float data type and how to take advantage of different conversion modes to generate compile-type constants using hls_float types.