This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Fix x86 sqrt rounding (bug 14032)
- From: Rich Felker <dalias at aerifal dot cx>
- To: Richard Henderson <rth at twiddle dot net>
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>, libc-alpha at sourceware dot org
- Date: Wed, 27 Nov 2013 18:23:38 -0500
- Subject: Re: Fix x86 sqrt rounding (bug 14032)
- Authentication-results: sourceware.org; auth=none
- References: <Pine dot LNX dot 4 dot 64 dot 1311271803540 dot 7837 at digraph dot polyomino dot org dot uk> <52966555 dot 20603 at twiddle dot net>
On Thu, Nov 28, 2013 at 10:34:13AM +1300, Richard Henderson wrote:
> On 11/28/2013 07:06 AM, Joseph S. Myers wrote:
> > ENTRY(__ieee754_sqrt)
> > fldl 4(%esp)
> > fsqrt
> > + fstsw %ax
> > + subl $12, %esp
> > + cfi_adjust_cfa_offset (12)
> > + fld %st
> > + fstpt (%esp)
> > + movl (%esp), %edx
> > + andl $0x7ff, %edx
> > + cmpl $0x400, %edx
> > + jne 1f
> > + andl $0x200, %eax
> > + subl $0x100, %eax
> > + subl %eax, (%esp)
> > + fstp %st
> > + fldt (%esp)
> > +1: fstpl (%esp)
> > + fldl (%esp)
> > + addl $12,%esp
> > + cfi_adjust_cfa_offset (-12)
> > ret
>
> Surely this is much more complex than simply setting the rounding precision to
> double before using fsqrt.
Setting the rounding precision is likely to be much slower, and has
issues with signals (signal handlers could be invoked with wrong
rounding precision, resulting in completely wrong results). Also, in
general, setting the rounding precision is not a valid solution to
excess-precision problems, since it doesn't handle denormals
correctly (the exponent still has full ld80 range), but for sqrt it
would work since the result of sqrt can never be denormal.
Rich