bug in logarithm()
Jeff Johnston
jjohnstn@redhat.com
Fri Oct 19 11:55:00 GMT 2007
Martin Koeppe wrote:
>
> Hi Jeff, hi Patrick,
>
> On Wed, 17 Oct 2007, Jeff Johnston wrote:
>> Patrick Mansfield wrote:
>>> On Wed, Oct 17, 2007 at 12:28:47PM +0200, Martin Koeppe wrote:
>>>
>>>> I'm using newlib on a i386 architecture, and now I wonder if it's
>>>> possible to configure libm in such a way that the fast asm versions
>>>> of e.g. log() are used. In my current newlib-libm.a there are the
>>>> entry points for _f_log() etc., but apparently log() doesn't make
>>>> use of _f_log().
>>>>
>>>> (How) Is it possible to configure newlib's libm to make use of
>>>> _f_log within log()?
>>>>
>>>> Thank you very much
>>>>
>>>
>>> They aren't compatible per comments in the code. You could call them
>>> directly. AFAIUI there should be prototypes and proper names (without
>>> underscore prefix, like #define f_log _f_log) for them in newlib, but I
>>> don't see any.
>>>
>>> -- Patrick Mansfield
>>>
>> Actually, they are meant to be called when the user specifies
>> -ffast-math on the compilation.
>>
>> The definitions used to be part of libc/include/machine/fastmath.h
>> with an i386 check. This got inadvertently left out when we
>> initially made the transition of newlib from internal to external
>> repositories.
>>
>> Anyway, I have added libc/machine/i386/machine/fastmath.h based on
>> the older sources plus a few changes. If you compile your code with
>> the -ffast-math option, <math.h> will bring in <machine/fastmath.h>
>> and you will get access to the few fast math routines available for
>> x86, including log().
>
> I use newlib's libm, and only the libm, not the whole libc+libm, on
> Interix, as replacement for the buggy standard libm there. So I don't
> want to use any different header files if at all possible.
>
> I can see from the code that e.g. log() and _f_log() don't provide the
> same functionality, e.g. errno is set by the former, but not by the
> latter. My question/wishlist item was more that I would like to
> compile newlib with some option like -ffast-math, or better a
> configure option, just like --enable-newlib-hw-fp, so that log()
> checks the argument and sets errno, but then calls _f_log() to
> calculate the logarithm instead of using the Newton algorithm.
Well, there's nothing preventing adding another function, lets say
_f_log_wrapper.c and changing the fastmath.h to call _f_log_wrapper
instead of _f_log. The wrapper can add the rudimentary checking and
errno setting and can then call _f_log. Remember that the fastmath
routines for x86 are only now being enabled so there won't be any legacy
usage of fastmath.h and --ffast-math behavior. If someone was calling
_f_log directly with valid inputs, you won't be touching it.
-- Jeff J.
>
> User programs then still could be further optimized by skipping errno
> processing and call _f_log() directly with -ffast-math if necessary,
> but even without that it would be reasonably fast.
>
Yes, agreed.
>
> BTW: Are there any snapshots available for easy building?
>
Nope, just the current repository.
> Martin
More information about the Newlib
mailing list