avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] Pow Function in avr8


From: Thomas, George
Subject: Re: [avr-libc-dev] Pow Function in avr8
Date: Thu, 29 Nov 2012 13:54:04 +0000

>
>If you know that the exponent is integral you may want to have a look at
>GCC's __builtin_powi* functions.
>
>http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
>
>You asked for a base of 2, maybe ldexp() fits your use case.
>
>Handling integral exponents separately will increase the code size
>because the exponent must be checked at run time and extra code must be
>executed in that case.

Tried an experiment with the the program that follow in studio to calculate the 
differences.

int getVal () {
        
        return 3;
}
int main(void)
{
        double d = __builtin_powi (7, getVal ());
        double f = pow (7, getVal ());
    while(1)
    {
        printf ("%f", d);
        printf ("%f", d);
    }
}

The builtin which called __powisf2 in libgcc.

The code size and cycles obtained in avrstudio6 were as follows.

Function  Size  Cycles
pow       152     5525
__powisf2 210     452


Also the code in libc seems to have checks already to check if its integer so 
would calling the libgcc function be advisable ?

-George-



reply via email to

[Prev in Thread] Current Thread [Next in Thread]