This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Consolidate some common code in s_sin.c


On 09/18/2013 09:27 AM, Siddhesh Poyarekar wrote:
> Hi,
> 
> This patch consolidates some of the common polynomial computations
> across functions into macros.  Verified that this does not result in
> any regressions on x86_64 and i686 (correctness and performance).  OK
> to commit?
> 
> Siddhesh
> 
> 	* sysdeps/ieee754/dbl-64/s_sin.c (POLYNOMIAL2): New macro.
> 	(POLYNOMIAL): Likewise.
> 	(TAYLOR_SINCOS): Likewise.
> 	(TAYLOR_SLOW): Likewise.
> 	(__sin): Use TAYLOR_SINCOS.
> 	(__cos): Likewise.
> 	(slow): Use TAYLOR_SLOW.
> 	(sloww): Likewise.
> 	(bsloww): Likewise.
> 	(csloww): Likewise.
> 
> diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
> index 5c388c8..c514a0a 100644
> --- a/sysdeps/ieee754/dbl-64/s_sin.c
> +++ b/sysdeps/ieee754/dbl-64/s_sin.c
> @@ -55,6 +55,36 @@
>  #include <math_private.h>
>  #include <fenv.h>
>  
> +#define POLYNOMIAL2(xx) ((((s5.x * (xx) + s4.x) * (xx) + s3.x) * (xx) + s2.x) \
> +			* (xx))
> +
> +#define POLYNOMIAL(xx) (POLYNOMIAL2 (xx) + s1.x)
> +
> +/* Both macros return result to LHS and correction in the last argument.  */
> +#define TAYLOR_SINCOS(xx, a, da, cor) \
> +({									      \
> +  double t = ((POLYNOMIAL (xx)  * (a) - 0.5 * (da))  * (xx) + (da));	      \
> +  double res = (a) + t;							      \
> +  (cor) = ((a) - res) + t;						      \
> +  res;									      \
> +})
> +
> +#define TAYLOR_SLOW(x0, dx, cor) \
> +({									      \
> +  static const double th2_36 = 206158430208.0;	/*    1.5*2**37   */	      \
> +  double xx = (x0) * (x0);						      \
> +  double x1 = ((x0) + th2_36) - th2_36;					      \
> +  double y = aa.x * x1 * x1 * x1;					      \
> +  double r = (x0) + y;							      \
> +  double x2 = ((x0) - x1) + (dx);					      \
> +  double t = (((POLYNOMIAL2 (xx) + bb.x) * xx + 3.0 * aa.x * x1 * x2)	      \
> +	      * (x0)  + aa.x * x2 * x2 * x2 + (dx));			      \
> +  t = (((x0) - r) + y) + t;						      \
> +  double res = r + t;							      \
> +  (cor) = (r - res) + t;						      \
> +  res;									      \
> +})

Could you add some comments on what these macros compute? I know the
original code is rather uncommented...

Andreas
-- 
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]