|
|
a2cf7d |
From 9f3ee7825b1eae00431ea6477fce8210aaced7db Mon Sep 17 00:00:00 2001
|
|
|
a2cf7d |
From: Stefan Liebler <stli@linux.ibm.com>
|
|
|
a2cf7d |
Date: Wed, 11 Dec 2019 15:09:30 +0100
|
|
|
a2cf7d |
Subject: [PATCH 22/28] S390: Use convert-to-fixed instruction for lround
|
|
|
a2cf7d |
functions.
|
|
|
a2cf7d |
|
|
|
a2cf7d |
If compiled with z196 zarch support, the convert-to-fixed instruction
|
|
|
a2cf7d |
is used to implement lround, lroundf, lroundl.
|
|
|
a2cf7d |
Otherwise the common-code implementation is used.
|
|
|
a2cf7d |
|
|
|
a2cf7d |
(cherry picked from commit 9d9f3527daf65fdca0eb46eaa324b81b8f94d88c)
|
|
|
a2cf7d |
---
|
|
|
a2cf7d |
sysdeps/s390/fpu/s_lround.c | 47 +++++++++++++++++++++++++++++++++++
|
|
|
a2cf7d |
sysdeps/s390/fpu/s_lroundf.c | 47 +++++++++++++++++++++++++++++++++++
|
|
|
a2cf7d |
sysdeps/s390/fpu/s_lroundl.c | 48 ++++++++++++++++++++++++++++++++++++
|
|
|
a2cf7d |
3 files changed, 142 insertions(+)
|
|
|
a2cf7d |
create mode 100644 sysdeps/s390/fpu/s_lround.c
|
|
|
a2cf7d |
create mode 100644 sysdeps/s390/fpu/s_lroundf.c
|
|
|
a2cf7d |
create mode 100644 sysdeps/s390/fpu/s_lroundl.c
|
|
|
a2cf7d |
|
|
|
a2cf7d |
diff --git a/sysdeps/s390/fpu/s_lround.c b/sysdeps/s390/fpu/s_lround.c
|
|
|
a2cf7d |
new file mode 100644
|
|
|
a2cf7d |
index 0000000000..9290ec32cd
|
|
|
a2cf7d |
--- /dev/null
|
|
|
a2cf7d |
+++ b/sysdeps/s390/fpu/s_lround.c
|
|
|
a2cf7d |
@@ -0,0 +1,47 @@
|
|
|
a2cf7d |
+/* lround() - 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 |
+/* The sizeof (long int) differs between s390x (8byte) and s390 (4byte).
|
|
|
a2cf7d |
+ Thus we need different instructions as the target size is encoded there.
|
|
|
a2cf7d |
+ Note: On s390 this instruction is only used if build with -mzarch. */
|
|
|
a2cf7d |
+# ifdef __s390x__
|
|
|
a2cf7d |
+# define INSN "cgdbra"
|
|
|
a2cf7d |
+# else
|
|
|
a2cf7d |
+# define INSN "cfdbra"
|
|
|
a2cf7d |
+# endif
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+long int
|
|
|
a2cf7d |
+__lround (double x)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ long int y;
|
|
|
a2cf7d |
+ /* The z196 zarch "convert to fixed" (cgdbra) instruction is rounding
|
|
|
a2cf7d |
+ x to the nearest integer with "ties away from 0" rounding mode
|
|
|
a2cf7d |
+ (M3-field: 1) where inexact exceptions are suppressed (M4-field: 4). */
|
|
|
a2cf7d |
+ __asm__ (INSN " %0,1,%1,4" : "=d" (y) : "f" (x) : "cc");
|
|
|
a2cf7d |
+ return y;
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+libm_alias_double (__lround, lround)
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#else
|
|
|
a2cf7d |
+# include <sysdeps/ieee754/dbl-64/s_lround.c>
|
|
|
a2cf7d |
+#endif
|
|
|
a2cf7d |
diff --git a/sysdeps/s390/fpu/s_lroundf.c b/sysdeps/s390/fpu/s_lroundf.c
|
|
|
a2cf7d |
new file mode 100644
|
|
|
a2cf7d |
index 0000000000..097b924c91
|
|
|
a2cf7d |
--- /dev/null
|
|
|
a2cf7d |
+++ b/sysdeps/s390/fpu/s_lroundf.c
|
|
|
a2cf7d |
@@ -0,0 +1,47 @@
|
|
|
a2cf7d |
+/* lroundf() - 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 |
+/* The sizeof (long int) differs between s390x (8byte) and s390 (4byte).
|
|
|
a2cf7d |
+ Thus we need different instructions as the target size is encoded there.
|
|
|
a2cf7d |
+ Note: On s390 this instruction is only used if build with -mzarch. */
|
|
|
a2cf7d |
+# ifdef __s390x__
|
|
|
a2cf7d |
+# define INSN "cgebra"
|
|
|
a2cf7d |
+# else
|
|
|
a2cf7d |
+# define INSN "cfebra"
|
|
|
a2cf7d |
+# endif
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+long int
|
|
|
a2cf7d |
+__lroundf (float x)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ long int y;
|
|
|
a2cf7d |
+ /* The z196 zarch "convert to fixed" (cgebra) instruction is rounding
|
|
|
a2cf7d |
+ x to the nearest integer with "ties away from 0" rounding mode
|
|
|
a2cf7d |
+ (M3-field: 1) where inexact exceptions are suppressed (M4-field: 4). */
|
|
|
a2cf7d |
+ __asm__ (INSN " %0,1,%1,4" : "=d" (y) : "f" (x) : "cc");
|
|
|
a2cf7d |
+ return y;
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+libm_alias_float (__lround, lround)
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#else
|
|
|
a2cf7d |
+# include <sysdeps/ieee754/flt-32/s_lroundf.c>
|
|
|
a2cf7d |
+#endif
|
|
|
a2cf7d |
diff --git a/sysdeps/s390/fpu/s_lroundl.c b/sysdeps/s390/fpu/s_lroundl.c
|
|
|
a2cf7d |
new file mode 100644
|
|
|
a2cf7d |
index 0000000000..0ef77dc667
|
|
|
a2cf7d |
--- /dev/null
|
|
|
a2cf7d |
+++ b/sysdeps/s390/fpu/s_lroundl.c
|
|
|
a2cf7d |
@@ -0,0 +1,48 @@
|
|
|
a2cf7d |
+/* lroundl() - 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 |
+/* The sizeof (long int) differs between s390x (8byte) and s390 (4byte).
|
|
|
a2cf7d |
+ Thus we need different instructions as the target size is encoded there.
|
|
|
a2cf7d |
+ Note: On s390 this instruction is only used if build with -mzarch. */
|
|
|
a2cf7d |
+# ifdef __s390x__
|
|
|
a2cf7d |
+# define INSN "cgxbra"
|
|
|
a2cf7d |
+# else
|
|
|
a2cf7d |
+# define INSN "cfxbra"
|
|
|
a2cf7d |
+# endif
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+long int
|
|
|
a2cf7d |
+__lroundl (_Float128 x)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ long int y;
|
|
|
a2cf7d |
+ /* The z196 zarch "convert to fixed" (cgxbra) instruction is rounding
|
|
|
a2cf7d |
+ x to the nearest integer with "ties away from 0" rounding mode
|
|
|
a2cf7d |
+ (M3-field: 1) where inexact exceptions are suppressed (M4-field: 4). */
|
|
|
a2cf7d |
+ __asm__ (INSN " %0,1,%1,4" : "=d" (y) : "f" (x) : "cc");
|
|
|
a2cf7d |
+ return y;
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+libm_alias_ldouble (__lround, lround)
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#else
|
|
|
a2cf7d |
+# include <sysdeps/ieee754/ldbl-128/s_lroundl.c>
|
|
|
a2cf7d |
+#endif
|
|
|
a2cf7d |
--
|
|
|
a2cf7d |
2.18.2
|
|
|
a2cf7d |
|