Operations with Explicit Precision Controls
The following operations leave the precision of the input
ap_float
-type variables untouched and allow you to control the output precision:
Rounding Mode Control For
ap_float to
ap_float Conversions
ap_float
to
ap_float
ConversionsSyntax
convert_to<output_exponent_width, output_mantissa_width, rounding_mode>
Description
Use this method to override the rounding mode set for an
ap_float
variable when converting the variable to a different precision. By default,
ap_float
to
ap_float
conversions use the rounding mode that you specified when you declared the variable.
Multiplication
Syntax
ihc::ap_float<output_exponent_width, output_mantissa_width>::mul <[accuracy_setting], [subnormal_setting]> (ap_float_a, ap_float_b)
Description
This math function supplements the basic multiplication operation performed by the multiplication (*) operator. Multiplies
and
without changing the input types and outputs an
ap_float_a
ap_float_b
ap_float
at the specified precision. The optional parameters are defined as follows:
- : Optional parameter to specify whether input and output numbers are flushed to zero when carrying out basic binary operations explicitly. Set this parameter with one of the following values:subnormal_settingsubnormal_settingParameter Valuessubnormal_settingValuesDescriptionihc::fp_config::FP_Subnormal::ONInput and output numbers in the subnormal range are preserved. The target FPGA device must have subnormal support. Subnormal support might require more FPGA area.ihc::fp_config::FP_Subnormal::OFFInput or output numbers in the subnormal range are flushed to zero.ihc::fp_config::FP_Subnormal::AUTOWith this setting, theIntel® oneAPIenables subnormal support only under the folllowing conditions:DPC++/C++Compiler
- The target FPGA device directly supports it.
- It does not incur any extra FPGA area overhead.
If you do not set theparameter, thesubnormal_settingihc::fp_config::FP_Subnormal::AUTOsubnormal setting is used by default. - : Optional parameter that influences trade-offs between the accuracy of the result due to different rounding decisions in the intermediary calculations and the FPGA area utilized by the generated hardware. Floating-point operations with less accurate results typically use fewer logic elements. For example, a divider with a high accuracy might use 20% more FPGA area than a divider with low accuracy. The low accuracy divider has a higher error bound [1 unit of least precision (ULP)] than a high accuracy divider (0.5 ULP).accuracy_settingSet this parameter with one of the following values:accuracy_settingParameter Valuesaccuracy_settingValuesDescriptionihc::fp_config::FP_Accuracy::HIGHUses the high precision version of the floating-point math operations. This is the default setting.ihc::fp_config::FP_Accuracy::LOWAllows the compiler to use a higher error bound to save on-chip area.If you do not set theaccuracy_settingparameter,ihc::fp_config::FP_Accuracy::HIGHaccuracy setting is used by default.
Addition/Subtraction/Division
Syntax
ihc::ap_float<output_exponent_width, output_mantissa_width>::add <[optional parameters]> (ap_float_a, ap_float_b)
ihc::ap_float<output_exponent_width, output_mantissa_width>::sub <[optional parameters]> (ap_float_a, ap_float_b)
ihc::ap_float<output_exponent_width, output_mantissa_width>::div <[optional parameters]> (ap_float_a, ap_float_b)
Description
These math functions supplement the basic math operations performed by the addition/subtraction/division ( and
by first casting
and
to the specified
+
/
−
//
) operators. Adds/subtracts/divides
ap_float_a
ap_float_b
ap_float_a
ap_float_b
ap_float
precision. The operation and output are at the specified precision.
You can also specify the optional parameters
and
described earlier.
accuracy_setting
subnormal_setting
If your SYCL code performs computations on constant/literal native floating-point values, the compiler can sometimes combine them at compile time and save area. This is a compiler optimization technique called
constant folding
or
constant propagation
. This optimization does not work for
ap_float
even when the operands are constant. You should compute your constant arithmetic in native types or precompute manually.