a2cf7d
From cf5397eb5b33bab37c16bcb2d1bbddbce1a27de2 Mon Sep 17 00:00:00 2001
a2cf7d
From: Stefan Liebler <stli@linux.ibm.com>
a2cf7d
Date: Wed, 11 Dec 2019 15:09:33 +0100
a2cf7d
Subject: [PATCH 25/28] S390: Implement roundtoint and converttoint and define
a2cf7d
 TOINT_INTRINSICS.
a2cf7d
a2cf7d
This patch implements roundtoint and convertoint for s390
a2cf7d
by using the load-fp-integer and convert-to-fixed instructions.
a2cf7d
Both functions are using "round to nearest with ties away from zero"
a2cf7d
rounding mode and do not raise inexact exceptions.
a2cf7d
a2cf7d
(cherry picked from commit 2763d3145a326aa9afa613fe9e1b444cf912a883)
a2cf7d
---
a2cf7d
 sysdeps/s390/fpu/math_private.h | 53 +++++++++++++++++++++++++++++++++
a2cf7d
 1 file changed, 53 insertions(+)
a2cf7d
 create mode 100644 sysdeps/s390/fpu/math_private.h
a2cf7d
a2cf7d
diff --git a/sysdeps/s390/fpu/math_private.h b/sysdeps/s390/fpu/math_private.h
a2cf7d
new file mode 100644
a2cf7d
index 0000000000..a1ae91a87c
a2cf7d
--- /dev/null
a2cf7d
+++ b/sysdeps/s390/fpu/math_private.h
a2cf7d
@@ -0,0 +1,53 @@
a2cf7d
+/* Configure optimized libm functions.  S390 version.
a2cf7d
+   Copyright (C) 2019 Free Software Foundation, Inc.
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
a2cf7d
+   License as published by the Free Software Foundation; either
a2cf7d
+   version 2.1 of the 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
+#ifndef S390_MATH_PRIVATE_H
a2cf7d
+#define S390_MATH_PRIVATE_H 1
a2cf7d
+
a2cf7d
+#include <stdint.h>
a2cf7d
+#include <math.h>
a2cf7d
+
a2cf7d
+#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
a2cf7d
+# define TOINT_INTRINSICS 1
a2cf7d
+
a2cf7d
+static inline double_t
a2cf7d
+roundtoint (double_t x)
a2cf7d
+{
a2cf7d
+  double_t y;
a2cf7d
+  /* The z196 zarch "load fp integer" (fidbra) instruction is rounding
a2cf7d
+     x to the nearest integer with ties away from zero (M3-field: 1)
a2cf7d
+     where inexact exceptions are suppressed (M4-field: 4).  */
a2cf7d
+  __asm__ ("fidbra %0,1,%1,4" : "=f" (y) : "f" (x));
a2cf7d
+  return y;
a2cf7d
+}
a2cf7d
+
a2cf7d
+static inline int32_t
a2cf7d
+converttoint (double_t x)
a2cf7d
+{
a2cf7d
+  int32_t y;
a2cf7d
+  /* The z196 zarch "convert to fixed" (cfdbra) instruction is rounding
a2cf7d
+     x to the nearest integer with ties away from zero (M3-field: 1)
a2cf7d
+     where inexact exceptions are suppressed (M4-field: 4).  */
a2cf7d
+  __asm__ ("cfdbra %0,1,%1,4" : "=d" (y) : "f" (x) : "cc");
a2cf7d
+  return y;
a2cf7d
+}
a2cf7d
+#endif
a2cf7d
+
a2cf7d
+#include_next <math_private.h>
a2cf7d
+
a2cf7d
+#endif
a2cf7d
-- 
a2cf7d
2.18.2
a2cf7d