mirror of
git://sourceware.org/git/glibc.git
synced 2025-02-23 13:09:58 +08:00
Clean up dbl-64 rint, nearbyint.
This commit is contained in:
parent
8e59da90ce
commit
f453b98b6b
@ -1,3 +1,12 @@
|
|||||||
|
2012-03-13 Joseph Myers <joseph@codesourcery.com>
|
||||||
|
|
||||||
|
* sysdeps/ieee754/dbl-64/s_nearbyint.c (__nearbyint): Do not
|
||||||
|
manipulate bits before adding and subtracting TWO52[sx].
|
||||||
|
* sysdeps/ieee754/dbl-64/s_rint.c (__rint): Likewise.
|
||||||
|
* sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c (__nearbyint):
|
||||||
|
Likewise.
|
||||||
|
* sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c (__rint): Likewise.
|
||||||
|
|
||||||
2012-03-13 David S. Miller <davem@davemloft.net>
|
2012-03-13 David S. Miller <davem@davemloft.net>
|
||||||
|
|
||||||
* sysdeps/sparc/Makefile: Remove rtld-global-offsets.sym handling.
|
* sysdeps/sparc/Makefile: Remove rtld-global-offsets.sym handling.
|
||||||
|
@ -38,18 +38,12 @@ double __nearbyint(double x)
|
|||||||
{
|
{
|
||||||
fenv_t env;
|
fenv_t env;
|
||||||
int32_t i0,j0,sx;
|
int32_t i0,j0,sx;
|
||||||
u_int32_t i,i1;
|
|
||||||
double w,t;
|
double w,t;
|
||||||
EXTRACT_WORDS(i0,i1,x);
|
GET_HIGH_WORD(i0,x);
|
||||||
sx = (i0>>31)&1;
|
sx = (i0>>31)&1;
|
||||||
j0 = ((i0>>20)&0x7ff)-0x3ff;
|
j0 = ((i0>>20)&0x7ff)-0x3ff;
|
||||||
if(j0<20) {
|
if(j0<52) {
|
||||||
if(j0<0) {
|
if(j0<0) {
|
||||||
if(((i0&0x7fffffff)|i1)==0) return x;
|
|
||||||
i1 |= (i0&0x0fffff);
|
|
||||||
i0 &= 0xfffe0000;
|
|
||||||
i0 |= ((i1|-i1)>>12)&0x80000;
|
|
||||||
SET_HIGH_WORD(x,i0);
|
|
||||||
feholdexcept (&env);
|
feholdexcept (&env);
|
||||||
w = TWO52[sx]+x;
|
w = TWO52[sx]+x;
|
||||||
t = w-TWO52[sx];
|
t = w-TWO52[sx];
|
||||||
@ -57,32 +51,11 @@ double __nearbyint(double x)
|
|||||||
GET_HIGH_WORD(i0,t);
|
GET_HIGH_WORD(i0,t);
|
||||||
SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31));
|
SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31));
|
||||||
return t;
|
return t;
|
||||||
} else {
|
|
||||||
i = (0x000fffff)>>j0;
|
|
||||||
if(((i0&i)|i1)==0) return x; /* x is integral */
|
|
||||||
i>>=1;
|
|
||||||
if(((i0&i)|i1)!=0) {
|
|
||||||
if (j0==19)
|
|
||||||
i1 = 0x40000000;
|
|
||||||
else if (j0<18)
|
|
||||||
i0 = (i0&(~i))|((0x20000)>>j0);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i0 &= ~i;
|
|
||||||
i1 = 0x80000000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (j0>51) {
|
} else {
|
||||||
if(j0==0x400) return x+x; /* inf or NaN */
|
if(j0==0x400) return x+x; /* inf or NaN */
|
||||||
else return x; /* x is integral */
|
else return x; /* x is integral */
|
||||||
} else {
|
|
||||||
i = ((u_int32_t)(0xffffffff))>>(j0-20);
|
|
||||||
if((i1&i)==0) return x; /* x is integral */
|
|
||||||
i>>=1;
|
|
||||||
if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));
|
|
||||||
}
|
}
|
||||||
INSERT_WORDS(x,i0,i1);
|
|
||||||
feholdexcept (&env);
|
feholdexcept (&env);
|
||||||
w = TWO52[sx]+x;
|
w = TWO52[sx]+x;
|
||||||
t = w-TWO52[sx];
|
t = w-TWO52[sx];
|
||||||
|
@ -33,49 +33,22 @@ double
|
|||||||
__rint(double x)
|
__rint(double x)
|
||||||
{
|
{
|
||||||
int32_t i0,j0,sx;
|
int32_t i0,j0,sx;
|
||||||
u_int32_t i,i1;
|
|
||||||
double w,t;
|
double w,t;
|
||||||
EXTRACT_WORDS(i0,i1,x);
|
GET_HIGH_WORD(i0,x);
|
||||||
sx = (i0>>31)&1;
|
sx = (i0>>31)&1;
|
||||||
j0 = ((i0>>20)&0x7ff)-0x3ff;
|
j0 = ((i0>>20)&0x7ff)-0x3ff;
|
||||||
if(j0<20) {
|
if(j0<52) {
|
||||||
if(j0<0) {
|
if(j0<0) {
|
||||||
if(((i0&0x7fffffff)|i1)==0) return x;
|
|
||||||
i1 |= (i0&0x0fffff);
|
|
||||||
i0 &= 0xfffe0000;
|
|
||||||
i0 |= ((i1|-i1)>>12)&0x80000;
|
|
||||||
SET_HIGH_WORD(x,i0);
|
|
||||||
w = TWO52[sx]+x;
|
w = TWO52[sx]+x;
|
||||||
t = w-TWO52[sx];
|
t = w-TWO52[sx];
|
||||||
GET_HIGH_WORD(i0,t);
|
GET_HIGH_WORD(i0,t);
|
||||||
SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31));
|
SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31));
|
||||||
return t;
|
return t;
|
||||||
} else {
|
|
||||||
i = (0x000fffff)>>j0;
|
|
||||||
if(((i0&i)|i1)==0) return x; /* x is integral */
|
|
||||||
i>>=1;
|
|
||||||
if(((i0&i)|i1)!=0) {
|
|
||||||
if (j0==19)
|
|
||||||
i1 = 0x40000000;
|
|
||||||
else if (j0<18)
|
|
||||||
i0 = (i0&(~i))|((0x20000)>>j0);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i0 &= ~i;
|
|
||||||
i1 = 0x80000000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (j0>51) {
|
} else {
|
||||||
if(j0==0x400) return x+x; /* inf or NaN */
|
if(j0==0x400) return x+x; /* inf or NaN */
|
||||||
else return x; /* x is integral */
|
else return x; /* x is integral */
|
||||||
} else {
|
|
||||||
i = ((u_int32_t)(0xffffffff))>>(j0-20);
|
|
||||||
if((i1&i)==0) return x; /* x is integral */
|
|
||||||
i>>=1;
|
|
||||||
if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));
|
|
||||||
}
|
}
|
||||||
INSERT_WORDS(x,i0,i1);
|
|
||||||
w = TWO52[sx]+x;
|
w = TWO52[sx]+x;
|
||||||
return w-TWO52[sx];
|
return w-TWO52[sx];
|
||||||
}
|
}
|
||||||
|
@ -41,29 +41,17 @@ __nearbyint(double x)
|
|||||||
j0 = ((i0>>52)&0x7ff)-0x3ff;
|
j0 = ((i0>>52)&0x7ff)-0x3ff;
|
||||||
if(__builtin_expect(j0<52, 1)) {
|
if(__builtin_expect(j0<52, 1)) {
|
||||||
if(j0<0) {
|
if(j0<0) {
|
||||||
if((i0&UINT64_C(0x7fffffffffffffff))==0) return x;
|
|
||||||
uint64_t i = i0 & UINT64_C(0xfffffffffffff);
|
|
||||||
i0 &= UINT64_C(0xfffe000000000000);
|
|
||||||
i0 |= (((i|-i) >> 12) & UINT64_C(0x8000000000000));
|
|
||||||
INSERT_WORDS64(x,i0);
|
|
||||||
libc_feholdexcept (&env);
|
libc_feholdexcept (&env);
|
||||||
double w = TWO52[sx]+x;
|
double w = TWO52[sx]+x;
|
||||||
double t = w-TWO52[sx];
|
double t = w-TWO52[sx];
|
||||||
math_opt_barrier(t);
|
math_opt_barrier(t);
|
||||||
libc_fesetenv (&env);
|
libc_fesetenv (&env);
|
||||||
return copysign(t, x);
|
return copysign(t, x);
|
||||||
} else {
|
|
||||||
uint64_t i = UINT64_C(0x000fffffffffffff)>>j0;
|
|
||||||
if((i0&i)==0) return x; /* x is integral */
|
|
||||||
i>>=1;
|
|
||||||
if((i0&i)!=0)
|
|
||||||
i0 = (i0&(~i))|(UINT64_C(0x4000000000000)>>j0);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(j0==0x400) return x+x; /* inf or NaN */
|
if(j0==0x400) return x+x; /* inf or NaN */
|
||||||
else return x; /* x is integral */
|
else return x; /* x is integral */
|
||||||
}
|
}
|
||||||
INSERT_WORDS64(x,i0);
|
|
||||||
libc_feholdexcept (&env);
|
libc_feholdexcept (&env);
|
||||||
double w = TWO52[sx]+x;
|
double w = TWO52[sx]+x;
|
||||||
double t = w-TWO52[sx];
|
double t = w-TWO52[sx];
|
||||||
|
@ -38,28 +38,16 @@ __rint(double x)
|
|||||||
j0 = ((i0>>52)&0x7ff)-0x3ff;
|
j0 = ((i0>>52)&0x7ff)-0x3ff;
|
||||||
if(j0<52) {
|
if(j0<52) {
|
||||||
if(j0<0) {
|
if(j0<0) {
|
||||||
if((i0 & UINT64_C(0x7fffffffffffffff))==0) return x;
|
|
||||||
uint64_t i = i0 & UINT64_C(0xfffffffffffff);
|
|
||||||
i0 &= UINT64_C(0xfffe000000000000);
|
|
||||||
i0 |= (((i|-i) >> 12) & UINT64_C(0x8000000000000));
|
|
||||||
INSERT_WORDS64(x,i0);
|
|
||||||
double w = TWO52[sx]+x;
|
double w = TWO52[sx]+x;
|
||||||
double t = w-TWO52[sx];
|
double t = w-TWO52[sx];
|
||||||
EXTRACT_WORDS64(i0,t);
|
EXTRACT_WORDS64(i0,t);
|
||||||
INSERT_WORDS64(t,(i0&UINT64_C(0x7fffffffffffffff))|(sx<<63));
|
INSERT_WORDS64(t,(i0&UINT64_C(0x7fffffffffffffff))|(sx<<63));
|
||||||
return t;
|
return t;
|
||||||
} else {
|
|
||||||
uint64_t i = UINT64_C(0x000fffffffffffff)>>j0;
|
|
||||||
if((i0&i)==0) return x; /* x is integral */
|
|
||||||
i>>=1;
|
|
||||||
if((i0&i)!=0)
|
|
||||||
i0 = (i0&(~i))|(UINT64_C(0x4000000000000)>>j0);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(j0==0x400) return x+x; /* inf or NaN */
|
if(j0==0x400) return x+x; /* inf or NaN */
|
||||||
else return x; /* x is integral */
|
else return x; /* x is integral */
|
||||||
}
|
}
|
||||||
INSERT_WORDS64(x,i0);
|
|
||||||
double w = TWO52[sx]+x;
|
double w = TWO52[sx]+x;
|
||||||
return w-TWO52[sx];
|
return w-TWO52[sx];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user