diff options
author | Ulrich Drepper <drepper@gmail.com> | 2011-10-15 20:22:59 -0400 |
---|---|---|
committer | Ulrich Drepper <drepper@gmail.com> | 2011-10-15 20:22:59 -0400 |
commit | bcf01e6d800e837622ddbc851b42b55fa99e5636 (patch) | |
tree | 5df0ae9971331105fe53de872895abb68d8276a5 /sysdeps/ieee754/flt-32 | |
parent | ba1a0d5938b53454a249d679ab90baf541cd91ad (diff) | |
download | glibc-bcf01e6d800e837622ddbc851b42b55fa99e5636.tar.gz glibc-bcf01e6d800e837622ddbc851b42b55fa99e5636.tar.xz glibc-bcf01e6d800e837622ddbc851b42b55fa99e5636.zip |
Optimize exp
Add __exp*_finite optimizations and rewrite some wrappers.
Diffstat (limited to 'sysdeps/ieee754/flt-32')
-rw-r--r-- | sysdeps/ieee754/flt-32/e_expf.c | 7 | ||||
-rw-r--r-- | sysdeps/ieee754/flt-32/w_expf.c | 90 |
2 files changed, 42 insertions, 55 deletions
diff --git a/sysdeps/ieee754/flt-32/e_expf.c b/sysdeps/ieee754/flt-32/e_expf.c index b9cd53c033..872d34bc5b 100644 --- a/sysdeps/ieee754/flt-32/e_expf.c +++ b/sysdeps/ieee754/flt-32/e_expf.c @@ -1,5 +1,5 @@ /* Single-precision floating point e^x. - Copyright (C) 1997, 1998, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 2005, 2006, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Geoffrey Keating <geoffk@ozemail.com.au> @@ -33,8 +33,8 @@ Then e^x is approximated as e^x = 2^n ( e^(t/512 + delta[t]) - + ( e^(t/512 + delta[t]) - * ( p(x + delta[t] + n * ln(2)) - delta ) ) ) + + ( e^(t/512 + delta[t]) + * ( p(x + delta[t] + n * ln(2)) - delta ) ) ) where - p(x) is a polynomial approximating e(x)-1; @@ -138,3 +138,4 @@ __ieee754_expf (float x) /* Return x, if x is a NaN or Inf; or overflow, otherwise. */ return TWO127*x; } +strong_alias (__ieee754_expf, __expf_finite) diff --git a/sysdeps/ieee754/flt-32/w_expf.c b/sysdeps/ieee754/flt-32/w_expf.c index 83b268f570..151c584547 100644 --- a/sysdeps/ieee754/flt-32/w_expf.c +++ b/sysdeps/ieee754/flt-32/w_expf.c @@ -1,60 +1,46 @@ -/* w_expf.c -- float version of w_exp.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#if defined(LIBM_SCCS) && !defined(lint) -static char rcsid[] = "$NetBSD: w_expf.c,v 1.3 1995/05/10 20:48:53 jtc Exp $"; -#endif - -/* - * wrapper expf(x) - */ - -#include "math.h" -#include "math_private.h" - -#ifdef __STDC__ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@gmail.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <math.h> +#include <math_private.h> + static const float -#else -static float -#endif o_threshold= 8.8722831726e+01, /* 0x42b17217 */ u_threshold= -1.0397208405e+02; /* 0xc2cff1b5 */ -#ifdef __STDC__ - float __expf(float x) /* wrapper expf */ -#else - float __expf(x) /* wrapper expf */ - float x; -#endif + +/* wrapper expf */ +float +__expf (float x) { -#ifdef _IEEE_LIBM - return __ieee754_expf(x); -#else - float z; - z = __ieee754_expf(x); - if(_LIB_VERSION == _IEEE_) return z; - if(__finitef(x)) { - if(x>o_threshold) - /* exp overflow */ - return (float)__kernel_standard((double)x,(double)x,106); - else if(x<u_threshold) - /* exp underflow */ - return (float)__kernel_standard((double)x,(double)x,107); - } - return z; -#endif + if (__builtin_expect (x > o_threshold, 0)) + { + if (_LIB_VERSION != _IEEE_) + return __kernel_standard_f (x, x, 106); + } + else if (__builtin_expect (x < u_threshold, 0)) + { + if (_LIB_VERSION != _IEEE_) + return __kernel_standard_f (x, x, 107); + } + + return __ieee754_expf (x); } hidden_def (__expf) weak_alias (__expf, expf) |