FFmpeg
Loading...
Searching...
No Matches
apv_dsp.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <stdint.h>
20#include <string.h>
21
22#include "checkasm.h"
23
24#include "libavutil/common.h"
26#include "libavcodec/apv_dsp.h"
27
28static const int8_t apv_trans_matrix[8][8] = {
29 { 64, 64, 64, 64, 64, 64, 64, 64 },
30 { 89, 75, 50, 18, -18, -50, -75, -89 },
31 { 84, 35, -35, -84, -84, -35, 35, 84 },
32 { 75, -18, -89, -50, 50, 89, 18, -75 },
33 { 64, -64, -64, 64, 64, -64, -64, 64 },
34 { 50, -89, 18, 75, -75, -18, 89, -50 },
35 { 35, -84, 84, -35, -35, 84, -84, 35 },
36 { 18, -50, 75, -89, 89, -75, 50, -18 },
37};
38
39static const uint8_t apv_level_scale[6] = { 40, 45, 51, 57, 64, 71 };
40
41// Make a set of quantised coefficients by sending a random residual
42// through a forward transform and quantisation: this keeps every
43// intermediate in the ranges a real encoder would produce (completely
44// random coefficients overflow the use of 16x16->32 multiplies in the
45// SIMD paths).
46static void generate_block(int16_t *input, const int16_t *qmatrix,
47 int bit_depth, int qp_shift, int dense)
48{
49 // 64-bit intermediates here avoid rounding issues.
50 int64_t residual[8][8], tmp[8][8];
51 int amplitude;
52
53 if (dense) {
54 // Dense blocks for benchmarking are fully random and uniform
55 // over the range.
56 amplitude = (1 << bit_depth) - 1;
57 } else {
58 // Random blocks for testing bias the amplitude, both to get
59 // smaller typical coefficients (including many zeroes) and to
60 // make clipping on the ends of the range more likely.
61 amplitude = (3 << (bit_depth - 2)) >> (rnd() % 8);
62 }
63 for (int y = 0; y < 8; y++) {
64 for (int x = 0; x < 8; x++)
65 residual[y][x] =
66 (int64_t)(rnd() % (2 * amplitude + 1)) - amplitude;
67 }
68
69 // Forward transform rows.
70 for (int y = 0; y < 8; y++) {
71 for (