Re: Bug fix for glibc broke freebsd build in REL_11_STABLE

Поиск
Список
Период
Сортировка
От Andrew Gierth
Тема Re: Bug fix for glibc broke freebsd build in REL_11_STABLE
Дата
Msg-id 87efe9ufy5.fsf@news-spur.riddles.org.uk
обсуждение исходный текст
Ответ на Re: Bug fix for glibc broke freebsd build in REL_11_STABLE  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
Ответы Re: Bug fix for glibc broke freebsd build in REL_11_STABLE  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Bug fix for glibc broke freebsd build in REL_11_STABLE  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
Список pgsql-hackers
>>>>> "Andrew" == Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
>>>>> "Andres" == Andres Freund <andres@anarazel.de> writes:

 Andres> Thomas and I are sitting in a cafe and are trying to figure out
 Andres> what's going on...

 Andrew> I have a standalone test case:

 Andrew> #include <stdio.h>
 Andrew> #include <math.h>

 Andrew> int main(int argc, char **argv)
 Andrew> {
 Andrew>     double d1 = (argc ? 1e180 : 0);
 Andrew>     double d2 = (argv ? 1e200 : 0);
 Andrew>     int r2 = __builtin_isinf(d1 * d2);
 Andrew>     int r1 = isinf(d1 * d2);
 Andrew>     printf("r1 = %d, r2 = %d\n", r1, r2);
 Andrew>     return 0;
 Andrew> }

 Andrew> Note that swapping the r1 and r2 lines makes the problem
 Andrew> disappear (!).

And that's the clue to why it happens.

The reason it behaves oddly is this: on i387 FPU (and NOT on arm32 or on
32-bit i386 with a modern architecture specified to the compiler), the
result of 1e200 * 1e180 is not in fact infinite, because it fits in an
80-bit long double. So __builtin_isinf reports that it is finite; but if
it gets stored to memory as a double (e.g. to pass as a parameter to a
function), it then becomes infinite.

 Andrew> cc -O2 -m32 flttst.c && ./a.out
 Andrew> r1 = 1, r2 = 0

Specifying a recent microarch makes it use 64-bit FP registers rather
than 80-bit ones:

cc -O2 -m32 -march=skylake flttst.c && ./a.out
r1 = 1, r2 = 1

-- 
Andrew (irc:RhodiumToad)


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Andrew Gierth
Дата:
Сообщение: Re: Bug fix for glibc broke freebsd build in REL_11_STABLE
Следующее
От: Alexander Korotkov
Дата:
Сообщение: Re: Bug in ginRedoRecompress that causes opaque data on page to be overrun