math: new software sqrt
authorSzabolcs Nagy <nsz@port70.net>
Sat, 13 Jun 2020 22:03:13 +0000 (22:03 +0000)
committerRich Felker <dalias@aerifal.cx>
Thu, 6 Aug 2020 03:05:33 +0000 (23:05 -0400)
commit97e9b73d59b65d445f2ba0b6294605eac1d72ecb
tree3093eb43c0653bec2d1e7bc6c87a47fceb1e607a
parentf1198ea3cfae3a3567e4ab4d2c741ed98b86f976
math: new software sqrt

approximate 1/sqrt(x) and sqrt(x) with goldschmidt iterations.
this is known to be a fast method for computing sqrt, but it is
tricky to get right, so added detailed comments.

use a lookup table for the initial estimate, this adds 256bytes
rodata but it can be shared between sqrt, sqrtf and sqrtl.
this saves one iteration compared to a linear estimate.

this is for soft float targets, but it supports fenv by using a
floating-point operation to get the final result.  the result
is correctly rounded in all rounding modes.  if fenv support is
turned off then the nearest rounded result is computed and
inexact exception is not signaled.

assumes fast 32bit integer arithmetics and 32 to 64bit mul.
src/math/sqrt.c
src/math/sqrt_data.c [new file with mode: 0644]
src/math/sqrt_data.h [new file with mode: 0644]