Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240828201514.GH10433@brightrain.aerifal.cx>
Date: Wed, 28 Aug 2024 16:15:14 -0400
From: Rich Felker <dalias@...c.org>
To: Alexander Monakov <amonakov@...ras.ru>
Cc: musl@...ts.openwall.com,
	Alex Rønne Petersen <alex@...xrp.com>
Subject: Re: [PATCH] configure: prevent compilers from turning a * b +
 c into fma(a, b, c)

On Wed, Aug 28, 2024 at 06:53:30PM +0300, Alexander Monakov 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).
> 
> 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.
> 
> [*] maybe modulo bugs in old releases where the backend doesn't respect
> -ffp-contract=off and which Glibc worked around with -mno-fused-madd.

I would rather havee it globally off, as the intent is that the code
be fully deterministic for a given ABI (excess precision being the
main thing that could differ by ABI), not randomly varying according
to how a compiler decides to optimize.

With that said, I don't see how the compiler could ever generate calls
to fma(), since we're -ffreestanding, but I think it could generate
inline fma instructions on targets where they're available, and this
is generally undesirable (see above). For gcc, I think -std=c99
already has that covered, but I'm not sure what clang does.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.