This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: double precision calculations in single precision code


Branko:

I think that the best and easiest thing for you to do is to rebuild to
avoid mathfp by not giving --enable-newlib-hw-fp to configure.  That
is, use libm/math, not libm/mathfp.

You should be OK using libm/math for the build in terms of not having
ay double operations "polluting" float functions.  If there are any,
they ought to be addressed.

Craig

On 10/24/2012 07:30 AM, Branko Drevenšek wrote:
Hi.

We have Newlib ported to our architecture. One of configurations that we support
is hardware single precision and soft-float double precision.

I have noticed unexpected double precision soft-float function calls in simple
code like x = sinf(y), where both x and y are single precision.

I have noticed that Newlib sinef function (libm/mathfp/sf_sine.c) contains lines
like:
/* Calculate the exponent. */
if (y < 0.0)
N = (int) (y * ONE_OVER_PI - 0.5);
else
N = (int) (y * ONE_OVER_PI + 0.5);

While y * ONE_OVER_PI gets calculated in single precision, that +- 0.5 causes
the result of multiplication being converted to double and then addition is done
in double using soft-float. For our case this has big performance penalty and
also requires double soft-float functions to be linked in, causing binary to grow.

Is 0.5 (instead of 0.5f) used by purpose or is that just wrong (and needs
fixing)? Where did those math. functions originate from?

Best regards,
Branko Drevensek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]