Libav
vp9dsp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.com>
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with Libav; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include <string.h>
22 
23 #include "libavutil/common.h"
24 #include "libavutil/internal.h"
25 #include "libavutil/intreadwrite.h"
26 
27 #include "libavcodec/vp9.h"
28 
29 #include "checkasm.h"
30 
31 static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
32 
33 #define BIT_DEPTH 8
34 #define SIZEOF_PIXEL ((BIT_DEPTH + 7) / 8)
35 #define DST_BUF_SIZE (size * size * SIZEOF_PIXEL)
36 #define SRC_BUF_STRIDE 72
37 #define SRC_BUF_SIZE ((size + 7) * SRC_BUF_STRIDE * SIZEOF_PIXEL)
38 #define src (buf + 3 * SIZEOF_PIXEL * (SRC_BUF_STRIDE + 1))
39 
40 #define randomize_buffers() \
41  do { \
42  uint32_t mask = pixel_mask[(BIT_DEPTH - 8) >> 1]; \
43  int k; \
44  for (k = 0; k < SRC_BUF_SIZE; k += 4) { \
45  uint32_t r = rnd() & mask; \
46  AV_WN32A(buf + k, r); \
47  } \
48  if (op == 1) { \
49  for (k = 0; k < DST_BUF_SIZE; k += 4) { \
50  uint32_t r = rnd() & mask; \
51  AV_WN32A(dst0 + k, r); \
52  AV_WN32A(dst1 + k, r); \
53  } \
54  } \
55  } while (0)
56 
57 static void check_mc(void)
58 {
59  static const char *const filter_names[4] = {
60  "8tap_smooth", "8tap_regular", "8tap_sharp", "bilin"
61  };
62  static const char *const subpel_names[2][2] = { { "", "h" }, { "v", "hv" } };
63  static const char *const op_names[2] = { "put", "avg" };
64 
65  LOCAL_ALIGNED_32(uint8_t, buf, [72 * 72 * 2]);
66  LOCAL_ALIGNED_32(uint8_t, dst0, [64 * 64 * 2]);
67  LOCAL_ALIGNED_32(uint8_t, dst1, [64 * 64 * 2]);
68  char str[256];
69  VP9DSPContext dsp;
70  int op, hsize, filter, dx, dy;
71 
73  void, uint8_t *dst, const uint8_t *ref,
74  ptrdiff_t dst_stride, ptrdiff_t ref_stride,
75  int h, int mx, int my);
76 
77  for (op = 0; op < 2; op++) {
78  ff_vp9dsp_init(&dsp);
79  for (hsize = 0; hsize < 5; hsize++) {
80  int size = 64 >> hsize;
81 
82  for (filter = 0; filter < 4; filter++) {
83  for (dx = 0; dx < 2; dx++) {
84  for (dy = 0; dy < 2; dy++) {
85  if (dx || dy) {
86  snprintf(str, sizeof(str), "%s_%s_%d%s", op_names[op],
87  filter_names[filter], size,
88  subpel_names[dy][dx]);
89  } else {
90  snprintf(str, sizeof(str), "%s%d", op_names[op], size);
91  }
92  if (check_func(dsp.mc[hsize][filter][op][dx][dy],
93  "vp9_%s", str)) {
94  int mx = dx ? 1 + (rnd() % 14) : 0;
95  int my = dy ? 1 + (rnd() % 14) : 0;
97  call_ref(dst0, src,
98  size * SIZEOF_PIXEL,
99  SRC_BUF_STRIDE * SIZEOF_PIXEL,
100  size, mx, my);
101  call_new(dst1, src,
102  size * SIZEOF_PIXEL,
103  SRC_BUF_STRIDE * SIZEOF_PIXEL,
104  size, mx, my);
105  if (memcmp(dst0, dst1, DST_BUF_SIZE))
106  fail();
107 
108  // SIMD implementations for each filter of subpel
109  // functions are identical
110  if (filter >= 1 && filter <= 2) continue;
111 
112  bench_new(dst1, src, size * SIZEOF_PIXEL,
113  SRC_BUF_STRIDE * SIZEOF_PIXEL,
114  size, mx, my);
115  }
116  }
117  }
118  }
119  }
120  }
121  report("mc");
122 }
123 
125 {
126  check_mc();
127 }
int size
#define SRC_BUF_STRIDE
Definition: vp9dsp.c:36
#define report
Definition: checkasm.h:83
vp9_mc_func mc[5][4][2][2][2]
Definition: vp9.h:210
#define src
Definition: vp9dsp.c:38
uint8_t
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
Definition: cpu.h:30
#define DST_BUF_SIZE
Definition: vp9dsp.c:35
#define fail()
Definition: checkasm.h:80
common internal API header
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
Definition: mpegaudioenc.c:307
#define SIZEOF_PIXEL
Definition: vp9dsp.c:34
av_cold void ff_vp9dsp_init(VP9DSPContext *dsp)
Definition: vp9dsp.c:2165
#define declare_func_emms(cpu_flags, ret,...)
Definition: checkasm.h:77
#define call_ref(...)
Definition: checkasm.h:86
static void check_mc(void)
Definition: vp9dsp.c:57
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:29
static const uint32_t pixel_mask[3]
Definition: vp9dsp.c:31
#define check_func(func,...)
Definition: checkasm.h:72
#define LOCAL_ALIGNED_32(t, v,...)
Definition: internal.h:117
#define randomize_buffers()
Definition: vp9dsp.c:40
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Definition: anm.c:76
common internal and external API header
#define rnd()
Definition: checkasm.h:65
void checkasm_check_vp9dsp(void)
Definition: vp9dsp.c:124
#define bench_new(...)
Definition: checkasm.h:173
#define call_new(...)
Definition: checkasm.h:141