Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 May 2015 23:14:58 -0700
From:      Steve Kargl <sgk@troutmask.apl.washington.edu>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        freebsd-numerics@freebsd.org
Subject:   Re: small cleanup patch for e_pow.c
Message-ID:  <20150510061458.GA82518@troutmask.apl.washington.edu>
In-Reply-To: <20150510113454.O841@besplex.bde.org>
References:  <20150510002910.GA82261@troutmask.apl.washington.edu> <20150510113454.O841@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, May 10, 2015 at 11:59:55AM +1000, Bruce Evans wrote:
> On Sat, 9 May 2015, Steve Kargl wrote:
> 
> > In reading, e_pow.c I found a small piece of code that
> > can be remove.  Anyone object?
> >
> > Index: src/e_pow.c
> > ===================================================================
> > --- src/e_pow.c	(revision 1603)
> > +++ src/e_pow.c	(working copy)
> > @@ -187,10 +187,6 @@ __ieee754_pow(double x, double y)
> >
> >     /* |y| is huge */
> > 	if(iy>0x41e00000) { /* if |y| > 2**31 */
> > -	    if(iy>0x43f00000){	/* if |y| > 2**64, must o/uflow */
> > -		if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
> > -		if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
> > -	    }
> > 	/* over/underflow if x is not close to one */
> > 	    if(ix<0x3fefffff) return (hy<0)? s*huge*huge:s*tiny*tiny;
> > 	    if(ix>0x3ff00000) return (hy>0)? s*huge*huge:s*tiny*tiny;
> 
> It seems to be just an optimization.  It is a large optimization for
> the huge args, but those are not common, and is at most a tiny
> pessimization for non-huge args (just an extra branch which can be
> predicted perfectly if non-huge args are never used).
> 

I don't see how this can be an optimization.  The code has the form

  if (|y| > 2**31) {
     if (|y| > 2**64) {
         if (a) return
         if (b) return
     }
     if (a') return
     if (b') return
     ...
   }

The difference between a and a' is <= instead of <, and similar for
b and b' with >= and >.  If either a or b would have return, so will
a' and b'.  If neither a nor b return, then neither a' nor b' will
return.  The a' and b' lines were added by das in r141296, where the
commit message says the change is for fdlibm 5.3 compatibility.

I'll also note that block like 'if (|y|>2**64) { }' is not present
in e_powf.c


-- 
Steve



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150510061458.GA82518>