Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 12 Aug 2021 00:16:10 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: Rich Felker <dalias@...c.org>
Cc: Stefan Kanthak <stefan.kanthak@...go.de>, musl@...ts.openwall.com
Subject: Re: [PATCH] Properly simplified nextafter()

* Rich Felker <dalias@...c.org> [2021-08-11 13:57:23 -0400]:
> On Wed, Aug 11, 2021 at 06:50:28PM +0200, Stefan Kanthak wrote:
> > Rich Felker <dalias@...c.org> wrote:
> > > static __inline unsigned __FLOAT_BITS(float __f)
> > > {
> > > union {float __f; unsigned __i;} __u;
> > > __u.__f = __f;
> > > return __u.__i;
> > > }
> > >
> > > #define isnan(x) ( \
> > > sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \
> > > sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \
> > > __fpclassifyl(x) == FP_NAN)
> > >
> > > So, nope.
> > 
> > GCC typically uses its __builtin_isnan() for isnan(), which doesn't
> > use integer instructions or reloads:
> 
> That's only if you #define isnan(x) __builtin_isnan(x)

even then it should use int arithmetics, see below

> 
> > $ cat isnan.c
> > int foo(double x) {
> >     return isnan(x);
> > }
> > int bar(double x) {
> >     return __builtin_isnan(x);
> > }
> > $ gcc -S -O3 -o- isnan.c
> > ....
> >         xorl    %eax, %eax
> >         ucomisd %xmm0, %xmm0
> >         setp    %al
> >         ret
> > ....
> 
> Which glibc, which is what you're using, does.

it is also wrong: isnan must not signal for signaling nan.

this is a gcc bug, it fails even with -fsignaling-nans
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66462

once that's fixed glibc will behave like musl.

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.