[01/14] Prepare vfprintf to use __printf_fp/__printf_fphex with float128 arg

Message ID 20180621021023.17036-2-gabriel@inconstante.eti.br
State New
Headers show
Series
  • Functions with format string for IEEE128 on powercpc64le
Related show

Commit Message

Gabriel F. T. Gomes June 21, 2018, 2:10 a.m.
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 printf-like functions is aware of these possibilites
and properly parses floating-point values from the variable arguments,
before making calls to __printf_fp and __printf_fphex.  These functions
are also aware of the format possibilites and know how to convert both
formats to string.

When library support for TS 18661-3 was added to glibc, __printf_fp and
__printf_fphex were extented with support for an additional type
(__float128/_Float128) with a different format (binary128).  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/_Float128, this patch extends __vfprintf_internal to properly
call __printf_fp and __printf_fphex with this new format.

Tested for powerpc64le (with additional patches to actually enable the
use of these preparations) and for x86_64.

	* libio/libioP.h (PRINTF_LDBL_USES_FLOAT128): New macro to be
	used as a mask for the mode argument of __vfprintf_internal.
	* stdio-common/printf-parse.h (printf_arg): New union member:
	pa_float128.
	* stdio-common/vfprintf-internal.c
	(LDBL_USES_FLOAT128): New macro.
	(PARSE_FLOAT_VA_ARG_EXTENDED): Likewise.
	(PARSE_FLOAT_VA_ARG): Likewise.
	(SETUP_FLOAT128_INFO): Likewise.
	(process_arg): Use PARSE_FLOAT_VA_ARG_EXTENDED and
	SETUP_FLOAT128_INFO.
	[__HAVE_FLOAT128_UNLIKE_LDBL] (printf_positional): Write
	floating-point value to the new union member, pa_float128.
---
 libio/libioP.h                   |  5 ++--
 stdio-common/printf-parse.h      |  3 ++
 stdio-common/vfprintf-internal.c | 62 +++++++++++++++++++++++++++++++---------
 3 files changed, 55 insertions(+), 15 deletions(-)

-- 
2.14.4

Comments

Joseph Myers June 21, 2018, 9:22 p.m. | #1
On Wed, 20 Jun 2018, Gabriel F. T. Gomes wrote:

> +#if __HAVE_FLOAT128_UNLIKE_LDBL

> +# define PARSE_FLOAT_VA_ARG_EXTENDED(INFO)				      \

> +  if (LDBL_USES_FLOAT128 && is_long_double)				      \

> +    {									      \

> +      INFO.is_binary128 = 1;						      \

> +      the_arg.pa_float128 = va_arg (ap, _Float128);			      \

> +    }									      \

> +  else									      \

> +    {									      \

> +      PARSE_FLOAT_VA_ARG (INFO)						      \

> +    }


I'd expect all these macros to be implemented in the do { ... } while (0) 
style, so that they do genuinely act as single statements when followed by 
';', and then to be followed by ';' at the sites where they are used (so 
avoiding editors messing up indentation at / after those sites), unless 
there is some reason that convention can't work here.

-- 
Joseph S. Myers
joseph@codesourcery.com
Gabriel F. T. Gomes Dec. 7, 2018, 8:15 p.m. | #2
On Thu, 21 Jun 2018, Joseph Myers wrote:

>On Wed, 20 Jun 2018, Gabriel F. T. Gomes wrote:

>

>> +#if __HAVE_FLOAT128_UNLIKE_LDBL

>> +# define PARSE_FLOAT_VA_ARG_EXTENDED(INFO)				      \

>> +  if (LDBL_USES_FLOAT128 && is_long_double)				      \

>> +    {									      \

>> +      INFO.is_binary128 = 1;						      \

>> +      the_arg.pa_float128 = va_arg (ap, _Float128);			      \

>> +    }									      \

>> +  else									      \

>> +    {									      \

>> +      PARSE_FLOAT_VA_ARG (INFO)						      \

>> +    }  

>

>I'd expect all these macros to be implemented in the do { ... } while (0) 

>style, so that they do genuinely act as single statements when followed by 

>';', and then to be followed by ';' at the sites where they are used (so 

>avoiding editors messing up indentation at / after those sites), unless 

>there is some reason that convention can't work here.


I have updated this patch for this comment and for comments to the removal
of __ldbl_is_dbl removal series that also apply here.  This is the updated
patch:

From 2fa3d126947dc63be408009b3b926c706bef3824 Mon Sep 17 00:00:00 2001
From: "Gabriel F. T. Gomes" <gabriel@inconstante.eti.br>

Date: Sun, 3 Jun 2018 17:20:43 -0300
Subject: [PATCH v2] Prepare vfprintf to use __printf_fp/__printf_fphex with
 float128 arg

Changes since v1:

  - Updated to the revised and integrated patches for __ldbl_is_dbl
    removal, i.e.: the patches in the following thread:
    <https://sourceware.org/ml/libc-alpha/2018-12/msg00186.html>.
    - Added description for the PRINTF_LDBL_USES_FLOAT128 macro.
    - Removed the LDBL_USES_FLOAT128 macro.
  - Added `do { } while (0)' to the PARSE_FLOAT_VA_ARG_EXTENDED,
    PARSE_FLOAT_VA_ARG, and SETUP_FLOAT128_INFO macros.  Appended
    expansions with `;', accordingly.

-- 8< --
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 printf-like functions is aware of these possibilities
and properly parses floating-point values from the variable arguments,
before making calls to __printf_fp and __printf_fphex.  These functions
are also aware of the format possibilities and know how to convert both
formats to string.

When library support for TS 18661-3 was added to glibc, __printf_fp and
__printf_fphex were extended with support for an additional type
(__float128/_Float128) with a different format (binary128).  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/_Float128, this patch extends __vfprintf_internal to properly
call __printf_fp and __printf_fphex with this new format.

Tested for powerpc64le (with additional patches to actually enable the
use of these preparations) and for x86_64.

	* libio/libioP.h (PRINTF_LDBL_USES_FLOAT128): New macro to be
	used as a mask for the mode argument of __vfprintf_internal.
	* stdio-common/printf-parse.h (printf_arg): New union member:
	pa_float128.
	* stdio-common/vfprintf-internal.c
	(PARSE_FLOAT_VA_ARG_EXTENDED): New macro.
	(PARSE_FLOAT_VA_ARG): Likewise.
	(SETUP_FLOAT128_INFO): Likewise.
	(process_arg): Use PARSE_FLOAT_VA_ARG_EXTENDED and
	SETUP_FLOAT128_INFO.
	[__HAVE_FLOAT128_UNLIKE_LDBL] (printf_positional): Write
	floating-point value to the new union member, pa_float128.
---
 libio/libioP.h                   | 18 ++++++++--
 stdio-common/printf-parse.h      |  3 ++
 stdio-common/vfprintf-internal.c | 74 +++++++++++++++++++++++++++++++++-------
 3 files changed, 79 insertions(+), 16 deletions(-)

diff --git a/libio/libioP.h b/libio/libioP.h
index 958ef9bffe..f3c1d886c0 100644
--- a/libio/libioP.h
+++ b/libio/libioP.h
@@ -705,9 +705,21 @@ extern int __vswprintf_internal (wchar_t *string, size_t maxlen,
    PRINTF_FORTIFY, when set to one, indicates that fortification checks
    are to be performed in input parameters.  This is used by the
    __*printf_chk functions, which are used when _FORTIFY_SOURCE is
-   defined to 1 or 2.  Otherwise, such checks are ignored.  */
-#define PRINTF_LDBL_IS_DBL 0x0001
-#define PRINTF_FORTIFY     0x0002
+   defined to 1 or 2.  Otherwise, such checks are ignored.
+
+   PRINTF_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 PRINTF_LDBL_IS_DBL		0x0001
+#define PRINTF_FORTIFY			0x0002
+#define PRINTF_LDBL_USES_FLOAT128	0x0004
 
 extern size_t _IO_getline (FILE *,char *, size_t, int, int);
 libc_hidden_proto (_IO_getline)
diff --git a/stdio-common/printf-parse.h b/stdio-common/printf-parse.h
index e07186ec83..9c79f3c862 100644
--- a/stdio-common/printf-parse.h
+++ b/stdio-common/printf-parse.h
@@ -57,6 +57,9 @@ union printf_arg
     unsigned long long int pa_u_long_long_int;
     double pa_double;
     long double pa_long_double;
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+    _Float128 pa_float128;
+#endif
     const char *pa_string;
     const wchar_t *pa_wstring;
     void *pa_pointer;
diff --git a/stdio-common/vfprintf-internal.c b/stdio-common/vfprintf-internal.c
index 61769e0ce1..4b74bfa31c 100644
--- a/stdio-common/vfprintf-internal.c
+++ b/stdio-common/vfprintf-internal.c
@@ -68,6 +68,53 @@
     } while (0)
 #define UNBUFFERED_P(S) ((S)->_flags & _IO_UNBUFFERED)
 
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+# define PARSE_FLOAT_VA_ARG_EXTENDED(INFO)				      \
+  do									      \
+    {									      \
+      if (is_long_double						      \
+	  && (mode_flags & PRINTF_LDBL_USES_FLOAT128) != 0)		      \
+	{								      \
+	  INFO.is_binary128 = 1;					      \
+	  the_arg.pa_float128 = va_arg (ap, _Float128);			      \
+	}								      \
+      else								      \
+	{								      \
+	  PARSE_FLOAT_VA_ARG (INFO);					      \
+	}								      \
+    } while (0)
+#else
+# define PARSE_FLOAT_VA_ARG_EXTENDED(INFO)				      \
+  PARSE_FLOAT_VA_ARG (INFO);
+#endif
+
+#define PARSE_FLOAT_VA_ARG(INFO)					      \
+  do									      \
+    {									      \
+      INFO.is_binary128 = 0;						      \
+      if (is_long_double)						      \
+	the_arg.pa_long_double = va_arg (ap, long double);		      \
+      else								      \
+	the_arg.pa_double = va_arg (ap, double);			      \
+    } while (0)
+
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+# define SETUP_FLOAT128_INFO(INFO)					      \
+  do									      \
+    {									      \
+      if ((mode_flags & PRINTF_LDBL_USES_FLOAT128) != 0)		      \
+	INFO.is_binary128 = is_long_double;				      \
+      else								      \
+	INFO.is_binary128 = 0;						      \
+    } while (0)
+#else
+# define SETUP_FLOAT128_INFO(INFO)					      \
+  do									      \
+    {									      \
+      INFO.is_binary128 = 0;						      \
+    } while (0)
+#endif
+
 #define done_add(val) \
   do {									      \
     unsigned int _val = val;						      \
@@ -771,10 +818,7 @@ static const uint8_t jump_table[] =
 					.wide = sizeof (CHAR_T) != 1,	      \
 					.is_binary128 = 0};		      \
 									      \
-	    if (is_long_double)						      \
-	      the_arg.pa_long_double = va_arg (ap, long double);	      \
-	    else							      \
-	      the_arg.pa_double = va_arg (ap, double);			      \
+	    PARSE_FLOAT_VA_ARG_EXTENDED (info);				      \
 	    ptr = (const void *) &the_arg;				      \
 									      \
 	    function_done = __printf_fp (s, &info, &ptr);		      \
@@ -787,8 +831,7 @@ static const uint8_t jump_table[] =
 		fspec->data_arg_type = PA_DOUBLE;			      \
 		fspec->info.is_long_double = 0;				      \
 	      }								      \
-	    /* Not supported by *printf functions.  */			      \
-	    fspec->info.is_binary128 = 0;				      \
+	    SETUP_FLOAT128_INFO (fspec->info);				      \
 									      \
 	    function_done = __printf_fp (s, &fspec->info, &ptr);	      \
 	  }								      \
@@ -831,10 +874,7 @@ static const uint8_t jump_table[] =
 					.wide = sizeof (CHAR_T) != 1,	      \
 					.is_binary128 = 0};		      \
 									      \
-	    if (is_long_double)						      \
-	      the_arg.pa_long_double = va_arg (ap, long double);	      \
-	    else							      \
-	      the_arg.pa_double = va_arg (ap, double);			      \
+	    PARSE_FLOAT_VA_ARG_EXTENDED (info);				      \
 	    ptr = (const void *) &the_arg;				      \
 									      \
 	    function_done = __printf_fphex (s, &info, &ptr);		      \
@@ -844,8 +884,7 @@ static const uint8_t jump_table[] =
 	    ptr = (const void *) &args_value[fspec->data_arg];		      \
 	    if (__glibc_unlikely ((mode_flags & PRINTF_LDBL_IS_DBL) != 0))    \
 	      fspec->info.is_long_double = 0;				      \
-	    /* Not supported by *printf functions.  */			      \
-	    fspec->info.is_binary128 = 0;				      \
+	    SETUP_FLOAT128_INFO (fspec->info);				      \
 									      \
 	    function_done = __printf_fphex (s, &fspec->info, &ptr);	      \
 	  }								      \
@@ -1869,6 +1908,10 @@ printf_positional (FILE *s, const CHAR_T *format, int readonly_format,
 	    args_value[cnt].pa_double = va_arg (*ap_savep, double);
 	    args_type[cnt] &= ~PA_FLAG_LONG_DOUBLE;
 	  }
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+	else if ((mode_flags & PRINTF_LDBL_USES_FLOAT128) != 0)
+	  args_value[cnt].pa_float128 = va_arg (*ap_savep, _Float128);
+#endif
 	else
 	  args_value[cnt].pa_long_double = va_arg (*ap_savep, long double);
 	break;
@@ -1887,7 +1930,12 @@ printf_positional (FILE *s, const CHAR_T *format, int readonly_format,
 	      (args_value[cnt].pa_user, ap_savep);
 	  }
 	else
-	  args_value[cnt].pa_long_double = 0.0;
+	  {
+	    args_value[cnt].pa_long_double = 0.0;
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+	    args_value[cnt].pa_float128 = 0;
+#endif
+	  }
 	break;
       case -1:
 	/* Error case.  Not all parameters appear in N$ format
-- 
2.14.5
Gabriel F. T. Gomes Dec. 18, 2018, 11:06 a.m. | #3
Ping.

This patch <https://sourceware.org/ml/libc-alpha/2018-12/msg00255.html> is
pending review.
Florian Weimer Dec. 18, 2018, 11:17 a.m. | #4
* Gabriel F. T. Gomes:

> +    } while (0)


Style issue: while should be on a separate line (occurs multiple times).
> @@ -1887,7 +1930,12 @@ printf_positional (FILE *s, const CHAR_T *format, int readonly_format,

>  	      (args_value[cnt].pa_user, ap_savep);

>  	  }

>  	else

> -	  args_value[cnt].pa_long_double = 0.0;

> +	  {

> +	    args_value[cnt].pa_long_double = 0.0;

> +#if __HAVE_FLOAT128_UNLIKE_LDBL

> +	    args_value[cnt].pa_float128 = 0;

> +#endif

> +	  }


This bit doesn't look right to me because args_value[cnt] is a union.
You need to assign to the right member, or perhaps zero-initialize using
memset.

Thanks,
Florian
Gabriel F. T. Gomes Dec. 18, 2018, 1:27 p.m. | #5
On Tue, 18 Dec 2018, Florian Weimer wrote:

>* Gabriel F. T. Gomes:

>>

>> @@ -1887,7 +1930,12 @@ printf_positional (FILE *s, const CHAR_T *format, int readonly_format,

>>  	      (args_value[cnt].pa_user, ap_savep);

>>  	  }

>>  	else

>> -	  args_value[cnt].pa_long_double = 0.0;

>> +	  {

>> +	    args_value[cnt].pa_long_double = 0.0;

>> +#if __HAVE_FLOAT128_UNLIKE_LDBL

>> +	    args_value[cnt].pa_float128 = 0;

>> +#endif

>> +	  }  

>

>This bit doesn't look right to me because args_value[cnt] is a union.

>You need to assign to the right member, or perhaps zero-initialize using

>memset.


Hmm, the original code doesn't seem to be dealing with anything particular
to the long double type.  It seems that assigning to .pa_long_double,
rather than to other members, was an arbitrary decision.  Do you know
why .pa_long_double was chosen?

So, if this code is just zero-initializing the memory, do you think I
should zero-initialize the whole of args_value/argsbuf.data when it gets
expanded (see below)?  Then I could remove the else block entirely.

Like this:

diff --git a/stdio-common/vfprintf-internal.c b/stdio-common/vfprintf-internal.c
index 61769e0ce1..17f1bae796 100644
--- a/stdio-common/vfprintf-internal.c
+++ b/stdio-common/vfprintf-internal.c
@@ -1789,10 +1789,11 @@ printf_positional (FILE *s, const CHAR_T *format, int readonly_format,
     if (!scratch_buffer_set_array_size (&argsbuf, nargs, bytes_per_arg))
       {
        done = -1;
        goto all_done;
       }
+    memset (argsbuf.data, 0, argsbuf.size);
     args_value = argsbuf.data;
     /* Set up the remaining two arrays to each point past the end of
        the prior array, since space for all three has been allocated
        now.  */
     args_size = &args_value[nargs].pa_int;
@@ -1884,12 +1885,10 @@ printf_positional (FILE *s, const CHAR_T *format, int readonly_format,
          {
            args_value[cnt].pa_user = alloca (args_size[cnt]);
            (*__printf_va_arg_table[args_type[cnt] - PA_LAST])
              (args_value[cnt].pa_user, ap_savep);
          }
-       else
-         args_value[cnt].pa_long_double = 0.0;
        break;
       case -1:
        /* Error case.  Not all parameters appear in N$ format
           strings.  We have no way to determine their type.  */
        assert ((mode_flags & PRINTF_FORTIFY) != 0);
Florian Weimer Dec. 19, 2018, 3:53 p.m. | #6
* Gabriel F. T. Gomes:

> On Tue, 18 Dec 2018, Florian Weimer wrote:

>

>>* Gabriel F. T. Gomes:

>>>

>>> @@ -1887,7 +1930,12 @@ printf_positional (FILE *s, const CHAR_T *format, int readonly_format,

>>>  	      (args_value[cnt].pa_user, ap_savep);

>>>  	  }

>>>  	else

>>> -	  args_value[cnt].pa_long_double = 0.0;

>>> +	  {

>>> +	    args_value[cnt].pa_long_double = 0.0;

>>> +#if __HAVE_FLOAT128_UNLIKE_LDBL

>>> +	    args_value[cnt].pa_float128 = 0;

>>> +#endif

>>> +	  }  

>>

>>This bit doesn't look right to me because args_value[cnt] is a union.

>>You need to assign to the right member, or perhaps zero-initialize using

>>memset.

>

> Hmm, the original code doesn't seem to be dealing with anything particular

> to the long double type.  It seems that assigning to .pa_long_double,

> rather than to other members, was an arbitrary decision.  Do you know

> why .pa_long_double was chosen?


Not really.  My guess it was expected that it would be the largest
member.

> So, if this code is just zero-initializing the memory, do you think I

> should zero-initialize the whole of args_value/argsbuf.data when it gets

> expanded (see below)?  Then I could remove the else block entirely.

>

> Like this:

>

> diff --git a/stdio-common/vfprintf-internal.c b/stdio-common/vfprintf-internal.c

> index 61769e0ce1..17f1bae796 100644

> --- a/stdio-common/vfprintf-internal.c

> +++ b/stdio-common/vfprintf-internal.c

> @@ -1789,10 +1789,11 @@ printf_positional (FILE *s, const CHAR_T *format, int readonly_format,

>      if (!scratch_buffer_set_array_size (&argsbuf, nargs, bytes_per_arg))

>        {

>         done = -1;

>         goto all_done;

>        }

> +    memset (argsbuf.data, 0, argsbuf.size);

>      args_value = argsbuf.data;

>      /* Set up the remaining two arrays to each point past the end of

>         the prior array, since space for all three has been allocated

>         now.  */

>      args_size = &args_value[nargs].pa_int;

> @@ -1884,12 +1885,10 @@ printf_positional (FILE *s, const CHAR_T *format, int readonly_format,

>           {

>             args_value[cnt].pa_user = alloca (args_size[cnt]);

>             (*__printf_va_arg_table[args_type[cnt] - PA_LAST])

>               (args_value[cnt].pa_user, ap_savep);

>           }

> -       else

> -         args_value[cnt].pa_long_double = 0.0;


I would haved expected

            memset (&args_value[cnt], 0, sizeof (args_value[cnt]));

under thelse branch.

Thanks,
Florian

Patch

diff --git a/libio/libioP.h b/libio/libioP.h
index e9446b87f2..fba4b52460 100644
--- a/libio/libioP.h
+++ b/libio/libioP.h
@@ -687,8 +687,9 @@  extern int __vswprintf_internal (wchar_t *string, size_t maxlen,
                                  unsigned int mode_flags);
 
 /* Flags for __v*printf_internal.  */
-#define PRINTF_LDBL_IS_DBL 0x0001
-#define PRINTF_FORTIFY     0x0002
+#define PRINTF_LDBL_IS_DBL		0x0001
+#define PRINTF_FORTIFY			0x0002
+#define PRINTF_LDBL_USES_FLOAT128	0x0004
 
 extern size_t _IO_getline (FILE *,char *, size_t, int, int);
 libc_hidden_proto (_IO_getline)
diff --git a/stdio-common/printf-parse.h b/stdio-common/printf-parse.h
index e07186ec83..9c79f3c862 100644
--- a/stdio-common/printf-parse.h
+++ b/stdio-common/printf-parse.h
@@ -57,6 +57,9 @@  union printf_arg
     unsigned long long int pa_u_long_long_int;
     double pa_double;
     long double pa_long_double;
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+    _Float128 pa_float128;
+#endif
     const char *pa_string;
     const wchar_t *pa_wstring;
     void *pa_pointer;
diff --git a/stdio-common/vfprintf-internal.c b/stdio-common/vfprintf-internal.c
index 2d9016e83b..95d36969d1 100644
--- a/stdio-common/vfprintf-internal.c
+++ b/stdio-common/vfprintf-internal.c
@@ -68,8 +68,43 @@ 
     } while (0)
 #define UNBUFFERED_P(S) ((S)->_flags & _IO_UNBUFFERED)
 #define LDBL_IS_DBL (__glibc_unlikely ((mode_flags & PRINTF_LDBL_IS_DBL) != 0))
+#define LDBL_USES_FLOAT128 ((mode_flags & PRINTF_LDBL_USES_FLOAT128) != 0)
 #define DO_FORTIFY  ((mode_flags & PRINTF_FORTIFY) != 0)
 
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+# define PARSE_FLOAT_VA_ARG_EXTENDED(INFO)				      \
+  if (LDBL_USES_FLOAT128 && is_long_double)				      \
+    {									      \
+      INFO.is_binary128 = 1;						      \
+      the_arg.pa_float128 = va_arg (ap, _Float128);			      \
+    }									      \
+  else									      \
+    {									      \
+      PARSE_FLOAT_VA_ARG (INFO)						      \
+    }
+#else
+# define PARSE_FLOAT_VA_ARG_EXTENDED(INFO)				      \
+  PARSE_FLOAT_VA_ARG (INFO)
+#endif
+
+#define PARSE_FLOAT_VA_ARG(INFO)					      \
+  INFO.is_binary128 = 0;						      \
+  if (is_long_double)							      \
+    the_arg.pa_long_double = va_arg (ap, long double);			      \
+  else									      \
+    the_arg.pa_double = va_arg (ap, double);
+
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+# define SETUP_FLOAT128_INFO(INFO)					      \
+  if (LDBL_USES_FLOAT128)						      \
+    INFO.is_binary128 = is_long_double;					      \
+  else									      \
+    INFO.is_binary128 = 0;
+#else
+# define SETUP_FLOAT128_INFO(INFO)					      \
+  INFO.is_binary128 = 0;
+#endif
+
 #define done_add(val) \
   do {									      \
     unsigned int _val = val;						      \
@@ -773,10 +808,7 @@  static const uint8_t jump_table[] =
 					.wide = sizeof (CHAR_T) != 1,	      \
 					.is_binary128 = 0};		      \
 									      \
-	    if (is_long_double)						      \
-	      the_arg.pa_long_double = va_arg (ap, long double);	      \
-	    else							      \
-	      the_arg.pa_double = va_arg (ap, double);			      \
+	    PARSE_FLOAT_VA_ARG_EXTENDED (info)				      \
 	    ptr = (const void *) &the_arg;				      \
 									      \
 	    function_done = __printf_fp (s, &info, &ptr);		      \
@@ -789,8 +821,7 @@  static const uint8_t jump_table[] =
 		fspec->data_arg_type = PA_DOUBLE;			      \
 		fspec->info.is_long_double = 0;				      \
 	      }								      \
-	    /* Not supported by *printf functions.  */			      \
-	    fspec->info.is_binary128 = 0;				      \
+	    SETUP_FLOAT128_INFO (fspec->info)				      \
 									      \
 	    function_done = __printf_fp (s, &fspec->info, &ptr);	      \
 	  }								      \
@@ -833,10 +864,7 @@  static const uint8_t jump_table[] =
 					.wide = sizeof (CHAR_T) != 1,	      \
 					.is_binary128 = 0};		      \
 									      \
-	    if (is_long_double)						      \
-	      the_arg.pa_long_double = va_arg (ap, long double);	      \
-	    else							      \
-	      the_arg.pa_double = va_arg (ap, double);			      \
+	    PARSE_FLOAT_VA_ARG_EXTENDED (info)				      \
 	    ptr = (const void *) &the_arg;				      \
 									      \
 	    function_done = __printf_fphex (s, &info, &ptr);		      \
@@ -846,8 +874,7 @@  static const uint8_t jump_table[] =
 	    ptr = (const void *) &args_value[fspec->data_arg];		      \
 	    if (LDBL_IS_DBL)                                            \
 	      fspec->info.is_long_double = 0;				      \
-	    /* Not supported by *printf functions.  */			      \
-	    fspec->info.is_binary128 = 0;				      \
+	    SETUP_FLOAT128_INFO (fspec->info)				      \
 									      \
 	    function_done = __printf_fphex (s, &fspec->info, &ptr);	      \
 	  }								      \
@@ -1871,6 +1898,10 @@  printf_positional (FILE *s, const CHAR_T *format, int readonly_format,
 	    args_value[cnt].pa_double = va_arg (*ap_savep, double);
 	    args_type[cnt] &= ~PA_FLAG_LONG_DOUBLE;
 	  }
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+	else if (LDBL_USES_FLOAT128)
+	  args_value[cnt].pa_float128 = va_arg (*ap_savep, _Float128);
+#endif
 	else
 	  args_value[cnt].pa_long_double = va_arg (*ap_savep, long double);
 	break;
@@ -1889,7 +1920,12 @@  printf_positional (FILE *s, const CHAR_T *format, int readonly_format,
 	      (args_value[cnt].pa_user, ap_savep);
 	  }
 	else
-	  args_value[cnt].pa_long_double = 0.0;
+	  {
+	    args_value[cnt].pa_long_double = 0.0;
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+	    args_value[cnt].pa_float128 = 0;
+#endif
+	  }
 	break;
       case -1:
 	/* Error case.  Not all parameters appear in N$ format