a2cf7d
From 429eff12541cc0779c381f84257c8860ece25b12 Mon Sep 17 00:00:00 2001
a2cf7d
From: Stefan Liebler <stli@linux.ibm.com>
a2cf7d
Date: Wed, 11 Dec 2019 15:09:29 +0100
a2cf7d
Subject: [PATCH 21/28] S390: Use convert-to-fixed instruction for llrint
a2cf7d
 functions.
a2cf7d
a2cf7d
If compiled with z196 zarch support, the convert-to-fixed instruction
a2cf7d
is used to implement llrint, llrintf, llrintl.
a2cf7d
Otherwise the common-code implementation is used.
a2cf7d
a2cf7d
(cherry picked from commit f10c1654fe13d797d2fd347dc47f72f93c58cf62)
a2cf7d
---
a2cf7d
 sysdeps/s390/fpu/s_llrint.c  | 50 +++++++++++++++++++++++++++++++++++
a2cf7d
 sysdeps/s390/fpu/s_llrintf.c | 50 +++++++++++++++++++++++++++++++++++
a2cf7d
 sysdeps/s390/fpu/s_llrintl.c | 51 ++++++++++++++++++++++++++++++++++++
a2cf7d
 3 files changed, 151 insertions(+)
a2cf7d
 create mode 100644 sysdeps/s390/fpu/s_llrint.c
a2cf7d
 create mode 100644 sysdeps/s390/fpu/s_llrintf.c
a2cf7d
 create mode 100644 sysdeps/s390/fpu/s_llrintl.c
a2cf7d
a2cf7d
diff --git a/sysdeps/s390/fpu/s_llrint.c b/sysdeps/s390/fpu/s_llrint.c
a2cf7d
new file mode 100644
a2cf7d
index 0000000000..edd796ae8c
a2cf7d
--- /dev/null
a2cf7d
+++ b/sysdeps/s390/fpu/s_llrint.c
a2cf7d
@@ -0,0 +1,50 @@
a2cf7d
+/* llrint() - 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
+#if defined __s390x__ && defined HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
a2cf7d
+/* We only support s390x as on s390 a long long int refers to a register pair
a2cf7d
+   of two 4byte registers instead of a 8byte register which is produced by the
a2cf7d
+   instruction.
a2cf7d
+   Note: On s390 this instruction would only be used if build with -mzarch.  */
a2cf7d
+# include <math.h>
a2cf7d
+# include <libm-alias-double.h>
a2cf7d
+
a2cf7d
+long long int
a2cf7d
+__llrint (double x)
a2cf7d
+{
a2cf7d
+  long long int y;
a2cf7d
+  /* The z196 zarch "convert to fixed" (cgdbra) instruction is rounding
a2cf7d
+     according to current rounding mode (M3-field: 0).
a2cf7d
+     First convert x with suppressed inexact exception and check if the
a2cf7d
+     resulting value is beyond the target limits (indicated by cc=3;
a2cf7d
+     Note: a nan is also indicated by cc=3).
a2cf7d
+     If the resulting value is within the target limits, redo
a2cf7d
+     without suppressing the inexact exception.  */
a2cf7d
+  __asm__ ("cgdbra %0,0,%1,4 \n\t"
a2cf7d
+	   "jo 1f \n\t"
a2cf7d
+	   "cgdbra %0,0,%1,0 \n\t"
a2cf7d
+	   "1:"
a2cf7d
+	   : "=&d" (y) : "f" (x) : "cc");
a2cf7d
+  return y;
a2cf7d
+}
a2cf7d
+libm_alias_double (__llrint, llrint)
a2cf7d
+
a2cf7d
+#else
a2cf7d
+# include <sysdeps/ieee754/dbl-64/s_llrint.c>
a2cf7d
+#endif
a2cf7d
diff --git a/sysdeps/s390/fpu/s_llrintf.c b/sysdeps/s390/fpu/s_llrintf.c
a2cf7d
new file mode 100644
a2cf7d
index 0000000000..3cbe7c581a
a2cf7d
--- /dev/null
a2cf7d
+++ b/sysdeps/s390/fpu/s_llrintf.c
a2cf7d
@@ -0,0 +1,50 @@
a2cf7d
+/* llrintf() - 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
+#if defined __s390x__ && defined HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
a2cf7d
+/* We only support s390x as on s390 a long long int refers to a register pair
a2cf7d
+   of two 4byte registers instead of a 8byte register which is produced by the
a2cf7d
+   instruction.
a2cf7d
+   Note: On s390 this instruction would only be used if build with -mzarch.  */
a2cf7d
+# include <math.h>
a2cf7d
+# include <libm-alias-float.h>
a2cf7d
+
a2cf7d
+long long int
a2cf7d
+__llrintf (float x)
a2cf7d
+{
a2cf7d
+  long long int y;
a2cf7d
+  /* The z196 zarch "convert to fixed" (cgebra) instruction is rounding
a2cf7d
+     according to current rounding mode (M3-field: 0).
a2cf7d
+     First convert x with suppressed inexact exception and check if the
a2cf7d
+     resulting value is beyond the target limits (indicated by cc=3;
a2cf7d
+     Note: a nan is also indicated by cc=3).
a2cf7d
+     If the resulting value is within the target limits, redo
a2cf7d
+     without suppressing the inexact exception.  */
a2cf7d
+  __asm__ ("cgebra %0,0,%1,4 \n\t"
a2cf7d
+	   "jo 1f \n\t"
a2cf7d
+	   "cgebra %0,0,%1,0 \n\t"
a2cf7d
+	   "1:"
a2cf7d
+	   : "=&d" (y) : "f" (x) : "cc");
a2cf7d
+  return y;
a2cf7d
+}
a2cf7d
+libm_alias_float (__llrint, llrint)
a2cf7d
+
a2cf7d
+#else
a2cf7d
+# include <sysdeps/ieee754/flt-32/s_llrintf.c>
a2cf7d
+#endif
a2cf7d
diff --git a/sysdeps/s390/fpu/s_llrintl.c b/sysdeps/s390/fpu/s_llrintl.c
a2cf7d
new file mode 100644
a2cf7d
index 0000000000..37eea5914f
a2cf7d
--- /dev/null
a2cf7d
+++ b/sysdeps/s390/fpu/s_llrintl.c
a2cf7d
@@ -0,0 +1,51 @@
a2cf7d
+/* llrintl() - 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
+#if defined __s390x__ && defined HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
a2cf7d
+/* We only support s390x as on s390 a long long int refers to a register pair
a2cf7d
+   of two 4byte registers instead of a 8byte register which is produced by the
a2cf7d
+   instruction.
a2cf7d
+   Note: On s390 this instruction would only be used if build with -mzarch.  */
a2cf7d
+# include <math.h>
a2cf7d
+# include <math_private.h>
a2cf7d
+# include <libm-alias-ldouble.h>
a2cf7d
+
a2cf7d
+long long int
a2cf7d
+__llrintl (_Float128 x)
a2cf7d
+{
a2cf7d
+  long long int y;
a2cf7d
+  /* The z196 zarch "convert to fixed" (cgxbra) instruction is rounding
a2cf7d
+     according to current rounding mode (M3-field: 0).
a2cf7d
+     First convert x with suppressed inexact exception and check if the
a2cf7d
+     resulting value is beyond the target limits (indicated by cc=3;
a2cf7d
+     Note: a nan is also indicated by cc=3).
a2cf7d
+     If the resulting value is within the target limits, redo
a2cf7d
+     without suppressing the inexact exception.  */
a2cf7d
+  __asm__ ("cgxbra %0,0,%1,4 \n\t"
a2cf7d
+	   "jo 1f \n\t"
a2cf7d
+	   "cgxbra %0,0,%1,0 \n\t"
a2cf7d
+	   "1:"
a2cf7d
+	   : "=&d" (y) : "f" (x) : "cc");
a2cf7d
+  return y;
a2cf7d
+}
a2cf7d
+libm_alias_ldouble (__llrint, llrint)
a2cf7d
+
a2cf7d
+#else
a2cf7d
+# include <sysdeps/ieee754/ldbl-128/s_llrintl.c>
a2cf7d
+#endif
a2cf7d
-- 
a2cf7d
2.18.2
a2cf7d