double precision calculations in single precision code
marco atzeri
marco.atzeri@gmail.com
Wed Oct 31 16:06:00 GMT 2012
On 10/24/2012 1:30 PM, 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?
>
I bet from the double version, that use exactly the same lines
and they are likely in that form from the begin in 98.
On CVS there is no change from inital import in 2000..
> Best regards,
> Branko Drevensek
More information about the Newlib
mailing list