FFmpeg
llviddspenc.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/common.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem_internal.h"
26 
28 
29 #include "checkasm.h"
30 
31 #define randomize_buffers(buf, size) \
32  do { \
33  int j; \
34  for (j = 0; j < size; j+=4) \
35  AV_WN32(buf + j, rnd()); \
36  } while (0)
37 
38 static const struct {uint8_t w, h, s;} planes[] = {
39  {16,16,16}, {21,23,25}, {32,17,48}, {15,128,16}, {128,127,128}
40 };
41 
42 #define MAX_STRIDE 128
43 #define MAX_HEIGHT 127
44 
46 {
47  int i;
48  LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE]);
49  LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE]);
50  LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE]);
51  LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE]);
52  LOCAL_ALIGNED_32(uint8_t, src2, [MAX_STRIDE]);
53  LOCAL_ALIGNED_32(uint8_t, src3, [MAX_STRIDE]);
54 
55  declare_func(void, uint8_t *dst, const uint8_t *src1,
56  const uint8_t *src2, intptr_t w);
57 
58  memset(dst0, 0, MAX_STRIDE);
59  memset(dst1, 0, MAX_STRIDE);
61  memcpy(src1, src0, MAX_STRIDE);
63  memcpy(src3, src2, MAX_STRIDE);
64 
65  if (check_func(c->diff_bytes, "diff_bytes")) {
66  for (i = 0; i < 5; i ++) {
67  call_ref(dst0, src0, src2, planes[i].w);
68  call_new(dst1, src1, src3, planes[i].w);
69  if (memcmp(dst0, dst1, planes[i].w))
70  fail();
71  }
72  bench_new(dst1, src0, src2, planes[4].w);
73  }
74 }
75 
77 {
78  int i;
79  LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE * MAX_HEIGHT]);
80  LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE * MAX_HEIGHT]);
83 
84  declare_func(void, uint8_t *dst, const uint8_t *src,
85  ptrdiff_t stride, ptrdiff_t width, int height);
86 
87  memset(dst0, 0, MAX_STRIDE * MAX_HEIGHT);
88  memset(dst1, 0, MAX_STRIDE * MAX_HEIGHT);
90  memcpy(src1, src0, MAX_STRIDE * MAX_HEIGHT);
91 
92  if (check_func(c->sub_left_predict, "sub_left_predict")) {
93  for (i = 0; i < 5; i ++) {
94  call_ref(dst0, src0, planes[i].s, planes[i].w, planes[i].h);
95  call_new(dst1, src1, planes[i].s, planes[i].w, planes[i].h);
96  if (memcmp(dst0, dst1, planes[i].w * planes[i].h))
97  fail();
98  break;
99  }
100  bench_new(dst1, src0, planes[4].s, planes[4].w, planes[4].h);
101  }
102 }
103 
105 {
108 
110  report("diff_bytes");
111 
113  report("sub_left_predict");
114 }
MAX_STRIDE
#define MAX_STRIDE
Definition: llviddspenc.c:42
mem_internal.h
src1
const pixel * src1
Definition: h264pred_template.c:421
w
uint8_t w
Definition: llviddspenc.c:38
check_func
#define check_func(func,...)
Definition: checkasm.h:180
call_ref
#define call_ref(...)
Definition: checkasm.h:195
planes
static const struct @466 planes[]
h
uint8_t h
Definition: llviddspenc.c:38
fail
#define fail()
Definition: checkasm.h:189
checkasm.h
check_diff_bytes
static void check_diff_bytes(LLVidEncDSPContext *c)
Definition: llviddspenc.c:45
intreadwrite.h
s
uint8_t s
Definition: llviddspenc.c:38
check_sub_left_pred
static void check_sub_left_pred(LLVidEncDSPContext *c)
Definition: llviddspenc.c:76
call_new
#define call_new(...)
Definition: checkasm.h:298
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:156
MAX_HEIGHT
#define MAX_HEIGHT
Definition: llviddspenc.c:43
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_llvidencdsp_init
av_cold void ff_llvidencdsp_init(LLVidEncDSPContext *c)
Definition: lossless_videoencdsp.c:100
height
#define height
Definition: dsp.h:85
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
checkasm_check_llviddspenc
void checkasm_check_llviddspenc(void)
Definition: llviddspenc.c:104
lossless_videoencdsp.h
report
#define report
Definition: checkasm.h:192
bench_new
#define bench_new(...)
Definition: checkasm.h:369
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
src2
const pixel * src2
Definition: h264pred_template.c:422
common.h
LLVidEncDSPContext
Definition: lossless_videoencdsp.h:25
stride
#define stride
Definition: h264pred_template.c:537
src0
const pixel *const src0
Definition: h264pred_template.c:420
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:184
width
#define width
Definition: dsp.h:85
randomize_buffers
#define randomize_buffers(buf, size)
Definition: llviddspenc.c:31
src
#define src
Definition: vp8dsp.c:248