diff mbox

[1/5] Consolidate reduce_and_compute code

Message ID 1471976565-3576-2-git-send-email-siddhesh@sourceware.org
State New
Headers show

Commit Message

Siddhesh Poyarekar Aug. 23, 2016, 6:22 p.m. UTC
This patch reshuffles the reduce_and_compute code so that the
structure matches other code structures of the same type elsewhere in
s_sin.c and s_sincos.c.  This is the beginning of an attempt to
consolidate and reduce code duplication in functions in s_sin.c to
make it easier to read and possibly also easier for the compiler to
optimize.

	* sysdeps/ieee754/dbl-64/s_sin.c (reduce_and_compute):
	Consolidate switch cases 0 and 2.
---
 sysdeps/ieee754/dbl-64/s_sin.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

Comments

Adhemerval Zanella Aug. 24, 2016, 1:52 a.m. UTC | #1
LGTM, this is mostly indentation.

> Em 23 de ago de 2016, às 15:22, Siddhesh Poyarekar <siddhesh@sourceware.org> escreveu:
> 
> This patch reshuffles the reduce_and_compute code so that the
> structure matches other code structures of the same type elsewhere in
> s_sin.c and s_sincos.c.  This is the beginning of an attempt to
> consolidate and reduce code duplication in functions in s_sin.c to
> make it easier to read and possibly also easier for the compiler to
> optimize.
> 
>    * sysdeps/ieee754/dbl-64/s_sin.c (reduce_and_compute):
>    Consolidate switch cases 0 and 2.
> ---
> sysdeps/ieee754/dbl-64/s_sin.c | 29 +++++++++++++----------------
> 1 file changed, 13 insertions(+), 16 deletions(-)
> 
> diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
> index 7c9a079..e1ee7a9 100644
> --- a/sysdeps/ieee754/dbl-64/s_sin.c
> +++ b/sysdeps/ieee754/dbl-64/s_sin.c
> @@ -249,23 +249,20 @@ reduce_and_compute (double x, unsigned int k)
>   k = (n + k) % 4;
>   switch (k)
>     {
> -      case 0:
> -    if (a * a < 0.01588)
> -      retval = bsloww (a, da, x, n);
> -    else
> -      retval = bsloww1 (a, da, x, n);
> -    break;
> -      case 2:
> -    if (a * a < 0.01588)
> -      retval = bsloww (-a, -da, x, n);
> -    else
> -      retval = bsloww1 (-a, -da, x, n);
> -    break;
> +    case 2:
> +      a = -a;
> +      da = -da;
> +    case 0:
> +      if (a * a < 0.01588)
> +    retval = bsloww (a, da, x, n);
> +      else
> +    retval = bsloww1 (a, da, x, n);
> +      break;
> 
> -      case 1:
> -      case 3:
> -    retval = bsloww2 (a, da, x, n);
> -    break;
> +    case 1:
> +    case 3:
> +      retval = bsloww2 (a, da, x, n);
> +      break;
>     }
>   return retval;
> }
> -- 
> 2.7.4
>
Joseph Myers Aug. 29, 2016, 4:03 p.m. UTC | #2
On Tue, 23 Aug 2016, Siddhesh Poyarekar wrote:

> +    case 2:
> +      a = -a;
> +      da = -da;
> +    case 0:

OK with a comment on this fallthrough (we might want to use the 
-Wimplicit-fallthrough being proposed for GCC 7...).
Siddhesh Poyarekar Aug. 30, 2016, 9:26 a.m. UTC | #3
On Monday 29 August 2016 09:33 PM, Joseph Myers wrote:
> OK with a comment on this fallthrough (we might want to use the 
> -Wimplicit-fallthrough being proposed for GCC 7...).
>

I pushed a separate commit with the fallthrough comment for both switch
blocks in s_sin.c.

Siddhesh
diff mbox

Patch

diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
index 7c9a079..e1ee7a9 100644
--- a/sysdeps/ieee754/dbl-64/s_sin.c
+++ b/sysdeps/ieee754/dbl-64/s_sin.c
@@ -249,23 +249,20 @@  reduce_and_compute (double x, unsigned int k)
   k = (n + k) % 4;
   switch (k)
     {
-      case 0:
-	if (a * a < 0.01588)
-	  retval = bsloww (a, da, x, n);
-	else
-	  retval = bsloww1 (a, da, x, n);
-	break;
-      case 2:
-	if (a * a < 0.01588)
-	  retval = bsloww (-a, -da, x, n);
-	else
-	  retval = bsloww1 (-a, -da, x, n);
-	break;
+    case 2:
+      a = -a;
+      da = -da;
+    case 0:
+      if (a * a < 0.01588)
+	retval = bsloww (a, da, x, n);
+      else
+	retval = bsloww1 (a, da, x, n);
+      break;
 
-      case 1:
-      case 3:
-	retval = bsloww2 (a, da, x, n);
-	break;
+    case 1:
+    case 3:
+      retval = bsloww2 (a, da, x, n);
+      break;
     }
   return retval;
 }