#include "aie/func_approx_fns.hpp"
template < typename T_D, typename T_L > void xf::dsp::aie::func_approx::getSqrt ( T_L* lut_values, const int coarseBits, const int fineBits, const int domainMode, const int shift )
Domain Mode Explanation.
The lookup table generation supports three domain modes for input normalization:
domainMode = 0 : Input domain [0, 1)
- LUT size: 2^coarseBits locations
- Full range utilization
- Best for functions naturally bounded in [0,1)
domainMode = 1 : Input domain [1, 2)
- LUT size: 2^(coarseBits-1) locations (half size of domainMode 0 and 1)
- Assumes MSB of input is always 1, should be cleared before kernel processing
- Optimal for functions with natural [1,2) domain (e.g., log)
domainMode = 2 : Input domain [1, 4)
- LUT size: 2^coarseBits locations
- First quadrant of LUT (0 to 1) unused but allocated
- May produce inaccurate results for inputs in [0,1)
getSqrt creates a lookup table for approximating the square-root function sqrt(x).
This function generates a piecewise linear approximation using slope-offset pairs. The recommended domainMode for getSqrt is 2 (domain 1 ≤ x < 4).
If domainMode = 1, where the input domain is 1 <= x < 2, it is expected that the most significant bit of coarseBits has been set to zero and will be ignored by the function approximation kernel when addressing the lookup table.
This means that the lookup table will be half the size of other domainMode (TP_DOMAIN_MODE) with a similar coarseBits value.
For domainMode values equal to 0 or 2, there are 2 ^ (coarseBits) locations, and when domainMode is equal to 1, there are 2 ^ (coarseBits - 1) locations.
float lut[512]; // 256 slope-offset pairs getSqrt<float, float>(lut, 8, 8, 2, 0); // 8-bit addressing, 8-bit interpolation, domain [1,4)
Parameters:
| T_D | Data type that will be input to the func_approx kernel (e.g., int16, int32, float, bfloat16). |
| T_L | Lookup table storage type. Should equal T_D except when T_D is bfloat16, then T_L should be float. |
| lut_values | A pointer to the memory where the lookup table of slope and offset values will be created. |
| coarseBits | Number of most significant bits used for table indexing. Determines table size:
|
| fineBits | Describes the number of bits in an input data sample used for fine interpolation. It determines the width of each location. |
| domainMode | The choice of TP_DOMAIN_MODE template parameter. This creates an approximation of f(x) where x is normalized over a specified domain. This can be:
|
| shift | The downward shift value that will be applied to each offset of a locations. This is only applicable to lookup tables with an integer type offset value. |