FFmpeg
hevc_add_res.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Alexandra Hájková
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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/intreadwrite.h"
24 
25 #include "libavcodec/hevcdsp.h"
26 
27 #include "checkasm.h"
28 
29 #define randomize_buffers(buf, size) \
30  do { \
31  int j; \
32  for (j = 0; j < size; j++) { \
33  int16_t r = rnd(); \
34  AV_WN16A(buf + j, r >> 3); \
35  } \
36  } while (0)
37 
38 #define randomize_buffers2(buf, size) \
39  do { \
40  int j; \
41  for (j = 0; j < size; j++) \
42  AV_WN16A(buf + j * 2, rnd() & 0x3FF); \
43  } while (0)
44 
45 static void compare_add_res(int size, ptrdiff_t stride, int overflow_test)
46 {
47  LOCAL_ALIGNED_32(int16_t, res0, [32 * 32]);
48  LOCAL_ALIGNED_32(int16_t, res1, [32 * 32]);
49  LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]);
50  LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]);
51 
52  declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t *res, ptrdiff_t stride);
53 
54  randomize_buffers(res0, size);
55  randomize_buffers2(dst0, size);
56  if (overflow_test)
57  res0[0] = 0x8000;
58  memcpy(res1, res0, sizeof(*res0) * size);
59  memcpy(dst1, dst0, sizeof(int16_t) * size);
60 
61  call_ref(dst0, res0, stride);
62  call_new(dst1, res1, stride);
63  if (memcmp(dst0, dst1, size))
64  fail();
65  bench_new(dst1, res1, stride);
66 }
67 
69 {
70  int i;
71 
72  for (i = 2; i <= 5; i++) {
73  int block_size = 1 << i;
74  int size = block_size * block_size;
75  ptrdiff_t stride = block_size << (bit_depth > 8);
76 
77  if (check_func(h.add_residual[i - 2], "hevc_add_res_%dx%d_%d", block_size, block_size, bit_depth)) {
78  compare_add_res(size, stride, 0);
79  // overflow test for res = -32768
80  compare_add_res(size, stride, 1);
81  }
82  }
83 }
84 
86 {
87  int bit_depth;
88 
89  for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
91 
92  ff_hevc_dsp_init(&h, bit_depth);
93  check_add_res(h, bit_depth);
94  }
95  report("add_residual");
96 }
#define randomize_buffers2(buf, size)
Definition: hevc_add_res.c:38
#define report
Definition: checkasm.h:126
uint8_t
ptrdiff_t size
Definition: opengl_enc.c:100
void checkasm_check_hevc_add_res(void)
Definition: hevc_add_res.c:85
#define fail()
Definition: checkasm.h:123
#define randomize_buffers(buf, size)
Definition: hevc_add_res.c:29
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:254
static void check_add_res(HEVCDSPContext h, int bit_depth)
Definition: hevc_add_res.c:68
#define declare_func_emms(cpu_flags, ret,...)
Definition: checkasm.h:120
#define call_ref(...)
Definition: checkasm.h:129
void ff_hevc_dsp_init(HEVCDSPContext *hevcdsp, int bit_depth)
Definition: hevcdsp.c:126
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:31
#define check_func(func,...)
Definition: checkasm.h:114
void(* add_residual[4])(uint8_t *dst, int16_t *res, ptrdiff_t stride)
Definition: hevcdsp.h:49
#define LOCAL_ALIGNED_32(t, v,...)
Definition: internal.h:137
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:104
#define bench_new(...)
Definition: checkasm.h:261
#define call_new(...)
Definition: checkasm.h:201
static void compare_add_res(int size, ptrdiff_t stride, int overflow_test)
Definition: hevc_add_res.c:45
int i
Definition: input.c:407