public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* libquadmath, glibc, and the Q format flag
@ 2023-02-01 10:56 Florian Weimer
  2023-02-01 11:07 ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2023-02-01 10:56 UTC (permalink / raw)
  To: libc-alpha, gcc, fortran

I recently discovered that libquadmath registers custom printf callbacks
on load.  As far as I can tell, this is done so that the Q format flag
can be used to print floating point numbers, using format strings such
as "%Qf".  To enable Q flag processing, libquadmath has to register
replacements for all floating point format specifiers (aAeEfFgG).

Unfortunately, this has the side effect that even with out the Q flag,
printing any floating point number enters a generic, slow path in glibc,
prior to the number formatting itself.  The effect is quite pronounced.
For example this admittedly silly benchmarking script

    for i=1,5000000 do
        print(i, i * math.pi)
    end

runs for 5.8 seconds without libquadmath.so.0 loaded on my x86-64
system.  With libquadmath.so.0 from GCC 12 loaded, it runs for 6.3
seconds.

This impacts most (all?) Fortran code on GNU/Linux because libgfortran
depends on libquadmath.

Would it make sense to transplant the implementation of the Q specifier
from libquadmath to glibc, and disable the registration code in
libquadmath if glibc is recent enough?  At least for the targets that
today have float128 support in glibc?

Thanks,
Florian


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: libquadmath, glibc, and the Q format flag
  2023-02-01 10:56 libquadmath, glibc, and the Q format flag Florian Weimer
@ 2023-02-01 11:07 ` Jakub Jelinek
  2023-02-01 11:29   ` Florian Weimer
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2023-02-01 11:07 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha, gcc, fortran

On Wed, Feb 01, 2023 at 11:56:42AM +0100, Florian Weimer via Gcc wrote:
> I recently discovered that libquadmath registers custom printf callbacks
> on load.  As far as I can tell, this is done so that the Q format flag
> can be used to print floating point numbers, using format strings such
> as "%Qf".  To enable Q flag processing, libquadmath has to register
> replacements for all floating point format specifiers (aAeEfFgG).
> 
> Unfortunately, this has the side effect that even with out the Q flag,
> printing any floating point number enters a generic, slow path in glibc,
> prior to the number formatting itself.  The effect is quite pronounced.
> For example this admittedly silly benchmarking script
> 
>     for i=1,5000000 do
>         print(i, i * math.pi)
>     end
> 
> runs for 5.8 seconds without libquadmath.so.0 loaded on my x86-64
> system.  With libquadmath.so.0 from GCC 12 loaded, it runs for 6.3
> seconds.
> 
> This impacts most (all?) Fortran code on GNU/Linux because libgfortran
> depends on libquadmath.

Not anymore.
If GCC is configured against new enough glibc (with _Float128 support)
libgfortran.so.5 is no longer linked against -lquadmath, and -lquadmath
is added only --as-needed to ld command line, so if all the Fortran object
files that need real(kind=16) (or quad complex) are built by such configured
GCC, -lquadmath is not linked in (just needs to be present).
And, even for C, users can just use the standard glibc _Float128 support
(if they don't mind strfromf128) if they target new enough glibc.
So, libquadmath should be left over for non-glibc uses or uses with old
glibc.

> Would it make sense to transplant the implementation of the Q specifier
> from libquadmath to glibc, and disable the registration code in
> libquadmath if glibc is recent enough?  At least for the targets that
> today have float128 support in glibc?

Thus I'm not sure it is worth it.

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: libquadmath, glibc, and the Q format flag
  2023-02-01 11:07 ` Jakub Jelinek
@ 2023-02-01 11:29   ` Florian Weimer
  2023-02-01 11:40     ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2023-02-01 11:29 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: libc-alpha, gcc, fortran

* Jakub Jelinek:

> On Wed, Feb 01, 2023 at 11:56:42AM +0100, Florian Weimer via Gcc wrote:
>> I recently discovered that libquadmath registers custom printf callbacks
>> on load.  As far as I can tell, this is done so that the Q format flag
>> can be used to print floating point numbers, using format strings such
>> as "%Qf".  To enable Q flag processing, libquadmath has to register
>> replacements for all floating point format specifiers (aAeEfFgG).
>> 
>> Unfortunately, this has the side effect that even with out the Q flag,
>> printing any floating point number enters a generic, slow path in glibc,
>> prior to the number formatting itself.  The effect is quite pronounced.
>> For example this admittedly silly benchmarking script
>> 
>>     for i=1,5000000 do
>>         print(i, i * math.pi)
>>     end
>> 
>> runs for 5.8 seconds without libquadmath.so.0 loaded on my x86-64
>> system.  With libquadmath.so.0 from GCC 12 loaded, it runs for 6.3
>> seconds.
>> 
>> This impacts most (all?) Fortran code on GNU/Linux because libgfortran
>> depends on libquadmath.
>
> Not anymore.
> If GCC is configured against new enough glibc (with _Float128 support)
> libgfortran.so.5 is no longer linked against -lquadmath, and -lquadmath
> is added only --as-needed to ld command line, so if all the Fortran object
> files that need real(kind=16) (or quad complex) are built by such configured
> GCC, -lquadmath is not linked in (just needs to be present).

Hmm, I missed that recent change.

Would it make sense to drop the libgfortran RPM dependency on
libquadmath in Fedora rawhide?

> And, even for C, users can just use the standard glibc _Float128 support
> (if they don't mind strfromf128) if they target new enough glibc.
> So, libquadmath should be left over for non-glibc uses or uses with old
> glibc.
>
>> Would it make sense to transplant the implementation of the Q specifier
>> from libquadmath to glibc, and disable the registration code in
>> libquadmath if glibc is recent enough?  At least for the targets that
>> today have float128 support in glibc?
>
> Thus I'm not sure it is worth it.

Yeah, if most implicit libquadmath uses are history, then it's probably
not going to be needed (unless some standard suggests to use the Q
flag).

Thanks,
Florian


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: libquadmath, glibc, and the Q format flag
  2023-02-01 11:29   ` Florian Weimer
@ 2023-02-01 11:40     ` Jakub Jelinek
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2023-02-01 11:40 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha, gcc, fortran

On Wed, Feb 01, 2023 at 12:29:02PM +0100, Florian Weimer via Gcc wrote:
> >> This impacts most (all?) Fortran code on GNU/Linux because libgfortran
> >> depends on libquadmath.
> >
> > Not anymore.
> > If GCC is configured against new enough glibc (with _Float128 support)
> > libgfortran.so.5 is no longer linked against -lquadmath, and -lquadmath
> > is added only --as-needed to ld command line, so if all the Fortran object
> > files that need real(kind=16) (or quad complex) are built by such configured
> > GCC, -lquadmath is not linked in (just needs to be present).
> 
> Hmm, I missed that recent change.
> 
> Would it make sense to drop the libgfortran RPM dependency on
> libquadmath in Fedora rawhide?

This is a downstream question.
We could drop it from libgfortran (package that contains just the shared
library), but we still need it on gcc-gfortran (as the library is used
during linking for backwards compatibility reasons).

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-01 11:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-01 10:56 libquadmath, glibc, and the Q format flag Florian Weimer
2023-02-01 11:07 ` Jakub Jelinek
2023-02-01 11:29   ` Florian Weimer
2023-02-01 11:40     ` Jakub Jelinek

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).