Coverage Report

Created: 2026-10-28 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvpx/vpx_dsp/fwd_txfm.c
Line
Count
Source
1
/*
2
 *  Copyright (c) 2015 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 "./vpx_dsp_rtcd.h"
13
#include "vpx_dsp/fwd_txfm.h"
14
15
827k
void vpx_fdct4x4_c(const int16_t *input, tran_low_t *output, int stride) {
16
  // The 2D transform is done with two passes which are actually pretty
17
  // similar. In the first one, we transform the columns and transpose
18
  // the results. In the second one, we transform the rows. To achieve that,
19
  // as the first pass results are transposed, we transpose the columns (that
20
  // is the transposed rows) and transpose the results (so that it goes back
21
  // in normal/row positions).
22
827k
  int pass;
23
  // We need an intermediate buffer between passes.
24
827k
  tran_low_t intermediate[4 * 4];
25
827k
  const tran_low_t *in_low = NULL;
26
827k
  tran_low_t *out = intermediate;
27
  // Do the two transform/transpose passes
28
2.48M
  for (pass = 0; pass < 2; ++pass) {
29
1.65M
    tran_high_t in_high[4];    // canbe16
30
1.65M
    tran_high_t step[4];       // canbe16
31
1.65M
    tran_high_t temp1, temp2;  // needs32
32
1.65M
    int i;
33
8.27M
    for (i = 0; i < 4; ++i) {
34
      // Load inputs.
35
6.62M
      if (pass == 0) {
36
3.31M
        in_high[0] = input[0 * stride] * 16;
37
3.31M
        in_high[1] = input[1 * stride] * 16;
38
3.31M
        in_high[2] = input[2 * stride] * 16;
39
3.31M
        in_high[3] = input[3 * stride] * 16;
40
3.31M
        if (i == 0 && in_high[0]) {
41
764k
          ++in_high[0];
42
764k
        }
43
3.31M
      } else {
44
3.31M
        assert(in_low != NULL);
45
3.31M
        in_high[0] = in_low[0 * 4];
46
3.31M
        in_high[1] = in_low[1 * 4];
47
3.31M
        in_high[2] = in_low[2 * 4];
48
3.31M
        in_high[3] = in_low[3 * 4];
49
3.31M
        ++in_low;
50
3.31M
      }
51
      // Transform.
52
6.62M
      step[0] = in_high[0] + in_high[3];
53
6.62M
      step[1] = in_high[1] + in_high[2];
54
6.62M
      step[2] = in_high[1] - in_high[2];
55
6.62M
      step[3] = in_high[0] - in_high[3];
56
6.62M
      temp1 = (step[0] + step[1]) * cospi_16_64;
57
6.62M
      temp2 = (step[0] - step[1]) * cospi_16_64;
58
6.62M
      out[0] = (tran_low_t)fdct_round_shift(temp1);
59
6.62M
      out[2] = (tran_low_t)fdct_round_shift(temp2);
60
6.62M
      temp1 = step[2] * cospi_24_64 + step[3] * cospi_8_64;
61
6.62M
      temp2 = -step[2] * cospi_8_64 + step[3] * cospi_24_64;
62
6.62M
      out[1] = (tran_low_t)fdct_round_shift(temp1);
63
6.62M
      out[3] = (tran_low_t)fdct_round_shift(temp2);
64
      // Do next column (which is a transposed row in second/horizontal pass)
65
6.62M
      ++input;
66
6.62M
      out += 4;
67
6.62M
    }
68
    // Setup in/out for next pass.
69
1.65M
    in_low = intermediate;
70
1.65M
    out = output;
71
1.65M
  }
72
73
827k
  {
74
827k
    int i, j;
75
4.13M
    for (i = 0; i < 4; ++i) {
76
16.5M
      for (j = 0; j < 4; ++j) output[j + i * 4] = (output[j + i * 4] + 1) >> 2;
77
3.31M
    }
78
827k
  }
79
827k
}
80
81
0
void vpx_fdct4x4_1_c(const int16_t *input, tran_low_t *output, int stride) {
82
0
  int r, c;
83
0
  tran_low_t sum = 0;
84
0
  for (r = 0; r < 4; ++r)
85
0
    for (c = 0; c < 4; ++c) sum += input[r * stride + c];
86
87
0
  output[0] = sum * 2;
88
0
}
89
90
268k
void vpx_fdct8x8_c(const int16_t *input, tran_low_t *output, int stride) {
91
268k
  int i, j;
92
268k
  tran_low_t intermediate[64];
93
268k
  int pass;
94
268k
  tran_low_t *out = intermediate;
95
268k
  const tran_low_t *in = NULL;
96
97
  // Transform columns
98
806k
  for (pass = 0; pass < 2; ++pass) {
99
537k
    tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;  // canbe16
100
537k
    tran_high_t t0, t1, t2, t3;                  // needs32
101
537k
    tran_high_t x0, x1, x2, x3;                  // canbe16
102
103
4.84M
    for (i = 0; i < 8; i++) {
104
      // stage 1
105
4.30M
      if (pass == 0) {
106
2.15M
        s0 = (input[0 * stride] + input[7 * stride]) * 4;
107
2.15M
        s1 = (input[1 * stride] + input[6 * stride]) * 4;
108
2.15M
        s2 = (input[2 * stride] + input[5 * stride]) * 4;
109
2.15M
        s3 = (input[3 * stride] + input[4 * stride]) * 4;
110
2.15M
        s4 = (input[3 * stride] - input[4 * stride]) * 4;
111
2.15M
        s5 = (input[2 * stride] - input[5 * stride]) * 4;
112
2.15M
        s6 = (input[1 * stride] - input[6 * stride]) * 4;
113
2.15M
        s7 = (input[0 * stride] - input[7 * stride]) * 4;
114
2.15M
        ++input;
115
2.15M
      } else {
116
2.15M
        s0 = in[0 * 8] + in[7 * 8];
117
2.15M
        s1 = in[1 * 8] + in[6 * 8];
118
2.15M
        s2 = in[2 * 8] + in[5 * 8];
119
2.15M
        s3 = in[3 * 8] + in[4 * 8];
120
2.15M
        s4 = in[3 * 8] - in[4 * 8];
121
2.15M
        s5 = in[2 * 8] - in[5 * 8];
122
2.15M
        s6 = in[1 * 8] - in[6 * 8];
123
2.15M
        s7 = in[0 * 8] - in[7 * 8];
124
2.15M
        ++in;
125
2.15M
      }
126
127
      // fdct4(step, step);
128
4.30M
      x0 = s0 + s3;
129
4.30M
      x1 = s1 + s2;
130
4.30M
      x2 = s1 - s2;
131
4.30M
      x3 = s0 - s3;
132
4.30M
      t0 = (x0 + x1) * cospi_16_64;
133
4.30M
      t1 = (x0 - x1) * cospi_16_64;
134
4.30M
      t2 = x2 * cospi_24_64 + x3 * cospi_8_64;
135
4.30M
      t3 = -x2 * cospi_8_64 + x3 * cospi_24_64;
136
4.30M
      out[0] = (tran_low_t)fdct_round_shift(t0);
137
4.30M
      out[2] = (tran_low_t)fdct_round_shift(t2);
138
4.30M
      out[4] = (tran_low_t)fdct_round_shift(t1);
139
4.30M
      out[6] = (tran_low_t)fdct_round_shift(t3);
140
141
      // Stage 2
142
4.30M
      t0 = (s6 - s5) * cospi_16_64;
143
4.30M
      t1 = (s6 + s5) * cospi_16_64;
144
4.30M
      t2 = fdct_round_shift(t0);
145
4.30M
      t3 = fdct_round_shift(t1);
146
147
      // Stage 3
148
4.30M
      x0 = s4 + t2;
149
4.30M
      x1 = s4 - t2;
150
4.30M
      x2 = s7 - t3;
151
4.30M
      x3 = s7 + t3;
152
153
      // Stage 4
154
4.30M
      t0 = x0 * cospi_28_64 + x3 * cospi_4_64;
155
4.30M
      t1 = x1 * cospi_12_64 + x2 * cospi_20_64;
156
4.30M
      t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
157
4.30M
      t3 = x3 * cospi_28_64 + x0 * -cospi_4_64;
158
4.30M
      out[1] = (tran_low_t)fdct_round_shift(t0);
159
4.30M
      out[3] = (tran_low_t)fdct_round_shift(t2);
160
4.30M
      out[5] = (tran_low_t)fdct_round_shift(t1);
161
4.30M
      out[7] = (tran_low_t)fdct_round_shift(t3);
162
4.30M
      out += 8;
163
4.30M
    }
164
537k
    in = intermediate;
165
537k
    out = output;
166
537k
  }
167
168
  // Rows
169
2.42M
  for (i = 0; i < 8; ++i) {
170
19.3M
    for (j = 0; j < 8; ++j) output[j + i * 8] /= 2;
171
2.15M
  }
172
268k
}
173
174
3.95k
void vpx_fdct8x8_1_c(const int16_t *input, tran_low_t *output, int stride) {
175
3.95k
  int r, c;
176
3.95k
  tran_low_t sum = 0;
177
35.6k
  for (r = 0; r < 8; ++r)
178
285k
    for (c = 0; c < 8; ++c) sum += input[r * stride + c];
179
180
3.95k
  output[0] = sum;
181
3.95k
}
182
183
66.9k
void vpx_fdct16x16_c(const int16_t *input, tran_low_t *output, int stride) {
184
  // The 2D transform is done with two passes which are actually pretty
185
  // similar. In the first one, we transform the columns and transpose
186
  // the results. In the second one, we transform the rows. To achieve that,
187
  // as the first pass results are transposed, we transpose the columns (that
188
  // is the transposed rows) and transpose the results (so that it goes back
189
  // in normal/row positions).
190
66.9k
  int pass;
191
  // We need an intermediate buffer between passes.
192
66.9k
  tran_low_t intermediate[256];
193
66.9k
  const tran_low_t *in_low = NULL;
194
66.9k
  tran_low_t *out = intermediate;
195
  // Do the two transform/transpose passes
196
200k
  for (pass = 0; pass < 2; ++pass) {
197
133k
    tran_high_t step1[8];      // canbe16
198
133k
    tran_high_t step2[8];      // canbe16
199
133k
    tran_high_t step3[8];      // canbe16
200
133k
    tran_high_t in_high[8];    // canbe16
201
133k
    tran_high_t temp1, temp2;  // needs32
202
133k
    int i;
203
2.27M
    for (i = 0; i < 16; i++) {
204
2.14M
      if (0 == pass) {
205
        // Calculate input for the first 8 results.
206
1.07M
        in_high[0] = (input[0 * stride] + input[15 * stride]) * 4;
207
1.07M
        in_high[1] = (input[1 * stride] + input[14 * stride]) * 4;
208
1.07M
        in_high[2] = (input[2 * stride] + input[13 * stride]) * 4;
209
1.07M
        in_high[3] = (input[3 * stride] + input[12 * stride]) * 4;
210
1.07M
        in_high[4] = (input[4 * stride] + input[11 * stride]) * 4;
211
1.07M
        in_high[5] = (input[5 * stride] + input[10 * stride]) * 4;
212
1.07M
        in_high[6] = (input[6 * stride] + input[9 * stride]) * 4;
213
1.07M
        in_high[7] = (input[7 * stride] + input[8 * stride]) * 4;
214
        // Calculate input for the next 8 results.
215
1.07M
        step1[0] = (input[7 * stride] - input[8 * stride]) * 4;
216
1.07M
        step1[1] = (input[6 * stride] - input[9 * stride]) * 4;
217
1.07M
        step1[2] = (input[5 * stride] - input[10 * stride]) * 4;
218
1.07M
        step1[3] = (input[4 * stride] - input[11 * stride]) * 4;
219
1.07M
        step1[4] = (input[3 * stride] - input[12 * stride]) * 4;
220
1.07M
        step1[5] = (input[2 * stride] - input[13 * stride]) * 4;
221
1.07M
        step1[6] = (input[1 * stride] - input[14 * stride]) * 4;
222
1.07M
        step1[7] = (input[0 * stride] - input[15 * stride]) * 4;
223
1.07M
      } else {
224
        // Calculate input for the first 8 results.
225
1.07M
        assert(in_low != NULL);
226
1.07M
        in_high[0] = ((in_low[0 * 16] + 1) >> 2) + ((in_low[15 * 16] + 1) >> 2);
227
1.07M
        in_high[1] = ((in_low[1 * 16] + 1) >> 2) + ((in_low[14 * 16] + 1) >> 2);
228
1.07M
        in_high[2] = ((in_low[2 * 16] + 1) >> 2) + ((in_low[13 * 16] + 1) >> 2);
229
1.07M
        in_high[3] = ((in_low[3 * 16] + 1) >> 2) + ((in_low[12 * 16] + 1) >> 2);
230
1.07M
        in_high[4] = ((in_low[4 * 16] + 1) >> 2) + ((in_low[11 * 16] + 1) >> 2);
231
1.07M
        in_high[5] = ((in_low[5 * 16] + 1) >> 2) + ((in_low[10 * 16] + 1) >> 2);
232
1.07M
        in_high[6] = ((in_low[6 * 16] + 1) >> 2) + ((in_low[9 * 16] + 1) >> 2);
233
1.07M
        in_high[7] = ((in_low[7 * 16] + 1) >> 2) + ((in_low[8 * 16] + 1) >> 2);
234
        // Calculate input for the next 8 results.
235
1.07M
        step1[0] = ((in_low[7 * 16] + 1) >> 2) - ((in_low[8 * 16] + 1) >> 2);
236
1.07M
        step1[1] = ((in_low[6 * 16] + 1) >> 2) - ((in_low[9 * 16] + 1) >> 2);
237
1.07M
        step1[2] = ((in_low[5 * 16] + 1) >> 2) - ((in_low[10 * 16] + 1) >> 2);
238
1.07M
        step1[3] = ((in_low[4 * 16] + 1) >> 2) - ((in_low[11 * 16] + 1) >> 2);
239
1.07M
        step1[4] = ((in_low[3 * 16] + 1) >> 2) - ((in_low[12 * 16] + 1) >> 2);
240
1.07M
        step1[5] = ((in_low[2 * 16] + 1) >> 2) - ((in_low[13 * 16] + 1) >> 2);
241
1.07M
        step1[6] = ((in_low[1 * 16] + 1) >> 2) - ((in_low[14 * 16] + 1) >> 2);
242
1.07M
        step1[7] = ((in_low[0 * 16] + 1) >> 2) - ((in_low[15 * 16] + 1) >> 2);
243
1.07M
        in_low++;
244
1.07M
      }
245
      // Work on the first eight values; fdct8(input, even_results);
246
2.14M
      {
247
2.14M
        tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;  // canbe16
248
2.14M
        tran_high_t t0, t1, t2, t3;                  // needs32
249
2.14M
        tran_high_t x0, x1, x2, x3;                  // canbe16
250
251
        // stage 1
252
2.14M
        s0 = in_high[0] + in_high[7];
253
2.14M
        s1 = in_high[1] + in_high[6];
254
2.14M
        s2 = in_high[2] + in_high[5];
255
2.14M
        s3 = in_high[3] + in_high[4];
256
2.14M
        s4 = in_high[3] - in_high[4];
257
2.14M
        s5 = in_high[2] - in_high[5];
258
2.14M
        s6 = in_high[1] - in_high[6];
259
2.14M
        s7 = in_high[0] - in_high[7];
260
261
        // fdct4(step, step);
262
2.14M
        x0 = s0 + s3;
263
2.14M
        x1 = s1 + s2;
264
2.14M
        x2 = s1 - s2;
265
2.14M
        x3 = s0 - s3;
266
2.14M
        t0 = (x0 + x1) * cospi_16_64;
267
2.14M
        t1 = (x0 - x1) * cospi_16_64;
268
2.14M
        t2 = x3 * cospi_8_64 + x2 * cospi_24_64;
269
2.14M
        t3 = x3 * cospi_24_64 - x2 * cospi_8_64;
270
2.14M
        out[0] = (tran_low_t)fdct_round_shift(t0);
271
2.14M
        out[4] = (tran_low_t)fdct_round_shift(t2);
272
2.14M
        out[8] = (tran_low_t)fdct_round_shift(t1);
273
2.14M
        out[12] = (tran_low_t)fdct_round_shift(t3);
274
275
        // Stage 2
276
2.14M
        t0 = (s6 - s5) * cospi_16_64;
277
2.14M
        t1 = (s6 + s5) * cospi_16_64;
278
2.14M
        t2 = fdct_round_shift(t0);
279
2.14M
        t3 = fdct_round_shift(t1);
280
281
        // Stage 3
282
2.14M
        x0 = s4 + t2;
283
2.14M
        x1 = s4 - t2;
284
2.14M
        x2 = s7 - t3;
285
2.14M
        x3 = s7 + t3;
286
287
        // Stage 4
288
2.14M
        t0 = x0 * cospi_28_64 + x3 * cospi_4_64;
289
2.14M
        t1 = x1 * cospi_12_64 + x2 * cospi_20_64;
290
2.14M
        t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
291
2.14M
        t3 = x3 * cospi_28_64 + x0 * -cospi_4_64;
292
2.14M
        out[2] = (tran_low_t)fdct_round_shift(t0);
293
2.14M
        out[6] = (tran_low_t)fdct_round_shift(t2);
294
2.14M
        out[10] = (tran_low_t)fdct_round_shift(t1);
295
2.14M
        out[14] = (tran_low_t)fdct_round_shift(t3);
296
2.14M
      }
297
      // Work on the next eight values; step1 -> odd_results
298
2.14M
      {
299
        // step 2
300
2.14M
        temp1 = (step1[5] - step1[2]) * cospi_16_64;
301
2.14M
        temp2 = (step1[4] - step1[3]) * cospi_16_64;
302
2.14M
        step2[2] = fdct_round_shift(temp1);
303
2.14M
        step2[3] = fdct_round_shift(temp2);
304
2.14M
        temp1 = (step1[4] + step1[3]) * cospi_16_64;
305
2.14M
        temp2 = (step1[5] + step1[2]) * cospi_16_64;
306
2.14M
        step2[4] = fdct_round_shift(temp1);
307
2.14M
        step2[5] = fdct_round_shift(temp2);
308
        // step 3
309
2.14M
        step3[0] = step1[0] + step2[3];
310
2.14M
        step3[1] = step1[1] + step2[2];
311
2.14M
        step3[2] = step1[1] - step2[2];
312
2.14M
        step3[3] = step1[0] - step2[3];
313
2.14M
        step3[4] = step1[7] - step2[4];
314
2.14M
        step3[5] = step1[6] - step2[5];
315
2.14M
        step3[6] = step1[6] + step2[5];
316
2.14M
        step3[7] = step1[7] + step2[4];
317
        // step 4
318
2.14M
        temp1 = step3[1] * -cospi_8_64 + step3[6] * cospi_24_64;
319
2.14M
        temp2 = step3[2] * cospi_24_64 + step3[5] * cospi_8_64;
320
2.14M
        step2[1] = fdct_round_shift(temp1);
321
2.14M
        step2[2] = fdct_round_shift(temp2);
322
2.14M
        temp1 = step3[2] * cospi_8_64 - step3[5] * cospi_24_64;
323
2.14M
        temp2 = step3[1] * cospi_24_64 + step3[6] * cospi_8_64;
324
2.14M
        step2[5] = fdct_round_shift(temp1);
325
2.14M
        step2[6] = fdct_round_shift(temp2);
326
        // step 5
327
2.14M
        step1[0] = step3[0] + step2[1];
328
2.14M
        step1[1] = step3[0] - step2[1];
329
2.14M
        step1[2] = step3[3] + step2[2];
330
2.14M
        step1[3] = step3[3] - step2[2];
331
2.14M
        step1[4] = step3[4] - step2[5];
332
2.14M
        step1[5] = step3[4] + step2[5];
333
2.14M
        step1[6] = step3[7] - step2[6];
334
2.14M
        step1[7] = step3[7] + step2[6];
335
        // step 6
336
2.14M
        temp1 = step1[0] * cospi_30_64 + step1[7] * cospi_2_64;
337
2.14M
        temp2 = step1[1] * cospi_14_64 + step1[6] * cospi_18_64;
338
2.14M
        out[1] = (tran_low_t)fdct_round_shift(temp1);
339
2.14M
        out[9] = (tran_low_t)fdct_round_shift(temp2);
340
2.14M
        temp1 = step1[2] * cospi_22_64 + step1[5] * cospi_10_64;
341
2.14M
        temp2 = step1[3] * cospi_6_64 + step1[4] * cospi_26_64;
342
2.14M
        out[5] = (tran_low_t)fdct_round_shift(temp1);
343
2.14M
        out[13] = (tran_low_t)fdct_round_shift(temp2);
344
2.14M
        temp1 = step1[3] * -cospi_26_64 + step1[4] * cospi_6_64;
345
2.14M
        temp2 = step1[2] * -cospi_10_64 + step1[5] * cospi_22_64;
346
2.14M
        out[3] = (tran_low_t)fdct_round_shift(temp1);
347
2.14M
        out[11] = (tran_low_t)fdct_round_shift(temp2);
348
2.14M
        temp1 = step1[1] * -cospi_18_64 + step1[6] * cospi_14_64;
349
2.14M
        temp2 = step1[0] * -cospi_2_64 + step1[7] * cospi_30_64;
350
2.14M
        out[7] = (tran_low_t)fdct_round_shift(temp1);
351
2.14M
        out[15] = (tran_low_t)fdct_round_shift(temp2);
352
2.14M
      }
353
      // Do next column (which is a transposed row in second/horizontal pass)
354
2.14M
      input++;
355
2.14M
      out += 16;
356
2.14M
    }
357
    // Setup in/out for next pass.
358
133k
    in_low = intermediate;
359
133k
    out = output;
360
133k
  }
361
66.9k
}
362
363
1.45k
void vpx_fdct16x16_1_c(const int16_t *input, tran_low_t *output, int stride) {
364
1.45k
  int r, c;
365
1.45k
  int sum = 0;
366
24.7k
  for (r = 0; r < 16; ++r)
367
396k
    for (c = 0; c < 16; ++c) sum += input[r * stride + c];
368
369
1.45k
  output[0] = (tran_low_t)(sum >> 1);
370
1.45k
}
371
372
231M
static INLINE tran_high_t dct_32_round(tran_high_t input) {
373
231M
  tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
374
  // TODO(debargha, peter.derivaz): Find new bounds for this assert,
375
  // and make the bounds consts.
376
  // assert(-131072 <= rv && rv <= 131071);
377
231M
  return rv;
378
231M
}
379
380
54.3M
static INLINE tran_high_t half_round_shift(tran_high_t input) {
381
54.3M
  tran_high_t rv = (input + 1 + (input < 0)) >> 2;
382
54.3M
  return rv;
383
54.3M
}
384
385
3.51M
void vpx_fdct32(const tran_high_t *input, tran_high_t *output, int round) {
386
3.51M
  tran_high_t step[32];
387
  // Stage 1
388
3.51M
  step[0] = input[0] + input[(32 - 1)];
389
3.51M
  step[1] = input[1] + input[(32 - 2)];
390
3.51M
  step[2] = input[2] + input[(32 - 3)];
391
3.51M
  step[3] = input[3] + input[(32 - 4)];
392
3.51M
  step[4] = input[4] + input[(32 - 5)];
393
3.51M
  step[5] = input[5] + input[(32 - 6)];
394
3.51M
  step[6] = input[6] + input[(32 - 7)];
395
3.51M
  step[7] = input[7] + input[(32 - 8)];
396
3.51M
  step[8] = input[8] + input[(32 - 9)];
397
3.51M
  step[9] = input[9] + input[(32 - 10)];
398
3.51M
  step[10] = input[10] + input[(32 - 11)];
399
3.51M
  step[11] = input[11] + input[(32 - 12)];
400
3.51M
  step[12] = input[12] + input[(32 - 13)];
401
3.51M
  step[13] = input[13] + input[(32 - 14)];
402
3.51M
  step[14] = input[14] + input[(32 - 15)];
403
3.51M
  step[15] = input[15] + input[(32 - 16)];
404
3.51M
  step[16] = -input[16] + input[(32 - 17)];
405
3.51M
  step[17] = -input[17] + input[(32 - 18)];
406
3.51M
  step[18] = -input[18] + input[(32 - 19)];
407
3.51M
  step[19] = -input[19] + input[(32 - 20)];
408
3.51M
  step[20] = -input[20] + input[(32 - 21)];
409
3.51M
  step[21] = -input[21] + input[(32 - 22)];
410
3.51M
  step[22] = -input[22] + input[(32 - 23)];
411
3.51M
  step[23] = -input[23] + input[(32 - 24)];
412
3.51M
  step[24] = -input[24] + input[(32 - 25)];
413
3.51M
  step[25] = -input[25] + input[(32 - 26)];
414
3.51M
  step[26] = -input[26] + input[(32 - 27)];
415
3.51M
  step[27] = -input[27] + input[(32 - 28)];
416
3.51M
  step[28] = -input[28] + input[(32 - 29)];
417
3.51M
  step[29] = -input[29] + input[(32 - 30)];
418
3.51M
  step[30] = -input[30] + input[(32 - 31)];
419
3.51M
  step[31] = -input[31] + input[(32 - 32)];
420
421
  // Stage 2
422
3.51M
  output[0] = step[0] + step[16 - 1];
423
3.51M
  output[1] = step[1] + step[16 - 2];
424
3.51M
  output[2] = step[2] + step[16 - 3];
425
3.51M
  output[3] = step[3] + step[16 - 4];
426
3.51M
  output[4] = step[4] + step[16 - 5];
427
3.51M
  output[5] = step[5] + step[16 - 6];
428
3.51M
  output[6] = step[6] + step[16 - 7];
429
3.51M
  output[7] = step[7] + step[16 - 8];
430
3.51M
  output[8] = -step[8] + step[16 - 9];
431
3.51M
  output[9] = -step[9] + step[16 - 10];
432
3.51M
  output[10] = -step[10] + step[16 - 11];
433
3.51M
  output[11] = -step[11] + step[16 - 12];
434
3.51M
  output[12] = -step[12] + step[16 - 13];
435
3.51M
  output[13] = -step[13] + step[16 - 14];
436
3.51M
  output[14] = -step[14] + step[16 - 15];
437
3.51M
  output[15] = -step[15] + step[16 - 16];
438
439
3.51M
  output[16] = step[16];
440
3.51M
  output[17] = step[17];
441
3.51M
  output[18] = step[18];
442
3.51M
  output[19] = step[19];
443
444
3.51M
  output[20] = dct_32_round((-step[20] + step[27]) * cospi_16_64);
445
3.51M
  output[21] = dct_32_round((-step[21] + step[26]) * cospi_16_64);
446
3.51M
  output[22] = dct_32_round((-step[22] + step[25]) * cospi_16_64);
447
3.51M
  output[23] = dct_32_round((-step[23] + step[24]) * cospi_16_64);
448
449
3.51M
  output[24] = dct_32_round((step[24] + step[23]) * cospi_16_64);
450
3.51M
  output[25] = dct_32_round((step[25] + step[22]) * cospi_16_64);
451
3.51M
  output[26] = dct_32_round((step[26] + step[21]) * cospi_16_64);
452
3.51M
  output[27] = dct_32_round((step[27] + step[20]) * cospi_16_64);
453
454
3.51M
  output[28] = step[28];
455
3.51M
  output[29] = step[29];
456
3.51M
  output[30] = step[30];
457
3.51M
  output[31] = step[31];
458
459
  // dump the magnitude by 4, hence the intermediate values are within
460
  // the range of 16 bits.
461
3.51M
  if (round) {
462
1.69M
    output[0] = half_round_shift(output[0]);
463
1.69M
    output[1] = half_round_shift(output[1]);
464
1.69M
    output[2] = half_round_shift(output[2]);
465
1.69M
    output[3] = half_round_shift(output[3]);
466
1.69M
    output[4] = half_round_shift(output[4]);
467
1.69M
    output[5] = half_round_shift(output[5]);
468
1.69M
    output[6] = half_round_shift(output[6]);
469
1.69M
    output[7] = half_round_shift(output[7]);
470
1.69M
    output[8] = half_round_shift(output[8]);
471
1.69M
    output[9] = half_round_shift(output[9]);
472
1.69M
    output[10] = half_round_shift(output[10]);
473
1.69M
    output[11] = half_round_shift(output[11]);
474
1.69M
    output[12] = half_round_shift(output[12]);
475
1.69M
    output[13] = half_round_shift(output[13]);
476
1.69M
    output[14] = half_round_shift(output[14]);
477
1.69M
    output[15] = half_round_shift(output[15]);
478
479
1.69M
    output[16] = half_round_shift(output[16]);
480
1.69M
    output[17] = half_round_shift(output[17]);
481
1.69M
    output[18] = half_round_shift(output[18]);
482
1.69M
    output[19] = half_round_shift(output[19]);
483
1.69M
    output[20] = half_round_shift(output[20]);
484
1.69M
    output[21] = half_round_shift(output[21]);
485
1.69M
    output[22] = half_round_shift(output[22]);
486
1.69M
    output[23] = half_round_shift(output[23]);
487
1.69M
    output[24] = half_round_shift(output[24]);
488
1.69M
    output[25] = half_round_shift(output[25]);
489
1.69M
    output[26] = half_round_shift(output[26]);
490
1.69M
    output[27] = half_round_shift(output[27]);
491
1.69M
    output[28] = half_round_shift(output[28]);
492
1.69M
    output[29] = half_round_shift(output[29]);
493
1.69M
    output[30] = half_round_shift(output[30]);
494
1.69M
    output[31] = half_round_shift(output[31]);
495
1.69M
  }
496
497
  // Stage 3
498
3.51M
  step[0] = output[0] + output[(8 - 1)];
499
3.51M
  step[1] = output[1] + output[(8 - 2)];
500
3.51M
  step[2] = output[2] + output[(8 - 3)];
501
3.51M
  step[3] = output[3] + output[(8 - 4)];
502
3.51M
  step[4] = -output[4] + output[(8 - 5)];
503
3.51M
  step[5] = -output[5] + output[(8 - 6)];
504
3.51M
  step[6] = -output[6] + output[(8 - 7)];
505
3.51M
  step[7] = -output[7] + output[(8 - 8)];
506
3.51M
  step[8] = output[8];
507
3.51M
  step[9] = output[9];
508
3.51M
  step[10] = dct_32_round((-output[10] + output[13]) * cospi_16_64);
509
3.51M
  step[11] = dct_32_round((-output[11] + output[12]) * cospi_16_64);
510
3.51M
  step[12] = dct_32_round((output[12] + output[11]) * cospi_16_64);
511
3.51M
  step[13] = dct_32_round((output[13] + output[10]) * cospi_16_64);
512
3.51M
  step[14] = output[14];
513
3.51M
  step[15] = output[15];
514
515
3.51M
  step[16] = output[16] + output[23];
516
3.51M
  step[17] = output[17] + output[22];
517
3.51M
  step[18] = output[18] + output[21];
518
3.51M
  step[19] = output[19] + output[20];
519
3.51M
  step[20] = -output[20] + output[19];
520
3.51M
  step[21] = -output[21] + output[18];
521
3.51M
  step[22] = -output[22] + output[17];
522
3.51M
  step[23] = -output[23] + output[16];
523
3.51M
  step[24] = -output[24] + output[31];
524
3.51M
  step[25] = -output[25] + output[30];
525
3.51M
  step[26] = -output[26] + output[29];
526
3.51M
  step[27] = -output[27] + output[28];
527
3.51M
  step[28] = output[28] + output[27];
528
3.51M
  step[29] = output[29] + output[26];
529
3.51M
  step[30] = output[30] + output[25];
530
3.51M
  step[31] = output[31] + output[24];
531
532
  // Stage 4
533
3.51M
  output[0] = step[0] + step[3];
534
3.51M
  output[1] = step[1] + step[2];
535
3.51M
  output[2] = -step[2] + step[1];
536
3.51M
  output[3] = -step[3] + step[0];
537
3.51M
  output[4] = step[4];
538
3.51M
  output[5] = dct_32_round((-step[5] + step[6]) * cospi_16_64);
539
3.51M
  output[6] = dct_32_round((step[6] + step[5]) * cospi_16_64);
540
3.51M
  output[7] = step[7];
541
3.51M
  output[8] = step[8] + step[11];
542
3.51M
  output[9] = step[9] + step[10];
543
3.51M
  output[10] = -step[10] + step[9];
544
3.51M
  output[11] = -step[11] + step[8];
545
3.51M
  output[12] = -step[12] + step[15];
546
3.51M
  output[13] = -step[13] + step[14];
547
3.51M
  output[14] = step[14] + step[13];
548
3.51M
  output[15] = step[15] + step[12];
549
550
3.51M
  output[16] = step[16];
551
3.51M
  output[17] = step[17];
552
3.51M
  output[18] = dct_32_round(step[18] * -cospi_8_64 + step[29] * cospi_24_64);
553
3.51M
  output[19] = dct_32_round(step[19] * -cospi_8_64 + step[28] * cospi_24_64);
554
3.51M
  output[20] = dct_32_round(step[20] * -cospi_24_64 + step[27] * -cospi_8_64);
555
3.51M
  output[21] = dct_32_round(step[21] * -cospi_24_64 + step[26] * -cospi_8_64);
556
3.51M
  output[22] = step[22];
557
3.51M
  output[23] = step[23];
558
3.51M
  output[24] = step[24];
559
3.51M
  output[25] = step[25];
560
3.51M
  output[26] = dct_32_round(step[26] * cospi_24_64 + step[21] * -cospi_8_64);
561
3.51M
  output[27] = dct_32_round(step[27] * cospi_24_64 + step[20] * -cospi_8_64);
562
3.51M
  output[28] = dct_32_round(step[28] * cospi_8_64 + step[19] * cospi_24_64);
563
3.51M
  output[29] = dct_32_round(step[29] * cospi_8_64 + step[18] * cospi_24_64);
564
3.51M
  output[30] = step[30];
565
3.51M
  output[31] = step[31];
566
567
  // Stage 5
568
3.51M
  step[0] = dct_32_round((output[0] + output[1]) * cospi_16_64);
569
3.51M
  step[1] = dct_32_round((-output[1] + output[0]) * cospi_16_64);
570
3.51M
  step[2] = dct_32_round(output[2] * cospi_24_64 + output[3] * cospi_8_64);
571
3.51M
  step[3] = dct_32_round(output[3] * cospi_24_64 - output[2] * cospi_8_64);
572
3.51M
  step[4] = output[4] + output[5];
573
3.51M
  step[5] = -output[5] + output[4];
574
3.51M
  step[6] = -output[6] + output[7];
575
3.51M
  step[7] = output[7] + output[6];
576
3.51M
  step[8] = output[8];
577
3.51M
  step[9] = dct_32_round(output[9] * -cospi_8_64 + output[14] * cospi_24_64);
578
3.51M
  step[10] = dct_32_round(output[10] * -cospi_24_64 + output[13] * -cospi_8_64);
579
3.51M
  step[11] = output[11];
580
3.51M
  step[12] = output[12];
581
3.51M
  step[13] = dct_32_round(output[13] * cospi_24_64 + output[10] * -cospi_8_64);
582
3.51M
  step[14] = dct_32_round(output[14] * cospi_8_64 + output[9] * cospi_24_64);
583
3.51M
  step[15] = output[15];
584
585
3.51M
  step[16] = output[16] + output[19];
586
3.51M
  step[17] = output[17] + output[18];
587
3.51M
  step[18] = -output[18] + output[17];
588
3.51M
  step[19] = -output[19] + output[16];
589
3.51M
  step[20] = -output[20] + output[23];
590
3.51M
  step[21] = -output[21] + output[22];
591
3.51M
  step[22] = output[22] + output[21];
592
3.51M
  step[23] = output[23] + output[20];
593
3.51M
  step[24] = output[24] + output[27];
594
3.51M
  step[25] = output[25] + output[26];
595
3.51M
  step[26] = -output[26] + output[25];
596
3.51M
  step[27] = -output[27] + output[24];
597
3.51M
  step[28] = -output[28] + output[31];
598
3.51M
  step[29] = -output[29] + output[30];
599
3.51M
  step[30] = output[30] + output[29];
600
3.51M
  step[31] = output[31] + output[28];
601
602
  // Stage 6
603
3.51M
  output[0] = step[0];
604
3.51M
  output[1] = step[1];
605
3.51M
  output[2] = step[2];
606
3.51M
  output[3] = step[3];
607
3.51M
  output[4] = dct_32_round(step[4] * cospi_28_64 + step[7] * cospi_4_64);
608
3.51M
  output[5] = dct_32_round(step[5] * cospi_12_64 + step[6] * cospi_20_64);
609
3.51M
  output[6] = dct_32_round(step[6] * cospi_12_64 + step[5] * -cospi_20_64);
610
3.51M
  output[7] = dct_32_round(step[7] * cospi_28_64 + step[4] * -cospi_4_64);
611
3.51M
  output[8] = step[8] + step[9];
612
3.51M
  output[9] = -step[9] + step[8];
613
3.51M
  output[10] = -step[10] + step[11];
614
3.51M
  output[11] = step[11] + step[10];
615
3.51M
  output[12] = step[12] + step[13];
616
3.51M
  output[13] = -step[13] + step[12];
617
3.51M
  output[14] = -step[14] + step[15];
618
3.51M
  output[15] = step[15] + step[14];
619
620
3.51M
  output[16] = step[16];
621
3.51M
  output[17] = dct_32_round(step[17] * -cospi_4_64 + step[30] * cospi_28_64);
622
3.51M
  output[18] = dct_32_round(step[18] * -cospi_28_64 + step[29] * -cospi_4_64);
623
3.51M
  output[19] = step[19];
624
3.51M
  output[20] = step[20];
625
3.51M
  output[21] = dct_32_round(step[21] * -cospi_20_64 + step[26] * cospi_12_64);
626
3.51M
  output[22] = dct_32_round(step[22] * -cospi_12_64 + step[25] * -cospi_20_64);
627
3.51M
  output[23] = step[23];
628
3.51M
  output[24] = step[24];
629
3.51M
  output[25] = dct_32_round(step[25] * cospi_12_64 + step[22] * -cospi_20_64);
630
3.51M
  output[26] = dct_32_round(step[26] * cospi_20_64 + step[21] * cospi_12_64);
631
3.51M
  output[27] = step[27];
632
3.51M
  output[28] = step[28];
633
3.51M
  output[29] = dct_32_round(step[29] * cospi_28_64 + step[18] * -cospi_4_64);
634
3.51M
  output[30] = dct_32_round(step[30] * cospi_4_64 + step[17] * cospi_28_64);
635
3.51M
  output[31] = step[31];
636
637
  // Stage 7
638
3.51M
  step[0] = output[0];
639
3.51M
  step[1] = output[1];
640
3.51M
  step[2] = output[2];
641
3.51M
  step[3] = output[3];
642
3.51M
  step[4] = output[4];
643
3.51M
  step[5] = output[5];
644
3.51M
  step[6] = output[6];
645
3.51M
  step[7] = output[7];
646
3.51M
  step[8] = dct_32_round(output[8] * cospi_30_64 + output[15] * cospi_2_64);
647
3.51M
  step[9] = dct_32_round(output[9] * cospi_14_64 + output[14] * cospi_18_64);
648
3.51M
  step[10] = dct_32_round(output[10] * cospi_22_64 + output[13] * cospi_10_64);
649
3.51M
  step[11] = dct_32_round(output[11] * cospi_6_64 + output[12] * cospi_26_64);
650
3.51M
  step[12] = dct_32_round(output[12] * cospi_6_64 + output[11] * -cospi_26_64);
651
3.51M
  step[13] = dct_32_round(output[13] * cospi_22_64 + output[10] * -cospi_10_64);
652
3.51M
  step[14] = dct_32_round(output[14] * cospi_14_64 + output[9] * -cospi_18_64);
653
3.51M
  step[15] = dct_32_round(output[15] * cospi_30_64 + output[8] * -cospi_2_64);
654
655
3.51M
  step[16] = output[16] + output[17];
656
3.51M
  step[17] = -output[17] + output[16];
657
3.51M
  step[18] = -output[18] + output[19];
658
3.51M
  step[19] = output[19] + output[18];
659
3.51M
  step[20] = output[20] + output[21];
660
3.51M
  step[21] = -output[21] + output[20];
661
3.51M
  step[22] = -output[22] + output[23];
662
3.51M
  step[23] = output[23] + output[22];
663
3.51M
  step[24] = output[24] + output[25];
664
3.51M
  step[25] = -output[25] + output[24];
665
3.51M
  step[26] = -output[26] + output[27];
666
3.51M
  step[27] = output[27] + output[26];
667
3.51M
  step[28] = output[28] + output[29];
668
3.51M
  step[29] = -output[29] + output[28];
669
3.51M
  step[30] = -output[30] + output[31];
670
3.51M
  step[31] = output[31] + output[30];
671
672
  // Final stage --- outputs indices are bit-reversed.
673
3.51M
  output[0] = step[0];
674
3.51M
  output[16] = step[1];
675
3.51M
  output[8] = step[2];
676
3.51M
  output[24] = step[3];
677
3.51M
  output[4] = step[4];
678
3.51M
  output[20] = step[5];
679
3.51M
  output[12] = step[6];
680
3.51M
  output[28] = step[7];
681
3.51M
  output[2] = step[8];
682
3.51M
  output[18] = step[9];
683
3.51M
  output[10] = step[10];
684
3.51M
  output[26] = step[11];
685
3.51M
  output[6] = step[12];
686
3.51M
  output[22] = step[13];
687
3.51M
  output[14] = step[14];
688
3.51M
  output[30] = step[15];
689
690
3.51M
  output[1] = dct_32_round(step[16] * cospi_31_64 + step[31] * cospi_1_64);
691
3.51M
  output[17] = dct_32_round(step[17] * cospi_15_64 + step[30] * cospi_17_64);
692
3.51M
  output[9] = dct_32_round(step[18] * cospi_23_64 + step[29] * cospi_9_64);
693
3.51M
  output[25] = dct_32_round(step[19] * cospi_7_64 + step[28] * cospi_25_64);
694
3.51M
  output[5] = dct_32_round(step[20] * cospi_27_64 + step[27] * cospi_5_64);
695
3.51M
  output[21] = dct_32_round(step[21] * cospi_11_64 + step[26] * cospi_21_64);
696
3.51M
  output[13] = dct_32_round(step[22] * cospi_19_64 + step[25] * cospi_13_64);
697
3.51M
  output[29] = dct_32_round(step[23] * cospi_3_64 + step[24] * cospi_29_64);
698
3.51M
  output[3] = dct_32_round(step[24] * cospi_3_64 + step[23] * -cospi_29_64);
699
3.51M
  output[19] = dct_32_round(step[25] * cospi_19_64 + step[22] * -cospi_13_64);
700
3.51M
  output[11] = dct_32_round(step[26] * cospi_11_64 + step[21] * -cospi_21_64);
701
3.51M
  output[27] = dct_32_round(step[27] * cospi_27_64 + step[20] * -cospi_5_64);
702
3.51M
  output[7] = dct_32_round(step[28] * cospi_7_64 + step[19] * -cospi_25_64);
703
3.51M
  output[23] = dct_32_round(step[29] * cospi_23_64 + step[18] * -cospi_9_64);
704
3.51M
  output[15] = dct_32_round(step[30] * cospi_15_64 + step[17] * -cospi_17_64);
705
3.51M
  output[31] = dct_32_round(step[31] * cospi_31_64 + step[16] * -cospi_1_64);
706
3.51M
}
707
708
942
void vpx_fdct32x32_c(const int16_t *input, tran_low_t *output, int stride) {
709
942
  int i, j;
710
942
  tran_high_t out[32 * 32];
711
712
  // Columns
713
31.0k
  for (i = 0; i < 32; ++i) {
714
30.1k
    tran_high_t temp_in[32], temp_out[32];
715
994k
    for (j = 0; j < 32; ++j) temp_in[j] = input[j * stride + i] * 4;
716
30.1k
    vpx_fdct32(temp_in, temp_out, 0);
717
994k
    for (j = 0; j < 32; ++j)
718
964k
      out[j * 32 + i] = (temp_out[j] + 1 + (temp_out[j] > 0)) >> 2;
719
30.1k
  }
720
721
  // Rows
722
31.0k
  for (i = 0; i < 32; ++i) {
723
30.1k
    tran_high_t temp_in[32], temp_out[32];
724
994k
    for (j = 0; j < 32; ++j) temp_in[j] = out[j + i * 32];
725
30.1k
    vpx_fdct32(temp_in, temp_out, 0);
726
994k
    for (j = 0; j < 32; ++j)
727
964k
      output[j + i * 32] =
728
964k
          (tran_low_t)((temp_out[j] + 1 + (temp_out[j] < 0)) >> 2);
729
30.1k
  }
730
942
}
731
732
// Note that although we use dct_32_round in dct32 computation flow,
733
// this 2d fdct32x32 for rate-distortion optimization loop is operating
734
// within 16 bits precision.
735
52.3k
void vpx_fdct32x32_rd_c(const int16_t *input, tran_low_t *output, int stride) {
736
52.3k
  int i, j;
737
52.3k
  tran_high_t out[32 * 32];
738
739
  // Columns
740
1.72M
  for (i = 0; i < 32; ++i) {
741
1.67M
    tran_high_t temp_in[32], temp_out[32];
742
55.2M
    for (j = 0; j < 32; ++j) temp_in[j] = input[j * stride + i] * 4;
743
1.67M
    vpx_fdct32(temp_in, temp_out, 0);
744
55.2M
    for (j = 0; j < 32; ++j)
745
      // TODO(cd): see quality impact of only doing
746
      //           output[j * 32 + i] = (temp_out[j] + 1) >> 2;
747
      //           PS: also change code in vpx_dsp/x86/vpx_dct_sse2.c
748
53.5M
      out[j * 32 + i] = (temp_out[j] + 1 + (temp_out[j] > 0)) >> 2;
749
1.67M
  }
750
751
  // Rows
752
1.72M
  for (i = 0; i < 32; ++i) {
753
1.67M
    tran_high_t temp_in[32], temp_out[32];
754
55.2M
    for (j = 0; j < 32; ++j) temp_in[j] = out[j + i * 32];
755
1.67M
    vpx_fdct32(temp_in, temp_out, 1);
756
55.2M
    for (j = 0; j < 32; ++j) output[j + i * 32] = (tran_low_t)temp_out[j];
757
1.67M
  }
758
52.3k
}
759
760
824
void vpx_fdct32x32_1_c(const int16_t *input, tran_low_t *output, int stride) {
761
824
  int r, c;
762
824
  int sum = 0;
763
27.1k
  for (r = 0; r < 32; ++r)
764
870k
    for (c = 0; c < 32; ++c) sum += input[r * stride + c];
765
766
824
  output[0] = (tran_low_t)(sum >> 3);
767
824
}
768
769
#if CONFIG_VP9_HIGHBITDEPTH
770
void vpx_highbd_fdct4x4_c(const int16_t *input, tran_low_t *output,
771
827k
                          int stride) {
772
827k
  vpx_fdct4x4_c(input, output, stride);
773
827k
}
774
775
void vpx_highbd_fdct8x8_c(const int16_t *input, tran_low_t *output,
776
268k
                          int stride) {
777
268k
  vpx_fdct8x8_c(input, output, stride);
778
268k
}
779
780
void vpx_highbd_fdct8x8_1_c(const int16_t *input, tran_low_t *output,
781
3.95k
                            int stride) {
782
3.95k
  vpx_fdct8x8_1_c(input, output, stride);
783
3.95k
}
784
785
void vpx_highbd_fdct16x16_c(const int16_t *input, tran_low_t *output,
786
66.9k
                            int stride) {
787
66.9k
  vpx_fdct16x16_c(input, output, stride);
788
66.9k
}
789
790
void vpx_highbd_fdct16x16_1_c(const int16_t *input, tran_low_t *output,
791
1.45k
                              int stride) {
792
1.45k
  vpx_fdct16x16_1_c(input, output, stride);
793
1.45k
}
794
795
void vpx_highbd_fdct32x32_c(const int16_t *input, tran_low_t *output,
796
942
                            int stride) {
797
942
  vpx_fdct32x32_c(input, output, stride);
798
942
}
799
800
void vpx_highbd_fdct32x32_rd_c(const int16_t *input, tran_low_t *output,
801
52.3k
                               int stride) {
802
52.3k
  vpx_fdct32x32_rd_c(input, output, stride);
803
52.3k
}
804
805
void vpx_highbd_fdct32x32_1_c(const int16_t *input, tran_low_t *output,
806
824
                              int stride) {
807
824
  vpx_fdct32x32_1_c(input, output, stride);
808
824
}
809
#endif  // CONFIG_VP9_HIGHBITDEPTH