tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: floating point woes on i386



At Sat, 27 Sep 2025 10:36:59 +0200, Joerg Sonnenberger <joerg%bec.de@localhost> wrote:
Subject: Re: floating point woes on i386
> 
> On 9/26/25 5:50 PM, RVP wrote:
> 
> > On Thu, 25 Sep 2025, Greg Troxel wrote:
> > 
> >> I ran paranoia (pkgsrc/benchmarks/paranoia) on 9 and 10.  On 9:
> >> 
> >>  The number of  FAILUREs  encountered =       3.
> >>  The number of  SERIOUS DEFECTs  discovered = 4.
> >>  The number of  DEFECTs  discovered =         3.
> >>  The number of  FLAWs  discovered =           2.
> >> 
> >> which is shocking, especially as I remember earlier NetBSD i386 versions
> >> being ok, like 5 or 7.
> >> 
> > 
> > Force strict standards compliance with
> > `-std=c89' or `-std=c99', or pass the
> > `-fexcess-precision=standard' flag to the compiler.
> 
> There is on newer i386 also the option of
> using -mfpmath=sse. That's strictly
> speaking the only way to get IEEE754
> semantics on i386.

On NetBSD/i386 10.0 with the system's GCC-10.5 the -mfpmath=sse option
doesn't actually do anything:

    cc1: warning: SSE instruction set disabled, using 387 arithmetics

Installing gcc14-14.3.0 from the official binary packages says exactly
the same thing:

    cc1: warning: SSE instruction set disabled, using 387 arithmetics


Only one the following options will reduce the number of flaws reported
by "paranoia" to just the one about sticky bit/guard digits:

	-O0			(which is explictly recommended in the
				pkg DESCR file for i386 and possibly
				has the effect of trimming excess
				precision by storing intermediate
				results in variables in enough cases)

or (along with -O2 or -O3):

	-ffloat-store		(which the pkg Makefile mentions, and
				which is a bit like a partial limited
				form of -fexcess-precision=standard)

or (along with -O2 or -O3):

	-std=c89		(which it should have anyway, and which
				turns on -fexcess-precision=standard)

(c99 "works" too, with only one additional compiler warning, which one
also sees without any '-std=' of course, but the code is quite obviously
written in/for c89)

or of course the underlying necessary option (also works with -O2 or -O3):

	-fexcess-precision=standard


Curiously -ffast-math reveals a bug somewhere, causing "paranoia" to
hang while "Searching for Radix and Precision." with both gcc-10.5 and
gcc-14.3.  (same with -Ofast)

Personally I think "paranoia", at least the current version, should
always be compiled with "-std=c89", and the fact that this turns on
"-fexcess-precision=standard" should be welcomed since the code in
"paranoia" is explictly looking to test _standard_ floating point
operations as implemented by the compiler (and optionally the hardware),
and so we need to tell the compiler that we're building code to do tests
of its ability to conform strictly to the standard.  Not (implicitly)
using "-fexcess-precision=standard" is _explicitly_ allowing the
compiler to work outside the standard and so a program designed to check
strict conformance _should_ then report flaws!

Maybe "make" should build it both ways (i.e. -fexcess-precision=standard
-fexcess-precision=fast, and maybe a third way with -ffast-math) and
"make benchmark" should run all tests to show explicitly on which
platforms the default (and fast) option is to "abuse" the standards to
some extent.

-- 
					Greg A. Woods <gwoods%acm.org@localhost>

Kelowna, BC     +1 250 762-7675           RoboHack <woods%robohack.ca@localhost>
Planix, Inc. <woods%planix.com@localhost>     Avoncote Farms <woods%avoncote.ca@localhost>

Attachment: pgpWbJ_Rytevh.pgp
Description: OpenPGP Digital Signature



Home | Main Index | Thread Index | Old Index