]> git.sesse.net Git - ffmpeg/commitdiff
checkasm: Add unit tests for h264qpel
authorHenrik Gramner <henrik@gramner.com>
Mon, 13 Jul 2015 21:11:25 +0000 (23:11 +0200)
committerLuca Barbato <lu_zero@gentoo.org>
Wed, 15 Jul 2015 17:47:07 +0000 (19:47 +0200)
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
tests/checkasm/Makefile
tests/checkasm/checkasm.c
tests/checkasm/checkasm.h
tests/checkasm/h264qpel.c [new file with mode: 0644]

index 33e2c09dc67535655be80ffa59169b75adcfbca6..0758746bc4e4458b3f0768f1c3f078975bc74e11 100644 (file)
@@ -1,5 +1,6 @@
 # libavcodec tests
 AVCODECOBJS-$(CONFIG_H264PRED) += h264pred.o
+AVCODECOBJS-$(CONFIG_H264QPEL) += h264qpel.o
 
 CHECKASMOBJS-$(CONFIG_AVCODEC) += $(AVCODECOBJS-yes)
 
index 59383b8931746ca465df5cbf4cb7e35df9542cfc..7b1ea8fa1ed5762b4b33ec0ae74ddccdc3b4dd54 100644 (file)
@@ -56,6 +56,9 @@
 static void (* const tests[])(void) = {
 #if CONFIG_H264PRED
     checkasm_check_h264pred,
+#endif
+#if CONFIG_H264QPEL
+    checkasm_check_h264qpel,
 #endif
     NULL
 };
index 90844e252cb2bdd669e52978cbe3cd0aeec249e6..1a46e9bb0a80c425460c4940d5b4f1efb84127ae 100644 (file)
@@ -30,6 +30,7 @@
 #include "libavutil/timer.h"
 
 void checkasm_check_h264pred(void);
+void checkasm_check_h264qpel(void);
 
 intptr_t (*checkasm_check_func(intptr_t (*func)(), const char *name, ...))() av_printf_format(2, 3);
 int checkasm_bench_func(void);
diff --git a/tests/checkasm/h264qpel.c b/tests/checkasm/h264qpel.c
new file mode 100644 (file)
index 0000000..3ec5f1c
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015 Henrik Gramner
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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,
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <string.h>
+#include "checkasm.h"
+#include "libavcodec/h264qpel.h"
+#include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
+
+static const uint32_t pixel_mask[3] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff };
+
+#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
+#define BUF_SIZE (2*16*(16+3+4))
+
+#define randomize_buffers()\
+    do {\
+        uint32_t mask = pixel_mask[bit_depth-8];\
+        int k;\
+        for (k = 0; k < BUF_SIZE; k += 4) {\
+            uint32_t r = rnd() & mask;\
+            AV_WN32A(buf0+k, r);\
+            AV_WN32A(buf1+k, r);\
+            r = rnd();\
+            AV_WN32A(dst0+k, r);\
+            AV_WN32A(dst1+k, r);\
+        }\
+    } while (0)
+
+#define src0 (buf0 + 3*2*16) /* h264qpel functions read data from negative src pointer offsets */
+#define src1 (buf1 + 3*2*16)
+
+void checkasm_check_h264qpel(void)
+{
+    DECLARE_ALIGNED(16, uint8_t, buf0)[BUF_SIZE];
+    DECLARE_ALIGNED(16, uint8_t, buf1)[BUF_SIZE];
+    DECLARE_ALIGNED(16, uint8_t, dst0)[BUF_SIZE];
+    DECLARE_ALIGNED(16, uint8_t, dst1)[BUF_SIZE];
+    H264QpelContext h;
+    int op, bit_depth, i, j;
+
+    for (op = 0; op < 2; op++) {
+        qpel_mc_func (*tab)[16] = op ? h.avg_h264_qpel_pixels_tab : h.put_h264_qpel_pixels_tab;
+        const char *op_name = op ? "avg" : "put";
+
+        for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
+            ff_h264qpel_init(&h, bit_depth);
+            for (i = 0; i < (op ? 3 : 4); i++) {
+                int size = 16 >> i;
+                for (j = 0; j < 16; j++) {
+                    if (check_func(tab[i][j], "%s_h264_qpel_%d_mc%d%d_%d", op_name, size, j&3, j>>2, bit_depth)) {
+                        randomize_buffers();
+                        call_ref(dst0, src0, (ptrdiff_t)size*SIZEOF_PIXEL);
+                        call_new(dst1, src1, (ptrdiff_t)size*SIZEOF_PIXEL);
+                        if (memcmp(buf0, buf1, BUF_SIZE) || memcmp(dst0, dst1, BUF_SIZE))
+                            fail();
+                        bench_new(dst1, src1, (ptrdiff_t)size*SIZEOF_PIXEL);
+                    }
+                }
+            }
+        }
+        report("%s_h264_qpel", op_name);
+    }
+}