From patchwork Tue Oct 15 19:05:05 2019 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: 34996 Received: (qmail 101127 invoked by alias); 15 Oct 2019 19:06:25 -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 101070 invoked by uid 89); 15 Oct 2019 19:06:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: smtpout1.mo528.mail-out.ovh.net From: "Gabriel F. T. Gomes" To: Subject: [PATCH 07/31] ldbl-128ibm-compat: Add regular character scanning functions Date: Tue, 15 Oct 2019 16:05:05 -0300 Message-ID: <20191015190529.11559-8-gabriel@inconstante.net.br> In-Reply-To: <20191015190529.11559-1-gabriel@inconstante.net.br> References: <20191015190529.11559-1-gabriel@inconstante.net.br> MIME-Version: 1.0 X-Ovh-Tracer-Id: 1776951529512816323 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedufedrjeefgddufeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenuc From: "Gabriel F. T. Gomes" The 'mode' argument to __vfscanf_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, SCANF_LDBL_USES_FLOAT128, which tells __vfscanf_internal to call __strtof128_internal, instead of __strtold_internal, and save the output into a _Float128 variable. Tested for powerpc64le. --- sysdeps/ieee754/ldbl-128ibm-compat/Makefile | 37 +++++- sysdeps/ieee754/ldbl-128ibm-compat/Versions | 8 ++ .../ldbl-128ibm-compat/ieee128-fscanf.c | 34 +++++ .../ldbl-128ibm-compat/ieee128-scanf.c | 34 +++++ .../ldbl-128ibm-compat/ieee128-sscanf.c | 38 ++++++ .../ldbl-128ibm-compat/ieee128-vfscanf.c | 26 ++++ .../ldbl-128ibm-compat/ieee128-vscanf.c | 26 ++++ .../ldbl-128ibm-compat/ieee128-vsscanf.c | 29 +++++ .../ldbl-128ibm-compat/test-scanf-ibm128.c | 1 + .../ldbl-128ibm-compat/test-scanf-ieee128.c | 1 + .../test-scanf-ldbl-compat-template.c | 117 ++++++++++++++++++ .../test-scanf-ldbl-compat.c | 10 ++ .../test-scanf-ldbl-compat.sh | 63 ++++++++++ 13 files changed, 421 insertions(+), 3 deletions(-) create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fscanf.c create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-scanf.c create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-sscanf.c create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfscanf.c create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vscanf.c create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsscanf.c create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ibm128.c create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ieee128.c create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat.c create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat.sh diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile index 7217987aa5..a1f0f7d74e 100644 --- a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile +++ b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile @@ -17,15 +17,23 @@ ldbl-extra-routines += printf_size \ wprintf \ vfwprintf \ vswprintf \ - vwprintf + vwprintf \ + fscanf \ + scanf \ + sscanf \ + vfscanf \ + vscanf \ + vsscanf # 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 +# and __float128 variables and union members). Likewise, reading these +# values reuses __strtof128_internal. Thus, the compilation of the +# following functions, must have -mfloat128 and -mabi=ibmlongdouble # passed to the compiler. CFLAGS-vfprintf-internal.c += -mfloat128 -mabi=ibmlongdouble CFLAGS-vfwprintf-internal.c += -mfloat128 -mabi=ibmlongdouble +CFLAGS-vfscanf-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. @@ -37,6 +45,29 @@ tests-internal += test-wprintf-ieee128 test-wprintf-ibm128 CFLAGS-test-wprintf-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi CFLAGS-test-wprintf-ibm128.c += -mabi=ibmlongdouble -Wno-psabi +tests-internal += test-scanf-ieee128 test-scanf-ibm128 +CFLAGS-test-scanf-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi +CFLAGS-test-scanf-ibm128.c += -mabi=ibmlongdouble -Wno-psabi + +$(objpfx)test-scanf-ieee128: gnulib-tests += $(f128-loader-link) + +ifeq ($(run-built-tests),yes) +tests-special += $(objpfx)test-scanf-ieee128.out +tests-special += $(objpfx)test-scanf-ibm128.out +endif + +$(objpfx)test-scanf-ieee128.out: \ + ../sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat.sh \ + $(objpfx)test-scanf-ieee128 + $(SHELL) $^ '$(test-program-prefix)' $@; \ + $(evaluate-test) + +$(objpfx)test-scanf-ibm128.out: \ + ../sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat.sh \ + $(objpfx)test-scanf-ibm128 + $(SHELL) $^ '$(test-program-prefix)' $@; \ + $(evaluate-test) + tests-internal += test-printf-size-ieee128 test-printf-size-ibm128 CFLAGS-test-printf-size-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi CFLAGS-test-printf-size-ibm128.c += -mabi=ibmlongdouble -Wno-psabi diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Versions b/sysdeps/ieee754/ldbl-128ibm-compat/Versions index e438c7c306..7971c7a7d1 100644 --- a/sysdeps/ieee754/ldbl-128ibm-compat/Versions +++ b/sysdeps/ieee754/ldbl-128ibm-compat/Versions @@ -164,5 +164,13 @@ libc { __vfwprintf_chkieee128; __vswprintf_chkieee128; __vwprintf_chkieee128; + + __fscanfieee128; + __scanfieee128; + __sscanfieee128; + + __vfscanfieee128; + __vscanfieee128; + __vsscanfieee128; } } diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fscanf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fscanf.c new file mode 100644 index 0000000000..f51e822094 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fscanf.c @@ -0,0 +1,34 @@ +/* Wrapper for fscanf. IEEE128 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 + . */ + +#include +#include + +extern int +___ieee128_fscanf (FILE *fp, const char *format, ...) +{ + va_list arg; + int done; + + va_start (arg, format); + done = __vfscanf_internal (fp, format, arg, SCANF_LDBL_USES_FLOAT128); + va_end (arg); + + return done; +} +strong_alias (___ieee128_fscanf, __fscanfieee128) diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-scanf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-scanf.c new file mode 100644 index 0000000000..571cf7d75d --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-scanf.c @@ -0,0 +1,34 @@ +/* Wrapper for scanf. IEEE128 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 + . */ + +#include +#include + +extern int +___ieee128_scanf (const char *format, ...) +{ + va_list arg; + int done; + + va_start (arg, format); + done = __vfscanf_internal (stdin, format, arg, SCANF_LDBL_USES_FLOAT128); + va_end (arg); + + return done; +} +strong_alias (___ieee128_scanf, __scanfieee128) diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-sscanf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-sscanf.c new file mode 100644 index 0000000000..7c932955f6 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-sscanf.c @@ -0,0 +1,38 @@ +/* Wrapper for sscanf. IEEE128 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 + . */ + +#include +#include +#include + +extern int +___ieee128_sscanf (const char *string, const char *format, ...) +{ + va_list arg; + int done; + + _IO_strfile sf; + FILE *fp = _IO_strfile_read (&sf, string); + + va_start (arg, format); + done = __vfscanf_internal (fp, format, arg, SCANF_LDBL_USES_FLOAT128); + va_end (arg); + + return done; +} +strong_alias (___ieee128_sscanf, __sscanfieee128) diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfscanf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfscanf.c new file mode 100644 index 0000000000..d6654e05f5 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfscanf.c @@ -0,0 +1,26 @@ +/* Wrapper for vfscanf. IEEE128 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 + . */ + +#include + +extern int +___ieee128_vfscanf (FILE *fp, const char *format, va_list ap) +{ + return __vfscanf_internal (fp, format, ap, SCANF_LDBL_USES_FLOAT128); +} +strong_alias (___ieee128_vfscanf, __vfscanfieee128) diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vscanf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vscanf.c new file mode 100644 index 0000000000..5780c062bb --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vscanf.c @@ -0,0 +1,26 @@ +/* Wrapper for vscanf. IEEE128 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 + . */ + +#include + +extern int +___ieee128_vscanf (const char *format, va_list ap) +{ + return __vfscanf_internal (stdin, format, ap, SCANF_LDBL_USES_FLOAT128); +} +strong_alias (___ieee128_vscanf, __vscanfieee128) diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsscanf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsscanf.c new file mode 100644 index 0000000000..8ff43a95c2 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsscanf.c @@ -0,0 +1,29 @@ +/* Wrapper for vsscanf. IEEE128 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 + . */ + +#include +#include + +extern int +___ieee128_vsscanf (const char *string, const char *format, va_list ap) +{ + _IO_strfile sf; + FILE *fp = _IO_strfile_read (&sf, string); + return __vfscanf_internal (fp, format, ap, SCANF_LDBL_USES_FLOAT128); +} +strong_alias (___ieee128_vsscanf, __vsscanfieee128) diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ibm128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ibm128.c new file mode 100644 index 0000000000..8cdee601f2 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ibm128.c @@ -0,0 +1 @@ +#include diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ieee128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ieee128.c new file mode 100644 index 0000000000..8cdee601f2 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ieee128.c @@ -0,0 +1 @@ +#include diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c new file mode 100644 index 0000000000..4590e9da96 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c @@ -0,0 +1,117 @@ +/* Test for the long double variants of *scanf 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 +#include + +#include + +#define CLEAR \ + va_start (args, format); \ + ld = va_arg (args, long double *); \ + *ld = 0; \ + va_end (args); + +#define CLEAR_VALUE value = 0; + +#define CHECK \ + va_start (args, format); \ + ld = va_arg (args, long double *); \ + va_end (args); \ + if (*ld == -1.0L) \ + printf ("OK"); \ + else \ + printf ("ERROR (%.60Lf)", *ld); \ + printf ("\n"); + +#define CHECK_VALUE \ + if (value == -1.0L) \ + printf ("OK"); \ + else \ + printf ("ERROR (%.60Lf)", value); \ + printf ("\n"); + +static void +do_test_call (FILE *stream, CHAR *string, const CHAR *format, ...) +{ + long double value; + long double *ld; + va_list args; + + CLEAR_VALUE + printf ("fscanf: "); + FSCANF (stream, format, &value); + CHECK_VALUE + + CLEAR_VALUE + printf ("scanf: "); + SCANF (format, &value); + CHECK_VALUE + + CLEAR_VALUE + printf ("sscanf: "); + SSCANF (string, format, &value); + CHECK_VALUE + + CLEAR + printf ("vfscanf: "); + va_start (args, format); + VFSCANF (stream, format, args); + va_end (args); + CHECK + + CLEAR + printf ("vscanf: "); + va_start (args, format); + VSCANF (format, args); + va_end (args); + CHECK + + CLEAR + printf ("vsscanf: "); + va_start (args, format); + VSSCANF (string, format, args); + va_end (args); + CHECK +} + +static int +do_test (void) +{ + CHAR string[256]; + long double ld; + + /* Scan in decimal notation. */ + STRCPY (string, + L ("-1.0\n") + L ("-1.0\n") ); + do_test_call (stdin, string, L("%Lf"), &ld); + + /* Scan in hexadecimal notation. */ + STRCPY (string, + L ("-0x1.0p+0\n") + L ("-0x1.0p+0\n") ); + do_test_call (stdin, string, L("%La"), &ld); + + return 0; +} + +#include diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat.c new file mode 100644 index 0000000000..0759d8afab --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat.c @@ -0,0 +1,10 @@ +#define CHAR char +#define L(x) x +#define FSCANF fscanf +#define SSCANF sscanf +#define SCANF scanf +#define VFSCANF vfscanf +#define VSSCANF vsscanf +#define VSCANF vscanf +#define STRCPY strcpy +#include diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat.sh b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat.sh new file mode 100644 index 0000000000..822b4c3607 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# Testing of *scanf. 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 + +cat <<'EOF' | +-1.000000000000000000000000000000000000000000000000000000000000 +-1.000000000000000000000000000000000000000000000000000000000000 +-1.000000000000000000000000000000000000000000000000000000000000 +-1.000000000000000000000000000000000000000000000000000000000000 +-0x1.000000000000000000000000000000000000000000000000000000000000p+0 +-0x1.000000000000000000000000000000000000000000000000000000000000p+0 +-0x1.000000000000000000000000000000000000000000000000000000000000p+0 +-0x1.000000000000000000000000000000000000000000000000000000000000p+0 +EOF +${test_program_prefix} \ + ${test_program} \ + - \ + > ${test_program_output} || status=1 + +cat <<'EOF' | +fscanf: OK +scanf: OK +sscanf: OK +vfscanf: OK +vscanf: OK +vsscanf: OK +fscanf: OK +scanf: OK +sscanf: OK +vfscanf: OK +vscanf: OK +vsscanf: OK +EOF +cmp - ${test_program_output} > /dev/null 2>&1 || +{ + status=1 + echo "*** output comparison failed" +} + +exit $status