[FFmpeg-devel] [PATCH 6/9] sbrdsp: unroll sbr_autocorrelate_c

Michael Niedermayer michaelni at gmx.at
Fri Apr 5 16:09:34 CEST 2013


On Thu, Apr 04, 2013 at 07:45:50PM +0000, Christophe Gisquet wrote:
> 1410 cycles to 1148 on Arrandale/Win64.
> ---
>  libavcodec/sbrdsp.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/libavcodec/sbrdsp.c b/libavcodec/sbrdsp.c
> index 6fede79..e2280cc 100644
> --- a/libavcodec/sbrdsp.c
> +++ b/libavcodec/sbrdsp.c
> @@ -122,9 +122,34 @@ static av_always_inline void autocorrelate(const float x[40][2],
>  
>  static void sbr_autocorrelate_c(const float x[40][2], float phi[3][2][2])
>  {
> +#if 0
> +    // This code is slower because it multiplies memory accesses.
> +    // It is left as eucational purpose and because it may offer
> +    // a better reference for writing arch-specific dsp functions.
>      autocorrelate(x, phi, 0);
>      autocorrelate(x, phi, 1);
>      autocorrelate(x, phi, 2);
> +#else
> +    float real_sum2 = x[ 0][0] * x[ 2][0] + x[ 0][1] * x[ 2][1];
> +    float imag_sum2 = x[ 0][0] * x[ 2][1] - x[ 0][1] * x[ 2][0];
> +    float real_sum1 = 0.f, imag_sum1 = 0.f, real_sum0 = 0.0f;
> +    int   i;
> +    for (i = 1; i < 38; i++) {
> +        real_sum0 += x[i][0] * x[i  ][0] + x[i][1] * x[i  ][1];
> +        real_sum1 += x[i][0] * x[i+1][0] + x[i][1] * x[i+1][1];
> +        imag_sum1 += x[i][0] * x[i+1][1] - x[i][1] * x[i+1][0];
> +        real_sum2 += x[i][0] * x[i+2][0] + x[i][1] * x[i+2][1];
> +        imag_sum2 += x[i][0] * x[i+2][1] - x[i][1] * x[i+2][0];
> +    }

writing the i=1 case seperately and starting the loop from i=2
avoids 3 additions by 0, its also a tiny bit faster here in practice

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Democracy is the form of government in which you can choose your dictator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130405/d0646424/attachment.asc>


More information about the ffmpeg-devel mailing list