a2cf7d
From 855d045bc26175195dadafc28abf84e7b6613aac Mon Sep 17 00:00:00 2001
a2cf7d
From: Stefan Liebler <stli@linux.ibm.com>
a2cf7d
Date: Wed, 11 Dec 2019 15:09:28 +0100
a2cf7d
Subject: [PATCH 19/28] S390: Use load-fp-integer instruction for roundeven
a2cf7d
 functions.
a2cf7d
a2cf7d
If compiled with z196 zarch support, the load-fp-integer instruction
a2cf7d
is used to implement roundeven, roundevenf, roundevenl.
a2cf7d
Otherwise the common-code implementation is used.
a2cf7d
a2cf7d
(cherry picked from commit 4399b163376b331773e43917dcf56ce68e43e6a0)
a2cf7d
---
a2cf7d
 sysdeps/s390/fpu/s_roundeven.c  | 39 +++++++++++++++++++++++++++++++++
a2cf7d
 sysdeps/s390/fpu/s_roundevenf.c | 38 ++++++++++++++++++++++++++++++++
a2cf7d
 sysdeps/s390/fpu/s_roundevenl.c | 39 +++++++++++++++++++++++++++++++++
a2cf7d
 3 files changed, 116 insertions(+)
a2cf7d
 create mode 100644 sysdeps/s390/fpu/s_roundeven.c
a2cf7d
 create mode 100644 sysdeps/s390/fpu/s_roundevenf.c
a2cf7d
 create mode 100644 sysdeps/s390/fpu/s_roundevenl.c
a2cf7d
a2cf7d
diff --git a/sysdeps/s390/fpu/s_roundeven.c b/sysdeps/s390/fpu/s_roundeven.c
a2cf7d
new file mode 100644
a2cf7d
index 0000000000..95a83a70e8
a2cf7d
--- /dev/null
a2cf7d
+++ b/sysdeps/s390/fpu/s_roundeven.c
a2cf7d
@@ -0,0 +1,39 @@
a2cf7d
+/* roundeven() - S390 version.
a2cf7d
+   Copyright (C) 2019 Free Software Foundation, Inc.
a2cf7d
+
a2cf7d
+   This file is part of the GNU C Library.
a2cf7d
+
a2cf7d
+   The GNU C Library is free software; you can redistribute it and/or
a2cf7d
+   modify it under the terms of the GNU Lesser General Public License as
a2cf7d
+   published by the Free Software Foundation; either version 2.1 of the
a2cf7d
+   License, or (at your option) any later version.
a2cf7d
+
a2cf7d
+   The GNU C Library is distributed in the hope that it will be useful,
a2cf7d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
a2cf7d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a2cf7d
+   Lesser General Public License for more details.
a2cf7d
+
a2cf7d
+   You should have received a copy of the GNU Lesser General Public
a2cf7d
+   License along with the GNU C Library; if not, see
a2cf7d
+   <https://www.gnu.org/licenses/>.  */
a2cf7d
+
a2cf7d
+#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
a2cf7d
+# include <math.h>
a2cf7d
+# include <libm-alias-double.h>
a2cf7d
+
a2cf7d
+double
a2cf7d
+__roundeven (double x)
a2cf7d
+{
a2cf7d
+  double y;
a2cf7d
+  /* The z196 zarch "load fp integer" (fidbra) instruction is rounding
a2cf7d
+     x to the nearest integer with "ties to even" rounding mode
a2cf7d
+     (M3-field: 4) where inexact exceptions are suppressed (M4-field: 4).  */
a2cf7d
+  __asm__ ("fidbra %0,4,%1,4" : "=f" (y) : "f" (x));
a2cf7d
+  return y;
a2cf7d
+}
a2cf7d
+hidden_def (__roundeven)
a2cf7d
+libm_alias_double (__roundeven, roundeven)
a2cf7d
+
a2cf7d
+#else
a2cf7d
+# include <sysdeps/ieee754/dbl-64/s_roundeven.c>
a2cf7d
+#endif
a2cf7d
diff --git a/sysdeps/s390/fpu/s_roundevenf.c b/sysdeps/s390/fpu/s_roundevenf.c
a2cf7d
new file mode 100644
a2cf7d
index 0000000000..c620a0189c
a2cf7d
--- /dev/null
a2cf7d
+++ b/sysdeps/s390/fpu/s_roundevenf.c
a2cf7d
@@ -0,0 +1,38 @@
a2cf7d
+/* roundevenf() - S390 version.
a2cf7d
+   Copyright (C) 2019 Free Software Foundation, Inc.
a2cf7d
+
a2cf7d
+   This file is part of the GNU C Library.
a2cf7d
+
a2cf7d
+   The GNU C Library is free software; you can redistribute it and/or
a2cf7d
+   modify it under the terms of the GNU Lesser General Public License as
a2cf7d
+   published by the Free Software Foundation; either version 2.1 of the
a2cf7d
+   License, or (at your option) any later version.
a2cf7d
+
a2cf7d
+   The GNU C Library is distributed in the hope that it will be useful,
a2cf7d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
a2cf7d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a2cf7d
+   Lesser General Public License for more details.
a2cf7d
+
a2cf7d
+   You should have received a copy of the GNU Lesser General Public
a2cf7d
+   License along with the GNU C Library; if not, see
a2cf7d
+   <https://www.gnu.org/licenses/>.  */
a2cf7d
+
a2cf7d
+#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
a2cf7d
+# include <math.h>
a2cf7d
+# include <libm-alias-float.h>
a2cf7d
+
a2cf7d
+float
a2cf7d
+__roundevenf (float x)
a2cf7d
+{
a2cf7d
+  float y;
a2cf7d
+  /* The z196 zarch "load fp integer" (fiebra) instruction is rounding
a2cf7d
+     x to the nearest integer with "ties to even" rounding mode
a2cf7d
+     (M3-field: 4) where inexact exceptions are suppressed (M4-field: 4).  */
a2cf7d
+  __asm__ ("fiebra %0,4,%1,4" : "=f" (y) : "f" (x));
a2cf7d
+  return y;
a2cf7d
+}
a2cf7d
+libm_alias_float (__roundeven, roundeven)
a2cf7d
+
a2cf7d
+#else
a2cf7d
+# include <sysdeps/ieee754/flt-32/s_roundevenf.c>
a2cf7d
+#endif
a2cf7d
diff --git a/sysdeps/s390/fpu/s_roundevenl.c b/sysdeps/s390/fpu/s_roundevenl.c
a2cf7d
new file mode 100644
a2cf7d
index 0000000000..3481af2665
a2cf7d
--- /dev/null
a2cf7d
+++ b/sysdeps/s390/fpu/s_roundevenl.c
a2cf7d
@@ -0,0 +1,39 @@
a2cf7d
+/* roundevenl() - S390 version.
a2cf7d
+   Copyright (C) 2019 Free Software Foundation, Inc.
a2cf7d
+
a2cf7d
+   This file is part of the GNU C Library.
a2cf7d
+
a2cf7d
+   The GNU C Library is free software; you can redistribute it and/or
a2cf7d
+   modify it under the terms of the GNU Lesser General Public License as
a2cf7d
+   published by the Free Software Foundation; either version 2.1 of the
a2cf7d
+   License, or (at your option) any later version.
a2cf7d
+
a2cf7d
+   The GNU C Library is distributed in the hope that it will be useful,
a2cf7d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
a2cf7d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a2cf7d
+   Lesser General Public License for more details.
a2cf7d
+
a2cf7d
+   You should have received a copy of the GNU Lesser General Public
a2cf7d
+   License along with the GNU C Library; if not, see
a2cf7d
+   <https://www.gnu.org/licenses/>.  */
a2cf7d
+
a2cf7d
+#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
a2cf7d
+# include <math.h>
a2cf7d
+# include <math_private.h>
a2cf7d
+# include <libm-alias-ldouble.h>
a2cf7d
+
a2cf7d
+_Float128
a2cf7d
+__roundevenl (_Float128 x)
a2cf7d
+{
a2cf7d
+  _Float128 y;
a2cf7d
+  /* The z196 zarch "load fp integer" (fixbra) instruction is rounding
a2cf7d
+     x to the nearest integer with "ties to even" rounding mode
a2cf7d
+     (M3-field: 4) where inexact exceptions are suppressed (M4-field: 4).  */
a2cf7d
+  __asm__ ("fixbra %0,4,%1,4" : "=f" (y) : "f" (x));
a2cf7d
+  return y;
a2cf7d
+}
a2cf7d
+libm_alias_ldouble (__roundeven, roundeven)
a2cf7d
+
a2cf7d
+#else
a2cf7d
+# include <sysdeps/ieee754/ldbl-128/s_roundevenl.c>
a2cf7d
+#endif
a2cf7d
-- 
a2cf7d
2.18.2
a2cf7d