Coverage Report

Created: 2026-10-28 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvpx/vp9/encoder/vp9_dct.c
Line
Count
Source
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
 *  that can be found in the LICENSE file in the root of the source
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
#include <assert.h>
12
#include <math.h>
13
14
#include "./vp9_rtcd.h"
15
#include "./vpx_config.h"
16
#include "./vpx_dsp_rtcd.h"
17
18
#include "vp9/common/vp9_blockd.h"
19
#include "vp9/common/vp9_idct.h"
20
#include "vpx_dsp/fwd_txfm.h"
21
#include "vpx_ports/mem.h"
22
23
3.45M
static void fdct4(const tran_low_t *input, tran_low_t *output) {
24
3.45M
  tran_high_t step[4];
25
3.45M
  tran_high_t temp1, temp2;
26
27
3.45M
  step[0] = input[0] + input[3];
28
3.45M
  step[1] = input[1] + input[2];
29
3.45M
  step[2] = input[1] - input[2];
30
3.45M
  step[3] = input[0] - input[3];
31
32
3.45M
  temp1 = (step[0] + step[1]) * cospi_16_64;
33
3.45M
  temp2 = (step[0] - step[1]) * cospi_16_64;
34
3.45M
  output[0] = (tran_low_t)fdct_round_shift(temp1);
35
3.45M
  output[2] = (tran_low_t)fdct_round_shift(temp2);
36
3.45M
  temp1 = step[2] * cospi_24_64 + step[3] * cospi_8_64;
37
3.45M
  temp2 = -step[2] * cospi_8_64 + step[3] * cospi_24_64;
38
3.45M
  output[1] = (tran_low_t)fdct_round_shift(temp1);
39
3.45M
  output[3] = (tran_low_t)fdct_round_shift(temp2);
40
3.45M
}
41
42
2.36M
static void fdct8(const tran_low_t *input, tran_low_t *output) {
43
2.36M
  tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;  // canbe16
44
2.36M
  tran_high_t t0, t1, t2, t3;                  // needs32
45
2.36M
  tran_high_t x0, x1, x2, x3;                  // canbe16
46
47
  // stage 1
48
2.36M
  s0 = input[0] + input[7];
49
2.36M
  s1 = input[1] + input[6];
50
2.36M
  s2 = input[2] + input[5];
51
2.36M
  s3 = input[3] + input[4];
52
2.36M
  s4 = input[3] - input[4];
53
2.36M
  s5 = input[2] - input[5];
54
2.36M
  s6 = input[1] - input[6];
55
2.36M
  s7 = input[0] - input[7];
56
57
  // fdct4(step, step);
58
2.36M
  x0 = s0 + s3;
59
2.36M
  x1 = s1 + s2;
60
2.36M
  x2 = s1 - s2;
61
2.36M
  x3 = s0 - s3;
62
2.36M
  t0 = (x0 + x1) * cospi_16_64;
63
2.36M
  t1 = (x0 - x1) * cospi_16_64;
64
2.36M
  t2 = x2 * cospi_24_64 + x3 * cospi_8_64;
65
2.36M
  t3 = -x2 * cospi_8_64 + x3 * cospi_24_64;
66
2.36M
  output[0] = (tran_low_t)fdct_round_shift(t0);
67
2.36M
  output[2] = (tran_low_t)fdct_round_shift(t2);
68
2.36M
  output[4] = (tran_low_t)fdct_round_shift(t1);
69
2.36M
  output[6] = (tran_low_t)fdct_round_shift(t3);
70
71
  // Stage 2
72
2.36M
  t0 = (s6 - s5) * cospi_16_64;
73
2.36M
  t1 = (s6 + s5) * cospi_16_64;
74
2.36M
  t2 = (tran_low_t)fdct_round_shift(t0);
75
2.36M
  t3 = (tran_low_t)fdct_round_shift(t1);
76
77
  // Stage 3
78
2.36M
  x0 = s4 + t2;
79
2.36M
  x1 = s4 - t2;
80
2.36M
  x2 = s7 - t3;
81
2.36M
  x3 = s7 + t3;
82
83
  // Stage 4
84
2.36M
  t0 = x0 * cospi_28_64 + x3 * cospi_4_64;
85
2.36M
  t1 = x1 * cospi_12_64 + x2 * cospi_20_64;
86
2.36M
  t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
87
2.36M
  t3 = x3 * cospi_28_64 + x0 * -cospi_4_64;
88
2.36M
  output[1] = (tran_low_t)fdct_round_shift(t0);
89
2.36M
  output[3] = (tran_low_t)fdct_round_shift(t2);
90
2.36M
  output[5] = (tran_low_t)fdct_round_shift(t1);
91
2.36M
  output[7] = (tran_low_t)fdct_round_shift(t3);
92
2.36M
}
93
94
1.56M
static void fdct16(const tran_low_t in[16], tran_low_t out[16]) {
95
1.56M
  tran_high_t step1[8];      // canbe16
96
1.56M
  tran_high_t step2[8];      // canbe16
97
1.56M
  tran_high_t step3[8];      // canbe16
98
1.56M
  tran_high_t input[8];      // canbe16
99
1.56M
  tran_high_t temp1, temp2;  // needs32
100
101
  // step 1
102
1.56M
  input[0] = in[0] + in[15];
103
1.56M
  input[1] = in[1] + in[14];
104
1.56M
  input[2] = in[2] + in[13];
105
1.56M
  input[3] = in[3] + in[12];
106
1.56M
  input[4] = in[4] + in[11];
107
1.56M
  input[5] = in[5] + in[10];
108
1.56M
  input[6] = in[6] + in[9];
109
1.56M
  input[7] = in[7] + in[8];
110
111
1.56M
  step1[0] = in[7] - in[8];
112
1.56M
  step1[1] = in[6] - in[9];
113
1.56M
  step1[2] = in[5] - in[10];
114
1.56M
  step1[3] = in[4] - in[11];
115
1.56M
  step1[4] = in[3] - in[12];
116
1.56M
  step1[5] = in[2] - in[13];
117
1.56M
  step1[6] = in[1] - in[14];
118
1.56M
  step1[7] = in[0] - in[15];
119
120
  // fdct8(step, step);
121
1.56M
  {
122
1.56M
    tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;  // canbe16
123
1.56M
    tran_high_t t0, t1, t2, t3;                  // needs32
124
1.56M
    tran_high_t x0, x1, x2, x3;                  // canbe16
125
126
    // stage 1
127
1.56M
    s0 = input[0] + input[7];
128
1.56M
    s1 = input[1] + input[6];
129
1.56M
    s2 = input[2] + input[5];
130
1.56M
    s3 = input[3] + input[4];
131
1.56M
    s4 = input[3] - input[4];
132
1.56M
    s5 = input[2] - input[5];
133
1.56M
    s6 = input[1] - input[6];
134
1.56M
    s7 = input[0] - input[7];
135
136
    // fdct4(step, step);
137
1.56M
    x0 = s0 + s3;
138
1.56M
    x1 = s1 + s2;
139
1.56M
    x2 = s1 - s2;
140
1.56M
    x3 = s0 - s3;
141
1.56M
    t0 = (x0 + x1) * cospi_16_64;
142
1.56M
    t1 = (x0 - x1) * cospi_16_64;
143
1.56M
    t2 = x3 * cospi_8_64 + x2 * cospi_24_64;
144
1.56M
    t3 = x3 * cospi_24_64 - x2 * cospi_8_64;
145
1.56M
    out[0] = (tran_low_t)fdct_round_shift(t0);
146
1.56M
    out[4] = (tran_low_t)fdct_round_shift(t2);
147
1.56M
    out[8] = (tran_low_t)fdct_round_shift(t1);
148
1.56M
    out[12] = (tran_low_t)fdct_round_shift(t3);
149
150
    // Stage 2
151
1.56M
    t0 = (s6 - s5) * cospi_16_64;
152
1.56M
    t1 = (s6 + s5) * cospi_16_64;
153
1.56M
    t2 = fdct_round_shift(t0);
154
1.56M
    t3 = fdct_round_shift(t1);
155
156
    // Stage 3
157
1.56M
    x0 = s4 + t2;
158
1.56M
    x1 = s4 - t2;
159
1.56M
    x2 = s7 - t3;
160
1.56M
    x3 = s7 + t3;
161
162
    // Stage 4
163
1.56M
    t0 = x0 * cospi_28_64 + x3 * cospi_4_64;
164
1.56M
    t1 = x1 * cospi_12_64 + x2 * cospi_20_64;
165
1.56M
    t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
166
1.56M
    t3 = x3 * cospi_28_64 + x0 * -cospi_4_64;
167
1.56M
    out[2] = (tran_low_t)fdct_round_shift(t0);
168
1.56M
    out[6] = (tran_low_t)fdct_round_shift(t2);
169
1.56M
    out[10] = (tran_low_t)fdct_round_shift(t1);
170
1.56M
    out[14] = (tran_low_t)fdct_round_shift(t3);
171
1.56M
  }
172
173
  // step 2
174
1.56M
  temp1 = (step1[5] - step1[2]) * cospi_16_64;
175
1.56M
  temp2 = (step1[4] - step1[3]) * cospi_16_64;
176
1.56M
  step2[2] = fdct_round_shift(temp1);
177
1.56M
  step2[3] = fdct_round_shift(temp2);
178
1.56M
  temp1 = (step1[4] + step1[3]) * cospi_16_64;
179
1.56M
  temp2 = (step1[5] + step1[2]) * cospi_16_64;
180
1.56M
  step2[4] = fdct_round_shift(temp1);
181
1.56M
  step2[5] = fdct_round_shift(temp2);
182
183
  // step 3
184
1.56M
  step3[0] = step1[0] + step2[3];
185
1.56M
  step3[1] = step1[1] + step2[2];
186
1.56M
  step3[2] = step1[1] - step2[2];
187
1.56M
  step3[3] = step1[0] - step2[3];
188
1.56M
  step3[4] = step1[7] - step2[4];
189
1.56M
  step3[5] = step1[6] - step2[5];
190
1.56M
  step3[6] = step1[6] + step2[5];
191
1.56M
  step3[7] = step1[7] + step2[4];
192
193
  // step 4
194
1.56M
  temp1 = step3[1] * -cospi_8_64 + step3[6] * cospi_24_64;
195
1.56M
  temp2 = step3[2] * cospi_24_64 + step3[5] * cospi_8_64;
196
1.56M
  step2[1] = fdct_round_shift(temp1);
197
1.56M
  step2[2] = fdct_round_shift(temp2);
198
1.56M
  temp1 = step3[2] * cospi_8_64 - step3[5] * cospi_24_64;
199
1.56M
  temp2 = step3[1] * cospi_24_64 + step3[6] * cospi_8_64;
200
1.56M
  step2[5] = fdct_round_shift(temp1);
201
1.56M
  step2[6] = fdct_round_shift(temp2);
202
203
  // step 5
204
1.56M
  step1[0] = step3[0] + step2[1];
205
1.56M
  step1[1] = step3[0] - step2[1];
206
1.56M
  step1[2] = step3[3] + step2[2];
207
1.56M
  step1[3] = step3[3] - step2[2];
208
1.56M
  step1[4] = step3[4] - step2[5];
209
1.56M
  step1[5] = step3[4] + step2[5];
210
1.56M
  step1[6] = step3[7] - step2[6];
211
1.56M
  step1[7] = step3[7] + step2[6];
212
213
  // step 6
214
1.56M
  temp1 = step1[0] * cospi_30_64 + step1[7] * cospi_2_64;
215
1.56M
  temp2 = step1[1] * cospi_14_64 + step1[6] * cospi_18_64;
216
1.56M
  out[1] = (tran_low_t)fdct_round_shift(temp1);
217
1.56M
  out[9] = (tran_low_t)fdct_round_shift(temp2);
218
219
1.56M
  temp1 = step1[2] * cospi_22_64 + step1[5] * cospi_10_64;
220
1.56M
  temp2 = step1[3] * cospi_6_64 + step1[4] * cospi_26_64;
221
1.56M
  out[5] = (tran_low_t)fdct_round_shift(temp1);
222
1.56M
  out[13] = (tran_low_t)fdct_round_shift(temp2);
223
224
1.56M
  temp1 = step1[3] * -cospi_26_64 + step1[4] * cospi_6_64;
225
1.56M
  temp2 = step1[2] * -cospi_10_64 + step1[5] * cospi_22_64;
226
1.56M
  out[3] = (tran_low_t)fdct_round_shift(temp1);
227
1.56M
  out[11] = (tran_low_t)fdct_round_shift(temp2);
228
229
1.56M
  temp1 = step1[1] * -cospi_18_64 + step1[6] * cospi_14_64;
230
1.56M
  temp2 = step1[0] * -cospi_2_64 + step1[7] * cospi_30_64;
231
1.56M
  out[7] = (tran_low_t)fdct_round_shift(temp1);
232
1.56M
  out[15] = (tran_low_t)fdct_round_shift(temp2);
233
1.56M
}
234
235
5.74M
static void fadst4(const tran_low_t *input, tran_low_t *output) {
236
5.74M
  tran_high_t x0, x1, x2, x3;
237
5.74M
  tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;
238
239
5.74M
  x0 = input[0];
240
5.74M
  x1 = input[1];
241
5.74M
  x2 = input[2];
242
5.74M
  x3 = input[3];
243
244
5.74M
  if (!(x0 | x1 | x2 | x3)) {
245
1.08M
    output[0] = output[1] = output[2] = output[3] = 0;
246
1.08M
    return;
247
1.08M
  }
248
249
4.65M
  s0 = sinpi_1_9 * x0;
250
4.65M
  s1 = sinpi_4_9 * x0;
251
4.65M
  s2 = sinpi_2_9 * x1;
252
4.65M
  s3 = sinpi_1_9 * x1;
253
4.65M
  s4 = sinpi_3_9 * x2;
254
4.65M
  s5 = sinpi_4_9 * x3;
255
4.65M
  s6 = sinpi_2_9 * x3;
256
4.65M
  s7 = x0 + x1 - x3;
257
258
4.65M
  x0 = s0 + s2 + s5;
259
4.65M
  x1 = sinpi_3_9 * s7;
260
4.65M
  x2 = s1 - s3 + s6;
261
4.65M
  x3 = s4;
262
263
4.65M
  s0 = x0 + x3;
264
4.65M
  s1 = x1;
265
4.65M
  s2 = x2 - x3;
266
4.65M
  s3 = x2 - x0 + x3;
267
268
  // 1-D transform scaling factor is sqrt(2).
269
4.65M
  output[0] = (tran_low_t)fdct_round_shift(s0);
270
4.65M
  output[1] = (tran_low_t)fdct_round_shift(s1);
271
4.65M
  output[2] = (tran_low_t)fdct_round_shift(s2);
272
4.65M
  output[3] = (tran_low_t)fdct_round_shift(s3);
273
4.65M
}
274
275
4.13M
static void fadst8(const tran_low_t *input, tran_low_t *output) {
276
4.13M
  tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;
277
278
4.13M
  tran_high_t x0 = input[7];
279
4.13M
  tran_high_t x1 = input[0];
280
4.13M
  tran_high_t x2 = input[5];
281
4.13M
  tran_high_t x3 = input[2];
282
4.13M
  tran_high_t x4 = input[3];
283
4.13M
  tran_high_t x5 = input[4];
284
4.13M
  tran_high_t x6 = input[1];
285
4.13M
  tran_high_t x7 = input[6];
286
287
  // stage 1
288
4.13M
  s0 = cospi_2_64 * x0 + cospi_30_64 * x1;
289
4.13M
  s1 = cospi_30_64 * x0 - cospi_2_64 * x1;
290
4.13M
  s2 = cospi_10_64 * x2 + cospi_22_64 * x3;
291
4.13M
  s3 = cospi_22_64 * x2 - cospi_10_64 * x3;
292
4.13M
  s4 = cospi_18_64 * x4 + cospi_14_64 * x5;
293
4.13M
  s5 = cospi_14_64 * x4 - cospi_18_64 * x5;
294
4.13M
  s6 = cospi_26_64 * x6 + cospi_6_64 * x7;
295
4.13M
  s7 = cospi_6_64 * x6 - cospi_26_64 * x7;
296
297
4.13M
  x0 = fdct_round_shift(s0 + s4);
298
4.13M
  x1 = fdct_round_shift(s1 + s5);
299
4.13M
  x2 = fdct_round_shift(s2 + s6);
300
4.13M
  x3 = fdct_round_shift(s3 + s7);
301
4.13M
  x4 = fdct_round_shift(s0 - s4);
302
4.13M
  x5 = fdct_round_shift(s1 - s5);
303
4.13M
  x6 = fdct_round_shift(s2 - s6);
304
4.13M
  x7 = fdct_round_shift(s3 - s7);
305
306
  // stage 2
307
4.13M
  s0 = x0;
308
4.13M
  s1 = x1;
309
4.13M
  s2 = x2;
310
4.13M
  s3 = x3;
311
4.13M
  s4 = cospi_8_64 * x4 + cospi_24_64 * x5;
312
4.13M
  s5 = cospi_24_64 * x4 - cospi_8_64 * x5;
313
4.13M
  s6 = -cospi_24_64 * x6 + cospi_8_64 * x7;
314
4.13M
  s7 = cospi_8_64 * x6 + cospi_24_64 * x7;
315
316
4.13M
  x0 = s0 + s2;
317
4.13M
  x1 = s1 + s3;
318
4.13M
  x2 = s0 - s2;
319
4.13M
  x3 = s1 - s3;
320
4.13M
  x4 = fdct_round_shift(s4 + s6);
321
4.13M
  x5 = fdct_round_shift(s5 + s7);
322
4.13M
  x6 = fdct_round_shift(s4 - s6);
323
4.13M
  x7 = fdct_round_shift(s5 - s7);
324
325
  // stage 3
326
4.13M
  s2 = cospi_16_64 * (x2 + x3);
327
4.13M
  s3 = cospi_16_64 * (x2 - x3);
328
4.13M
  s6 = cospi_16_64 * (x6 + x7);
329
4.13M
  s7 = cospi_16_64 * (x6 - x7);
330
331
4.13M
  x2 = fdct_round_shift(s2);
332
4.13M
  x3 = fdct_round_shift(s3);
333
4.13M
  x6 = fdct_round_shift(s6);
334
4.13M
  x7 = fdct_round_shift(s7);
335
336
4.13M
  output[0] = (tran_low_t)x0;
337
4.13M
  output[1] = (tran_low_t)-x4;
338
4.13M
  output[2] = (tran_low_t)x6;
339
4.13M
  output[3] = (tran_low_t)-x2;
340
4.13M
  output[4] = (tran_low_t)x3;
341
4.13M
  output[5] = (tran_low_t)-x7;
342
4.13M
  output[6] = (tran_low_t)x5;
343
4.13M
  output[7] = (tran_low_t)-x1;
344
4.13M
}
345
346
2.65M
static void fadst16(const tran_low_t *input, tran_low_t *output) {
347
2.65M
  tran_high_t s0, s1, s2, s3, s4, s5, s6, s7, s8;
348
2.65M
  tran_high_t s9, s10, s11, s12, s13, s14, s15;
349
350
2.65M
  tran_high_t x0 = input[15];
351
2.65M
  tran_high_t x1 = input[0];
352
2.65M
  tran_high_t x2 = input[13];
353
2.65M
  tran_high_t x3 = input[2];
354
2.65M
  tran_high_t x4 = input[11];
355
2.65M
  tran_high_t x5 = input[4];
356
2.65M
  tran_high_t x6 = input[9];
357
2.65M
  tran_high_t x7 = input[6];
358
2.65M
  tran_high_t x8 = input[7];
359
2.65M
  tran_high_t x9 = input[8];
360
2.65M
  tran_high_t x10 = input[5];
361
2.65M
  tran_high_t x11 = input[10];
362
2.65M
  tran_high_t x12 = input[3];
363
2.65M
  tran_high_t x13 = input[12];
364
2.65M
  tran_high_t x14 = input[1];
365
2.65M
  tran_high_t x15 = input[14];
366
367
  // stage 1
368
2.65M
  s0 = x0 * cospi_1_64 + x1 * cospi_31_64;
369
2.65M
  s1 = x0 * cospi_31_64 - x1 * cospi_1_64;
370
2.65M
  s2 = x2 * cospi_5_64 + x3 * cospi_27_64;
371
2.65M
  s3 = x2 * cospi_27_64 - x3 * cospi_5_64;
372
2.65M
  s4 = x4 * cospi_9_64 + x5 * cospi_23_64;
373
2.65M
  s5 = x4 * cospi_23_64 - x5 * cospi_9_64;
374
2.65M
  s6 = x6 * cospi_13_64 + x7 * cospi_19_64;
375
2.65M
  s7 = x6 * cospi_19_64 - x7 * cospi_13_64;
376
2.65M
  s8 = x8 * cospi_17_64 + x9 * cospi_15_64;
377
2.65M
  s9 = x8 * cospi_15_64 - x9 * cospi_17_64;
378
2.65M
  s10 = x10 * cospi_21_64 + x11 * cospi_11_64;
379
2.65M
  s11 = x10 * cospi_11_64 - x11 * cospi_21_64;
380
2.65M
  s12 = x12 * cospi_25_64 + x13 * cospi_7_64;
381
2.65M
  s13 = x12 * cospi_7_64 - x13 * cospi_25_64;
382
2.65M
  s14 = x14 * cospi_29_64 + x15 * cospi_3_64;
383
2.65M
  s15 = x14 * cospi_3_64 - x15 * cospi_29_64;
384
385
2.65M
  x0 = fdct_round_shift(s0 + s8);
386
2.65M
  x1 = fdct_round_shift(s1 + s9);
387
2.65M
  x2 = fdct_round_shift(s2 + s10);
388
2.65M
  x3 = fdct_round_shift(s3 + s11);
389
2.65M
  x4 = fdct_round_shift(s4 + s12);
390
2.65M
  x5 = fdct_round_shift(s5 + s13);
391
2.65M
  x6 = fdct_round_shift(s6 + s14);
392
2.65M
  x7 = fdct_round_shift(s7 + s15);
393
2.65M
  x8 = fdct_round_shift(s0 - s8);
394
2.65M
  x9 = fdct_round_shift(s1 - s9);
395
2.65M
  x10 = fdct_round_shift(s2 - s10);
396
2.65M
  x11 = fdct_round_shift(s3 - s11);
397
2.65M
  x12 = fdct_round_shift(s4 - s12);
398
2.65M
  x13 = fdct_round_shift(s5 - s13);
399
2.65M
  x14 = fdct_round_shift(s6 - s14);
400
2.65M
  x15 = fdct_round_shift(s7 - s15);
401
402
  // stage 2
403
2.65M
  s0 = x0;
404
2.65M
  s1 = x1;
405
2.65M
  s2 = x2;
406
2.65M
  s3 = x3;
407
2.65M
  s4 = x4;
408
2.65M
  s5 = x5;
409
2.65M
  s6 = x6;
410
2.65M
  s7 = x7;
411
2.65M
  s8 = x8 * cospi_4_64 + x9 * cospi_28_64;
412
2.65M
  s9 = x8 * cospi_28_64 - x9 * cospi_4_64;
413
2.65M
  s10 = x10 * cospi_20_64 + x11 * cospi_12_64;
414
2.65M
  s11 = x10 * cospi_12_64 - x11 * cospi_20_64;
415
2.65M
  s12 = -x12 * cospi_28_64 + x13 * cospi_4_64;
416
2.65M
  s13 = x12 * cospi_4_64 + x13 * cospi_28_64;
417
2.65M
  s14 = -x14 * cospi_12_64 + x15 * cospi_20_64;
418
2.65M
  s15 = x14 * cospi_20_64 + x15 * cospi_12_64;
419
420
2.65M
  x0 = s0 + s4;
421
2.65M
  x1 = s1 + s5;
422
2.65M
  x2 = s2 + s6;
423
2.65M
  x3 = s3 + s7;
424
2.65M
  x4 = s0 - s4;
425
2.65M
  x5 = s1 - s5;
426
2.65M
  x6 = s2 - s6;
427
2.65M
  x7 = s3 - s7;
428
2.65M
  x8 = fdct_round_shift(s8 + s12);
429
2.65M
  x9 = fdct_round_shift(s9 + s13);
430
2.65M
  x10 = fdct_round_shift(s10 + s14);
431
2.65M
  x11 = fdct_round_shift(s11 + s15);
432
2.65M
  x12 = fdct_round_shift(s8 - s12);
433
2.65M
  x13 = fdct_round_shift(s9 - s13);
434
2.65M
  x14 = fdct_round_shift(s10 - s14);
435
2.65M
  x15 = fdct_round_shift(s11 - s15);
436
437
  // stage 3
438
2.65M
  s0 = x0;
439
2.65M
  s1 = x1;
440
2.65M
  s2 = x2;
441
2.65M
  s3 = x3;
442
2.65M
  s4 = x4 * cospi_8_64 + x5 * cospi_24_64;
443
2.65M
  s5 = x4 * cospi_24_64 - x5 * cospi_8_64;
444
2.65M
  s6 = -x6 * cospi_24_64 + x7 * cospi_8_64;
445
2.65M
  s7 = x6 * cospi_8_64 + x7 * cospi_24_64;
446
2.65M
  s8 = x8;
447
2.65M
  s9 = x9;
448
2.65M
  s10 = x10;
449
2.65M
  s11 = x11;
450
2.65M
  s12 = x12 * cospi_8_64 + x13 * cospi_24_64;
451
2.65M
  s13 = x12 * cospi_24_64 - x13 * cospi_8_64;
452
2.65M
  s14 = -x14 * cospi_24_64 + x15 * cospi_8_64;
453
2.65M
  s15 = x14 * cospi_8_64 + x15 * cospi_24_64;
454
455
2.65M
  x0 = s0 + s2;
456
2.65M
  x1 = s1 + s3;
457
2.65M
  x2 = s0 - s2;
458
2.65M
  x3 = s1 - s3;
459
2.65M
  x4 = fdct_round_shift(s4 + s6);
460
2.65M
  x5 = fdct_round_shift(s5 + s7);
461
2.65M
  x6 = fdct_round_shift(s4 - s6);
462
2.65M
  x7 = fdct_round_shift(s5 - s7);
463
2.65M
  x8 = s8 + s10;
464
2.65M
  x9 = s9 + s11;
465
2.65M
  x10 = s8 - s10;
466
2.65M
  x11 = s9 - s11;
467
2.65M
  x12 = fdct_round_shift(s12 + s14);
468
2.65M
  x13 = fdct_round_shift(s13 + s15);
469
2.65M
  x14 = fdct_round_shift(s12 - s14);
470
2.65M
  x15 = fdct_round_shift(s13 - s15);
471
472
  // stage 4
473
2.65M
  s2 = (-cospi_16_64) * (x2 + x3);
474
2.65M
  s3 = cospi_16_64 * (x2 - x3);
475
2.65M
  s6 = cospi_16_64 * (x6 + x7);
476
2.65M
  s7 = cospi_16_64 * (-x6 + x7);
477
2.65M
  s10 = cospi_16_64 * (x10 + x11);
478
2.65M
  s11 = cospi_16_64 * (-x10 + x11);
479
2.65M
  s14 = (-cospi_16_64) * (x14 + x15);
480
2.65M
  s15 = cospi_16_64 * (x14 - x15);
481
482
2.65M
  x2 = fdct_round_shift(s2);
483
2.65M
  x3 = fdct_round_shift(s3);
484
2.65M
  x6 = fdct_round_shift(s6);
485
2.65M
  x7 = fdct_round_shift(s7);
486
2.65M
  x10 = fdct_round_shift(s10);
487
2.65M
  x11 = fdct_round_shift(s11);
488
2.65M
  x14 = fdct_round_shift(s14);
489
2.65M
  x15 = fdct_round_shift(s15);
490
491
2.65M
  output[0] = (tran_low_t)x0;
492
2.65M
  output[1] = (tran_low_t)-x8;
493
2.65M
  output[2] = (tran_low_t)x12;
494
2.65M
  output[3] = (tran_low_t)-x4;
495
2.65M
  output[4] = (tran_low_t)x6;
496
2.65M
  output[5] = (tran_low_t)x14;
497
2.65M
  output[6] = (tran_low_t)x10;
498
2.65M
  output[7] = (tran_low_t)x2;
499
2.65M
  output[8] = (tran_low_t)x3;
500
2.65M
  output[9] = (tran_low_t)x11;
501
2.65M
  output[10] = (tran_low_t)x15;
502
2.65M
  output[11] = (tran_low_t)x7;
503
2.65M
  output[12] = (tran_low_t)x5;
504
2.65M
  output[13] = (tran_low_t)-x13;
505
2.65M
  output[14] = (tran_low_t)x9;
506
2.65M
  output[15] = (tran_low_t)-x1;
507
2.65M
}
508
509
static const transform_2d FHT_4[] = {
510
  { fdct4, fdct4 },   // DCT_DCT  = 0
511
  { fadst4, fdct4 },  // ADST_DCT = 1
512
  { fdct4, fadst4 },  // DCT_ADST = 2
513
  { fadst4, fadst4 }  // ADST_ADST = 3
514
};
515
516
static const transform_2d FHT_8[] = {
517
  { fdct8, fdct8 },   // DCT_DCT  = 0
518
  { fadst8, fdct8 },  // ADST_DCT = 1
519
  { fdct8, fadst8 },  // DCT_ADST = 2
520
  { fadst8, fadst8 }  // ADST_ADST = 3
521
};
522
523
static const transform_2d FHT_16[] = {
524
  { fdct16, fdct16 },   // DCT_DCT  = 0
525
  { fadst16, fdct16 },  // ADST_DCT = 1
526
  { fdct16, fadst16 },  // DCT_ADST = 2
527
  { fadst16, fadst16 }  // ADST_ADST = 3
528
};
529
530
void vp9_fht4x4_c(const int16_t *input, tran_low_t *output, int stride,
531
1.14M
                  int tx_type) {
532
1.14M
  if (tx_type == DCT_DCT) {
533
0
    vpx_fdct4x4_c(input, output, stride);
534
1.14M
  } else {
535
1.14M
    tran_low_t out[4 * 4];
536
1.14M
    int i, j;
537
1.14M
    tran_low_t temp_in[4], temp_out[4];
538
1.14M
    const transform_2d ht = FHT_4[tx_type];
539
540
    // Columns
541
5.74M
    for (i = 0; i < 4; ++i) {
542
22.9M
      for (j = 0; j < 4; ++j) temp_in[j] = input[j * stride + i] * 16;
543
4.59M
      if (i == 0 && temp_in[0]) temp_in[0] += 1;
544
4.59M
      ht.cols(temp_in, temp_out);
545
22.9M
      for (j = 0; j < 4; ++j) out[j * 4 + i] = temp_out[j];
546
4.59M
    }
547
548
    // Rows
549
5.74M
    for (i = 0; i < 4; ++i) {
550
22.9M
      for (j = 0; j < 4; ++j) temp_in[j] = out[j + i * 4];
551
4.59M
      ht.rows(temp_in, temp_out);
552
22.9M
      for (j = 0; j < 4; ++j) output[j + i * 4] = (temp_out[j] + 1) >> 2;
553
4.59M
    }
554
1.14M
  }
555
1.14M
}
556
557
void vp9_fht8x8_c(const int16_t *input, tran_low_t *output, int stride,
558
406k
                  int tx_type) {
559
406k
  if (tx_type == DCT_DCT) {
560
0
    vpx_fdct8x8_c(input, output, stride);
561
406k
  } else {
562
406k
    tran_low_t out[64];
563
406k
    int i, j;
564
406k
    tran_low_t temp_in[8], temp_out[8];
565
406k
    const transform_2d ht = FHT_8[tx_type];
566
567
    // Columns
568
3.65M
    for (i = 0; i < 8; ++i) {
569
29.2M
      for (j = 0; j < 8; ++j) temp_in[j] = input[j * stride + i] * 4;
570
3.25M
      ht.cols(temp_in, temp_out);
571
29.2M
      for (j = 0; j < 8; ++j) out[j * 8 + i] = temp_out[j];
572
3.25M
    }
573
574
    // Rows
575
3.65M
    for (i = 0; i < 8; ++i) {
576
29.2M
      for (j = 0; j < 8; ++j) temp_in[j] = out[j + i * 8];
577
3.25M
      ht.rows(temp_in, temp_out);
578
29.2M
      for (j = 0; j < 8; ++j)
579
26.0M
        output[j + i * 8] = (temp_out[j] + (temp_out[j] < 0)) >> 1;
580
3.25M
    }
581
406k
  }
582
406k
}
583
584
/* 4-point reversible, orthonormal Walsh-Hadamard in 3.5 adds, 0.5 shifts per
585
   pixel. */
586
26.0k
void vp9_fwht4x4_c(const int16_t *input, tran_low_t *output, int stride) {
587
26.0k
  int i;
588
26.0k
  tran_high_t a1, b1, c1, d1, e1;
589
26.0k
  const int16_t *ip_pass0 = input;
590
26.0k
  const tran_low_t *ip = NULL;
591
26.0k
  tran_low_t *op = output;
592
593
130k
  for (i = 0; i < 4; i++) {
594
104k
    a1 = ip_pass0[0 * stride];
595
104k
    b1 = ip_pass0[1 * stride];
596
104k
    c1 = ip_pass0[2 * stride];
597
104k
    d1 = ip_pass0[3 * stride];
598
599
104k
    a1 += b1;
600
104k
    d1 = d1 - c1;
601
104k
    e1 = (a1 - d1) >> 1;
602
104k
    b1 = e1 - b1;
603
104k
    c1 = e1 - c1;
604
104k
    a1 -= c1;
605
104k
    d1 += b1;
606
104k
    op[0] = (tran_low_t)a1;
607
104k
    op[4] = (tran_low_t)c1;
608
104k
    op[8] = (tran_low_t)d1;
609
104k
    op[12] = (tran_low_t)b1;
610
611
104k
    ip_pass0++;
612
104k
    op++;
613
104k
  }
614
26.0k
  ip = output;
615
26.0k
  op = output;
616
617
130k
  for (i = 0; i < 4; i++) {
618
104k
    a1 = ip[0];
619
104k
    b1 = ip[1];
620
104k
    c1 = ip[2];
621
104k
    d1 = ip[3];
622
623
104k
    a1 += b1;
624
104k
    d1 -= c1;
625
104k
    e1 = (a1 - d1) >> 1;
626
104k
    b1 = e1 - b1;
627
104k
    c1 = e1 - c1;
628
104k
    a1 -= c1;
629
104k
    d1 += b1;
630
104k
    op[0] = (tran_low_t)(a1 * UNIT_QUANT_FACTOR);
631
104k
    op[1] = (tran_low_t)(c1 * UNIT_QUANT_FACTOR);
632
104k
    op[2] = (tran_low_t)(d1 * UNIT_QUANT_FACTOR);
633
104k
    op[3] = (tran_low_t)(b1 * UNIT_QUANT_FACTOR);
634
635
104k
    ip += 4;
636
104k
    op += 4;
637
104k
  }
638
26.0k
}
639
640
void vp9_fht16x16_c(const int16_t *input, tran_low_t *output, int stride,
641
131k
                    int tx_type) {
642
131k
  if (tx_type == DCT_DCT) {
643
0
    vpx_fdct16x16_c(input, output, stride);
644
131k
  } else {
645
131k
    tran_low_t out[256];
646
131k
    int i, j;
647
131k
    tran_low_t temp_in[16], temp_out[16];
648
131k
    const transform_2d ht = FHT_16[tx_type];
649
650
    // Columns
651
2.24M
    for (i = 0; i < 16; ++i) {
652
35.8M
      for (j = 0; j < 16; ++j) temp_in[j] = input[j * stride + i] * 4;
653
2.11M
      ht.cols(temp_in, temp_out);
654
35.8M
      for (j = 0; j < 16; ++j)
655
33.7M
        out[j * 16 + i] = (temp_out[j] + 1 + (temp_out[j] < 0)) >> 2;
656
2.11M
    }
657
658
    // Rows
659
2.24M
    for (i = 0; i < 16; ++i) {
660
35.8M
      for (j = 0; j < 16; ++j) temp_in[j] = out[j + i * 16];
661
2.11M
      ht.rows(temp_in, temp_out);
662
35.8M
      for (j = 0; j < 16; ++j) output[j + i * 16] = temp_out[j];
663
2.11M
    }
664
131k
  }
665
131k
}
666
667
#if CONFIG_VP9_HIGHBITDEPTH
668
void vp9_highbd_fht4x4_c(const int16_t *input, tran_low_t *output, int stride,
669
1.14M
                         int tx_type) {
670
1.14M
  vp9_fht4x4_c(input, output, stride, tx_type);
671
1.14M
}
672
673
void vp9_highbd_fht8x8_c(const int16_t *input, tran_low_t *output, int stride,
674
406k
                         int tx_type) {
675
406k
  vp9_fht8x8_c(input, output, stride, tx_type);
676
406k
}
677
678
void vp9_highbd_fwht4x4_c(const int16_t *input, tran_low_t *output,
679
26.0k
                          int stride) {
680
26.0k
  vp9_fwht4x4_c(input, output, stride);
681
26.0k
}
682
683
void vp9_highbd_fht16x16_c(const int16_t *input, tran_low_t *output, int stride,
684
131k
                           int tx_type) {
685
131k
  vp9_fht16x16_c(input, output, stride, tx_type);
686
131k
}
687
#endif  // CONFIG_VP9_HIGHBITDEPTH