unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Gabriel F. T. Gomes" <gabriel@inconstante.net.br>
To: <libc-alpha@sourceware.org>
Subject: [PATCH 1/6] ldbl-128ibm-compat: Add regular character printing functions
Date: Fri, 9 Aug 2019 15:31:49 -0300	[thread overview]
Message-ID: <20190809183154.32605-2-gabriel@inconstante.net.br> (raw)
In-Reply-To: <20190809183154.32605-1-gabriel@inconstante.net.br>

From: "Gabriel F. T. Gomes" <gabrielftg@linux.ibm.com>

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 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.

Many files from the stdio-common, wcsmbs, argp, misc, and libio
directories will have IEEE binary128 counterparts.  Setting the correct
compiler options to these files (original and counterparts) would
produce a large amount of repetitive Makefile rules.  To avoid this
repetition, this patch adds a Makefile routine that iterates over the
files adding or removing the appropriate flags.

Tested for powerpc64le.

	* elf/tst-addr1.c (do_test): Accept redirections of printf to
	__printfieee128.

	* sysdeps/ieee754/ldbl-128ibm-compat/Makefile
	[subdir == stdio-common] (routines): Move the addition of
	printf_size to ldbl-extra-routines.
	[subdir == stdio-common] (ldbl-extra-routines): New variable.
	[subdir == stdio-common] (ldbl-ibm128-files): New variable.
	[subdir == stdio-common] (obj-suf-foreach): New routine.
	[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.

	* sysdeps/ieee754/ldbl-128ibm-compat/Versions: (libc): Add
	__asprintfieee128, __dprintfieee128, __fprintfieee128,
	__printfieee128, __snprintfieee128, __sprintfieee128,
	__vasprintfieee128, __vdprintfieee128, __vfprintfieee128,
	__vprintfieee128, __vsnprintfieee128, and __vsprintfieee128.

	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-asprintf.c: New file.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-dprintf.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fprintf.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-printf.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-sprintf.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vasprintf.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vdprintf.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfprintf.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vprintf.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsnprintf.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsprintf.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/unix/sysv/linux/powerpc/powerpc64/le/ldbl-128ibm-compat-abi.h:
	Likewise.
---
 elf/tst-addr1.c                               |   7 +-
 sysdeps/ieee754/ldbl-128ibm-compat/Makefile   |  45 ++++-
 sysdeps/ieee754/ldbl-128ibm-compat/Versions   |  15 ++
 .../ldbl-128ibm-compat/ieee128-asprintf.c     |  35 ++++
 .../ldbl-128ibm-compat/ieee128-dprintf.c      |  34 ++++
 .../ldbl-128ibm-compat/ieee128-fprintf.c      |  34 ++++
 .../ldbl-128ibm-compat/ieee128-printf.c       |  35 ++++
 .../ldbl-128ibm-compat/ieee128-snprintf.c     |  35 ++++
 .../ldbl-128ibm-compat/ieee128-sprintf.c      |  35 ++++
 .../ldbl-128ibm-compat/ieee128-vasprintf.c    |  27 +++
 .../ldbl-128ibm-compat/ieee128-vdprintf.c     |  26 +++
 .../ldbl-128ibm-compat/ieee128-vfprintf.c     |  26 +++
 .../ldbl-128ibm-compat/ieee128-vprintf.c      |  27 +++
 .../ldbl-128ibm-compat/ieee128-vsnprintf.c    |  28 +++
 .../ldbl-128ibm-compat/ieee128-vsprintf.c     |  27 +++
 .../ldbl-128ibm-compat/test-printf-ibm128.c   |   1 +
 .../ldbl-128ibm-compat/test-printf-ieee128.c  |   1 +
 .../test-printf-ldbl-compat.c                 | 171 ++++++++++++++++++
 .../powerpc64/le/ldbl-128ibm-compat-abi.h     |   8 +
 19 files changed, 615 insertions(+), 2 deletions(-)
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-asprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-dprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-printf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-sprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vasprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vdprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsnprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsprintf.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/unix/sysv/linux/powerpc/powerpc64/le/ldbl-128ibm-compat-abi.h

diff --git a/elf/tst-addr1.c b/elf/tst-addr1.c
index 68ff74aabd..ee81acda5b 100644
--- a/elf/tst-addr1.c
+++ b/elf/tst-addr1.c
@@ -19,7 +19,12 @@ do_test (void)
 		rather than in the binary.  printf and _IO_printf
 		are aliased and which one comes first in the
 		hash table is up to the linker.  */
-	     && strcmp (i.dli_sname, "_IO_printf") != 0);
+	     && strcmp (i.dli_sname, "_IO_printf") != 0
+	     /* On architectures where long double with IEEE binary128
+		format is available as a third option (initially, true
+		for powerpc64le), printf may be redirected to
+		__printfieee128.  */
+	     && strcmp (i.dli_sname, "__printfieee128") != 0);
 }
 
 #include <support/test-driver.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
index 412beb5b5c..102973add9 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
@@ -1,5 +1,30 @@
 ifeq ($(subdir),stdio-common)
-routines += ieee128-printf_size
+ldbl-extra-routines += printf_size \
+		       asprintf \
+		       dprintf \
+		       fprintf \
+		       printf \
+		       snprintf \
+		       sprintf \
+		       vasprintf \
+		       vdprintf \
+		       vfprintf \
+		       vprintf \
+		       vsnprintf \
+		       vsprintf
+
+# Printing long double values with IEEE binary128 format reuses 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 and -mabi=ibmlongdouble
+# passed to the compiler.
+CFLAGS-vfprintf-internal.c += -mfloat128 -mabi=ibmlongdouble
+
+# 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
 
 tests-internal += test-printf-size-ieee128 test-printf-size-ibm128
 CFLAGS-test-printf-size-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi
@@ -20,3 +45,21 @@ $(objpfx)test-printf-size-ibm128.out: \
 	$(SHELL) $^ '$(test-program-prefix)' $@; \
 	$(evaluate-test)
 endif
+
+# Add IEEE binary128 files as make targets.
+routines += $(foreach r,$(ldbl-extra-routines),ieee128-$(r))
+
+# On powerpc64le, the routines responsible for converting between long
+# double and string (e.g.: printf, scanf, strtold, strfroml) default to
+# IBM long double mode.  When support for TS 18661-3 was added, several
+# internal functions were modified so that they could also handle
+# floating-point variables with IEEE binary128 format, but as an
+# additional type, _Float128.
+#
+# The following rule ensures that the string conversion routines will
+# always be built in IBM long double mode, with additional support for
+# IEEE binary128, through the use of -mabi=ibmlongdouble and -mfloat128.
+ldbl-ibm128-files := $(objpfx)test-%-ibm128^ \
+		     $(foreach r,$(ldbl-extra-routines),$(objpfx)$(r)^) \
+		     $(foreach r,$(ldbl-extra-routines),$(objpfx)$(r)-internal^)
+obj-suf-foreach = $(foreach suf,$(all-object-suffixes),$(subst ^,$(suf),$(1)))
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Versions b/sysdeps/ieee754/ldbl-128ibm-compat/Versions
index 4aa34dbe59..6a27befed2 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/Versions
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/Versions
@@ -120,4 +120,19 @@ libc {
     __wcstoieee128_l;
 
     __printf_sizeieee128;
+
+    __asprintfieee128;
+    __dprintfieee128;
+    __fprintfieee128;
+    __printfieee128;
+    __snprintfieee128;
+    __sprintfieee128;
+
+    __vasprintfieee128;
+    __vdprintfieee128;
+    __vfprintfieee128;
+    __vprintfieee128;
+    __vsnprintfieee128;
+    __vsprintfieee128;
   }
+}
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-asprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-asprintf.c
new file mode 100644
index 0000000000..35c909b124
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-asprintf.c
@@ -0,0 +1,35 @@
+/* Wrapper for asprintf.  IEEE128 version.
+   Copyright (C) 2019 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 <libio/libioP.h>
+
+extern int
+___ieee128_asprintf (char **string_ptr, const char *format, ...)
+{
+  va_list ap;
+  int done;
+
+  va_start (ap, format);
+  done = __vasprintf_internal (string_ptr, format, ap,
+			       PRINTF_LDBL_USES_FLOAT128);
+  va_end (ap);
+
+  return done;
+}
+strong_alias (___ieee128_asprintf, __asprintfieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-dprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-dprintf.c
new file mode 100644
index 0000000000..0c66c9758b
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-dprintf.c
@@ -0,0 +1,34 @@
+/* Wrapper for dprintf.  IEEE128 version.
+   Copyright (C) 2019 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 <libio/libioP.h>
+
+extern int
+___ieee128_dprintf (int d, const char *format, ...)
+{
+  va_list ap;
+  int done;
+
+  va_start (ap, format);
+  done = __vdprintf_internal (d, format, ap, PRINTF_LDBL_USES_FLOAT128);
+  va_end (ap);
+
+  return done;
+}
+strong_alias (___ieee128_dprintf, __dprintfieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fprintf.c
new file mode 100644
index 0000000000..b4b945092a
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fprintf.c
@@ -0,0 +1,34 @@
+/* Wrapper for fprintf.  IEEE128 version.
+   Copyright (C) 2019 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 <libio/libioP.h>
+
+extern int
+___ieee128_fprintf (FILE *fp, const char *format, ...)
+{
+  va_list ap;
+  int done;
+
+  va_start (ap, format);
+  done = __vfprintf_internal (fp, format, ap, PRINTF_LDBL_USES_FLOAT128);
+  va_end (ap);
+
+  return done;
+}
+strong_alias (___ieee128_fprintf, __fprintfieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-printf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-printf.c
new file mode 100644
index 0000000000..a1c6d7e0cf
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-printf.c
@@ -0,0 +1,35 @@
+/* Wrapper for printf.  IEEE128 version.
+   Copyright (C) 2019 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 <libio/libioP.h>
+
+extern int
+___ieee128_printf (const char *format, ...)
+{
+  va_list ap;
+  int done;
+
+  va_start (ap, format);
+  done = __vfprintf_internal (stdout, format, ap,
+			      PRINTF_LDBL_USES_FLOAT128);
+  va_end (ap);
+
+  return done;
+}
+strong_alias (___ieee128_printf, __printfieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c
new file mode 100644
index 0000000000..2c09a75d59
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c
@@ -0,0 +1,35 @@
+/* Wrapper for snprintf.  IEEE128 version.
+   Copyright (C) 2019 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 <libio/libioP.h>
+
+extern int
+___ieee128_snprintf (char *s, size_t maxlen, const char *format, ...)
+{
+  va_list ap;
+  int done;
+
+  va_start (ap, format);
+  done = __vsnprintf_internal (s, maxlen, format, ap,
+			       PRINTF_LDBL_USES_FLOAT128);
+  va_end (ap);
+
+  return done;
+}
+strong_alias (___ieee128_snprintf, __snprintfieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-sprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-sprintf.c
new file mode 100644
index 0000000000..727a403634
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-sprintf.c
@@ -0,0 +1,35 @@
+/* Wrapper for sprintf.  IEEE128 version.
+   Copyright (C) 2019 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 <libio/libioP.h>
+
+extern int
+___ieee128_sprintf (char *s, const char *format, ...)
+{
+  va_list ap;
+  int done;
+
+  va_start (ap, format);
+  done = __vsprintf_internal (s, -1, format, ap,
+			      PRINTF_LDBL_USES_FLOAT128);
+  va_end (ap);
+
+  return done;
+}
+strong_alias (___ieee128_sprintf, __sprintfieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vasprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vasprintf.c
new file mode 100644
index 0000000000..650e40affb
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vasprintf.c
@@ -0,0 +1,27 @@
+/* Wrapper for vasprintf.  IEEE128 version.
+   Copyright (C) 2019 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_vasprintf (char **result_ptr, const char *format, va_list ap)
+{
+  return __vasprintf_internal (result_ptr, format, ap,
+			       PRINTF_LDBL_USES_FLOAT128);
+}
+strong_alias (___ieee128_vasprintf, __vasprintfieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vdprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vdprintf.c
new file mode 100644
index 0000000000..88fbb3743d
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vdprintf.c
@@ -0,0 +1,26 @@
+/* Wrapper for vdprintf.  IEEE128 version.
+   Copyright (C) 2019 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_vdprintf (int d, const char *format, va_list ap)
+{
+  return __vdprintf_internal (d, format, ap, PRINTF_LDBL_USES_FLOAT128);
+}
+strong_alias (___ieee128_vdprintf, __vdprintfieee128)
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..ecc2fd36da
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfprintf.c
@@ -0,0 +1,26 @@
+/* Wrapper for vfprintf.  IEEE128 version.
+   Copyright (C) 2019 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);
+}
+strong_alias (___ieee128_vfprintf, __vfprintfieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vprintf.c
new file mode 100644
index 0000000000..35347c60be
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vprintf.c
@@ -0,0 +1,27 @@
+/* Wrapper for vprintf.  IEEE128 version.
+   Copyright (C) 2019 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_vprintf (const char *format, va_list ap)
+{
+  return __vfprintf_internal (stdout, format, ap,
+			      PRINTF_LDBL_USES_FLOAT128);
+}
+strong_alias (___ieee128_vprintf, __vprintfieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsnprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsnprintf.c
new file mode 100644
index 0000000000..963b0cb228
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsnprintf.c
@@ -0,0 +1,28 @@
+/* Wrapper for vsnprintf.  IEEE128 version.
+   Copyright (C) 2019 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_vsnprintf (char *string, size_t maxlen, const char *format,
+		      va_list ap)
+{
+  return __vsnprintf_internal (string, maxlen, format, ap,
+			       PRINTF_LDBL_USES_FLOAT128);
+}
+strong_alias (___ieee128_vsnprintf, __vsnprintfieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsprintf.c
new file mode 100644
index 0000000000..822cc31c16
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsprintf.c
@@ -0,0 +1,27 @@
+/* Wrapper for vsprintf.  IEEE128 version.
+   Copyright (C) 2019 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_vsprintf (char *string, const char *format, va_list ap)
+{
+  return __vsprintf_internal (string, -1, format, ap,
+			      PRINTF_LDBL_USES_FLOAT128);
+}
+strong_alias (___ieee128_vsprintf, __vsprintfieee128)
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..939a6aad9c
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c
@@ -0,0 +1,171 @@
+/* Test for the long double variants of *printf functions.
+   Copyright (C) 2019 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 <stdlib.h>
+
+#include <support/capture_subprocess.h>
+#include <support/check.h>
+
+static void
+do_test_call_varg (FILE *stream, const char *format, ...)
+{
+  char *buffer = NULL;
+  char string[128];
+  va_list args;
+
+  printf ("%15s", "vasprintf: ");
+  va_start (args, format);
+  vasprintf (&buffer, format, args);
+  va_end (args);
+  if (buffer == NULL)
+    printf ("Error using vasprintf\n");
+  else
+    {
+      printf ("%s", buffer);
+      free (buffer);
+    }
+  printf ("\n");
+
+  printf ("%15s", "vdprintf: ");
+  va_start (args, format);
+  vdprintf (fileno (stream), format, args);
+  va_end (args);
+  printf ("\n");
+
+  printf ("%15s", "vfprintf: ");
+  va_start (args, format);
+  vfprintf (stream, format, args);
+  va_end (args);
+  printf ("\n");
+
+  printf ("%15s", "vprintf: ");
+  va_start (args, format);
+  vprintf (format, args);
+  va_end (args);
+  printf ("\n");
+
+  printf ("%15s", "vsnprintf: ");
+  va_start (args, format);
+  vsnprintf (string, 127, format, args);
+  va_end (args);
+  printf ("%s", string);
+  printf ("\n");
+
+  printf ("%15s", "vsprintf: ");
+  va_start (args, format);
+  vsprintf (string, format, args);
+  va_end (args);
+  printf ("%s", string);
+  printf ("\n");
+}
+
+static void
+do_test_call_rarg (FILE *stream, const char *format, long double ld)
+{
+  char *buffer = NULL;
+  char string[128];
+
+  printf ("%15s", "asprintf: ");
+  asprintf (&buffer, format, ld);
+  if (buffer == NULL)
+    printf ("Error using asprintf\n");
+  else
+    {
+      printf ("%s", buffer);
+      free (buffer);
+    }
+  printf ("\n");
+
+  printf ("%15s", "dprintf: ");
+  dprintf (fileno (stream), format, ld);
+  printf ("\n");
+
+  printf ("%15s", "fprintf: ");
+  fprintf (stream, format, ld);
+  printf ("\n");
+
+  printf ("%15s", "printf: ");
+  printf (format, ld);
+  printf ("\n");
+
+  printf ("%15s", "snprintf: ");
+  snprintf (string, 127, format, ld);
+  printf ("%s", string);
+  printf ("\n");
+
+  printf ("%15s", "sprintf: ");
+  sprintf (string, format, ld);
+  printf ("%s", string);
+  printf ("\n");
+}
+
+static void
+do_test_call (void)
+{
+  long double ld = -1;
+
+  /* Print in decimal notation.  */
+  do_test_call_rarg (stdout, "%.10Lf", ld);
+  do_test_call_varg (stdout, "%.10Lf", ld);
+
+  /* Print in hexadecimal notation.  */
+  do_test_call_rarg (stdout, "%.10La", ld);
+  do_test_call_varg (stdout, "%.10La", ld);
+}
+
+static int
+do_test (void)
+{
+  struct support_capture_subprocess result;
+  result = support_capture_subprocess ((void *) &do_test_call, NULL);
+
+  /* Compare against the expected output.  */
+  const char *expected =
+    "     asprintf: -1.0000000000\n"
+    "      dprintf: -1.0000000000\n"
+    "      fprintf: -1.0000000000\n"
+    "       printf: -1.0000000000\n"
+    "     snprintf: -1.0000000000\n"
+    "      sprintf: -1.0000000000\n"
+    "    vasprintf: -1.0000000000\n"
+    "     vdprintf: -1.0000000000\n"
+    "     vfprintf: -1.0000000000\n"
+    "      vprintf: -1.0000000000\n"
+    "    vsnprintf: -1.0000000000\n"
+    "     vsprintf: -1.0000000000\n"
+    "     asprintf: -0x1.0000000000p+0\n"
+    "      dprintf: -0x1.0000000000p+0\n"
+    "      fprintf: -0x1.0000000000p+0\n"
+    "       printf: -0x1.0000000000p+0\n"
+    "     snprintf: -0x1.0000000000p+0\n"
+    "      sprintf: -0x1.0000000000p+0\n"
+    "    vasprintf: -0x1.0000000000p+0\n"
+    "     vdprintf: -0x1.0000000000p+0\n"
+    "     vfprintf: -0x1.0000000000p+0\n"
+    "      vprintf: -0x1.0000000000p+0\n"
+    "    vsnprintf: -0x1.0000000000p+0\n"
+    "     vsprintf: -0x1.0000000000p+0\n";
+  TEST_COMPARE_STRING (expected, result.out.buffer);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
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..285216b231
--- /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.31
+#define LDBL_IBM128_COMPAT_VERSION	GLIBC_2_31
-- 
2.21.0


  reply	other threads:[~2019-08-09 18:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-09 18:31 [PATCH 0/6] IEEE long double printf and friends for powerpc64le Gabriel F. T. Gomes
2019-08-09 18:31 ` Gabriel F. T. Gomes [this message]
2019-08-14 11:46   ` [PATCH 1/6] ldbl-128ibm-compat: Add regular character printing functions Florian Weimer
2019-08-15 18:30     ` Gabriel F. T. Gomes
2019-09-02 14:03       ` Gabriel F. T. Gomes
2019-09-02 14:28         ` Florian Weimer
2019-09-02 15:11           ` Gabriel F. T. Gomes
2019-08-09 18:31 ` [PATCH 2/6] ldbl-128ibm-compat: Add wide " Gabriel F. T. Gomes
2019-08-09 18:31 ` [PATCH 3/6] ldbl-128ibm-compat: Add regular character, fortified " Gabriel F. T. Gomes
2019-08-09 18:31 ` [PATCH 4/6] ldbl-128ibm-compat: Add wide " Gabriel F. T. Gomes
2019-08-09 18:31 ` [PATCH 5/6] ldbl-128ibm-compat: Test double values Gabriel F. T. Gomes
2019-08-09 18:31 ` [PATCH 6/6] ldbl-128ibm-compat: Test positional arguments Gabriel F. T. Gomes
2019-09-02 14:15 ` Ping. Re: [PATCH 0/6] IEEE long double printf and friends for powerpc64le Gabriel F. T. Gomes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190809183154.32605-2-gabriel@inconstante.net.br \
    --to=gabriel@inconstante.net.br \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).