Re: Optimization bug with floating-point?

From: Steve Kargl <sgk_at_troutmask.apl.washington.edu>
Date: Wed, 13 Mar 2019 09:13:26 -0700
On Wed, Mar 13, 2019 at 04:56:26PM +0100, Hans Petter Selasky wrote:
> On 3/13/19 4:50 PM, Steve Kargl wrote:
> > Using sin() and cos() directly as in
> > 
> > /* Double precision csinh() without using C's double complex.s */
> > void
> > dp_csinh(double x, double y, double *re, double *im)
> > {
> >     double c, s;
> >     *re = sinh(x) * cos(y);
> >     *im = cosh(x) * sin(y);
> > }
> > 
> > does not change the result.  I'll also note that libm
> > is compiled by clang, and I do not recompile it for the
> > tests.  Both gcc8 and cc are using the same libm.
> > 
> > I've also tested clang of amd64 with the -m32, it fails
> > as well.
> 
> Hi,
> 
> I cannot see this is failing with 11-stable userland. Can you check with 
> objdump() that clang doesn't optimise it to sincos() ?

It doesn't.

% nm z | grep sin
         U csinhf
00401360 T dp_csinh
         U sin
         U sinh

> FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564) (based on 
> LLVM 3.8.0)
> Target: x86_64-unknown-freebsd11.0

The test does not fail on x86_64 unless you add the -m32 option,
which forces i386 behavior.

cc --version
FreeBSD clang version 7.0.1 (tags/RELEASE_701/final 349250)
(based on LLVM 7.0.1)
Target: x86_64-unknown-freebsd13.0

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

cc -fno-builtin -O2 -o z a.c -lm -m32 && ./z
Max u: 23.061242
Count: 39

> Thread model: posix
> InstalledDir: /usr/bin
> 
> cc -lm -O2 -Wall test.c && ./a.out
> Max ULP: 2.297073
> Count: 0

add -m32.

> 
> clang40 -lm -O2 test6.c
>  > ./a.out
> Max ULP: 2.297073
> Count: 0
> 
> clang50 -lm -O2 test6.c
>  > ./a.out
> Max ULP: 2.297073
> Count: 0
> 
> clang60 -lm -O2 test6.c
>  > ./a.out
> Max ULP: 2.297073
> Count: 0

-- 
Steve
Received on Wed Mar 13 2019 - 15:13:43 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:20 UTC