diff mbox

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

Message ID 2cd1db88-c1f8-16a1-9670-b30df834f570@gmail.com
State New
Headers show

Commit Message

Skakov Pavel Oct. 10, 2019, 12:18 a.m. UTC
Made it easier for compiler to optimize array indexes when unpacking YUV.

Comments

Michael Niedermayer Oct. 11, 2019, 7:40 p.m. UTC | #1
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@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@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


[...]
diff mbox

Patch

From 29b2437e04d6af1c5093efcaac6f8bc852525d78 Mon Sep 17 00:00:00 2001
From: Pavel Skakov <pavelsx@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@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++;
                         } else {
                             src += 2;
                         }
@@ -399,7 +400,7 @@  static void unpack_yuv(TiffContext *s, AVFrame *p,
             for (i = 0; i < w; i++) {
                 for (j = 0; j < s->subsampling[1]; j++)
                     for (k = 0; k < s->subsampling[0]; k++)
-                        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++;
                 *pu++ = *src++;
                 *pv++ = *src++;
             }
@@ -407,8 +408,8 @@  static void unpack_yuv(TiffContext *s, AVFrame *p,
             for (i = 0; i < w; i++) {
                 for (j = 0; j < s->subsampling[1]; j++)
                     for (k = 0; k < s->subsampling[0]; k++) {
-                        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++;
                     }
                 *pu++ = *src++;
                 *pu++ = *src++;
-- 
2.13.2.windows.1