The tests are inspired by similar tests for vp9 by
Ronald Bultje.
---
Amended the includes as suggested by Diego, added missing
tests for the simple variant of loop filters.
---
tests/checkasm/Makefile | 1 +
tests/checkasm/checkasm.c | 3 +
tests/checkasm/checkasm.h | 1 +
tests/checkasm/vp8dsp.c | 516 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 521 insertions(+)
create mode 100644 tests/checkasm/vp8dsp.c
diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 3c23853..7c1d0ec 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -5,6 +5,7 @@ AVCODECOBJS-$(CONFIG_FMTCONVERT) += fmtconvert.o
AVCODECOBJS-$(CONFIG_H264DSP) += h264dsp.o
AVCODECOBJS-$(CONFIG_H264PRED) += h264pred.o
AVCODECOBJS-$(CONFIG_H264QPEL) += h264qpel.o
+AVCODECOBJS-$(CONFIG_VP8DSP) += vp8dsp.o
# decoders/encoders
AVCODECOBJS-$(CONFIG_DCA_DECODER) += dcadsp.o synth_filter.o
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 15f9f68..739da61 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -89,6 +89,9 @@ static const struct {
#if CONFIG_V210_ENCODER
{ "v210enc", checkasm_check_v210enc },
#endif
+#if CONFIG_VP8DSP
+ { "vp8dsp", checkasm_check_vp8dsp },
+#endif
{ NULL }
};
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 0faf3ba..7f15b9c 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -40,6 +40,7 @@ void checkasm_check_h264qpel(void);
void checkasm_check_hevc_mc(void);
void checkasm_check_synth_filter(void);
void checkasm_check_v210enc(void);
+void checkasm_check_vp8dsp(void);
void *checkasm_check_func(void *func, const char *name, ...)
av_printf_format(2, 3);
int checkasm_bench_func(void);
diff --git a/tests/checkasm/vp8dsp.c b/tests/checkasm/vp8dsp.c
new file mode 100644
index 0000000..412bdad
--- /dev/null
+++ b/tests/checkasm/vp8dsp.c
@@ -0,0 +1,516 @@
+/*
+ * Copyright (c) 2016 Martin Storsjo
+ *
+ * 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 "libavcodec/avcodec.h"
+#include "libavcodec/vp8dsp.h"
+
+#include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
+
+#include "checkasm.h"
+
+#define PIXEL_STRIDE 16
+
+#define randomize_buffers(src, dst, stride, coef) \
+ do { \
+ int x, y; \
+ for (y = 0; y < 4; y++) { \
+ AV_WN32A((src) + y * (stride), rnd()); \
+ AV_WN32A((dst) + y * (stride), rnd()); \
+ for (x = 0; x < 4; x++) \
+ (coef)[y * 4 + x] = (src)[y * (stride) + x] - \
+ (dst)[y * (stride) + x]; \
+ } \
+ } while (0)
+
+static void dct4x4(int16_t *coef)
+{
+ int i;
+ for (i = 0; i < 4; i++) {
+ const int a1 = (coef[i*4 + 0] + coef[i*4 + 3]) * 8;
+ const int b1 = (coef[i*4 + 1] + coef[i*4 + 2]) * 8;
+ const int c1 = (coef[i*4 + 1] - coef[i*4 + 2]) * 8;
+ const int d1 = (coef[i*4 + 0] - coef[i*4 + 3]) * 8;
+ coef[i*4 + 0] = a1 + b1;
+ coef[i*4 + 1] = (c1 * 2217 + d1 * 5352 + 14500) >> 12;
+ coef[i*4 + 2] = a1 - b1;
+ coef[i*4 + 3] = (d1 * 2217 - c1 * 5352 + 7500) >> 12;
+ }
+ for (i = 0; i < 4; i++) {
+ const int a1 = coef[i + 0*4] + coef[i + 3*4];
+ const int b1 = coef[i + 1*4] + coef[i + 2*4];
+ const int c1 = coef[i + 1*4] - coef[i + 2*4];
+ const int d1 = coef[i + 0*4] - coef[i + 3*4];
+ coef[i + 0*4] = (a1 + b1 + 7) >> 4;
+ coef[i + 1*4] = ((c1 * 2217 + d1 * 5352 + 12000) >> 16) + !!d1;
+ coef[i + 2*4] = (a1 - b1 + 7) >> 4;
+ coef[i + 3*4] = (d1 * 2217 - c1 * 5352 + 51000) >> 16;
+ }
+}
+
+static void wht4x4(int16_t *coef)
+{
+ int i;
+ for (i = 0; i < 4; i++) {
+ int a1 = coef[0 * 4 + i];
+ int b1 = coef[1 * 4 + i];
+ int c1 = coef[2 * 4 + i];
+ int d1 = coef[3 * 4 + i];
+ int e1;
+ a1 += b1;
+ d1 -= c1;
+ e1 = (a1 - d1) >> 1;
+ b1 = e1 - b1;
+ c1 = e1 - c1;
+ a1 -= c1;
+ d1 += b1;
+ coef[0 * 4 + i] = a1;
+ coef[1 * 4 + i] = c1;
+ coef[2 * 4 + i] = d1;
+ coef[3 * 4 + i] = b1;
+ }
+ for (i = 0; i < 4; i++) {
+ int a1 = coef[i * 4 + 0];
+ int b1 = coef[i * 4 + 1];
+ int c1 = coef[i * 4 + 2];
+ int d1 = coef[i * 4 + 3];
+ int e1;
+ a1 += b1;
+ d1 -= c1;
+ e1 = (a1 - d1) >> 1;
+ b1 = e1 - b1;
+ c1 = e1 - c1;
+ a1 -= c1;
+ d1 += b1;
+ coef[i * 4 + 0] = a1 * 2;
+ coef[i * 4 + 1] = c1 * 2;
+ coef[i * 4 + 2] = d1 * 2;
+ coef[i * 4 + 3] = b1 * 2;
+ }
+}
+
+static void check_idct(void)
+{
+ LOCAL_ALIGNED_16(uint8_t, src, [4 * 4]);
+ LOCAL_ALIGNED_16(uint8_t, dst, [4 * 4]);
+ LOCAL_ALIGNED_16(uint8_t, dst0, [4 * 4]);
+ LOCAL_ALIGNED_16(uint8_t, dst1, [4 * 4]);
+ LOCAL_ALIGNED_16(int16_t, coef, [4 * 4]);
+ LOCAL_ALIGNED_16(int16_t, subcoef0, [4 * 4]);
+ LOCAL_ALIGNED_16(int16_t, subcoef1, [4 * 4]);
+ VP8DSPContext d;
+ int dc;
+ declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t *block,
ptrdiff_t stride);
+
+ ff_vp8dsp_init(&d);
+ randomize_buffers(src, dst, 4, coef);
+
+ dct4x4(coef);
+
+ for (dc = 0; dc <= 1; dc++) {
+ void (*idct)(uint8_t *, int16_t *, ptrdiff_t) = dc ? d.vp8_idct_dc_add
: d.vp8_idct_add;
+
+ if (check_func(idct, "vp8_idct_%sadd", dc ? "dc_" : "")) {
+ if (dc) {
+ memset(subcoef0, 0, 4 * 4 * sizeof(int16_t));
+ subcoef0[0] = coef[0];
+ } else {
+ memcpy(subcoef0, coef, 4 * 4 * sizeof(int16_t));
+ }
+ memcpy(dst0, dst, 4 * 4);
+ memcpy(dst1, dst, 4 * 4);
+ memcpy(subcoef1, subcoef0, 4 * 4 * sizeof(int16_t));
+ // Note, this uses a pixel stride of 4, even though the real
decoder uses a stride as a
+ // multiple of 16. If optimizations want to take advantage of
that, this test needs to be
+ // updated to make it more like the h264dsp tests.
+ call_ref(dst0, subcoef0, 4);
+ call_new(dst1, subcoef1, 4);
+ if (memcmp(dst0, dst1, 4 * 4) ||
+ memcmp(subcoef0, subcoef1, 4 * 4 * sizeof(int16_t)))
+ fail();
+
+ bench_new(dst1, subcoef1, 4);
+ }
+ }
+}
+
+static void check_idct_dc4(void)
+{
+ LOCAL_ALIGNED_16(uint8_t, src, [4 * 4 * 4]);
+ LOCAL_ALIGNED_16(uint8_t, dst, [4 * 4 * 4]);
+ LOCAL_ALIGNED_16(uint8_t, dst0, [4 * 4 * 4]);
+ LOCAL_ALIGNED_16(uint8_t, dst1, [4 * 4 * 4]);
+ LOCAL_ALIGNED_16(int16_t, coef, [4], [4 * 4]);
+ LOCAL_ALIGNED_16(int16_t, subcoef0, [4], [4 * 4]);
+ LOCAL_ALIGNED_16(int16_t, subcoef1, [4], [4 * 4]);
+ VP8DSPContext d;
+ int i, chroma;
+ declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t
block[4][16], ptrdiff_t stride);
+
+ ff_vp8dsp_init(&d);
+
+ for (chroma = 0; chroma <= 1; chroma++) {
+ void (*idct4dc)(uint8_t *, int16_t[4][16], ptrdiff_t) = chroma ?
d.vp8_idct_dc_add4uv : d.vp8_idct_dc_add4y;
+ if (check_func(idct4dc, "vp8_idct_dc_add4%s", chroma ? "uv" : "y")) {
+ int stride = chroma ? 8 : 16;
+ int w = chroma ? 2 : 4;
+ for (i = 0; i < 4; i++) {
+ int blockx = 4 * (i % w);
+ int blocky = 4 * (i / w);
+ randomize_buffers(src + stride * blocky + blockx, dst + stride
* blocky + blockx, stride, coef[i]);
+ dct4x4(coef[i]);
+ memset(&coef[i][1], 0, 15 * sizeof(int16_t));
+ }
+
+ memcpy(dst0, dst, 4 * 4 * 4);
+ memcpy(dst1, dst, 4 * 4 * 4);
+ memcpy(subcoef0, coef, 4 * 4 * 4 * sizeof(int16_t));
+ memcpy(subcoef1, coef, 4 * 4 * 4 * sizeof(int16_t));
+ call_ref(dst0, subcoef0, stride);
+ call_new(dst1, subcoef1, stride);
+ if (memcmp(dst0, dst1, 4 * 4 * 4) ||
+ memcmp(subcoef0, subcoef1, 4 * 4 * 4 * sizeof(int16_t)))
+ fail();
+ bench_new(dst1, subcoef1, stride);
+ }
+ }
+
+}
+
+static void check_luma_dc_wht(void)
+{
+ LOCAL_ALIGNED_16(int16_t, dc, [4 * 4]);
+ LOCAL_ALIGNED_16(int16_t, dc0, [4 * 4]);
+ LOCAL_ALIGNED_16(int16_t, dc1, [4 * 4]);
+ int16_t block[4][4][16];
+ LOCAL_ALIGNED_16(int16_t, block0, [4], [4][16]);
+ LOCAL_ALIGNED_16(int16_t, block1, [4], [4][16]);
+ VP8DSPContext d;
+ int dc_only;
+ int blockx, blocky;
+ declare_func_emms(AV_CPU_FLAG_MMX, void, int16_t block[4][4][16], int16_t
dc[16]);
+
+ ff_vp8dsp_init(&d);
+
+ for (blocky = 0; blocky < 4; blocky++) {
+ for (blockx = 0; blockx < 4; blockx++) {
+ uint8_t src[16], dst[16];
+ randomize_buffers(src, dst, 4, block[blocky][blockx]);
+
+ dct4x4(block[blocky][blockx]);
+ dc[blocky * 4 + blockx] = block[blocky][blockx][0];
+ block[blocky][blockx][0] = rnd();
+ }
+ }
+ wht4x4(dc);
+
+ for (dc_only = 0; dc_only <= 1; dc_only++) {
+ void (*idct)(int16_t [4][4][16], int16_t [16]) = dc_only ?
d.vp8_luma_dc_wht_dc : d.vp8_luma_dc_wht;
+
+ if (check_func(idct, "vp8_luma_dc_wht%s", dc_only ? "_dc" : "")) {
+ if (dc_only) {
+ memset(dc0, 0, 16 * sizeof(int16_t));
+ dc0[0] = dc[0];
+ } else {
+ memcpy(dc0, dc, 16 * sizeof(int16_t));
+ }
+ memcpy(dc1, dc0, 16 * sizeof(int16_t));
+ memcpy(block0, block, 4 * 4 * 16 * sizeof(int16_t));
+ memcpy(block1, block, 4 * 4 * 16 * sizeof(int16_t));
+ call_ref(block0, dc0);
+ call_new(block1, dc1);
+ if (memcmp(block0, block1, 4 * 4 * 16 * sizeof(int16_t)) ||
+ memcmp(dc0, dc1, 16 * sizeof(int16_t)))
+ fail();
+ bench_new(block1, dc1);
+ }
+ }
+}
+
+#define SRC_BUF_STRIDE 32
+#define SRC_BUF_SIZE ((size + 5) * SRC_BUF_STRIDE)
+// The 2 * stride + 2 offset is necessary to avoid reading out of bounds,