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