[Ffmpeg-cvslog] r8474 - trunk/libavcodec/resample2.c

Michael Niedermayer michaelni
Thu Mar 22 11:47:01 CET 2007


Hi

On Wed, Mar 21, 2007 at 10:50:06PM -0500, Rich Felker wrote:
> On Thu, Mar 22, 2007 at 01:52:49AM +0100, michael wrote:
> > Author: michael
> > Date: Thu Mar 22 01:52:49 2007
> > New Revision: 8474
> > 
> > Modified:
> >    trunk/libavcodec/resample2.c
> > 
> > Log:
> > optimize bessel function instead of trusting gcc to do trivial optimizations (as gcc doesnt ...)
> > 
> > 
> > Modified: trunk/libavcodec/resample2.c
> > ==============================================================================
> > --- trunk/libavcodec/resample2.c	(original)
> > +++ trunk/libavcodec/resample2.c	Thu Mar 22 01:52:49 2007
> > @@ -71,9 +71,10 @@ static double bessel(double x){
> >      double t=1;
> >      int i;
> >  
> > +    x= x*x/4;
> >      for(i=1; i<50; i++){
> > -        t *= i;
> > -        v += pow(x*x/4, i)/(t*t);
> > +        t *= x/(i*i);
> > +        v += t;
> 
> This is not trivial and most likely an illegal optimization for the
> compiler to make. As soon as you go to floating point, algebraic
> identities simply fail to hold in the general case, and
> "optimizations" using them will make code do the wrong things in
> corner cases. You may not care about the corner cases, but the
> compiler can't know that. So floating point optimization of this sort
> always needs to be done explicitly by the coder.

hmm

for(i=1; i<50; i++){
    t *= i;
    v += pow(x*x/4, i)/(t*t);

factoring the x*x/4 out doesnt need any algebraic identities

x= x*x/4
for(i=1; i<50; i++){
    t *= i;
    v += pow(x, i)/(t*t);

to factor out the pow() your needing algebraic identities depends on how pow
is defined either way the associative law for multiplication is enough and
i cant think of a case where the associative law for multiplication if its 
used by the compiler would affect the result by more than a negligible amount
also gcc could have flags (like intels c compiler IIRC) to enable specific
not 100% safe optimizatons

x= x*x/4
for(i=1; i<50; i++){
    t *= i;
    t2 *= x;
    v += t2/(t*t);

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-cvslog/attachments/20070322/6dbaa204/attachment.pgp>



More information about the ffmpeg-cvslog mailing list