diff mbox series

[RFC,v2,2/3] ldbl-128ibm-compat: Use __vfprintf_internal for ieee128-vfprintf on powerpc64le

Message ID 20180605222120.24696-3-gabriel@inconstante.eti.br
State New
Headers show
Series stdio/wchar/argp/err/error.h functions for powerpc64le | expand

Commit Message

Gabriel F. T. Gomes June 5, 2018, 10:21 p.m. UTC
The 'mode' argument to __vfprintf_internal allows the selection of the
long double format for all long double arguments requested by the format
string.  Currently, there are two possibilities: long double with the
same format as double or long double as something else.  The 'something
else' format varies between architectures, and on powerpc64le, it means
IBM Extended Precision format.

In preparation for the third option of long double format on
powerpc64le, this patch adds a new mode mask, PRINTF_LDBL_USES_IEEE128,
and code to correctly parse floating-point values from the variable
arguments.  Support for printing floating-point values with binary128
format is already available on powerpc64le for use by the implementation
of strfromf128, thus, the new code saves the floating-point values into
variables of type __float128 and adjusts the parameters to __printf_fp
and __printf_fphex as if it was a call from strfromf128.

Tested for powerpc64le.

	* sysdeps/ieee754/ldbl-128ibm-compat/Makefile: New file.
	[subdir == stdio-common] (routines): Add ieee128-vfprintf.
	[subdir == stdio-common] (CFLAGS-vfprintf-internal.c): New
	variable.  Add -mfloat128 to the compilation of
	vfprintf-internal.c, so that it gets support for the use of
	__printf_fp and __printf_fphex with __float128 parameter.
	[subdir == stdio-common] (tests-internal): Add
	test-printf-ieee128 and test-printf-ibm128.
	[subdir == stdio-common] (CFLAGS-test-printf-ieee128.c): New
	variable to add the relevant -mabi flags to the compilation.
	[subdir == stdio-common] (CFLAGS-test-printf-ibm128.c): Likewise.
	[subdir == stdio-common && run-built-tests == yes]
	(tests-special): Add $(objpfx)test-printf-ieee128.out and
	$(objpfx)test-printf-ibm128.out.
	[subdir == stdio-common] ($(objpfx)test-printf-ieee128.out):
	New build and test rule.
	[subdir == stdio-common] ($(objpfx)test-printf-ibm128.out):
	Likewise.

	* sysdeps/ieee754/ldbl-128ibm-compat/Versions: New file.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfprintf.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ibm128.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ieee128.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.sh:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ldbl-128ibm-compat-abi.h:
	Likewise.
---
 sysdeps/ieee754/ldbl-128ibm-compat/Makefile        | 34 +++++++++++++++
 sysdeps/ieee754/ldbl-128ibm-compat/Versions        | 10 +++++
 .../ieee754/ldbl-128ibm-compat/ieee128-vfprintf.c  | 25 +++++++++++
 .../ldbl-128ibm-compat/test-printf-ibm128.c        |  1 +
 .../ldbl-128ibm-compat/test-printf-ieee128.c       |  1 +
 .../ldbl-128ibm-compat/test-printf-ldbl-compat.c   | 51 ++++++++++++++++++++++
 .../ldbl-128ibm-compat/test-printf-ldbl-compat.sh  | 42 ++++++++++++++++++
 .../powerpc/powerpc64/le/ldbl-128ibm-compat-abi.h  |  8 ++++
 8 files changed, 172 insertions(+)
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/Makefile
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/Versions
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ibm128.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ieee128.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.sh
 create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ldbl-128ibm-compat-abi.h

Comments

Gabriel F. T. Gomes June 5, 2018, 10:55 p.m. UTC | #1
On Tue, 05 Jun 2018, Gabriel F. T. Gomes wrote:

>In preparation for the third option of long double format on
>powerpc64le, this patch adds a new mode mask, PRINTF_LDBL_USES_IEEE128,
>and code to correctly parse floating-point values from the variable
>arguments.

Argh, this comment is only relevant to the first patch in this set.  I
rewrote the whole paragraph as:

In preparation for the third option of long double format on
powerpc64le, this patch uses the new mode mask, PRINTF_LDBL_USES_FLOAT128,
which tells __vfprintf_internal to save the floating-point values into
variables of type __float128 and adjusts the parameters to __printf_fp
and __printf_fphex as if it was a call from strfromf128.
diff mbox series

Patch

diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
new file mode 100644
index 0000000000..87c3241622
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
@@ -0,0 +1,34 @@ 
+ifeq ($(subdir),stdio-common)
+# Wrappers for *printf functions that take long double arguments with
+# IEEE binary128 format
+routines += ieee128-vfprintf
+
+# Printing long double values with IEEE binary128 format reuses the part
+# of the internal float128 implementation (__printf_fp, __printf_fphex,
+# and __float128 variables and union members).  Thus, the compilation of
+# the following functions, must have -mfloat128 passed to the compiler.
+CFLAGS-vfprintf-internal.c += -mfloat128
+
+# Basic tests for the implementation of long double with IEEE binary128
+# format and for the related redirections in installed headers.
+tests-internal += test-printf-ieee128 test-printf-ibm128
+CFLAGS-test-printf-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi
+CFLAGS-test-printf-ibm128.c += -mabi=ibmlongdouble -Wno-psabi
+
+ifeq ($(run-built-tests),yes)
+tests-special += $(objpfx)test-printf-ieee128.out
+tests-special += $(objpfx)test-printf-ibm128.out
+endif
+
+$(objpfx)test-printf-ieee128.out: \
+  ../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.sh \
+  $(objpfx)test-printf-ieee128
+	$(SHELL) $^ '$(test-program-prefix)' $@; \
+	$(evaluate-test)
+
+$(objpfx)test-printf-ibm128.out: \
+  ../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.sh \
+  $(objpfx)test-printf-ibm128
+	$(SHELL) $^ '$(test-program-prefix)' $@; \
+	$(evaluate-test)
+endif
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Versions b/sysdeps/ieee754/ldbl-128ibm-compat/Versions
new file mode 100644
index 0000000000..d6eaf4e649
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/Versions
@@ -0,0 +1,10 @@ 
+%include <ldbl-128ibm-compat-abi.h>
+%ifndef LDBL_IBM128_VERSION
+% error "ldbl-128ibm-compat-abi.h must define LDBL_IBM128_VERSION"
+%endif
+
+libc {
+  LDBL_IBM128_VERSION {
+    __ieee128_vfprintf;
+  }
+}
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfprintf.c
new file mode 100644
index 0000000000..811e6f324e
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfprintf.c
@@ -0,0 +1,25 @@ 
+/* Wrapper for vfprintf.  IEEE128 version.
+   Copyright (C) 1991-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <libio/libioP.h>
+
+extern int
+__ieee128_vfprintf (FILE *fp, const char *format, va_list ap)
+{
+  return __vfprintf_internal (fp, format, ap, PRINTF_LDBL_USES_FLOAT128);
+}
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ibm128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ibm128.c
new file mode 100644
index 0000000000..5de4ea3e7f
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ibm128.c
@@ -0,0 +1 @@ 
+#include <test-printf-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ieee128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ieee128.c
new file mode 100644
index 0000000000..5de4ea3e7f
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ieee128.c
@@ -0,0 +1 @@ 
+#include <test-printf-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c
new file mode 100644
index 0000000000..03014507b4
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c
@@ -0,0 +1,51 @@ 
+/* Test for the long double variants of *printf functions.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#include <support/check.h>
+
+static void
+do_test_call_varg (FILE *stream, const char *format, ...)
+{
+  va_list args;
+
+  printf ("%20s", "vfprintf: ");
+  va_start (args, format);
+  vfprintf (stream, format, args);
+  va_end (args);
+  printf ("\n");
+}
+
+static int
+do_test (void)
+{
+  long double ld = -1;
+
+  /* Print in decimal notation.  */
+  do_test_call_varg (stdout, "%.60Lf", ld);
+
+  /* Print in hexadecimal notation.  */
+  do_test_call_varg (stdout, "%.60La", ld);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.sh b/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.sh
new file mode 100644
index 0000000000..d5a8463935
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.sh
@@ -0,0 +1,42 @@ 
+#!/bin/sh
+# Testing of *printf.  IEEE binary128 for powerpc64le version.
+# Copyright (C) 2018 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+
+test_program=$1; shift
+test_program_prefix=$1; shift
+test_program_output=$1; shift
+
+status=0
+
+${test_program_prefix} \
+  ${test_program} \
+  > ${test_program_output} || status=1
+
+cat <<'EOF' |
+          vfprintf: -1.000000000000000000000000000000000000000000000000000000000000
+          vfprintf: -0x1.000000000000000000000000000000000000000000000000000000000000p+0
+EOF
+cmp - ${test_program_output} > /dev/null 2>&1 ||
+{
+  status=1
+  echo "*** output comparison failed"
+}
+
+exit $status
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ldbl-128ibm-compat-abi.h b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ldbl-128ibm-compat-abi.h
new file mode 100644
index 0000000000..6eb0e72b07
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ldbl-128ibm-compat-abi.h
@@ -0,0 +1,8 @@ 
+/* ABI version for long double switch to IEEE 128-bit floating point..
+   This is used by the Versions and math_ldbl_opt.h files in
+   sysdeps/ieee754/ldbl-128ibm-compat/.  It gives the ABI version where
+   long double == ibm128 was replaced with long double == _Float128
+   for libm *l functions and libc functions using long double.  */
+
+#define LDBL_IBM128_VERSION		GLIBC_2.28
+#define LDBL_IBM128_COMPAT_VERSION	GLIBC_2_28