diff options
13 files changed, 421 insertions, 3 deletions
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile index 7217987..a1f0f7d 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 e438c7c..7971c7a 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 0000000..f9de397 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fscanf.c @@ -0,0 +1,34 @@ +/* Wrapper for fscanf. 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_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 0000000..9a3ea13 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-scanf.c @@ -0,0 +1,34 @@ +/* Wrapper for scanf. 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_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 0000000..b774b62 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-sscanf.c @@ -0,0 +1,38 @@ +/* Wrapper for sscanf. 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 <strfile.h> +#include <libioP.h> + +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 0000000..85af831 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vfscanf.c @@ -0,0 +1,26 @@ +/* Wrapper for vfscanf. 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_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 0000000..1f35923 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vscanf.c @@ -0,0 +1,26 @@ +/* Wrapper for vscanf. 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_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 0000000..b5cc8ec --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vsscanf.c @@ -0,0 +1,29 @@ +/* Wrapper for vsscanf. 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 <strfile.h> +#include <libioP.h> + +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 0000000..8cdee60 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ibm128.c @@ -0,0 +1 @@ +#include <test-scanf-ldbl-compat.c> 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 0000000..8cdee60 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ieee128.c @@ -0,0 +1 @@ +#include <test-scanf-ldbl-compat.c> 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 0000000..585d138 --- /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) 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 <string.h> +#include <wchar.h> + +#include <support/check.h> + +#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 <support/test-driver.c> 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 0000000..0759d8a --- /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 <test-scanf-ldbl-compat-template.c> 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 0000000..9a2c683 --- /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) 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/>. + +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 |