FFmpeg
Loading...
Searching...
No Matches
rv34dsp.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Institute of Software Chinese Academy of Sciences (ISCAS).
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 <stddef.h>
22#include <stdint.h>
23#include <string.h>
24
26#include "libavutil/macros.h"
28
29#include "libavcodec/mathops.h"
30#include "libavcodec/rv34dsp.h"
31
32#include "checkasm.h"
33
34#define randomize(buf, len) \
35 do { \
36 for (int i = 0; i < len; i++) \
37 buf[i] = rnd(); \
38 } while (0)
39
41 declare_func(void, int16_t *block);
42
43 if (check_func(s->rv34_inv_transform_dc, "rv34_inv_transform_dc")) {
44 DECLARE_ALIGNED_16(int16_t, p1)[4*4];
45 DECLARE_ALIGNED_16(int16_t, p2)[4*4];
46
48 memcpy(p2, p1, sizeof(p1));
49
50 call_ref(p1);
51 call_new(p2);
52
53 if (memcmp(p1, p2, sizeof(p1))) {
54 fail();
55 }
56
57 bench_new(p1);
58 }
59
60 report("rv34_inv_transform_dc");
61}
62
64 declare_func(void, uint8_t *dst, ptrdiff_t stride, int dc);
65
66 if (check_func(s->rv34_idct_dc_add, "rv34_idct_dc_add")) {
67 DECLARE_ALIGNED_16(uint8_t, p1)[4*4];
68 DECLARE_ALIGNED_16(uint8_t, p2)[4*4];
69
71 memcpy(p2, p1, sizeof(p1));
72
73 call_ref(p1, 4, 5);
74 call_new(p2, 4, 5);
75
76 if (memcmp(p1, p2, sizeof(p1))) {
77 fail();
78 }
79
80 bench_new(p1, 4, 5);
81 }
82
83 report("rv34_idct_dc_add");
84}
85
86static void test_rv34_idct_add(const RV34DSPContext *const s)
87{
88 enum {
89 MAX_STRIDE = 256, ///< arbitrary, should be divisible by four
90 };
91 declare_func(void, uint8_t *dst, ptrdiff_t stride, int16_t *block);
92
93 if (check_func(s->rv34_idct_add, "rv34_idct_add")) {
94 DECLARE_ALIGNED_16(int16_t, block_ref)[4*4];
95 DECLARE_ALIGNED_16(int16_t, block_new)[4*4];
96
97 DECLARE_ALIGNED_4(uint8_t, dst_ref)[4*MAX_STRIDE + 4];
98 DECLARE_ALIGNED_4(uint8_t, dst_new)[4*MAX_STRIDE + 4];
99
100 ptrdiff_t stride = FFALIGN(1 + rnd() % MAX_STRIDE, 4);
101 uint8_t *dst_refp = dst_ref, *dst_newp = dst_new;
102
103 if (rnd() & 1) { // negate stride
104 dst_refp += 3 * stride;
105 dst_newp += 3 * stride;
106 stride = -stride;
107 }
108
109 for (size_t i = 0; i < FF_ARRAY_ELEMS(block_ref); ++i)
110 block_ref[i] = sign_extend(rnd(), 10);
111 for (size_t i = 0; i < sizeof(dst_ref); i += 4)
112 AV_WN32A(dst_ref + i, rnd());
113 memcpy(block_new, block_ref, sizeof(block_new));
114 memcpy(dst_new, dst_ref, sizeof(dst_new));
115
116 call_ref(dst_refp, stride, block_ref);
117 call_new(dst_newp, stride, block_new);
118
119 if (memcmp(dst_ref, dst_new, sizeof(dst_new)) ||
120 memcmp(block_ref, block_new, sizeof(block_new)))
121 fail();
122
123 bench_new(dst_newp, stride, block_new);
124 }
125
126 report("rv34_idct_add");
127}
128
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define rnd
Definition checkasm.h:136
static int16_t block[64]
Definition dct.c:125
#define declare_func
Definition test.h:489
#define fail
Definition test.h:479
#define bench_new
Definition test.h:487
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
#define AV_WN32A(p, v)
av_cold void ff_rv34dsp_init(RV34DSPContext *c)
Definition rv34dsp.c:131
Utility Preprocessor macros.
#define FFALIGN(x, a)
Definition macros.h:78
static av_const int sign_extend(int val, unsigned bits)
Definition mathops.h:135
#define DECLARE_ALIGNED_4(t, v)
#define DECLARE_ALIGNED_16(t, v)
RV30/40 decoder motion compensation functions.
#define FF_ARRAY_ELEMS(a)
#define stride
#define MAX_STRIDE
Definition hpeldsp.c:31
static void test_rv34_idct_add(const RV34DSPContext *const s)
Definition rv34dsp.c:86
#define randomize(buf, len)
Definition rv34dsp.c:34
void checkasm_check_rv34dsp(void)
Definition rv34dsp.c:129
static void test_rv34_idct_dc_add(RV34DSPContext *s)
Definition rv34dsp.c:63
static void test_rv34_inv_transform_dc(RV34DSPContext *s)
Definition rv34dsp.c:40