[FFmpeg-devel] [PATCH v2 4/4] avcodec/tiff: small compiling optimization

Michael Niedermayer michael at niedermayer.cc
Fri Oct 11 22:40:33 EEST 2019


On Thu, Oct 10, 2019 at 03:18:26AM +0300, Skakov Pavel wrote:
> Made it easier for compiler to optimize array indexes when unpacking YUV.

>  tiff.c |   19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
> ab39e158e34253528edf4f3a2e90efb3a6e89d80  0004-avcodec-tiff-small-compiling-optimization.patch
> From 29b2437e04d6af1c5093efcaac6f8bc852525d78 Mon Sep 17 00:00:00 2001
> From: Pavel Skakov <pavelsx at gmail.com>
> Date: Thu, 10 Oct 2019 02:43:34 +0300
> Subject: [PATCH 4/4] avcodec/tiff: small compiling optimization
> 
> Signed-off-by: Pavel Skakov <pavelsx at gmail.com>
> ---
>  libavcodec/tiff.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> index be46db961c..71584b1c86 100644
> --- a/libavcodec/tiff.c
> +++ b/libavcodec/tiff.c
> @@ -358,11 +358,12 @@ static void unpack_gray(TiffContext *s, AVFrame *p,
>      }
>  }
>  
> -static void unpack_yuv(TiffContext *s, AVFrame *p,
> +static void unpack_yuv(TiffContext *av_restrict s, AVFrame *av_restrict p,
>                         const uint8_t *src, int lnum)
>  {
> -    int i, j, k;
> -    int w       = (s->width - 1) / s->subsampling[0] + 1;
> +    size_t i, j, k;
> +    size_t w       = (s->width - 1) / s->subsampling[0] + 1;
> +    uint8_t *py = &p->data[0][lnum * p->linesize[0]];
>      uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]];
>      uint8_t *pv = &p->data[2][lnum / s->subsampling[1] * p->linesize[2]];
>      if (s->width % s->subsampling[0] || s->height % s->subsampling[1]) {
> @@ -371,7 +372,7 @@ static void unpack_yuv(TiffContext *s, AVFrame *p,
>                  for (j = 0; j < s->subsampling[1]; j++)
>                      for (k = 0; k < s->subsampling[0]; k++)
>                          if (j < s->height - lnum && i * s->subsampling[0] + k < s->width) {
> -                            p->data[0][(lnum + j) * p->linesize[0] + i * s->subsampling[0] + k] = *src++;
> +                            py[j * p->linesize[0] + i * s->subsampling[0] + k] = *src++;
>                          } else {
>                              src++;
>                          }
> @@ -383,8 +384,8 @@ static void unpack_yuv(TiffContext *s, AVFrame *p,
>                  for (j = 0; j < s->subsampling[1]; j++)
>                      for (k = 0; k < s->subsampling[0]; k++)
>                          if (j < s->height - lnum && i * s->subsampling[0] + k < s->width) {
> -                            p->data[0][(lnum + j) * p->linesize[0] + (i * s->subsampling[0] + k)*2    ] = *src++;
> -                            p->data[0][(lnum + j) * p->linesize[0] + (i * s->subsampling[0] + k)*2 + 1] = *src++;
> +                            py[j * p->linesize[0] + (i * s->subsampling[0] + k)*2    ] = *src++;
> +                            py[j * p->linesize[0] + (i * s->subsampling[0] + k)*2 + 1] = *src++;

maybe you want to eliminate all p-> / s-> dereferencing


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20191011/3f40bdd1/attachment.sig>


More information about the ffmpeg-devel mailing list