[FFmpeg-cvslog] Merge commit '105998fb5ca3c343f5c8cb39ce3197f87a5e4d36'

Matthieu Bouron git at videolan.org
Wed Jul 13 17:23:13 CEST 2016


ffmpeg | branch: master | Matthieu Bouron <matthieu.bouron at stupeflix.com> | Wed Jul 13 17:16:14 2016 +0200| [a91c330a29f3fa49f5a2991ce52e04213fe68f7b] | committer: Matthieu Bouron

Merge commit '105998fb5ca3c343f5c8cb39ce3197f87a5e4d36'

* commit '105998fb5ca3c343f5c8cb39ce3197f87a5e4d36':
  checkasm: Add tests for h264 idct

Merged-by: Matthieu Bouron <matthieu.bouron at stupeflix.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a91c330a29f3fa49f5a2991ce52e04213fe68f7b
---

 tests/checkasm/Makefile   |    1 +
 tests/checkasm/checkasm.c |    3 +
 tests/checkasm/checkasm.h |    1 +
 tests/checkasm/h264dsp.c  |  232 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 237 insertions(+)

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index db7395e..b886cb0 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -3,6 +3,7 @@
 AVCODECOBJS-$(CONFIG_BSWAPDSP)          += bswapdsp.o
 AVCODECOBJS-$(CONFIG_FLACDSP)           += flacdsp.o
 AVCODECOBJS-$(CONFIG_FMTCONVERT)        += fmtconvert.o
+AVCODECOBJS-$(CONFIG_H264DSP)           += h264dsp.o
 AVCODECOBJS-$(CONFIG_H264PRED)          += h264pred.o
 AVCODECOBJS-$(CONFIG_H264QPEL)          += h264qpel.o
 AVCODECOBJS-$(CONFIG_VIDEODSP)          += videodsp.o
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index e4ca116..cca227a 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -80,6 +80,9 @@ static const struct {
     #if CONFIG_FMTCONVERT
         { "fmtconvert", checkasm_check_fmtconvert },
     #endif
+    #if CONFIG_H264DSP
+        { "h264dsp", checkasm_check_h264dsp },
+    #endif
     #if CONFIG_H264PRED
         { "h264pred", checkasm_check_h264pred },
     #endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 5a76f74..17374b4 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -36,6 +36,7 @@ void checkasm_check_bswapdsp(void);
 void checkasm_check_colorspace(void);
 void checkasm_check_flacdsp(void);
 void checkasm_check_fmtconvert(void);
+void checkasm_check_h264dsp(void);
 void checkasm_check_h264pred(void);
 void checkasm_check_h264qpel(void);
 void checkasm_check_jpeg2000dsp(void);
diff --git a/tests/checkasm/h264dsp.c b/tests/checkasm/h264dsp.c
new file mode 100644
index 0000000..e2060db
--- /dev/null
+++ b/tests/checkasm/h264dsp.c
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2016 Martin Storsjo
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <string.h>
+#include "checkasm.h"
+#include "libavcodec/avcodec.h"
+#include "libavcodec/h264dsp.h"
+#include "libavutil/common.h"
+#include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
+
+static const uint32_t pixel_mask[3] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff };
+
+#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
+#define SIZEOF_COEF  (2 * ((bit_depth + 7) / 8))
+#define PIXEL_STRIDE 16
+
+#define randomize_buffers()                                                  \
+    do {                                                                     \
+        uint32_t mask = pixel_mask[bit_depth - 8];                           \
+        for (y = 0; y < sz; y++) {                                           \
+            for (x = 0; x < sz * SIZEOF_PIXEL; x += 4) {                     \
+                AV_WN32A(src + y * PIXEL_STRIDE + x, rnd() & mask);          \
+                AV_WN32A(dst + y * PIXEL_STRIDE + x, rnd() & mask);          \
+            }                                                                \
+            for (x = 0; x < sz; x++) {                                       \
+                if (bit_depth == 8) {                                        \
+                    coef[y * sz + x] = src[y * PIXEL_STRIDE + x] -           \
+                                       dst[y * PIXEL_STRIDE + x];            \
+                } else {                                                     \
+                    ((int32_t *)coef)[y * sz + x] =                          \
+                        ((uint16_t *)src)[y * (PIXEL_STRIDE/2) + x] -        \
+                        ((uint16_t *)dst)[y * (PIXEL_STRIDE/2) + x];         \
+                }                                                            \
+            }                                                                \
+        }                                                                    \
+    } while (0)
+
+#define dct4x4_impl(size, dctcoef)                                           \
+static void dct4x4_##size(dctcoef *coef)                                     \
+{                                                                            \
+    int i, y, x;                                                             \
+    dctcoef tmp[16];                                                         \
+    for (i = 0; i < 4; i++) {                                                \
+        const int z0 = coef[i*4 + 0] + coef[i*4 + 3];                        \
+        const int z1 = coef[i*4 + 1] + coef[i*4 + 2];                        \
+        const int z2 = coef[i*4 + 0] - coef[i*4 + 3];                        \
+        const int z3 = coef[i*4 + 1] - coef[i*4 + 2];                        \
+        tmp[i + 4*0] =   z0 +   z1;                                          \
+        tmp[i + 4*1] = 2*z2 +   z3;                                          \
+        tmp[i + 4*2] =   z0 -   z1;                                          \
+        tmp[i + 4*3] =   z2 - 2*z3;                                          \
+    }                                                                        \
+    for (i = 0; i < 4; i++) {                                                \
+        const int z0 = tmp[i*4 + 0] + tmp[i*4 + 3];                          \
+        const int z1 = tmp[i*4 + 1] + tmp[i*4 + 2];                          \
+        const int z2 = tmp[i*4 + 0] - tmp[i*4 + 3];                          \
+        const int z3 = tmp[i*4 + 1] - tmp[i*4 + 2];                          \
+        coef[i*4 + 0] =   z0 +   z1;                                         \
+        coef[i*4 + 1] = 2*z2 +   z3;                                         \
+        coef[i*4 + 2] =   z0 -   z1;                                         \
+        coef[i*4 + 3] =   z2 - 2*z3;                                         \
+    }                                                                        \
+    for (y = 0; y < 4; y++) {                                                \
+        for (x = 0; x < 4; x++) {                                            \
+            static const int scale[] = { 13107 * 10, 8066 * 13, 5243 * 16 }; \
+            const int idx = (y & 1) + (x & 1);                               \
+            coef[y*4 + x] = (coef[y*4 + x] * scale[idx] + (1 << 14)) >> 15;  \
+        }                                                                    \
+    }                                                                        \
+}
+
+#define DCT8_1D(src, srcstride, dst, dststride) do {                         \
+    const int a0 = (src)[srcstride * 0] + (src)[srcstride * 7];              \
+    const int a1 = (src)[srcstride * 0] - (src)[srcstride * 7];              \
+    const int a2 = (src)[srcstride * 1] + (src)[srcstride * 6];              \
+    const int a3 = (src)[srcstride * 1] - (src)[srcstride * 6];              \
+    const int a4 = (src)[srcstride * 2] + (src)[srcstride * 5];              \
+    const int a5 = (src)[srcstride * 2] - (src)[srcstride * 5];              \
+    const int a6 = (src)[srcstride * 3] + (src)[srcstride * 4];              \
+    const int a7 = (src)[srcstride * 3] - (src)[srcstride * 4];              \
+    const int b0 = a0 + a6;                                                  \
+    const int b1 = a2 + a4;                                                  \
+    const int b2 = a0 - a6;                                                  \
+    const int b3 = a2 - a4;                                                  \
+    const int b4 = a3 + a5 + (a1 + (a1 >> 1));                               \
+    const int b5 = a1 - a7 - (a5 + (a5 >> 1));                               \
+    const int b6 = a1 + a7 - (a3 + (a3 >> 1));                               \
+    const int b7 = a3 - a5 + (a7 + (a7 >> 1));                               \
+    (dst)[dststride * 0] =  b0 +  b1;                                        \
+    (dst)[dststride * 1] =  b4 + (b7 >> 2);                                  \
+    (dst)[dststride * 2] =  b2 + (b3 >> 1);                                  \
+    (dst)[dststride * 3] =  b5 + (b6 >> 2);                                  \
+    (dst)[dststride * 4] =  b0  - b1;                                        \
+    (dst)[dststride * 5] =  b6 - (b5 >> 2);                                  \
+    (dst)[dststride * 6] = (b2 >> 1) - b3;                                   \
+    (dst)[dststride * 7] = (b4 >> 2) - b7;                                   \
+} while (0)
+
+#define dct8x8_impl(size, dctcoef)                                           \
+static void dct8x8_##size(dctcoef *coef)                                     \
+{                                                                            \
+    int i, x, y;                                                             \
+    dctcoef tmp[64];                                                         \
+    for (i = 0; i < 8; i++)                                                  \
+        DCT8_1D(coef + i, 8, tmp + i, 8);                                    \
+                                                                             \
+    for (i = 0; i < 8; i++)                                                  \
+        DCT8_1D(tmp + 8*i, 1, coef + i, 8);                                  \
+                                                                             \
+    for (y = 0; y < 8; y++) {                                                \
+        for (x = 0; x < 8; x++) {                                            \
+            static const int scale[] = {                                     \
+                13107 * 20, 11428 * 18, 20972 * 32,                          \
+                12222 * 19, 16777 * 25, 15481 * 24,                          \
+            };                                                               \
+            static const int idxmap[] = {                                    \
+                0, 3, 4, 3,                                                  \
+                3, 1, 5, 1,                                                  \
+                4, 5, 2, 5,                                                  \
+                3, 1, 5, 1,                                                  \
+            };                                                               \
+            const int idx = idxmap[(y & 3) * 4 + (x & 3)];                   \
+            coef[y*8 + x] = ((int64_t)coef[y*8 + x] *                        \
+                             scale[idx] + (1 << 17)) >> 18;                  \
+        }                                                                    \
+    }                                                                        \
+}
+
+dct4x4_impl(16, int16_t)
+dct4x4_impl(32, int32_t)
+
+dct8x8_impl(16, int16_t)
+dct8x8_impl(32, int32_t)
+
+static void dct4x4(int16_t *coef, int bit_depth)
+{
+    if (bit_depth == 8)
+        dct4x4_16(coef);
+    else
+        dct4x4_32((int32_t *) coef);
+}
+
+static void dct8x8(int16_t *coef, int bit_depth)
+{
+    if (bit_depth == 8) {
+        dct8x8_16(coef);
+    } else {
+        dct8x8_32((int32_t *) coef);
+    }
+}
+
+
+static void check_idct(void)
+{
+    LOCAL_ALIGNED_16(uint8_t, src,  [8 * 8 * 2]);
+    LOCAL_ALIGNED_16(uint8_t, dst,  [8 * 8 * 2]);
+    LOCAL_ALIGNED_16(uint8_t, dst0, [8 * 8 * 2]);
+    LOCAL_ALIGNED_16(uint8_t, dst1_base, [8 * 8 * 2 + 32]);
+    LOCAL_ALIGNED_16(int16_t, coef, [8 * 8 * 2]);
+    LOCAL_ALIGNED_16(int16_t, subcoef0, [8 * 8 * 2]);
+    LOCAL_ALIGNED_16(int16_t, subcoef1, [8 * 8 * 2]);
+    H264DSPContext h;
+    int bit_depth, sz, align;
+    int x, y, dc;
+    declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t *block, int stride);
+
+    for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
+        ff_h264dsp_init(&h, bit_depth, 1);
+        for (sz = 4; sz <= 8; sz += 4) {
+            randomize_buffers();
+
+            if (sz == 4)
+                dct4x4(coef, bit_depth);
+            else
+                dct8x8(coef, bit_depth);
+
+            for (dc = 0; dc <= 1; dc++) {
+                void (*idct)(uint8_t *, int16_t *, int) = NULL;
+                switch ((sz << 1) | dc) {
+                case (4 << 1) | 0: idct = h.h264_idct_add; break;
+                case (4 << 1) | 1: idct = h.h264_idct_dc_add; break;
+                case (8 << 1) | 0: idct = h.h264_idct8_add; break;
+                case (8 << 1) | 1: idct = h.h264_idct8_dc_add; break;
+                }
+                if (check_func(idct, "h264_idct%d_add%s_%dbpp", sz, dc ? "_dc" : "", bit_depth)) {
+                    for (align = 0; align < 16; align += sz * SIZEOF_PIXEL) {
+                        uint8_t *dst1 = dst1_base + align;
+                        if (dc) {
+                            memset(subcoef0, 0, sz * sz * SIZEOF_COEF);
+                            memcpy(subcoef0, coef, SIZEOF_COEF);
+                        } else {
+                            memcpy(subcoef0, coef, sz * sz * SIZEOF_COEF);
+                        }
+                        memcpy(dst0, dst, sz * PIXEL_STRIDE);
+                        memcpy(dst1, dst, sz * PIXEL_STRIDE);
+                        memcpy(subcoef1, subcoef0, sz * sz * SIZEOF_COEF);
+                        call_ref(dst0, subcoef0, PIXEL_STRIDE);
+                        call_new(dst1, subcoef1, PIXEL_STRIDE);
+                        if (memcmp(dst0, dst1, sz * PIXEL_STRIDE) ||
+                            memcmp(subcoef0, subcoef1, sz * sz * SIZEOF_COEF))
+                            fail();
+                        bench_new(dst1, subcoef1, sz * SIZEOF_PIXEL);
+                    }
+                }
+            }
+        }
+    }
+    report("idct");
+}
+
+void checkasm_check_h264dsp(void)
+{
+    check_idct();
+}


======================================================================

diff --cc tests/checkasm/Makefile
index db7395e,3c23853..b886cb0
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@@ -1,19 -1,15 +1,20 @@@
  # libavcodec tests
  # subsystems
  AVCODECOBJS-$(CONFIG_BSWAPDSP)          += bswapdsp.o
 +AVCODECOBJS-$(CONFIG_FLACDSP)           += flacdsp.o
  AVCODECOBJS-$(CONFIG_FMTCONVERT)        += fmtconvert.o
+ AVCODECOBJS-$(CONFIG_H264DSP)           += h264dsp.o
  AVCODECOBJS-$(CONFIG_H264PRED)          += h264pred.o
  AVCODECOBJS-$(CONFIG_H264QPEL)          += h264qpel.o
 +AVCODECOBJS-$(CONFIG_VIDEODSP)          += videodsp.o
  
  # decoders/encoders
 -AVCODECOBJS-$(CONFIG_DCA_DECODER)       += dcadsp.o synth_filter.o
 -AVCODECOBJS-$(CONFIG_HEVC_DECODER)      += hevc_mc.o
 +AVCODECOBJS-$(CONFIG_ALAC_DECODER)      += alacdsp.o
 +AVCODECOBJS-$(CONFIG_DCA_DECODER)       += synth_filter.o
 +AVCODECOBJS-$(CONFIG_JPEG2000_DECODER)  += jpeg2000dsp.o
 +AVCODECOBJS-$(CONFIG_PIXBLOCKDSP)       += pixblockdsp.o
  AVCODECOBJS-$(CONFIG_V210_ENCODER)      += v210enc.o
 +AVCODECOBJS-$(CONFIG_VP9_DECODER)       += vp9dsp.o
  
  CHECKASMOBJS-$(CONFIG_AVCODEC)          += $(AVCODECOBJS-yes)
  
diff --cc tests/checkasm/checkasm.c
index e4ca116,15f9f68..cca227a
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@@ -64,51 -64,30 +64,54 @@@ static const struct 
      const char *name;
      void (*func)(void);
  } tests[] = {
 -#if CONFIG_BSWAPDSP
 -    { "bswapdsp", checkasm_check_bswapdsp },
 +#if CONFIG_AVCODEC
 +    #if CONFIG_ALAC_DECODER
 +        { "alacdsp", checkasm_check_alacdsp },
 +    #endif
 +    #if CONFIG_BSWAPDSP
 +        { "bswapdsp", checkasm_check_bswapdsp },
 +    #endif
 +    #if CONFIG_DCA_DECODER
 +        { "synth_filter", checkasm_check_synth_filter },
 +    #endif
 +    #if CONFIG_FLACDSP
 +        { "flacdsp", checkasm_check_flacdsp },
 +    #endif
 +    #if CONFIG_FMTCONVERT
 +        { "fmtconvert", checkasm_check_fmtconvert },
 +    #endif
++    #if CONFIG_H264DSP
++        { "h264dsp", checkasm_check_h264dsp },
++    #endif
 +    #if CONFIG_H264PRED
 +        { "h264pred", checkasm_check_h264pred },
 +    #endif
 +    #if CONFIG_H264QPEL
 +        { "h264qpel", checkasm_check_h264qpel },
 +    #endif
 +    #if CONFIG_JPEG2000_DECODER
 +        { "jpeg2000dsp", checkasm_check_jpeg2000dsp },
 +    #endif
 +    #if CONFIG_PIXBLOCKDSP
 +        { "pixblockdsp", checkasm_check_pixblockdsp },
 +    #endif
 +    #if CONFIG_V210_ENCODER
 +        { "v210enc", checkasm_check_v210enc },
 +    #endif
 +    #if CONFIG_VP9_DECODER
 +        { "vp9dsp", checkasm_check_vp9dsp },
 +    #endif
 +    #if CONFIG_VIDEODSP
 +        { "videodsp", checkasm_check_videodsp },
 +    #endif
  #endif
 -#if CONFIG_DCA_DECODER
 -    { "dcadsp", checkasm_check_dcadsp },
 -    { "synth_filter", checkasm_check_synth_filter },
 -#endif
 -#if CONFIG_FMTCONVERT
 -    { "fmtconvert", checkasm_check_fmtconvert },
 -#endif
 -#if CONFIG_H264DSP
 -    { "h264dsp", checkasm_check_h264dsp },
 -#endif
 -#if CONFIG_H264PRED
 -    { "h264pred", checkasm_check_h264pred },
 -#endif
 -#if CONFIG_H264QPEL
 -    { "h264qpel", checkasm_check_h264qpel },
 -#endif
 -#if CONFIG_HEVC_DECODER
 -    { "hevc_mc", checkasm_check_hevc_mc },
 -#endif
 -#if CONFIG_V210_ENCODER
 -    { "v210enc", checkasm_check_v210enc },
 +#if CONFIG_AVFILTER
 +    #if CONFIG_BLEND_FILTER
 +        { "vf_blend", checkasm_check_blend },
 +    #endif
 +    #if CONFIG_COLORSPACE_FILTER
 +        { "vf_colorspace", checkasm_check_colorspace },
 +    #endif
  #endif
      { NULL }
  };
diff --cc tests/checkasm/checkasm.h
index 5a76f74,619ebc7..17374b4
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@@ -30,20 -30,15 +30,21 @@@
  #include "libavutil/lfg.h"
  #include "libavutil/timer.h"
  
 +void checkasm_check_alacdsp(void);
 +void checkasm_check_blend(void);
  void checkasm_check_bswapdsp(void);
 -void checkasm_check_dcadsp(void);
 +void checkasm_check_colorspace(void);
 +void checkasm_check_flacdsp(void);
  void checkasm_check_fmtconvert(void);
+ void checkasm_check_h264dsp(void);
  void checkasm_check_h264pred(void);
  void checkasm_check_h264qpel(void);
 -void checkasm_check_hevc_mc(void);
 +void checkasm_check_jpeg2000dsp(void);
 +void checkasm_check_pixblockdsp(void);
  void checkasm_check_synth_filter(void);
  void checkasm_check_v210enc(void);
 +void checkasm_check_vp9dsp(void);
 +void checkasm_check_videodsp(void);
  
  void *checkasm_check_func(void *func, const char *name, ...) av_printf_format(2, 3);
  int checkasm_bench_func(void);
diff --cc tests/checkasm/h264dsp.c
index 0000000,082c3d4..e2060db
mode 000000,100644..100644
--- a/tests/checkasm/h264dsp.c
+++ b/tests/checkasm/h264dsp.c
@@@ -1,0 -1,232 +1,232 @@@
+ /*
+  * Copyright (c) 2016 Martin Storsjo
+  *
 - * This file is part of Libav.
++ * This file is part of FFmpeg.
+  *
 - * Libav is free software; you can redistribute it and/or modify
++ * FFmpeg is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License as published by
+  * the Free Software Foundation; either version 2 of the License, or
+  * (at your option) any later version.
+  *
 - * Libav is distributed in the hope that it will be useful,
++ * FFmpeg is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License along
 - * with Libav; if not, write to the Free Software Foundation, Inc.,
++ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+  */
+ 
+ #include <string.h>
+ #include "checkasm.h"
+ #include "libavcodec/avcodec.h"
+ #include "libavcodec/h264dsp.h"
+ #include "libavutil/common.h"
+ #include "libavutil/internal.h"
+ #include "libavutil/intreadwrite.h"
+ 
+ static const uint32_t pixel_mask[3] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff };
+ 
+ #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
+ #define SIZEOF_COEF  (2 * ((bit_depth + 7) / 8))
+ #define PIXEL_STRIDE 16
+ 
+ #define randomize_buffers()                                                  \
+     do {                                                                     \
+         uint32_t mask = pixel_mask[bit_depth - 8];                           \
+         for (y = 0; y < sz; y++) {                                           \
+             for (x = 0; x < sz * SIZEOF_PIXEL; x += 4) {                     \
+                 AV_WN32A(src + y * PIXEL_STRIDE + x, rnd() & mask);          \
+                 AV_WN32A(dst + y * PIXEL_STRIDE + x, rnd() & mask);          \
+             }                                                                \
+             for (x = 0; x < sz; x++) {                                       \
+                 if (bit_depth == 8) {                                        \
+                     coef[y * sz + x] = src[y * PIXEL_STRIDE + x] -           \
+                                        dst[y * PIXEL_STRIDE + x];            \
+                 } else {                                                     \
+                     ((int32_t *)coef)[y * sz + x] =                          \
+                         ((uint16_t *)src)[y * (PIXEL_STRIDE/2) + x] -        \
+                         ((uint16_t *)dst)[y * (PIXEL_STRIDE/2) + x];         \
+                 }                                                            \
+             }                                                                \
+         }                                                                    \
+     } while (0)
+ 
+ #define dct4x4_impl(size, dctcoef)                                           \
+ static void dct4x4_##size(dctcoef *coef)                                     \
+ {                                                                            \
+     int i, y, x;                                                             \
+     dctcoef tmp[16];                                                         \
+     for (i = 0; i < 4; i++) {                                                \
+         const int z0 = coef[i*4 + 0] + coef[i*4 + 3];                        \
+         const int z1 = coef[i*4 + 1] + coef[i*4 + 2];                        \
+         const int z2 = coef[i*4 + 0] - coef[i*4 + 3];                        \
+         const int z3 = coef[i*4 + 1] - coef[i*4 + 2];                        \
+         tmp[i + 4*0] =   z0 +   z1;                                          \
+         tmp[i + 4*1] = 2*z2 +   z3;                                          \
+         tmp[i + 4*2] =   z0 -   z1;                                          \
+         tmp[i + 4*3] =   z2 - 2*z3;                                          \
+     }                                                                        \
+     for (i = 0; i < 4; i++) {                                                \
+         const int z0 = tmp[i*4 + 0] + tmp[i*4 + 3];                          \
+         const int z1 = tmp[i*4 + 1] + tmp[i*4 + 2];                          \
+         const int z2 = tmp[i*4 + 0] - tmp[i*4 + 3];                          \
+         const int z3 = tmp[i*4 + 1] - tmp[i*4 + 2];                          \
+         coef[i*4 + 0] =   z0 +   z1;                                         \
+         coef[i*4 + 1] = 2*z2 +   z3;                                         \
+         coef[i*4 + 2] =   z0 -   z1;                                         \
+         coef[i*4 + 3] =   z2 - 2*z3;                                         \
+     }                                                                        \
+     for (y = 0; y < 4; y++) {                                                \
+         for (x = 0; x < 4; x++) {                                            \
+             static const int scale[] = { 13107 * 10, 8066 * 13, 5243 * 16 }; \
+             const int idx = (y & 1) + (x & 1);                               \
+             coef[y*4 + x] = (coef[y*4 + x] * scale[idx] + (1 << 14)) >> 15;  \
+         }                                                                    \
+     }                                                                        \
+ }
+ 
+ #define DCT8_1D(src, srcstride, dst, dststride) do {                         \
+     const int a0 = (src)[srcstride * 0] + (src)[srcstride * 7];              \
+     const int a1 = (src)[srcstride * 0] - (src)[srcstride * 7];              \
+     const int a2 = (src)[srcstride * 1] + (src)[srcstride * 6];              \
+     const int a3 = (src)[srcstride * 1] - (src)[srcstride * 6];              \
+     const int a4 = (src)[srcstride * 2] + (src)[srcstride * 5];              \
+     const int a5 = (src)[srcstride * 2] - (src)[srcstride * 5];              \
+     const int a6 = (src)[srcstride * 3] + (src)[srcstride * 4];              \
+     const int a7 = (src)[srcstride * 3] - (src)[srcstride * 4];              \
+     const int b0 = a0 + a6;                                                  \
+     const int b1 = a2 + a4;                                                  \
+     const int b2 = a0 - a6;                                                  \
+     const int b3 = a2 - a4;                                                  \
+     const int b4 = a3 + a5 + (a1 + (a1 >> 1));                               \
+     const int b5 = a1 - a7 - (a5 + (a5 >> 1));                               \
+     const int b6 = a1 + a7 - (a3 + (a3 >> 1));                               \
+     const int b7 = a3 - a5 + (a7 + (a7 >> 1));                               \
+     (dst)[dststride * 0] =  b0 +  b1;                                        \
+     (dst)[dststride * 1] =  b4 + (b7 >> 2);                                  \
+     (dst)[dststride * 2] =  b2 + (b3 >> 1);                                  \
+     (dst)[dststride * 3] =  b5 + (b6 >> 2);                                  \
+     (dst)[dststride * 4] =  b0  - b1;                                        \
+     (dst)[dststride * 5] =  b6 - (b5 >> 2);                                  \
+     (dst)[dststride * 6] = (b2 >> 1) - b3;                                   \
+     (dst)[dststride * 7] = (b4 >> 2) - b7;                                   \
+ } while (0)
+ 
+ #define dct8x8_impl(size, dctcoef)                                           \
+ static void dct8x8_##size(dctcoef *coef)                                     \
+ {                                                                            \
+     int i, x, y;                                                             \
+     dctcoef tmp[64];                                                         \
+     for (i = 0; i < 8; i++)                                                  \
+         DCT8_1D(coef + i, 8, tmp + i, 8);                                    \
+                                                                              \
+     for (i = 0; i < 8; i++)                                                  \
+         DCT8_1D(tmp + 8*i, 1, coef + i, 8);                                  \
+                                                                              \
+     for (y = 0; y < 8; y++) {                                                \
+         for (x = 0; x < 8; x++) {                                            \
+             static const int scale[] = {                                     \
+                 13107 * 20, 11428 * 18, 20972 * 32,                          \
+                 12222 * 19, 16777 * 25, 15481 * 24,                          \
+             };                                                               \
+             static const int idxmap[] = {                                    \
+                 0, 3, 4, 3,                                                  \
+                 3, 1, 5, 1,                                                  \
+                 4, 5, 2, 5,                                                  \
+                 3, 1, 5, 1,                                                  \
+             };                                                               \
+             const int idx = idxmap[(y & 3) * 4 + (x & 3)];                   \
+             coef[y*8 + x] = ((int64_t)coef[y*8 + x] *                        \
+                              scale[idx] + (1 << 17)) >> 18;                  \
+         }                                                                    \
+     }                                                                        \
+ }
+ 
+ dct4x4_impl(16, int16_t)
+ dct4x4_impl(32, int32_t)
+ 
+ dct8x8_impl(16, int16_t)
+ dct8x8_impl(32, int32_t)
+ 
+ static void dct4x4(int16_t *coef, int bit_depth)
+ {
+     if (bit_depth == 8)
+         dct4x4_16(coef);
+     else
+         dct4x4_32((int32_t *) coef);
+ }
+ 
+ static void dct8x8(int16_t *coef, int bit_depth)
+ {
+     if (bit_depth == 8) {
+         dct8x8_16(coef);
+     } else {
+         dct8x8_32((int32_t *) coef);
+     }
+ }
+ 
+ 
+ static void check_idct(void)
+ {
+     LOCAL_ALIGNED_16(uint8_t, src,  [8 * 8 * 2]);
+     LOCAL_ALIGNED_16(uint8_t, dst,  [8 * 8 * 2]);
+     LOCAL_ALIGNED_16(uint8_t, dst0, [8 * 8 * 2]);
+     LOCAL_ALIGNED_16(uint8_t, dst1_base, [8 * 8 * 2 + 32]);
+     LOCAL_ALIGNED_16(int16_t, coef, [8 * 8 * 2]);
+     LOCAL_ALIGNED_16(int16_t, subcoef0, [8 * 8 * 2]);
+     LOCAL_ALIGNED_16(int16_t, subcoef1, [8 * 8 * 2]);
+     H264DSPContext h;
+     int bit_depth, sz, align;
+     int x, y, dc;
+     declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t *block, int stride);
+ 
+     for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
+         ff_h264dsp_init(&h, bit_depth, 1);
+         for (sz = 4; sz <= 8; sz += 4) {
+             randomize_buffers();
+ 
+             if (sz == 4)
+                 dct4x4(coef, bit_depth);
+             else
+                 dct8x8(coef, bit_depth);
+ 
+             for (dc = 0; dc <= 1; dc++) {
+                 void (*idct)(uint8_t *, int16_t *, int) = NULL;
+                 switch ((sz << 1) | dc) {
+                 case (4 << 1) | 0: idct = h.h264_idct_add; break;
+                 case (4 << 1) | 1: idct = h.h264_idct_dc_add; break;
+                 case (8 << 1) | 0: idct = h.h264_idct8_add; break;
+                 case (8 << 1) | 1: idct = h.h264_idct8_dc_add; break;
+                 }
+                 if (check_func(idct, "h264_idct%d_add%s_%dbpp", sz, dc ? "_dc" : "", bit_depth)) {
+                     for (align = 0; align < 16; align += sz * SIZEOF_PIXEL) {
+                         uint8_t *dst1 = dst1_base + align;
+                         if (dc) {
+                             memset(subcoef0, 0, sz * sz * SIZEOF_COEF);
+                             memcpy(subcoef0, coef, SIZEOF_COEF);
+                         } else {
+                             memcpy(subcoef0, coef, sz * sz * SIZEOF_COEF);
+                         }
+                         memcpy(dst0, dst, sz * PIXEL_STRIDE);
+                         memcpy(dst1, dst, sz * PIXEL_STRIDE);
+                         memcpy(subcoef1, subcoef0, sz * sz * SIZEOF_COEF);
+                         call_ref(dst0, subcoef0, PIXEL_STRIDE);
+                         call_new(dst1, subcoef1, PIXEL_STRIDE);
+                         if (memcmp(dst0, dst1, sz * PIXEL_STRIDE) ||
+                             memcmp(subcoef0, subcoef1, sz * sz * SIZEOF_COEF))
+                             fail();
+                         bench_new(dst1, subcoef1, sz * SIZEOF_PIXEL);
+                     }
+                 }
+             }
+         }
+     }
+     report("idct");
+ }
+ 
+ void checkasm_check_h264dsp(void)
+ {
+     check_idct();
+ }



More information about the ffmpeg-cvslog mailing list