Coverage Report

Created: 2026-03-31 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/av1/common/av1_txfm.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2017, Alliance for Open Media. All rights reserved.
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#include <inttypes.h>
13
14
#include "config/aom_dsp_rtcd.h"
15
#include "config/av1_rtcd.h"
16
17
#include "av1/common/av1_txfm.h"
18
19
// av1_cospi_arr[i][j] = (int)round(cos(PI*j/128) * (1<<(cos_bit_min+i)));
20
const int32_t av1_cospi_arr_data[4][64] = {
21
  { 1024, 1024, 1023, 1021, 1019, 1016, 1013, 1009, 1004, 999, 993, 987, 980,
22
    972,  964,  955,  946,  936,  926,  915,  903,  891,  878, 865, 851, 837,
23
    822,  807,  792,  775,  759,  742,  724,  706,  688,  669, 650, 630, 610,
24
    590,  569,  548,  526,  505,  483,  460,  438,  415,  392, 369, 345, 321,
25
    297,  273,  249,  224,  200,  175,  150,  125,  100,  75,  50,  25 },
26
  { 2048, 2047, 2046, 2042, 2038, 2033, 2026, 2018, 2009, 1998, 1987,
27
    1974, 1960, 1945, 1928, 1911, 1892, 1872, 1851, 1829, 1806, 1782,
28
    1757, 1730, 1703, 1674, 1645, 1615, 1583, 1551, 1517, 1483, 1448,
29
    1412, 1375, 1338, 1299, 1260, 1220, 1179, 1138, 1096, 1053, 1009,
30
    965,  921,  876,  830,  784,  737,  690,  642,  595,  546,  498,
31
    449,  400,  350,  301,  251,  201,  151,  100,  50 },
32
  { 4096, 4095, 4091, 4085, 4076, 4065, 4052, 4036, 4017, 3996, 3973,
33
    3948, 3920, 3889, 3857, 3822, 3784, 3745, 3703, 3659, 3612, 3564,
34
    3513, 3461, 3406, 3349, 3290, 3229, 3166, 3102, 3035, 2967, 2896,
35
    2824, 2751, 2675, 2598, 2520, 2440, 2359, 2276, 2191, 2106, 2019,
36
    1931, 1842, 1751, 1660, 1567, 1474, 1380, 1285, 1189, 1092, 995,
37
    897,  799,  700,  601,  501,  401,  301,  201,  101 },
38
  { 8192, 8190, 8182, 8170, 8153, 8130, 8103, 8071, 8035, 7993, 7946,
39
    7895, 7839, 7779, 7713, 7643, 7568, 7489, 7405, 7317, 7225, 7128,
40
    7027, 6921, 6811, 6698, 6580, 6458, 6333, 6203, 6070, 5933, 5793,
41
    5649, 5501, 5351, 5197, 5040, 4880, 4717, 4551, 4383, 4212, 4038,
42
    3862, 3683, 3503, 3320, 3135, 2948, 2760, 2570, 2378, 2185, 1990,
43
    1795, 1598, 1401, 1202, 1003, 803,  603,  402,  201 }
44
};
45
46
// av1_sinpi_arr_data[i][j] = (int)round((sqrt(2) * sin(j*Pi/9) * 2 / 3) * (1
47
// << (cos_bit_min + i))) modified so that elements j=1,2 sum to element j=4.
48
const int32_t av1_sinpi_arr_data[4][5] = { { 0, 330, 621, 836, 951 },
49
                                           { 0, 660, 1241, 1672, 1901 },
50
                                           { 0, 1321, 2482, 3344, 3803 },
51
                                           { 0, 2642, 4964, 6689, 7606 } };
52
53
// The reduced bit-width arrays are only used in the Arm Neon implementations
54
// in av1_fwd_txfm2d_neon.c for now.
55
#if HAVE_NEON
56
// Constants are stored in groups of four, where symmetrical constants in the
57
// cospi array are stored adjacent in memory, followed immediately by the same
58
// constants but negated, i.e.:
59
//   f(i,j) = (int)round(cos(PI*j/128) * (1<<(cos_bit_min+i))) << (3-i)
60
// and then in memory we store 4-tuples of constants together as:
61
//   f4(i,j) = [ f(i,j), f(i,64-j), -f(i,j), -f(i,64-j) ]
62
//
63
// Constants are stored in Q2.13 format, see:
64
// https://en.wikipedia.org/wiki/Q_(number_format)
65
//
66
// The order of the constants is such that increasing subdivisions of 64 store
67
// f4 tuples contiguously:
68
// av1_cospi_arr_q13_data[i] = {
69
//   f4(i,32),  // f(i,32) twice
70
//   f4(i,16),  // f(i,16) and f(i,48), f4(i,32) skipped since present above.
71
//   f4(i,8), f(i,24), // f4(i,16) and f4(i,32) skipped since present above.
72
//   f4(i,4), f(i,12), f4(i,20), f4(i,28),
73
//   f4(i,2), f4(i,6), f4(i,10), f4(i,14), f4(i,18), ...
74
//   f4(i,1), f4(i,3), f4(i,5), f4(i,7), f4(i,9), f4(i,11), ...
75
// }
76
const int16_t av1_cospi_arr_q13_data[4][128] = {
77
  {
78
      5792,  5792,  -5792, -5792, 7568,  3136,  -7568, -3136, 8032,  1600,
79
      -8032, -1600, 6808,  4552,  -6808, -4552, 8152,  800,   -8152, -800,
80
      7840,  2376,  -7840, -2376, 7224,  3864,  -7224, -3864, 6336,  5200,
81
      -6336, -5200, 8184,  400,   -8184, -400,  8104,  1200,  -8104, -1200,
82
      7944,  1992,  -7944, -1992, 7712,  2760,  -7712, -2760, 7408,  3504,
83
      -7408, -3504, 7024,  4208,  -7024, -4208, 6576,  4880,  -6576, -4880,
84
      6072,  5504,  -6072, -5504, 8192,  200,   -8192, -200,  8168,  600,
85
      -8168, -600,  8128,  1000,  -8128, -1000, 8072,  1400,  -8072, -1400,
86
      7992,  1792,  -7992, -1792, 7896,  2184,  -7896, -2184, 7776,  2568,
87
      -7776, -2568, 7640,  2952,  -7640, -2952, 7488,  3320,  -7488, -3320,
88
      7320,  3680,  -7320, -3680, 7128,  4040,  -7128, -4040, 6920,  4384,
89
      -6920, -4384, 6696,  4720,  -6696, -4720, 6456,  5040,  -6456, -5040,
90
      6200,  5352,  -6200, -5352, 5936,  5648,  -5936, -5648,
91
  },
92
  {
93
      5792,  5792,  -5792, -5792, 7568,  3136,  -7568, -3136, 8036,  1600,
94
      -8036, -1600, 6812,  4552,  -6812, -4552, 8152,  804,   -8152, -804,
95
      7840,  2380,  -7840, -2380, 7224,  3860,  -7224, -3860, 6332,  5196,
96
      -6332, -5196, 8184,  400,   -8184, -400,  8104,  1204,  -8104, -1204,
97
      7948,  1992,  -7948, -1992, 7712,  2760,  -7712, -2760, 7404,  3504,
98
      -7404, -3504, 7028,  4212,  -7028, -4212, 6580,  4880,  -6580, -4880,
99
      6068,  5500,  -6068, -5500, 8188,  200,   -8188, -200,  8168,  604,
100
      -8168, -604,  8132,  1004,  -8132, -1004, 8072,  1400,  -8072, -1400,
101
      7992,  1796,  -7992, -1796, 7896,  2184,  -7896, -2184, 7780,  2568,
102
      -7780, -2568, 7644,  2948,  -7644, -2948, 7488,  3320,  -7488, -3320,
103
      7316,  3684,  -7316, -3684, 7128,  4036,  -7128, -4036, 6920,  4384,
104
      -6920, -4384, 6696,  4716,  -6696, -4716, 6460,  5040,  -6460, -5040,
105
      6204,  5352,  -6204, -5352, 5932,  5648,  -5932, -5648,
106
  },
107
  {
108
      5792,  5792,  -5792, -5792, 7568,  3134,  -7568, -3134, 8034,  1598,
109
      -8034, -1598, 6812,  4552,  -6812, -4552, 8152,  802,   -8152, -802,
110
      7840,  2378,  -7840, -2378, 7224,  3862,  -7224, -3862, 6332,  5196,
111
      -6332, -5196, 8182,  402,   -8182, -402,  8104,  1202,  -8104, -1202,
112
      7946,  1990,  -7946, -1990, 7714,  2760,  -7714, -2760, 7406,  3502,
113
      -7406, -3502, 7026,  4212,  -7026, -4212, 6580,  4880,  -6580, -4880,
114
      6070,  5502,  -6070, -5502, 8190,  202,   -8190, -202,  8170,  602,
115
      -8170, -602,  8130,  1002,  -8130, -1002, 8072,  1400,  -8072, -1400,
116
      7992,  1794,  -7992, -1794, 7896,  2184,  -7896, -2184, 7778,  2570,
117
      -7778, -2570, 7644,  2948,  -7644, -2948, 7490,  3320,  -7490, -3320,
118
      7318,  3684,  -7318, -3684, 7128,  4038,  -7128, -4038, 6922,  4382,
119
      -6922, -4382, 6698,  4718,  -6698, -4718, 6458,  5040,  -6458, -5040,
120
      6204,  5350,  -6204, -5350, 5934,  5648,  -5934, -5648,
121
  },
122
  {
123
      5793,  5793,  -5793, -5793, 7568,  3135,  -7568, -3135, 8035,  1598,
124
      -8035, -1598, 6811,  4551,  -6811, -4551, 8153,  803,   -8153, -803,
125
      7839,  2378,  -7839, -2378, 7225,  3862,  -7225, -3862, 6333,  5197,
126
      -6333, -5197, 8182,  402,   -8182, -402,  8103,  1202,  -8103, -1202,
127
      7946,  1990,  -7946, -1990, 7713,  2760,  -7713, -2760, 7405,  3503,
128
      -7405, -3503, 7027,  4212,  -7027, -4212, 6580,  4880,  -6580, -4880,
129
      6070,  5501,  -6070, -5501, 8190,  201,   -8190, -201,  8170,  603,
130
      -8170, -603,  8130,  1003,  -8130, -1003, 8071,  1401,  -8071, -1401,
131
      7993,  1795,  -7993, -1795, 7895,  2185,  -7895, -2185, 7779,  2570,
132
      -7779, -2570, 7643,  2948,  -7643, -2948, 7489,  3320,  -7489, -3320,
133
      7317,  3683,  -7317, -3683, 7128,  4038,  -7128, -4038, 6921,  4383,
134
      -6921, -4383, 6698,  4717,  -6698, -4717, 6458,  5040,  -6458, -5040,
135
      6203,  5351,  -6203, -5351, 5933,  5649,  -5933, -5649,
136
  }
137
};
138
139
// av1_sinpi_arr_q13_data[i][j] =
140
//   round((sqrt2 * sin((j+1)*Pi/9) * 2/3) * (1 << (cos_bit_min + i))) << (3-i)
141
// modified so that elements j=0,1 sum to element j=3.
142
// See also: https://en.wikipedia.org/wiki/Q_(number_format)
143
const int16_t av1_sinpi_arr_q13_data[4][4] = { { 2640, 4968, 6688, 7608 },
144
                                               { 2640, 4964, 6688, 7604 },
145
                                               { 2642, 4964, 6688, 7606 },
146
                                               { 2642, 4964, 6689, 7606 } };
147
148
// Constants are stored in pairs, where symmetrical constants in the
149
// cospi array are stored adjacent in memory, i.e.:
150
//   f(i,j) = (int)round(cos(PI*j/128) * (1<<(cos_bit_min+i)))
151
// and then in memory we store 4-tuples of constants together as:
152
//   f2(i,j) = [ f(i,j), f(i,64-j) ]
153
const int32_t av1_cospi_arr_s32_data[4][66] = {
154
  {
155
      1024, 0,    1024, 25,   1023, 50,   1021, 75,  1019, 100, 1016,
156
      125,  1013, 150,  1009, 175,  1004, 200,  999, 224,  993, 249,
157
      987,  273,  980,  297,  972,  321,  964,  345, 955,  369, 946,
158
      392,  936,  415,  926,  438,  915,  460,  903, 483,  891, 505,
159
      878,  526,  865,  548,  851,  569,  837,  590, 822,  610, 807,
160
      630,  792,  650,  775,  669,  759,  688,  742, 706,  724, 724,
161
  },
162
  {
163
      2048, 0,    2047, 50,   2046, 100,  2042, 151,  2038, 201,  2033,
164
      251,  2026, 301,  2018, 350,  2009, 400,  1998, 449,  1987, 498,
165
      1974, 546,  1960, 595,  1945, 642,  1928, 690,  1911, 737,  1892,
166
      784,  1872, 830,  1851, 876,  1829, 921,  1806, 965,  1782, 1009,
167
      1757, 1053, 1730, 1096, 1703, 1138, 1674, 1179, 1645, 1220, 1615,
168
      1260, 1583, 1299, 1551, 1338, 1517, 1375, 1483, 1412, 1448, 1448,
169
  },
170
  {
171
      4096, 0,    4095, 101,  4091, 201,  4085, 301,  4076, 401,  4065,
172
      501,  4052, 601,  4036, 700,  4017, 799,  3996, 897,  3973, 995,
173
      3948, 1092, 3920, 1189, 3889, 1285, 3857, 1380, 3822, 1474, 3784,
174
      1567, 3745, 1660, 3703, 1751, 3659, 1842, 3612, 1931, 3564, 2019,
175
      3513, 2106, 3461, 2191, 3406, 2276, 3349, 2359, 3290, 2440, 3229,
176
      2520, 3166, 2598, 3102, 2675, 3035, 2751, 2967, 2824, 2896, 2896,
177
  },
178
  {
179
      8192, 0,    8190, 201,  8182, 402,  8170, 603,  8153, 803,  8130,
180
      1003, 8103, 1202, 8071, 1401, 8035, 1598, 7993, 1795, 7946, 1990,
181
      7895, 2185, 7839, 2378, 7779, 2570, 7713, 2760, 7643, 2948, 7568,
182
      3135, 7489, 3320, 7405, 3503, 7317, 3683, 7225, 3862, 7128, 4038,
183
      7027, 4212, 6921, 4383, 6811, 4551, 6698, 4717, 6580, 4880, 6458,
184
      5040, 6333, 5197, 6203, 5351, 6070, 5501, 5933, 5649, 5793, 5793,
185
  }
186
};
187
188
#endif  // HAVE_NEON
189
190
0
void av1_round_shift_array_c(int32_t *arr, int size, int bit) {
191
0
  int i;
192
0
  if (bit == 0) {
193
0
    return;
194
0
  } else {
195
0
    if (bit > 0) {
196
0
      for (i = 0; i < size; i++) {
197
0
        arr[i] = round_shift(arr[i], bit);
198
0
      }
199
0
    } else {
200
0
      for (i = 0; i < size; i++) {
201
0
        arr[i] = (int32_t)clamp64(((int64_t)1 << (-bit)) * arr[i], INT32_MIN,
202
0
                                  INT32_MAX);
203
0
      }
204
0
    }
205
0
  }
206
0
}
207
208
const TXFM_TYPE av1_txfm_type_ls[5][TX_TYPES_1D] = {
209
  { TXFM_TYPE_DCT4, TXFM_TYPE_ADST4, TXFM_TYPE_ADST4, TXFM_TYPE_IDENTITY4 },
210
  { TXFM_TYPE_DCT8, TXFM_TYPE_ADST8, TXFM_TYPE_ADST8, TXFM_TYPE_IDENTITY8 },
211
  { TXFM_TYPE_DCT16, TXFM_TYPE_ADST16, TXFM_TYPE_ADST16, TXFM_TYPE_IDENTITY16 },
212
  { TXFM_TYPE_DCT32, TXFM_TYPE_INVALID, TXFM_TYPE_INVALID,
213
    TXFM_TYPE_IDENTITY32 },
214
  { TXFM_TYPE_DCT64, TXFM_TYPE_INVALID, TXFM_TYPE_INVALID, TXFM_TYPE_INVALID }
215
};
216
217
const int8_t av1_txfm_stage_num_list[TXFM_TYPES] = {
218
  4,   // TXFM_TYPE_DCT4
219
  6,   // TXFM_TYPE_DCT8
220
  8,   // TXFM_TYPE_DCT16
221
  10,  // TXFM_TYPE_DCT32
222
  12,  // TXFM_TYPE_DCT64
223
  7,   // TXFM_TYPE_ADST4
224
  8,   // TXFM_TYPE_ADST8
225
  10,  // TXFM_TYPE_ADST16
226
  1,   // TXFM_TYPE_IDENTITY4
227
  1,   // TXFM_TYPE_IDENTITY8
228
  1,   // TXFM_TYPE_IDENTITY16
229
  1,   // TXFM_TYPE_IDENTITY32
230
};
231
232
void av1_range_check_buf(int32_t stage, const int32_t *input,
233
0
                         const int32_t *buf, int32_t size, int8_t bit) {
234
#if CONFIG_COEFFICIENT_RANGE_CHECKING
235
  const int64_t max_value = (1LL << (bit - 1)) - 1;
236
  const int64_t min_value = -(1LL << (bit - 1));
237
238
  int in_range = 1;
239
240
  for (int i = 0; i < size; ++i) {
241
    if (buf[i] < min_value || buf[i] > max_value) {
242
      in_range = 0;
243
    }
244
  }
245
246
  if (!in_range) {
247
    fprintf(stderr, "Error: coeffs contain out-of-range values\n");
248
    fprintf(stderr, "size: %d\n", size);
249
    fprintf(stderr, "stage: %d\n", stage);
250
    fprintf(stderr, "allowed range: [%" PRId64 ";%" PRId64 "]\n", min_value,
251
            max_value);
252
253
    fprintf(stderr, "coeffs: ");
254
255
    fprintf(stderr, "[");
256
    for (int j = 0; j < size; j++) {
257
      if (j > 0) fprintf(stderr, ", ");
258
      fprintf(stderr, "%d", input[j]);
259
    }
260
    fprintf(stderr, "]\n");
261
262
    fprintf(stderr, "   buf: ");
263
264
    fprintf(stderr, "[");
265
    for (int j = 0; j < size; j++) {
266
      if (j > 0) fprintf(stderr, ", ");
267
      fprintf(stderr, "%d", buf[j]);
268
    }
269
    fprintf(stderr, "]\n\n");
270
  }
271
272
  assert(in_range);
273
#else
274
0
  (void)stage;
275
0
  (void)input;
276
0
  (void)buf;
277
0
  (void)size;
278
0
  (void)bit;
279
0
#endif
280
0
}