From patchwork Tue Jun 5 22:21:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel F. T. Gomes" X-Patchwork-Id: 27654 Received: (qmail 50623 invoked by alias); 5 Jun 2018 22:21:43 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 50446 invoked by uid 89); 5 Jun 2018 22:21:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=varies, reuses, notation X-HELO: mo19.mail-out.ovh.net From: "Gabriel F. T. Gomes" To: Subject: [RFC PATCH v2 2/3] ldbl-128ibm-compat: Use __vfprintf_internal for ieee128-vfprintf on powerpc64le Date: Tue, 5 Jun 2018 19:21:19 -0300 Message-ID: <20180605222120.24696-3-gabriel@inconstante.eti.br> In-Reply-To: <20180605222120.24696-1-gabriel@inconstante.eti.br> References: <20180605222120.24696-1-gabriel@inconstante.eti.br> MIME-Version: 1.0 X-ClientProxiedBy: EX3.emp.local (172.16.2.3) To EX4.emp.local (172.16.2.4) X-Ovh-Tracer-Id: 931963651768635075 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrjeeggddutdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecu 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 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 +%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 + . */ + +#include + +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 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 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 + . */ + +#include +#include +#include + +#include + +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 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 +# . + +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