Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Mar 2019 14:24:55 -0700
From:      Steve Kargl <sgk@troutmask.apl.washington.edu>
To:        John Baldwin <jhb@freebsd.org>
Cc:        freebsd-toolchain@freebsd.org, freebsd-current@freebsd.org
Subject:   Re: Optimization bug with floating-point?
Message-ID:  <20190313212455.GA37717@troutmask.apl.washington.edu>
In-Reply-To: <e638e0bf-b8d0-9bd1-d034-8acc6eef872c@FreeBSD.org>
References:  <20190313024506.GA31746@troutmask.apl.washington.edu> <20190313151635.GA34757@troutmask.apl.washington.edu> <e290b68f-7a1d-2456-4a0c-9f7dfd303f55@FreeBSD.org> <20190313164039.GA35340@troutmask.apl.washington.edu> <e638e0bf-b8d0-9bd1-d034-8acc6eef872c@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Mar 13, 2019 at 10:16:12AM -0700, John Baldwin wrote:
> On 3/13/19 9:40 AM, Steve Kargl wrote:
> > On Wed, Mar 13, 2019 at 09:32:57AM -0700, John Baldwin wrote:
> >> On 3/13/19 8:16 AM, Steve Kargl wrote:
> >>> On Tue, Mar 12, 2019 at 07:45:41PM -0700, Steve Kargl wrote:
> >>>>
> >>>> gcc8 --version
> >>>> gcc8 (FreeBSD Ports Collection) 8.3.0
> >>>>
> >>>> gcc8 -fno-builtin -o z a.c -lm && ./z
> >>>> gcc8 -O -fno-builtin -o z a.c -lm && ./z
> >>>> gcc8 -O2 -fno-builtin -o z a.c -lm && ./z
> >>>> gcc8 -O3 -fno-builtin -o z a.c -lm && ./z
> >>>>
> >>>> Max ULP: 2.297073
> >>>> Count: 0           (# of ULP that exceed 21)
> >>>>
> >>>
> >>> clang agrees with gcc8 if one changes ...
> >>>
> >>>> int
> >>>> main(void)
> >>>> {
> >>>>    double re, im, u, ur, ui;
> >>>>    float complex f;
> >>>>    float x, y;
> >>>
> >>> this line to "volatile float x, y".
> >>
> >> So it seems to be a regression in clang 7 vs clang 6?
> >>
> > 
> > /usr/local/bin/clang60 has the same problem.  
> > 
> > % /usr/local/bin/clang60 -o z -O2 a.c -lm && ./z
> >   Maximum ULP: 23.061242
> > # of ULP > 21: 39
> > 
> > Adding volatile as in the above "fixes" the problem.
> > 
> > AFAICT, this a i386/387 code generation problem.  Perhaps,
> > an alignment issue?
> 
> Oh, I misread your earlier e-mail to say that clang60 worked.
> 
> One issue I'm aware of is that clang does not have any support for the
> special arrangement FreeBSD/i386 uses where it uses different precision
> for registers vs in-memory for some of the floating point types (GCC has
> a special hack that is only used on FreeBSD for this but isn't used on
> any other OS's).  I wonder if that could be a factor?  Volatile probably
> forces a round trip between memory which might explain why this is the
> case.
> 

I went looking for this special hack.  In gcc/gccx/config/i386,
one finds 

/* FreeBSD sets the rounding precision of the FPU to 53 bits.  Let the
   compiler get the contents of <float.h> and std::numeric_limits correct.  */
#undef TARGET_96_ROUND_53_LONG_DOUBLE
#define TARGET_96_ROUND_53_LONG_DOUBLE (!TARGET_64BIT)

So, taking this as a hunch, I added ieeefp.h to my test program
and called 'fpsetprec(FP_PD)' as the first executable statement.
This then results in

% cc -fno-builtin -m32 -O2 -o z b.o a.c -lm && ./z
Max u: 2.297073
Count: 0

So, is there a way to correctly build clang for i386/387
to automatically set the precision correctly?

-- 
Steve



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20190313212455.GA37717>