mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "Alex Rønne Petersen" <alex@alexrp.com>
To: Alexander Monakov <amonakov@ispras.ru>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] configure: prevent compilers from turning a * b + c into fma(a, b, c)
Date: Wed, 28 Aug 2024 18:31:42 +0200	[thread overview]
Message-ID: <CAH9TF6OC6Xf2VGSjpkDfVU12gRJfue1y-UDK=9rO6RnHtWn-fg@mail.gmail.com> (raw)
In-Reply-To: <eff0e8c6-e360-ff7d-fd20-e0f868d45c8a@ispras.ru>

On Wed, Aug 28, 2024 at 5:53 PM Alexander Monakov <amonakov@ispras.ru> wrote:
>
>
> On Wed, 28 Aug 2024, Alex Rønne Petersen wrote:
>
> > I've seen Clang do this for expressions in the fma() implementation itself,
> > which of course led to infinite recursion. This happened when targeting
> > arm-linux-musleabi with full soft float mode and -march=armv8-a. I imagine
> > it's possible for GCC to do similar silliness.
>
> musl passes -std=c99 to the compiler, and in all GCC releases so far* that
> disables FMA contraction (as opposed to -std=gnu99 or whichever -std=gnuXX
> is enabled by default, where unrestricted contraction is implicitly enabled,
> i.e. the non-standard and dangerous -ffp-contract=fast mode).

OK, that part can definitely be left out. I only added it for good
measure; I haven't actually seen the issue occur with GCC.

>
> Clang respects #pragma STDC FP_CONTRACT OFF, so that is available as
> a smaller hammer than disabling fma across the board. Breaking up
> contractable expression in fma*.c will work too.

That pragma indeed seems to work. I suppose we could just add it to
the fma*() implementations and call it a day? I'm unsure if there are
other functions that might be affected by this.

>
> [*] maybe modulo bugs in old releases where the backend doesn't respect
> -ffp-contract=off and which Glibc worked around with -mno-fused-madd.
>
> Alexander

  reply	other threads:[~2024-08-28 16:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-28 15:28 Alex Rønne Petersen
2024-08-28 15:53 ` Alexander Monakov
2024-08-28 16:31   ` Alex Rønne Petersen [this message]
2024-08-28 20:15   ` Rich Felker
2024-08-28 20:32     ` Alexander Monakov
2024-08-28 20:47       ` Rich Felker
2024-08-28 21:11         ` Alexander Monakov
2024-08-29 13:37           ` Alex Rønne Petersen
2024-08-28 19:56 ` Alexander Monakov
2024-08-29 13:36   ` Alex Rønne Petersen
2024-08-29 15:09     ` Alexander Monakov

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='CAH9TF6OC6Xf2VGSjpkDfVU12gRJfue1y-UDK=9rO6RnHtWn-fg@mail.gmail.com' \
    --to=alex@alexrp.com \
    --cc=amonakov@ispras.ru \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).