dfa500
From dd8bfb911e89f3ad1da5cfa5618a8c52c62bb095 Mon Sep 17 00:00:00 2001
dfa500
From: Stefan Liebler <stli@linux.ibm.com>
dfa500
Date: Wed, 11 Dec 2019 15:09:31 +0100
dfa500
Subject: [PATCH 23/28] S390: Use convert-to-fixed instruction for llround
dfa500
 functions.
dfa500
dfa500
If compiled with z196 zarch support, the convert-to-fixed instruction
dfa500
is used to implement llround, llroundf, llroundl.
dfa500
Otherwise the common-code implementation is used.
dfa500
dfa500
(cherry picked from commit 7d42d614fdc2c9d9f6ad46111bd6130501d50460)
dfa500
---
dfa500
 sysdeps/s390/fpu/s_llround.c  | 42 ++++++++++++++++++++++++++++++++++
dfa500
 sysdeps/s390/fpu/s_llroundf.c | 42 ++++++++++++++++++++++++++++++++++
dfa500
 sysdeps/s390/fpu/s_llroundl.c | 43 +++++++++++++++++++++++++++++++++++
dfa500
 3 files changed, 127 insertions(+)
dfa500
 create mode 100644 sysdeps/s390/fpu/s_llround.c
dfa500
 create mode 100644 sysdeps/s390/fpu/s_llroundf.c
dfa500
 create mode 100644 sysdeps/s390/fpu/s_llroundl.c
dfa500
dfa500
diff --git a/sysdeps/s390/fpu/s_llround.c b/sysdeps/s390/fpu/s_llround.c
dfa500
new file mode 100644
dfa500
index 0000000000..f4a1b21637
dfa500
--- /dev/null
dfa500
+++ b/sysdeps/s390/fpu/s_llround.c
dfa500
@@ -0,0 +1,42 @@
dfa500
+/* llround() - S390 version.
dfa500
+   Copyright (C) 2019 Free Software Foundation, Inc.
dfa500
+
dfa500
+   This file is part of the GNU C Library.
dfa500
+
dfa500
+   The GNU C Library is free software; you can redistribute it and/or
dfa500
+   modify it under the terms of the GNU Lesser General Public License as
dfa500
+   published by the Free Software Foundation; either version 2.1 of the
dfa500
+   License, or (at your option) any later version.
dfa500
+
dfa500
+   The GNU C Library is distributed in the hope that it will be useful,
dfa500
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
dfa500
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dfa500
+   Lesser General Public License for more details.
dfa500
+
dfa500
+   You should have received a copy of the GNU Lesser General Public
dfa500
+   License along with the GNU C Library; if not, see
dfa500
+   <https://www.gnu.org/licenses/>.  */
dfa500
+
dfa500
+#if defined __s390x__ && defined HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
dfa500
+/* We only support s390x as on s390 a long long int refers to a register pair
dfa500
+   of two 4byte registers instead of a 8byte register which is produced by the
dfa500
+   instruction.
dfa500
+   Note: On s390 this instruction would only be used if build with -mzarch.  */
dfa500
+# include <math.h>
dfa500
+# include <libm-alias-double.h>
dfa500
+
dfa500
+long long int
dfa500
+__llround (double x)
dfa500
+{
dfa500
+  long long int y;
dfa500
+  /* The z196 zarch "convert to fixed" (cgdbra) instruction is rounding
dfa500
+     x to the nearest integer with "ties away from 0" rounding mode
dfa500
+     (M3-field: 1) where inexact exceptions are suppressed (M4-field: 4).  */
dfa500
+  __asm__ ("cgdbra %0,1,%1,4" : "=d" (y) : "f" (x) : "cc");
dfa500
+  return y;
dfa500
+}
dfa500
+libm_alias_double (__llround, llround)
dfa500
+
dfa500
+#else
dfa500
+# include <sysdeps/ieee754/dbl-64/s_llround.c>
dfa500
+#endif
dfa500
diff --git a/sysdeps/s390/fpu/s_llroundf.c b/sysdeps/s390/fpu/s_llroundf.c
dfa500
new file mode 100644
dfa500
index 0000000000..d202f4be8c
dfa500
--- /dev/null
dfa500
+++ b/sysdeps/s390/fpu/s_llroundf.c
dfa500
@@ -0,0 +1,42 @@
dfa500
+/* llroundf() - S390 version.
dfa500
+   Copyright (C) 2019 Free Software Foundation, Inc.
dfa500
+
dfa500
+   This file is part of the GNU C Library.
dfa500
+
dfa500
+   The GNU C Library is free software; you can redistribute it and/or
dfa500
+   modify it under the terms of the GNU Lesser General Public License as
dfa500
+   published by the Free Software Foundation; either version 2.1 of the
dfa500
+   License, or (at your option) any later version.
dfa500
+
dfa500
+   The GNU C Library is distributed in the hope that it will be useful,
dfa500
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
dfa500
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dfa500
+   Lesser General Public License for more details.
dfa500
+
dfa500
+   You should have received a copy of the GNU Lesser General Public
dfa500
+   License along with the GNU C Library; if not, see
dfa500
+   <https://www.gnu.org/licenses/>.  */
dfa500
+
dfa500
+#if defined __s390x__ && defined HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
dfa500
+/* We only support s390x as on s390 a long long int refers to a register pair
dfa500
+   of two 4byte registers instead of a 8byte register which is produced by the
dfa500
+   instruction.
dfa500
+   Note: On s390 this instruction would only be used if build with -mzarch.  */
dfa500
+# include <math.h>
dfa500
+# include <libm-alias-float.h>
dfa500
+
dfa500
+long long int
dfa500
+__llroundf (float x)
dfa500
+{
dfa500
+  long long int y;
dfa500
+  /* The z196 zarch "convert to fixed" (cgebra) instruction is rounding
dfa500
+     x to the nearest integer with "ties away from 0" rounding mode
dfa500
+     (M3-field: 1) where inexact exceptions are suppressed (M4-field: 4).  */
dfa500
+  __asm__ ("cgebra %0,1,%1,4" : "=d" (y) : "f" (x) : "cc");
dfa500
+  return y;
dfa500
+}
dfa500
+libm_alias_float (__llround, llround)
dfa500
+
dfa500
+#else
dfa500
+# include <sysdeps/ieee754/flt-32/s_llroundf.c>
dfa500
+#endif
dfa500
diff --git a/sysdeps/s390/fpu/s_llroundl.c b/sysdeps/s390/fpu/s_llroundl.c
dfa500
new file mode 100644
dfa500
index 0000000000..58976cd5c5
dfa500
--- /dev/null
dfa500
+++ b/sysdeps/s390/fpu/s_llroundl.c
dfa500
@@ -0,0 +1,43 @@
dfa500
+/* llroundl() - S390 version.
dfa500
+   Copyright (C) 2019 Free Software Foundation, Inc.
dfa500
+
dfa500
+   This file is part of the GNU C Library.
dfa500
+
dfa500
+   The GNU C Library is free software; you can redistribute it and/or
dfa500
+   modify it under the terms of the GNU Lesser General Public License as
dfa500
+   published by the Free Software Foundation; either version 2.1 of the
dfa500
+   License, or (at your option) any later version.
dfa500
+
dfa500
+   The GNU C Library is distributed in the hope that it will be useful,
dfa500
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
dfa500
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dfa500
+   Lesser General Public License for more details.
dfa500
+
dfa500
+   You should have received a copy of the GNU Lesser General Public
dfa500
+   License along with the GNU C Library; if not, see
dfa500
+   <https://www.gnu.org/licenses/>.  */
dfa500
+
dfa500
+#if defined __s390x__ && defined HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
dfa500
+/* We only support s390x as on s390 a long long int refers to a register pair
dfa500
+   of two 4byte registers instead of a 8byte register which is produced by the
dfa500
+   instruction.
dfa500
+   Note: On s390 this instruction would only be used if build with -mzarch.  */
dfa500
+# include <math.h>
dfa500
+# include <math_private.h>
dfa500
+# include <libm-alias-ldouble.h>
dfa500
+
dfa500
+long long int
dfa500
+__llroundl (_Float128 x)
dfa500
+{
dfa500
+  long long int y;
dfa500
+  /* The z196 zarch "convert to fixed" (cgxbra) instruction is rounding
dfa500
+     x to the nearest integer with "ties away from 0" rounding mode
dfa500
+     (M3-field: 1) where inexact exceptions are suppressed (M4-field: 4).  */
dfa500
+  __asm__ ("cgxbra %0,1,%1,4" : "=d" (y) : "f" (x) : "cc");
dfa500
+  return y;
dfa500
+}
dfa500
+libm_alias_ldouble (__llround, llround)
dfa500
+
dfa500
+#else
dfa500
+# include <sysdeps/ieee754/ldbl-128/s_llroundl.c>
dfa500
+#endif
dfa500
-- 
dfa500
2.18.2
dfa500