981dc9
From af123aa95091d3d2d1b4ff027cf806ca1721d29d Mon Sep 17 00:00:00 2001
981dc9
From: Stefan Liebler <stli@linux.ibm.com>
981dc9
Date: Wed, 11 Dec 2019 15:09:14 +0100
981dc9
Subject: [PATCH 01/28] Always use wordsize-64 version of s_nearbyint.c.
981dc9
981dc9
This patch replaces s_nearbyint.c in sysdeps/dbl-64 with the one in
981dc9
sysdeps/dbl-64/wordsize-64 and removes the latter one.
981dc9
The code is not changed except changes in code style.
981dc9
981dc9
Also adjusted the include path in x86_64 file.
981dc9
981dc9
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
981dc9
---
981dc9
 sysdeps/ieee754/dbl-64/s_nearbyint.c             | 38 ++++++--------
981dc9
 sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c | 65 ------------------------
981dc9
 sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c     |  2 +-
981dc9
 3 files changed, 17 insertions(+), 88 deletions(-)
981dc9
 delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c
981dc9
981dc9
Note: tweaked by DJ for backport; some portions handled by glibc-rh1780204-07.patch
981dc9
981dc9
diff -rupN a/sysdeps/ieee754/dbl-64/s_nearbyint.c b/sysdeps/ieee754/dbl-64/s_nearbyint.c
981dc9
--- a/sysdeps/ieee754/dbl-64/s_nearbyint.c	2020-04-09 21:17:04.281854809 -0400
981dc9
+++ b/sysdeps/ieee754/dbl-64/s_nearbyint.c	2020-04-09 21:28:13.380741798 -0400
981dc9
@@ -10,10 +10,6 @@
981dc9
  * ====================================================
981dc9
  */
981dc9
 
981dc9
-#if defined(LIBM_SCCS) && !defined(lint)
981dc9
-static char rcsid[] = "$NetBSD: s_rint.c,v 1.8 1995/05/10 20:48:04 jtc Exp $";
981dc9
-#endif
981dc9
-
981dc9
 /*
981dc9
  * rint(x)
981dc9
  * Return x rounded to integral value according to the prevailing
981dc9
@@ -44,35 +40,33 @@ __nearbyint (double x)
981dc9
 		-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
981dc9
   };
981dc9
   fenv_t env;
981dc9
-  int32_t i0, j0, sx;
981dc9
-  double w, t;
981dc9
-  GET_HIGH_WORD (i0, x);
981dc9
-  sx = (i0 >> 31) & 1;
981dc9
-  j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
981dc9
-  if (j0 < 52)
981dc9
+  int64_t i0, sx;
981dc9
+  int32_t j0;
981dc9
+  EXTRACT_WORDS64 (i0, x);
981dc9
+  sx = (i0 >> 63) & 1;
981dc9
+  j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
981dc9
+  if (__glibc_likely (j0 < 52))
981dc9
     {
981dc9
       if (j0 < 0)
981dc9
 	{
981dc9
 	  libc_feholdexcept (&env;;
981dc9
-	  w = TWO52[sx] + math_opt_barrier (x);
981dc9
-	  t = w - TWO52[sx];
981dc9
+	  double w = TWO52[sx] + math_opt_barrier (x);
981dc9
+	  double t =  w - TWO52[sx];
981dc9
 	  math_force_eval (t);
981dc9
 	  libc_fesetenv (&env;;
981dc9
-	  GET_HIGH_WORD (i0, t);
981dc9
-	  SET_HIGH_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
981dc9
-	  return t;
981dc9
+	  return copysign (t, x);
981dc9
 	}
981dc9
     }
981dc9
   else
981dc9
     {
981dc9
       if (j0 == 0x400)
981dc9
-	return x + x;                   /* inf or NaN */
981dc9
+	return x + x;			/* inf or NaN  */
981dc9
       else
981dc9
-	return x;                       /* x is integral */
981dc9
+	return x;			/* x is integral  */
981dc9
     }
981dc9
   libc_feholdexcept (&env;;
981dc9
-  w = TWO52[sx] + math_opt_barrier (x);
981dc9
-  t = w - TWO52[sx];
981dc9
+  double w = TWO52[sx] + math_opt_barrier (x);
981dc9
+  double t = w - TWO52[sx];
981dc9
   math_force_eval (t);
981dc9
   libc_fesetenv (&env;;
981dc9
   return t;
981dc9
diff -rupN a/sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c
981dc9
--- a/sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c	2018-08-01 01:10:47.000000000 -0400
981dc9
+++ b/sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c	1969-12-31 19:00:00.000000000 -0500
981dc9
@@ -1,64 +0,0 @@
981dc9
-/* Adapted for use as nearbyint by Ulrich Drepper <drepper@cygnus.com>.  */
981dc9
-/*
981dc9
- * ====================================================
981dc9
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
981dc9
- *
981dc9
- * Developed at SunPro, a Sun Microsystems, Inc. business.
981dc9
- * Permission to use, copy, modify, and distribute this
981dc9
- * software is freely granted, provided that this notice
981dc9
- * is preserved.
981dc9
- * ====================================================
981dc9
- */
981dc9
-
981dc9
-/*
981dc9
- * rint(x)
981dc9
- * Return x rounded to integral value according to the prevailing
981dc9
- * rounding mode.
981dc9
- * Method:
981dc9
- *	Using floating addition.
981dc9
- * Exception:
981dc9
- *	Inexact flag raised if x not equal to rint(x).
981dc9
- */
981dc9
-
981dc9
-#include <fenv.h>
981dc9
-#include <math.h>
981dc9
-#include <math-barriers.h>
981dc9
-#include <math_private.h>
981dc9
-#include <libm-alias-double.h>
981dc9
-
981dc9
-static const double
981dc9
-TWO52[2]={
981dc9
-  4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
981dc9
- -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
981dc9
-};
981dc9
-
981dc9
-double
981dc9
-__nearbyint(double x)
981dc9
-{
981dc9
-	fenv_t env;
981dc9
-	int64_t i0,sx;
981dc9
-	int32_t j0;
981dc9
-	EXTRACT_WORDS64(i0,x);
981dc9
-	sx = (i0>>63)&1;
981dc9
-	j0 = ((i0>>52)&0x7ff)-0x3ff;
981dc9
-	if(__builtin_expect(j0<52, 1)) {
981dc9
-	    if(j0<0) {
981dc9
-		libc_feholdexcept (&env;;
981dc9
-		double w = TWO52[sx] + math_opt_barrier (x);
981dc9
-		double t =  w-TWO52[sx];
981dc9
-		math_force_eval (t);
981dc9
-		libc_fesetenv (&env;;
981dc9
-		return __copysign (t, x);
981dc9
-	    }
981dc9
-	} else {
981dc9
-	    if(j0==0x400) return x+x;	/* inf or NaN */
981dc9
-	    else return x;		/* x is integral */
981dc9
-	}
981dc9
-	libc_feholdexcept (&env;;
981dc9
-	double w = TWO52[sx] + math_opt_barrier (x);
981dc9
-	double t = w-TWO52[sx];
981dc9
-	math_force_eval (t);
981dc9
-	libc_fesetenv (&env;;
981dc9
-	return t;
981dc9
-}
981dc9
-libm_alias_double (__nearbyint, nearbyint)
981dc9
diff -rupN a/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c b/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c
981dc9
--- a/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c	2018-08-01 01:10:47.000000000 -0400
981dc9
+++ b/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c	2020-04-09 21:28:13.205735274 -0400
981dc9
@@ -1,3 +1,3 @@
981dc9
 #undef __nearbyint
981dc9
 #define __nearbyint __nearbyint_c
981dc9
-#include <sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c>
981dc9
+#include <sysdeps/ieee754/dbl-64/s_nearbyint.c>