public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Gabriel F. T. Gomes" <gabriel@inconstante.eti.br>
To: Joseph Myers <joseph@codesourcery.com>
Cc: <libc-alpha@sourceware.org>
Subject: Re: [PATCH 02/14] Prepare vfscanf to use __strtof128_internal
Date: Fri, 07 Dec 2018 20:16:00 -0000	[thread overview]
Message-ID: <20181207180911.3e951697@tereshkova> (raw)
In-Reply-To: <alpine.DEB.2.20.1806212135010.19363@digraph.polyomino.org.uk>

On Thu, 21 Jun 2018, Joseph Myers wrote:

>On Wed, 20 Jun 2018, Gabriel F. T. Gomes wrote:
>
>> On powerpc64le, long double can currently take two formats: the same as
>> double (-mlong-double-64) or IBM Extended Precision (default with
>> -mlong-double-128 or explicitly with -mabi=ibmlongdouble).  The internal
>> implementation of scanf-like functions is aware of these possibilites
>> and, based on the format in use, properly calls __strtold_internal or
>> __strtod_internal, saving the return to a variable of type double or
>> long double.
>> 
>> When library support for TS 18661-3 was added to glibc, a new function,
>> __strtof128_internal, was added to enable reading of floating-point
>> values with IEEE binary128 format into the _Float128 type.  Now that
>> powerpc64le is getting support for its third long double format, and
>> taking into account that this format is the same as the format of
>> _Float128, this patch extends __vfscanf_internal and __vfwscanf_internal
>> to call __strtof128_internal when appropriate.  The result gets saved
>> into a variable of _Float128 type.  
>
>This patch is OK once Zack's patches are reviewed and checked in.

I have now committed this patch, adapted for current master, and
with the descriptive comment for the SCANF_LDBL_USES_FLOAT128 macro.


From 10446f5d9f2cf4d91c8ae483fd2b5470242ae2a1 Mon Sep 17 00:00:00 2001
From: "Gabriel F. T. Gomes" <gabriel@inconstante.eti.br>
Date: Sun, 10 Jun 2018 22:42:34 -0300
Subject: [PATCH] Prepare vfscanf to use __strtof128_internal

On powerpc64le, long double can currently take two formats: the same as
double (-mlong-double-64) or IBM Extended Precision (default with
-mlong-double-128 or explicitly with -mabi=ibmlongdouble).  The internal
implementation of scanf-like functions is aware of these possibilites
and, based on the format in use, properly calls __strtold_internal or
__strtod_internal, saving the return to a variable of type double or
long double.

When library support for TS 18661-3 was added to glibc, a new function,
__strtof128_internal, was added to enable reading of floating-point
values with IEEE binary128 format into the _Float128 type.  Now that
powerpc64le is getting support for its third long double format, and
taking into account that this format is the same as the format of
_Float128, this patch extends __vfscanf_internal and __vfwscanf_internal
to call __strtof128_internal or __wcstof128_internal when appropriate.
The result gets saved into a variable of _Float128 type.

Tested for powerpc64le.
---
 ChangeLog                       | 12 ++++++++++++
 libio/libioP.h                  | 18 +++++++++++++++---
 stdio-common/vfscanf-internal.c | 14 ++++++++++++++
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 998f4c153f..c6ad912b11 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2018-12-07  Gabriel F. T. Gomes  <gabriel@inconstante.eti.br>
+
+	* libio/libioP.h (SCANF_LDBL_USES_FLOAT128): New macro to be
+	used as a mask for the mode argument of __vfscanf_internal and
+	__vfwscanf_internal.
+	* stdio-common/vfscanf-internal.c
+	[defined COMPILE_WSCANF && __HAVE_FLOAT128_UNLIKE_LDBL]
+	(__strtof128_internal): Define to __wcstof128_internal.
+	[__HAVE_FLOAT128_UNLIKE_LDBL] (__vfscanf_internal): Call
+	__strtof128_internal or __wcstof128_internal when the format of
+	long double is the same as _Float128.
+
 2018-12-05  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
 	* include/unistd.h (__confstr): Add prototype and hidden prototype.
diff --git a/libio/libioP.h b/libio/libioP.h
index ce5228e382..958ef9bffe 100644
--- a/libio/libioP.h
+++ b/libio/libioP.h
@@ -759,9 +759,21 @@ extern off64_t _IO_seekpos_unlocked (FILE *, off64_t, int)
    allocation for input strings with %as, %aS and %a[, a GNU extension,
    is disabled. This is the behavior that the __isoc99_scanf family of
    functions use.  When the flag is set to zero, automatic allocation is
-   enabled.  */
-#define SCANF_LDBL_IS_DBL 0x0001
-#define SCANF_ISOC99_A    0x0002
+   enabled.
+
+   SCANF_LDBL_USES_FLOAT128 is used on platforms where the long double
+   format used to be different from the IEC 60559 double format *and*
+   also different from the Quadruple 128-bits IEC 60559 format (such as
+   the IBM Extended Precision format on powerpc or the 80-bits IEC 60559
+   format on x86), but was later converted to the Quadruple 128-bits IEC
+   60559 format, which is the same format that the _Float128 always has
+   (hence the `USES_FLOAT128' suffix in the name of the flag).  When set
+   to one, this macros indicates that long double values are to be
+   handled as having this new format.  Otherwise, they should be handled
+   as the previous format on that platform.  */
+#define SCANF_LDBL_IS_DBL		0x0001
+#define SCANF_ISOC99_A			0x0002
+#define SCANF_LDBL_USES_FLOAT128	0x0004
 
 extern int __vfscanf_internal (FILE *fp, const char *format, va_list argp,
 			       unsigned int flags)
diff --git a/stdio-common/vfscanf-internal.c b/stdio-common/vfscanf-internal.c
index 19cfef0906..5d002078d8 100644
--- a/stdio-common/vfscanf-internal.c
+++ b/stdio-common/vfscanf-internal.c
@@ -98,6 +98,9 @@
 # define __strtold_internal	__wcstold_internal
 # define __strtod_internal	__wcstod_internal
 # define __strtof_internal	__wcstof_internal
+# if __HAVE_FLOAT128_UNLIKE_LDBL
+#  define __strtof128_internal	__wcstof128_internal
+# endif
 
 # define L_(Str)	L##Str
 # define CHAR_T		wchar_t
@@ -2420,6 +2423,17 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr,
 	      done = EOF;
 	      goto errout;
 	    }
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+	  if ((flags & LONGDBL) \
+	       && (mode_flags & SCANF_LDBL_USES_FLOAT128) != 0)
+	    {
+	      _Float128 d = __strtof128_internal
+		(char_buffer_start (&charbuf), &tw, flags & GROUP);
+	      if (!(flags & SUPPRESS) && tw != char_buffer_start (&charbuf))
+		*ARG (_Float128 *) = d;
+	    }
+	  else
+#endif
 	  if ((flags & LONGDBL) \
 	      && __glibc_likely ((mode_flags & SCANF_LDBL_IS_DBL) == 0))
 	    {
-- 
2.14.5

  parent reply	other threads:[~2018-12-07 20:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-21  2:10 [PATCH 00/14] Functions with format string for IEEE128 on powercpc64le Gabriel F. T. Gomes
2018-06-21  2:10 ` [PATCH 02/14] Prepare vfscanf to use __strtof128_internal Gabriel F. T. Gomes
2018-06-21 21:35   ` Joseph Myers
2018-06-21 21:39     ` Zack Weinberg
2018-12-07 20:16     ` Gabriel F. T. Gomes [this message]
2018-06-21  2:10 ` [PATCH 01/14] Prepare vfprintf to use __printf_fp/__printf_fphex with float128 arg Gabriel F. T. Gomes
2018-06-21 21:22   ` Joseph Myers
2018-12-07 20:16     ` Gabriel F. T. Gomes
2018-12-18 11:18       ` Ping Re: [PATCH v2] " Gabriel F. T. Gomes
2018-12-18 12:13       ` [PATCH 01/14] " Florian Weimer
2018-12-18 13:37         ` Gabriel F. T. Gomes
2018-12-19 15:57           ` Florian Weimer
2018-06-21  2:10 ` [PATCH 03/14] Add internal implementations for argp.h, err.h, and error.h functions Gabriel F. T. Gomes
2018-06-21 21:36   ` Joseph Myers
2018-06-21  2:11 ` [PATCH 11/14] ldbl-128ibm-compat: Add argp_error and argp_failure Gabriel F. T. Gomes
2018-06-21  2:11 ` [PATCH 08/14] ldbl-128ibm-compat: Test double values Gabriel F. T. Gomes
2018-06-21  2:11 ` [PATCH 05/14] ldbl-128ibm-compat: Add wide character printing functions Gabriel F. T. Gomes
2018-06-21  2:11 ` [PATCH 12/14] ldbl-128ibm-compat: Add err.h functions Gabriel F. T. Gomes
2018-06-21  2:11 ` [PATCH 04/14] ldbl-128ibm-compat: Add regular character printing functions Gabriel F. T. Gomes
2018-06-21 21:03   ` Joseph Myers
2018-06-21  2:11 ` [PATCH 06/14] ldbl-128ibm-compat: Add regular character, fortified " Gabriel F. T. Gomes
2018-06-21  2:11 ` [PATCH 10/14] ldbl-128ibm-compat: Add wide character scanning functions Gabriel F. T. Gomes
2018-06-21  2:11 ` [PATCH 14/14] ldbl-128ibm-compat: Add tests for err.h and error.h functions Gabriel F. T. Gomes
2018-06-21  2:11 ` [PATCH 07/14] ldbl-128ibm-compat: Add wide character, fortified printing functions Gabriel F. T. Gomes
2018-06-21  2:11 ` [PATCH 09/14] ldbl-128ibm-compat: Add regular character scanning functions Gabriel F. T. Gomes
2018-06-21  2:11 ` [PATCH 13/14] ldbl-128ibm-compat: Add error.h functions Gabriel F. T. Gomes
2018-06-21 16:44 ` [PATCH 00/14] Functions with format string for IEEE128 on powercpc64le Joseph Myers

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

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

  git send-email \
    --in-reply-to=20181207180911.3e951697@tereshkova \
    --to=gabriel@inconstante.eti.br \
    --cc=joseph@codesourcery.com \
    --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).