mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
ieee754: provide gcc builtins based generic sqrt functions
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
@ -60,4 +60,7 @@
|
|||||||
# define USE_COPYSIGNF128_BUILTIN 0
|
# define USE_COPYSIGNF128_BUILTIN 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define USE_SQRT_BUILTIN 0
|
||||||
|
#define USE_SQRTF_BUILTIN 0
|
||||||
|
|
||||||
#endif /* math-use-builtins.h */
|
#endif /* math-use-builtins.h */
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include <math_private.h>
|
#include <math_private.h>
|
||||||
#include <fenv_private.h>
|
#include <fenv_private.h>
|
||||||
#include <libm-alias-finite.h>
|
#include <libm-alias-finite.h>
|
||||||
|
#include <math-use-builtins.h>
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
/* An ultimate sqrt routine. Given an IEEE double machine number x */
|
/* An ultimate sqrt routine. Given an IEEE double machine number x */
|
||||||
@ -50,6 +51,10 @@
|
|||||||
double
|
double
|
||||||
__ieee754_sqrt (double x)
|
__ieee754_sqrt (double x)
|
||||||
{
|
{
|
||||||
|
#if USE_SQRT_BUILTIN
|
||||||
|
return __builtin_sqrt (x);
|
||||||
|
#else
|
||||||
|
/* Use generic implementation. */
|
||||||
static const double
|
static const double
|
||||||
rt0 = 9.99999999859990725855365213134618E-01,
|
rt0 = 9.99999999859990725855365213134618E-01,
|
||||||
rt1 = 4.99999999495955425917856814202739E-01,
|
rt1 = 4.99999999495955425917856814202739E-01,
|
||||||
@ -138,6 +143,7 @@ __ieee754_sqrt (double x)
|
|||||||
return (x - x) / (x - x); /* sqrt(-ve)=sNaN */
|
return (x - x) / (x - x); /* sqrt(-ve)=sNaN */
|
||||||
return 0x1p-256 * __ieee754_sqrt (x * 0x1p512);
|
return 0x1p-256 * __ieee754_sqrt (x * 0x1p512);
|
||||||
}
|
}
|
||||||
|
#endif /* ! USE_SQRT_BUILTIN */
|
||||||
}
|
}
|
||||||
#ifndef __ieee754_sqrt
|
#ifndef __ieee754_sqrt
|
||||||
libm_alias_finite (__ieee754_sqrt, __sqrt)
|
libm_alias_finite (__ieee754_sqrt, __sqrt)
|
||||||
|
@ -16,12 +16,15 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <math_private.h>
|
#include <math_private.h>
|
||||||
#include <libm-alias-finite.h>
|
#include <libm-alias-finite.h>
|
||||||
|
#include <math-use-builtins.h>
|
||||||
static const float one = 1.0, tiny=1.0e-30;
|
|
||||||
|
|
||||||
float
|
float
|
||||||
__ieee754_sqrtf(float x)
|
__ieee754_sqrtf(float x)
|
||||||
{
|
{
|
||||||
|
#if USE_SQRTF_BUILTIN
|
||||||
|
return __builtin_sqrtf (x);
|
||||||
|
#else
|
||||||
|
/* Use generic implementation. */
|
||||||
float z;
|
float z;
|
||||||
int32_t sign = (int)0x80000000;
|
int32_t sign = (int)0x80000000;
|
||||||
int32_t ix,s,q,m,t,i;
|
int32_t ix,s,q,m,t,i;
|
||||||
@ -70,10 +73,10 @@ __ieee754_sqrtf(float x)
|
|||||||
|
|
||||||
/* use floating add to find out rounding direction */
|
/* use floating add to find out rounding direction */
|
||||||
if(ix!=0) {
|
if(ix!=0) {
|
||||||
z = one-tiny; /* trigger inexact flag */
|
z = 0x1p0 - 0x1.4484cp-100; /* trigger inexact flag. */
|
||||||
if (z>=one) {
|
if (z >= 0x1p0) {
|
||||||
z = one+tiny;
|
z = 0x1p0 + 0x1.4484cp-100;
|
||||||
if (z>one)
|
if (z > 0x1p0)
|
||||||
q += 2;
|
q += 2;
|
||||||
else
|
else
|
||||||
q += (q&1);
|
q += (q&1);
|
||||||
@ -83,6 +86,7 @@ __ieee754_sqrtf(float x)
|
|||||||
ix += (m <<23);
|
ix += (m <<23);
|
||||||
SET_FLOAT_WORD(z,ix);
|
SET_FLOAT_WORD(z,ix);
|
||||||
return z;
|
return z;
|
||||||
|
#endif /* ! USE_SQRTF_BUILTIN */
|
||||||
}
|
}
|
||||||
#ifndef __ieee754_sqrtf
|
#ifndef __ieee754_sqrtf
|
||||||
libm_alias_finite (__ieee754_sqrtf, __sqrtf)
|
libm_alias_finite (__ieee754_sqrtf, __sqrtf)
|
||||||
|
@ -108,4 +108,7 @@
|
|||||||
# define USE_COPYSIGNF128_BUILTIN 0
|
# define USE_COPYSIGNF128_BUILTIN 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define USE_SQRT_BUILTIN 0
|
||||||
|
#define USE_SQRTF_BUILTIN 0
|
||||||
|
|
||||||
#endif /* math-use-builtins.h */
|
#endif /* math-use-builtins.h */
|
||||||
|
Reference in New Issue
Block a user