|
|
7c0489 |
From 90e84ac5ac8e774ce0cfd3abc5f7d8834efd2c9b Mon Sep 17 00:00:00 2001
|
|
|
7c0489 |
From: Stefan Liebler <stli@linux.ibm.com>
|
|
|
7c0489 |
Date: Wed, 11 Dec 2019 15:09:29 +0100
|
|
|
7c0489 |
Subject: [PATCH 20/28] S390: Use convert-to-fixed instruction for lrint
|
|
|
7c0489 |
functions.
|
|
|
7c0489 |
|
|
|
7c0489 |
If compiled with z196 zarch support, the convert-to-fixed instruction
|
|
|
7c0489 |
is used to implement lrint, lrintf, lrintl.
|
|
|
7c0489 |
Otherwise the common-code implementation is used.
|
|
|
7c0489 |
|
|
|
7c0489 |
(cherry picked from commit e3f07622209c1b4436ef364b134dfd2cd4ca9976)
|
|
|
7c0489 |
---
|
|
|
7c0489 |
sysdeps/s390/fpu/s_lrint.c | 55 ++++++++++++++++++++++++++++++++++++
|
|
|
7c0489 |
sysdeps/s390/fpu/s_lrintf.c | 55 ++++++++++++++++++++++++++++++++++++
|
|
|
7c0489 |
sysdeps/s390/fpu/s_lrintl.c | 56 +++++++++++++++++++++++++++++++++++++
|
|
|
7c0489 |
3 files changed, 166 insertions(+)
|
|
|
7c0489 |
create mode 100644 sysdeps/s390/fpu/s_lrint.c
|
|
|
7c0489 |
create mode 100644 sysdeps/s390/fpu/s_lrintf.c
|
|
|
7c0489 |
create mode 100644 sysdeps/s390/fpu/s_lrintl.c
|
|
|
7c0489 |
|
|
|
7c0489 |
diff --git a/sysdeps/s390/fpu/s_lrint.c b/sysdeps/s390/fpu/s_lrint.c
|
|
|
7c0489 |
new file mode 100644
|
|
|
7c0489 |
index 0000000000..7be60665b5
|
|
|
7c0489 |
--- /dev/null
|
|
|
7c0489 |
+++ b/sysdeps/s390/fpu/s_lrint.c
|
|
|
7c0489 |
@@ -0,0 +1,55 @@
|
|
|
7c0489 |
+/* lrint() - S390 version.
|
|
|
7c0489 |
+ Copyright (C) 2019 Free Software Foundation, Inc.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ This file is part of the GNU C Library.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
7c0489 |
+ modify it under the terms of the GNU Lesser General Public License as
|
|
|
7c0489 |
+ published by the Free Software Foundation; either version 2.1 of the
|
|
|
7c0489 |
+ License, or (at your option) any later version.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
7c0489 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7c0489 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
7c0489 |
+ Lesser General Public License for more details.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
7c0489 |
+ License along with the GNU C Library; if not, see
|
|
|
7c0489 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
|
|
|
7c0489 |
+# include <math.h>
|
|
|
7c0489 |
+# include <libm-alias-double.h>
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+/* The sizeof (long int) differs between s390x (8byte) and s390 (4byte).
|
|
|
7c0489 |
+ Thus we need different instructions as the target size is encoded there.
|
|
|
7c0489 |
+ Note: On s390 this instruction is only used if build with -mzarch. */
|
|
|
7c0489 |
+# ifdef __s390x__
|
|
|
7c0489 |
+# define INSN "cgdbra"
|
|
|
7c0489 |
+# else
|
|
|
7c0489 |
+# define INSN "cfdbra"
|
|
|
7c0489 |
+# endif
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+long int
|
|
|
7c0489 |
+__lrint (double x)
|
|
|
7c0489 |
+{
|
|
|
7c0489 |
+ long int y;
|
|
|
7c0489 |
+ /* The z196 zarch "convert to fixed" (cgdbra) instruction is rounding
|
|
|
7c0489 |
+ according to current rounding mode (M3-field: 0).
|
|
|
7c0489 |
+ First convert x with suppressed inexact exception and check if the
|
|
|
7c0489 |
+ resulting value is beyond the target limits (indicated by cc=3;
|
|
|
7c0489 |
+ Note: a nan is also indicated by cc=3).
|
|
|
7c0489 |
+ If the resulting value is within the target limits, redo
|
|
|
7c0489 |
+ without suppressing the inexact exception. */
|
|
|
7c0489 |
+ __asm__ (INSN " %0,0,%1,4 \n\t"
|
|
|
7c0489 |
+ "jo 1f \n\t"
|
|
|
7c0489 |
+ INSN " %0,0,%1,0 \n\t"
|
|
|
7c0489 |
+ "1:"
|
|
|
7c0489 |
+ : "=&d" (y) : "f" (x) : "cc");
|
|
|
7c0489 |
+ return y;
|
|
|
7c0489 |
+}
|
|
|
7c0489 |
+libm_alias_double (__lrint, lrint)
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+#else
|
|
|
7c0489 |
+# include <sysdeps/ieee754/dbl-64/s_lrint.c>
|
|
|
7c0489 |
+#endif
|
|
|
7c0489 |
diff --git a/sysdeps/s390/fpu/s_lrintf.c b/sysdeps/s390/fpu/s_lrintf.c
|
|
|
7c0489 |
new file mode 100644
|
|
|
7c0489 |
index 0000000000..d6a2a4081a
|
|
|
7c0489 |
--- /dev/null
|
|
|
7c0489 |
+++ b/sysdeps/s390/fpu/s_lrintf.c
|
|
|
7c0489 |
@@ -0,0 +1,55 @@
|
|
|
7c0489 |
+/* lrintf() - S390 version.
|
|
|
7c0489 |
+ Copyright (C) 2019 Free Software Foundation, Inc.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ This file is part of the GNU C Library.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
7c0489 |
+ modify it under the terms of the GNU Lesser General Public License as
|
|
|
7c0489 |
+ published by the Free Software Foundation; either version 2.1 of the
|
|
|
7c0489 |
+ License, or (at your option) any later version.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
7c0489 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7c0489 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
7c0489 |
+ Lesser General Public License for more details.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
7c0489 |
+ License along with the GNU C Library; if not, see
|
|
|
7c0489 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
|
|
|
7c0489 |
+# include <math.h>
|
|
|
7c0489 |
+# include <libm-alias-float.h>
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+/* The sizeof (long int) differs between s390x (8byte) and s390 (4byte).
|
|
|
7c0489 |
+ Thus we need different instructions as the target size is encoded there.
|
|
|
7c0489 |
+ Note: On s390 this instruction is only used if build with -mzarch. */
|
|
|
7c0489 |
+# ifdef __s390x__
|
|
|
7c0489 |
+# define INSN "cgebra"
|
|
|
7c0489 |
+# else
|
|
|
7c0489 |
+# define INSN "cfebra"
|
|
|
7c0489 |
+# endif
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+long int
|
|
|
7c0489 |
+__lrintf (float x)
|
|
|
7c0489 |
+{
|
|
|
7c0489 |
+ long int y;
|
|
|
7c0489 |
+ /* The z196 zarch "convert to fixed" (cgebra) instruction is rounding
|
|
|
7c0489 |
+ according to current rounding mode (M3-field: 0).
|
|
|
7c0489 |
+ First convert x with suppressed inexact exception and check if the
|
|
|
7c0489 |
+ resulting value is beyond the target limits (indicated by cc=3;
|
|
|
7c0489 |
+ Note: a nan is also indicated by cc=3).
|
|
|
7c0489 |
+ If the resulting value is within the target limits, redo
|
|
|
7c0489 |
+ without suppressing the inexact exception. */
|
|
|
7c0489 |
+ __asm__ (INSN " %0,0,%1,4 \n\t"
|
|
|
7c0489 |
+ "jo 1f \n\t"
|
|
|
7c0489 |
+ INSN " %0,0,%1,0 \n\t"
|
|
|
7c0489 |
+ "1:"
|
|
|
7c0489 |
+ : "=&d" (y) : "f" (x) : "cc");
|
|
|
7c0489 |
+ return y;
|
|
|
7c0489 |
+}
|
|
|
7c0489 |
+libm_alias_float (__lrint, lrint)
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+#else
|
|
|
7c0489 |
+# include <sysdeps/ieee754/flt-32/s_lrintf.c>
|
|
|
7c0489 |
+#endif
|
|
|
7c0489 |
diff --git a/sysdeps/s390/fpu/s_lrintl.c b/sysdeps/s390/fpu/s_lrintl.c
|
|
|
7c0489 |
new file mode 100644
|
|
|
7c0489 |
index 0000000000..2d386ecff9
|
|
|
7c0489 |
--- /dev/null
|
|
|
7c0489 |
+++ b/sysdeps/s390/fpu/s_lrintl.c
|
|
|
7c0489 |
@@ -0,0 +1,56 @@
|
|
|
7c0489 |
+/* lrintl() - S390 version.
|
|
|
7c0489 |
+ Copyright (C) 2019 Free Software Foundation, Inc.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ This file is part of the GNU C Library.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
7c0489 |
+ modify it under the terms of the GNU Lesser General Public License as
|
|
|
7c0489 |
+ published by the Free Software Foundation; either version 2.1 of the
|
|
|
7c0489 |
+ License, or (at your option) any later version.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
7c0489 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7c0489 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
7c0489 |
+ Lesser General Public License for more details.
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
7c0489 |
+ License along with the GNU C Library; if not, see
|
|
|
7c0489 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
|
|
|
7c0489 |
+# include <math.h>
|
|
|
7c0489 |
+# include <math_private.h>
|
|
|
7c0489 |
+# include <libm-alias-ldouble.h>
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+/* The sizeof (long int) differs between s390x (8byte) and s390 (4byte).
|
|
|
7c0489 |
+ Thus we need different instructions as the target size is encoded there.
|
|
|
7c0489 |
+ Note: On s390 this instruction is only used if build with -mzarch. */
|
|
|
7c0489 |
+# ifdef __s390x__
|
|
|
7c0489 |
+# define INSN "cgxbra"
|
|
|
7c0489 |
+# else
|
|
|
7c0489 |
+# define INSN "cfxbra"
|
|
|
7c0489 |
+# endif
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+long int
|
|
|
7c0489 |
+__lrintl (_Float128 x)
|
|
|
7c0489 |
+{
|
|
|
7c0489 |
+ long int y;
|
|
|
7c0489 |
+ /* The z196 zarch "convert to fixed" (cgxbra) instruction is rounding
|
|
|
7c0489 |
+ according to current rounding mode (M3-field: 0).
|
|
|
7c0489 |
+ First convert x with suppressed inexact exception and check if the
|
|
|
7c0489 |
+ resulting value is beyond the target limits (indicated by cc=3;
|
|
|
7c0489 |
+ Note: a nan is also indicated by cc=3).
|
|
|
7c0489 |
+ If the resulting value is within the target limits, redo
|
|
|
7c0489 |
+ without suppressing the inexact exception. */
|
|
|
7c0489 |
+ __asm__ (INSN " %0,0,%1,4 \n\t"
|
|
|
7c0489 |
+ "jo 1f \n\t"
|
|
|
7c0489 |
+ INSN " %0,0,%1,0 \n\t"
|
|
|
7c0489 |
+ "1:"
|
|
|
7c0489 |
+ : "=&d" (y) : "f" (x) : "cc");
|
|
|
7c0489 |
+ return y;
|
|
|
7c0489 |
+}
|
|
|
7c0489 |
+libm_alias_ldouble (__lrint, lrint)
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+#else
|
|
|
7c0489 |
+# include <sysdeps/ieee754/ldbl-128/s_lrintl.c>
|
|
|
7c0489 |
+#endif
|
|
|
7c0489 |
--
|
|
|
7c0489 |
2.18.2
|
|
|
7c0489 |
|