[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-hackers
Subject:    [PATCH] libm -- optimize __ldexp_cexp[f]
From:       Steve Kargl <sgk () troutmask ! apl ! washington ! edu>
Date:       2020-09-20 0:25:06
Message-ID: 20200920002506.GA47948 () troutmask ! apl ! washington ! edu
[Download RAW message or body]

The following patch is an opimization for he kernels
used by cexp(x) and cexpf(x).

. Use sincos[f] instead of a call to cos[f] and a 
  call to sin[f].
. While here, alphabetize declaration.

--- /usr/src/lib/msun/src/k_exp.c	2019-02-23 07:45:03.879997000 -0800
+++ src/k_exp.c	2019-12-26 08:15:30.109189000 -0800
@@ -88,7 +88,7 @@
 double complex
 __ldexp_cexp(double complex z, int expt)
 {
-	double x, y, exp_x, scale1, scale2;
+	double c, exp_x, s, scale1, scale2, x, y;
 	int ex_expt, half_expt;
 
 	x = creal(z);
@@ -105,6 +105,7 @@
 	half_expt = expt - half_expt;
 	INSERT_WORDS(scale2, (0x3ff + half_expt) << 20, 0);
 
-	return (CMPLX(cos(y) * exp_x * scale1 * scale2,
-	    sin(y) * exp_x * scale1 * scale2));
+	sincos(y, &s, &c);
+	return (CMPLX(c * exp_x * scale1 * scale2,
+	    s * exp_x * scale1 * scale2));
 }
--- /usr/src/lib/msun/src/k_expf.c	2019-02-23 07:45:03.881215000 -0800
+++ src/k_expf.c	2019-12-26 08:15:30.109818000 -0800
@@ -71,7 +71,7 @@
 float complex
 __ldexp_cexpf(float complex z, int expt)
 {
-	float x, y, exp_x, scale1, scale2;
+	float c, exp_x, s, scale1, scale2, x, y;
 	int ex_expt, half_expt;
 
 	x = crealf(z);
@@ -84,6 +84,7 @@
 	half_expt = expt - half_expt;
 	SET_FLOAT_WORD(scale2, (0x7f + half_expt) << 23);
 
-	return (CMPLXF(cosf(y) * exp_x * scale1 * scale2,
-	    sinf(y) * exp_x * scale1 * scale2));
+	sincosf(y, &s, &c);
+	return (CMPLXF(c * exp_x * scale1 * scale2,
+	    s * exp_x * scale1 * scale2));
 }

-- 
Steve
_______________________________________________
freebsd-hackers@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic