[vorbis-dev] trivial optimization to psy.c

Adam Spragg adam_spragg at novaclarion.com
Wed Jun 28 07:44:28 PDT 2000



Hmmmm....to cut down by one addition per iteration, you might like to try...

for (i=work,j=f;i<work+n;++i,++j) {
    *i=fabs(*j);
    if(*i>specmax)
        specmax=*i;
}

Where i and j are pointers to relevant types. This way, you're not
incrementing i, then adding it to &f[0], and adding it to &work[0] - you're
just incrementing two pointers.

If you're compiler aint that great at optimizing, it might give you a touch
extra speed. Of course, the fabs() is going to take up most of the time here,
so it's probably pretty academic anyway... :)

Just my £0.02

Adam

Andy Key wrote:
> 
> Hi all,
> 
> The following is a trivial patch to psy.c, but combining the two loops saves
> a percent or two (according to gprof).
> 
> =================================================================
> --- psy.c       Mon Jun 19 12:05:57 2000
> +++ -   Wed Jun 28 15:14:17 2000
> @@ -550,12 +550,11 @@
>    frameno++;
>    memset(flr,0,n*sizeof(double));
> 
> -  for(i=0;i<n;i++)work[i]=fabs(f[i]);
> -
> -  /* find the highest peak so we know the limits */
>    for(i=0;i<n;i++){
> -    if(work[i]>specmax)specmax=work[i];
> -  }
> +    work[i]=fabs(f[i]);
> +    if(work[i]>specmax)
> +      specmax=work[i];
> +    }
>    specmax=todB(specmax);
> 
>    /* don't use the smoothed data for noise */
> =================================================================
> 
> -Andy


-- 
grep "caffeine" < coke >> /dev/brain

----------------
The opinions expressed in this email are mine alone, and do not neccesarily
represent those of my employer, my parents, or the people who wrote the email
software I use.

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/




More information about the Vorbis-dev mailing list