Modified Fast Inverse Square Root and Square Root Approximation Algorithms: The Method of Switching Magic Constants

被引:10
|
作者
Moroz, Leonid V. [1 ]
Samotyy, Volodymyr V. [2 ,3 ]
Horyachyy, Oleh Y. [1 ]
机构
[1] Lviv Polytech Natl Univ, Informat Technol Secur Dept, UA-79013 Lvov, Ukraine
[2] Cracow Univ Technol, Automat & Informat Technol Dept, PL-31155 Krakow, Poland
[3] Lviv State Univ Life Safety, Informat Secur Management Dept, UA-79007 Lvov, Ukraine
关键词
elementary function approximation; fast inverse square root algorithm; IEEE; 754; standard; Newton-Raphson method; fused multiply-add; algorithm design and analysis; maximum relative error; optimization; performance evaluation; processors and microprocessors;
D O I
10.3390/computation9020021
中图分类号
O1 [数学];
学科分类号
0701 ; 070101 ;
摘要
Many low-cost platforms that support floating-point arithmetic, such as microcontrollers and field-programmable gate arrays, do not include fast hardware or software methods for calculating the square root and/or reciprocal square root. Typically, such functions are implemented using direct lookup tables or polynomial approximations, with a subsequent application of the Newton-Raphson method. Other, more complex solutions include high-radix digit-recurrence and bipartite or multipartite table-based methods. In contrast, this article proposes a simple modification of the fast inverse square root method that has high accuracy and relatively low latency. Algorithms are given in C/C++ for single- and double-precision numbers in the IEEE 754 format for both square root and reciprocal square root functions. These are based on the switching of magic constants in the initial approximation, depending on the input interval of the normalized floating-point numbers, in order to minimize the maximum relative error on each subinterval after the first iteration-giving 13 correct bits of the result. Our experimental results show that the proposed algorithms provide a fairly good trade-off between accuracy and latency after two iterations for numbers of type float, and after three iterations for numbers of type double when using fused multiply-add instructions-giving almost complete accuracy.
引用
收藏
页码:1 / 23
页数:22
相关论文
共 50 条