From: David Mosberger-Tang <davidm@AZStarNet.com>
Subject: Re: GCC bug???
Date: Fri, 15 Mar 1996 16:52:50 -0700 [thread overview]
Message-ID: <199603152352.QAA06765@koala.azstarnet.com> (raw)
>>>>> On Fri, 15 Mar 1996 16:54:16 -0600 (CST), (cosc1) 95h02740 <yxc02740@Bayou.UH.EDU> said:
>> I'm not sure if this qualifies as a bug in the technical sense,
>> but it seems at least to be an inconsistany between Alpha
>> Linux/GCC and x86 Linux/GCC. I ran into this problem with the
>> math lib function pow(), but it may occur elsewhere. It occurs
>> when incorrectly typed variables (ints, or longs) are passed to
>> the pow() function, which as I understand, expects doubles. I
>> compiled the following code with GCC on a Linux/Pentium system
>> and it works fine:
Yansong> It is not a GCC bug, but it is a library bug. It turns out
Yansong> that the linux/alpha's libm.a is not only slow, but also
Yansong> buggy.
Not just buggy and slow, but incomplete, too! E.g., the Bessel
functions are missing. Moreover, it doesn't support float operations
either (as opposed to double... :-)
Why am I so happy about it? Well, here is where GNU libc comes in: it
just switched to a new math library that looks fairly complete and is
specifically for IEEE-754. With it, I get:
<--begin script-->
$ uname -a
Linux koala.azstarnet.com 1.3.74 #60 Fri Mar 15 07:47:00 MST 1996alpha alpha
$ cat foo.c
#include <math.h>
main()
{
int i;
double x,y;
for (i=0;i<21;i++)
{
x= pow(2.0,i);
y = (int)x;
printf("%d %g %g\n",i,x,y);
}
}
$ gcc foo.c -lm
$ ./a.out
0 1 1
1 2 2
2 4 4
3 8 8
4 16 16
5 32 32
<--end script-->
So it does seem to work fine. What's the catch? Well, I won't have
time to do any serious testing of libm any time soon (the GNU libc
folks are looking for a test suite, however, and I hear there may be
something that is freely available, so this may not be as bad as it
sounds). Since there do seem to be people out there that (a) have
more use for libm than I do (povray is about as tough as it gets with
me) and (b) are more knowledgable with math, I propose that interested
parties take a look at the libm as it comes with GNU libc. I'd be
happy to make a precompiled libm and the sources available so that
anybody interested could hack away. I see the following areas could
use improvements:
(1) The current Alpha hardware does not support exceptional
numbers (non-finite) such as denormals or infinities or NaNs.
This has two effects: First, it *may* affect the correctness of some
algorithms (e.g., the library may assume that the smallest finite
positive number divided by two gives a denormalized result,
not 0 as the Alpha hw provides by default). While this is
possible source of concern, I don't think it will be a major
headache (doesn't the x87 FPU do something similar? But maybe
I'm confusing it with the i960). More importantly: since the Alpha
hardware will trap on input of any non-finite number, there is no
*need* to check for such values. This often allows to speed up the
implementation significantly. The C compiler will tell you what
degree of IEEE compliance is in effect by the presence/absence of
two CPP macros:
_IEEE_FP => non-finite numbers are supported
(with current chips, via compiler/OS
support)
_IEEE_FP_INEXACT
=> non-finite numbers as well as the
IEEE INEXACT flag are supported
That is, if neither macro is defined, there is no point in
checking for (or generating) non-finite numbers.
(2) A lot of the float/double constants in the sources
reappear over and over again. It would be quite a bit
more efficient to gather those constants into a single
array. With current Linux/Alpha compiler technology,
this would typically save one memory access per constant.
Oh, I did tune Linus's sqrt() a little bit more and we're now pretty
competitive with the OSF/1 version (basically, we beat them whenever
you don't do sqrt() for a living---i.e., whenever not all of the sqrt
code/data is in the cache, which is not uncommon). It also seems to
be accurate: after testing it on 437,689,015,671 random numbers, I
haven't found a single case where the result would have deviated from
the result of the OSF/1 libm by a single bit.
But other than this, not much has happened libm wise, AFAIK.
--david
next reply other threads:[~1996-03-15 23:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-03-15 23:52 David Mosberger-Tang [this message]
-- strict thread matches above, loose matches on Subject: below --
1997-04-05 16:22 gcc bug? Michael Alan Dorman
[not found] <199603152047.PAA02208@Adeno.wistar.upenn.edu>
1996-03-15 22:54 ` GCC bug??? yxc02740
1996-03-15 20:47 Jeff Taylor
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox