#include "aie/func_approx_fns.hpp"
template < typename T_D, typename T_L > void xf::dsp::aie::func_approx::getInvSqrt ( T_L* lut_values, const int coarseBits, const int fineBits, const int domainMode, const int shift )
getInvSqrt creates a lookup table for approximating the inverse square-root function 1/sqrt(x).
This function generates a piecewise linear approximation for the inverse square root using slope-offset pairs. The recommended domainMode for getInvSqrt 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 getInvSqrt<float, float>(lut, 8, 8, 2, 0); // For 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 | Number of least significant bits used for linear interpolation within each table entry. |
| 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 location. This is only applicable to lookup tables with an integer type offset value. |